X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fnetserv.c;h=bafb1fe8c1599508e894ceb3b2db275bd2660031;hb=62573489ded016c3436c4e9eb99f1974ee296e4f;hp=221c8ff9df0d388d633a9d81696356fa519e4cd8;hpb=3d236f777bca55fef0f6b23122b6affd0f424249;p=rocksndiamonds.git diff --git a/src/netserv.c b/src/netserv.c index 221c8ff9..bafb1fe8 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -27,22 +27,14 @@ #include #include "netserv.h" - - - -extern int verbose; - -extern void copydown(char *, char *, int); -extern void fatal(char *); - - +#include "misc.h" static int clients = 0; static int bots = 0; static int onceonly = 0; static int timetoplay = 0; -static int daemon = 0; -static int level = 5; +static int is_daemon = 0; +static int levelnr = 5; static int mode = -1; static int paused = 0; @@ -83,7 +75,7 @@ static fd_set fds; static void syserr(char *s) { - if (!daemon) + if (!is_daemon) fprintf(stderr, "fatal: %s failed.\n", s); exit(1); } @@ -91,7 +83,8 @@ static void syserr(char *s) static void addtobuffer(struct user *u, unsigned char *b, int len) { if (u->nwrite + len >= MAX_BUFFER_SIZE) - fatal("Internal error: send buffer overflow"); + Error(ERR_EXIT, "internal error: network send buffer overflow"); + memcpy(u->writbuf + u->nwrite, b, len); u->nwrite += len; } @@ -188,7 +181,7 @@ static void dropuser(struct user *u) if (clients == 0) { mode = -1; - level = 5; + levelnr = 5; timetoplay = 0; } } @@ -198,9 +191,8 @@ static void new_connect(int fd) struct user *u, *v; unsigned char nxn; - u = malloc(sizeof (struct user)); - if (!u) - fatal("Out of memory"); + u = checked_malloc(sizeof (struct user)); + u->fd = fd; u->nick[0] = 0; u->next = user0; @@ -270,6 +262,7 @@ static void Handle_OP_PROTOCOL_VERSION(struct user *u, unsigned int len) static void Handle_OP_NUMBER_WANTED(struct user *u) { struct user *v; + int client_nr = u->number; int nr_wanted = buf[2]; int nr_is_free = 1; @@ -302,11 +295,16 @@ static void Handle_OP_NUMBER_WANTED(struct user *u) if (nr_is_free) u->number = nr_wanted; - buf[0] = 0; + buf[0] = client_nr; buf[1] = OP_NUMBER_WANTED; buf[2] = nr_wanted; buf[3] = u->number; + + /* sendtoone(u, 4); + */ + + broadcast(NULL, 4, 0); } static void Handle_OP_NICKNAME(struct user *u, unsigned int len) @@ -356,11 +354,11 @@ static void Handle_OP_NICKNAME(struct user *u, unsigned int len) sendtoone(u, 2+strlen(v->nick)); } } - if (level != 5) + if (levelnr != 5) { buf[0] = 0; buf[1] = OP_LEVEL; - buf[2] = level; + buf[2] = levelnr; sendtoone(u, 3); } if (mode >= 0) @@ -455,8 +453,8 @@ static void Handle_OP_STOP_PLAYING(struct user *u) static void Handle_OP_MOVE_FIGURE(struct user *u) { struct user *v; - int actions_complete = 1; int last_client_nr = 0; + int i; /* store player action */ for (v=user0; v; v=v->next) @@ -472,14 +470,15 @@ static void Handle_OP_MOVE_FIGURE(struct user *u) for (v=user0; v; v=v->next) { if (!v->action_received) - { - actions_complete = 0; - break; - } + return; + + if (v->number > last_client_nr) + last_client_nr = v->number; } - if (!actions_complete) - return; + /* initialize all player actions to zero */ + for (i=0; inext) @@ -487,9 +486,6 @@ static void Handle_OP_MOVE_FIGURE(struct user *u) buf[6 + v->number-1] = v->action; v->action = 0; v->action_received = 0; - - if (v->number > last_client_nr) - last_client_nr = v->number; } buf[2] = (unsigned char)((frame_counter >> 24) & 0xff); @@ -518,7 +514,7 @@ void NetworkServer(int port, int serveronly) unsigned int len; struct protoent *tcpproto; struct timeval tv; - int daemon = 0; + int is_daemon = 0; #ifndef NeXT struct sigaction sact; @@ -558,7 +554,7 @@ void NetworkServer(int port, int serveronly) listen(lfd, 5); - if (daemon) + if (is_daemon) { /* become a daemon, breaking all ties with the controlling terminal */ verbose = 0; @@ -693,7 +689,7 @@ void NetworkServer(int port, int serveronly) } memcpy(buf, &u->readbuf[4], len); u->nread -= 4 + len; - copydown(u->readbuf, u->readbuf + 4 + len, u->nread); + memmove(u->readbuf, u->readbuf + 4 + len, u->nread); buf[0] = u->number; if (!u->introduced && buf[1] != OP_NICKNAME) @@ -781,7 +777,7 @@ void NetworkServer(int port, int serveronly) break; case OP_LEVEL: - level = buf[2]; + levelnr = buf[2]; if (verbose) printf("RND_SERVER: client %d (%s) sets level %d\n", u->number, u->nick, buf[2]); broadcast(NULL, 3, 0);