- len = readbuf[3];
- if (readbuf[0] || readbuf[1] || readbuf[2])
- fatal("Wrong server line length");
-
- memcpy(buf, &readbuf[4], len);
- nread -= 4 + len;
- copydown(readbuf, readbuf + 4 + len, nread);
-
- switch(buf[1])
- {
- case OP_YOUARE:
- printf("OP_YOUARE: %d\n", buf[0]);
- break;
-
- case OP_NEW:
- printf("OP_NEW: %d\n", buf[0]);
- sprintf(msgbuf, "new client %d connected", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_GONE:
- printf("OP_GONE: %d\n", buf[0]);
- sprintf(msgbuf, "client %d disconnected", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_BADVERS:
- {
- static char tmpbuf[128];
-
- sprintf(tmpbuf, "Protocol version mismatch: server expects %d.%d.x instead of %d.%d.%d\n", buf[2], buf[3], PROT_VERS_1, PROT_VERS_2, PROT_VERS_3);
- fatal(tmpbuf);
- }
- break;
-
- case OP_PLAY:
- printf("OP_PLAY: %d\n", buf[0]);
- sprintf(msgbuf, "client %d starts game", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_PAUSE:
- printf("OP_PAUSE: %d\n", buf[0]);
- sprintf(msgbuf, "client %d pauses game", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_CONT:
- printf("OP_CONT: %d\n", buf[0]);
- sprintf(msgbuf, "client %d continues game", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_WON:
- printf("OP_WON: %d\n", buf[0]);
- sprintf(msgbuf, "client %d wins the game", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_ZERO:
- printf("OP_ZERO: %d\n", buf[0]);
- sprintf(msgbuf, "client %d resets game counters", buf[0]);
- sysmsg(msgbuf);
- break;
-
- case OP_NICK:
- printf("OP_NICK: %d\n", buf[0]);
- sprintf(msgbuf, "client %d calls itself %s", buf[0], &buf[2]);
- sysmsg(msgbuf);
- break;
-
- case OP_MSG:
- printf("OP_MSG: %d\n", buf[0]);
- sprintf(msgbuf, "client %d sends message", buf[0]);
- break;
-
- case OP_LOST:
- printf("OP_MSG: %d\n", buf[0]);
- sprintf(msgbuf, "client %d has lost", buf[0]);
- break;
-
- case OP_LEVEL:
- printf("OP_MSG: %d\n", buf[0]);
- sprintf(msgbuf, "client %d sets level to %d", buf[0], buf[2]);
- break;
- }
- }
-
- fflush(stdout);
-}
-
-
-
-static void HandleNetworking()
-{
- static struct timeval tv = { 0, 0 };
- fd_set rfds;
- int r = 0;
-
- if (standalone)