rnd-19981017-1
[rocksndiamonds.git] / src / netserv.c
index e81d88168da69c4c3c00269ba7eb6b545f7df361..5b32ba044322f5d825f080b5c0bacb53f18f95d3 100644 (file)
 #include <netdb.h>
 
 #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 is_daemon = 0;
-static int level = 5;
+static int levelnr = 5;
 static int mode = -1;
 static int paused = 0;
 
@@ -81,22 +73,23 @@ static unsigned long frame_counter = 0;
 
 static fd_set fds;
 
-void syserr(char *s)
+static void syserr(char *s)
 {
   if (!is_daemon)
     fprintf(stderr, "fatal: %s failed.\n", s);
   exit(1);
 }
 
-void addtobuffer(struct user *u, unsigned char *b, int len)
+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;
 }
 
-void flushuser(struct user *u)
+static void flushuser(struct user *u)
 {
   if (u->nwrite)
   {
@@ -105,7 +98,7 @@ void flushuser(struct user *u)
   }
 }
 
-void broadcast(struct user *except, int len, int activeonly)
+static void broadcast(struct user *except, int len, int activeonly)
 {
   struct user *u;
 
@@ -116,18 +109,18 @@ void broadcast(struct user *except, int len, int activeonly)
       addtobuffer(u, realbuf, 4 + len);
 }
 
-void sendtoone(struct user *to, int len)
+static void sendtoone(struct user *to, int len)
 {
   realbuf[0] = realbuf[1] = realbuf[2] = 0;
   realbuf[3] = (unsigned char)len;
   addtobuffer(to, realbuf, 4 + len);
 }
 
-void dropuser(struct user *u)
+static void dropuser(struct user *u)
 {
   struct user *v, *w;
   
-  if (verbose)
+  if (options.verbose)
     printf("RND_SERVER: dropping client %d (%s)\n", u->number, u->nick);
 
   if (u == user0)
@@ -177,7 +170,7 @@ void dropuser(struct user *u)
 
   if (onceonly && clients == bots)
   {
-    if (verbose)
+    if (options.verbose)
     {
       printf("RND_SERVER: no clients left\n");
       printf("RND_SERVER: aborting\n");
@@ -188,15 +181,209 @@ void dropuser(struct user *u)
   if (clients == 0)
   {
     mode = -1;
-    level = 5;
+    levelnr = 5;
     timetoplay = 0;
   }
 }
 
-void do_play()
+static void new_connect(int fd)
+{
+  struct user *u, *v;
+  unsigned char nxn;
+
+  u = checked_malloc(sizeof (struct user));
+
+  u->fd = fd;
+  u->nick[0] = 0;
+  u->next = user0;
+  u->nextvictim = NULL;
+  u->active = 0;
+  u->nread = 0;
+  u->nwrite = 0;
+  u->playing = 0;
+  u->isbot = 0;
+  u->introduced = 0;
+  u->games = 0;
+  u->action = 0;
+  u->action_received = 0;
+
+  user0 = u;
+
+  nxn = 1;
+
+ again:
+  v = u->next;
+  while(v)
+  {
+    if (v->number == nxn)
+    {
+      nxn++;
+      goto again;
+    }
+    v = v->next;
+  }
+
+  u->number = nxn;
+  if (options.verbose)
+    printf("RND_SERVER: client %d connecting from %s\n", nxn, inet_ntoa(saddr.sin_addr));
+  clients++;
+
+  buf[0] = 0;
+  buf[1] = OP_YOUR_NUMBER;
+  buf[2] = u->number;
+  sendtoone(u, 3);
+}
+
+static void Handle_OP_PROTOCOL_VERSION(struct user *u, unsigned int len)
+{
+  if (len != 5 || buf[2] != PROT_VERS_1 || buf[3] != PROT_VERS_2)
+  {
+    if (options.verbose)
+      printf("RND_SERVER: client %d (%s) has wrong protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]);
+
+    buf[0] = 0;
+    buf[1] = OP_BADVERS;
+    buf[2] = PROT_VERS_1;
+    buf[3] = PROT_VERS_2;
+    buf[4] = PROT_VERS_3;
+    sendtoone(u, 5);
+    flushuser(u);
+
+    dropuser(u);
+    interrupt = 1;
+  }
+  else
+  {
+    if (options.verbose)
+      printf("RND_SERVER: client %d (%s) uses protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]);
+  }
+}
+
+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;
+
+  if (options.verbose)
+    printf("RND_SERVER: client %d (%s) wants to switch to # %d\n",
+          u->number, u->nick, nr_wanted);
+
+  for (v=user0; v; v=v->next)
+  {
+    if (v->number == nr_wanted)
+    {
+      nr_is_free = 0;
+      break;
+    }
+  }
+
+  if (options.verbose)
+  {
+    if (nr_is_free)
+      printf("RND_SERVER: client %d (%s) switches to # %d\n",
+            u->number, u->nick, nr_wanted);
+    else if (u->number == nr_wanted)
+      printf("RND_SERVER: client %d (%s) still has # %d\n",
+            u->number, u->nick, nr_wanted);
+    else
+      printf("RND_SERVER: client %d (%s) cannot switch (client %d still exists)\n",
+            u->number, u->nick, nr_wanted);
+  }
+
+  if (nr_is_free)
+    u->number = nr_wanted;
+
+  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)
+{
+  struct user *v;
+  int i;
+
+  if (len>16)
+    len=16;
+  memcpy(u->nick, &buf[2], len-2);
+  u->nick[len-2] = 0;
+  for (i=0; i<len-2; i++)
+  {
+    if (u->nick[i] < ' ' || 
+       (u->nick[i] > 0x7e && u->nick[i] <= 0xa0))
+    {
+      u->nick[i] = 0;
+      break;
+    }
+  }
+
+  if (!u->introduced)
+  {
+    buf[0] = u->number;
+    buf[1] = OP_PLAYER_CONNECTED;
+    broadcast(u, 2, 0);
+  }
+             
+  if (options.verbose)
+    printf("RND_SERVER: client %d calls itself \"%s\"\n", u->number, u->nick);
+  buf[1] = OP_NICKNAME;
+  broadcast(u, len, 0);
+
+  if (!u->introduced)
+  {
+    for (v=user0; v; v=v->next)
+    {
+      if (v != u && v->introduced)
+      {
+       buf[0] = v->number;
+       buf[1] = OP_PLAYER_CONNECTED;
+       buf[2] = (v->games >> 8);
+       buf[3] = (v->games & 0xff);
+       sendtoone(u, 4);
+       buf[1] = OP_NICKNAME;
+       memcpy(&buf[2], v->nick, 14);
+       sendtoone(u, 2+strlen(v->nick));
+      }
+    }
+    if (levelnr != 5)
+    {
+      buf[0] = 0;
+      buf[1] = OP_LEVEL;
+      buf[2] = levelnr;
+      sendtoone(u, 3);
+    }
+    if (mode >= 0)
+    {
+      buf[1] = OP_MODE;
+      buf[2] = mode;
+      sendtoone(u, 3);
+    }
+  }
+
+  u->introduced = 1;
+}
+
+static void Handle_OP_START_PLAYING(struct user *u)
 {
   struct user *v, *w;
 
+  if (options.verbose)
+    printf("RND_SERVER: client %d (%s) starts game [level %d from levedir %d (%s)]\n",
+          u->number, u->nick,
+          (buf[2] << 8) + buf[3],
+          (buf[4] << 8) + buf[5],
+          &buf[6]);
+  timetoplay = 0;
+
   for (w=user0; w; w=w->next)
   {
     if (w->introduced)
@@ -238,59 +425,87 @@ void do_play()
   }
 
   broadcast(NULL, 10 + strlen(&buf[10])+1, 0);
-
 }
 
-void new_connect(int fd)
+static void Handle_OP_PAUSE_PLAYING(struct user *u)
 {
-  struct user *u, *v;
-  unsigned char nxn;
+  if (options.verbose)
+    printf("RND_SERVER: client %d (%s) pauses game\n", u->number, u->nick);
+  broadcast(NULL, 2, 0);
+  paused = 1;
+}
 
-  u = malloc(sizeof (struct user));
-  if (!u)
-    fatal("Out of memory");
-  u->fd = fd;
-  u->nick[0] = 0;
-  u->next = user0;
-  u->nextvictim = NULL;
-  u->active = 0;
-  u->nread = 0;
-  u->nwrite = 0;
-  u->playing = 0;
-  u->isbot = 0;
-  u->introduced = 0;
-  u->games = 0;
-  u->action = 0;
-  u->action_received = 0;
+static void Handle_OP_CONTINUE_PLAYING(struct user *u)
+{
+  if (options.verbose)
+    printf("RND_SERVER: client %d (%s) continues game\n", u->number, u->nick);
+  broadcast(NULL, 2, 0);
+  paused = 0;
+}
 
-  user0 = u;
+static void Handle_OP_STOP_PLAYING(struct user *u)
+{
+  if (options.verbose)
+    printf("RND_SERVER: client %d (%s) stops game\n", u->number, u->nick);
+  broadcast(NULL, 2, 0);
+}
 
-  nxn = 1;
+static void Handle_OP_MOVE_FIGURE(struct user *u)
+{
+  struct user *v;
+  int last_client_nr = 0;
+  int i;
 
-again:
-  v = u->next;
-  while(v)
+  /* store player action */
+  for (v=user0; v; v=v->next)
   {
-    if (v->number == nxn)
+    if (v->number == u->number)
     {
-      nxn++;
-      goto again;
+      v->action = buf[2];
+      v->action_received = 1;
     }
-    v = v->next;
   }
 
-  u->number = nxn;
-  if (verbose)
-    printf("RND_SERVER: client %d connecting from %s\n", nxn, inet_ntoa(saddr.sin_addr));
-  clients++;
+  /* check if server received action from each player */
+  for (v=user0; v; v=v->next)
+  {
+    if (!v->action_received)
+      return;
 
-  buf[0] = 0;
-  buf[1] = OP_YOUR_NUMBER;
-  buf[2] = u->number;
-  sendtoone(u, 3);
+    if (v->number > last_client_nr)
+      last_client_nr = v->number;
+  }
+
+  /* initialize all player actions to zero */
+  for (i=0; i<last_client_nr; i++)
+    buf[6 + i] = 0;
+
+  /* broadcast actions of all players to all players */
+  for (v=user0; v; v=v->next)
+  {
+    buf[6 + v->number-1] = v->action;
+    v->action = 0;
+    v->action_received = 0;
+  }
+
+  buf[2] = (unsigned char)((frame_counter >> 24) & 0xff);
+  buf[3] = (unsigned char)((frame_counter >> 16) & 0xff);
+  buf[4] = (unsigned char)((frame_counter >>  8) & 0xff);
+  buf[5] = (unsigned char)((frame_counter >>  0) & 0xff);
+
+  broadcast(NULL, 6 + last_client_nr, 0);
+
+  frame_counter++;
+
+  /*
+    if (verbose)
+    printf("RND_SERVER: frame %d: client %d (%s) moves player [0x%02x]\n",
+    frame_counter,
+    u->number, u->nick, buf[2]);
+  */
 }
 
-void NetworkServer(int port, int onceonly)
+void NetworkServer(int port, int serveronly)
 {
   int i, sl, on;
   struct user *u, *v, *w;
@@ -308,6 +523,9 @@ void NetworkServer(int port, int onceonly)
   if (port == 0)
     port = DEFAULTPORT;
 
+  if (!serveronly)
+    onceonly = 1;
+
   if ((tcpproto = getprotobyname("tcp")) != NULL)
     tcp = tcpproto->p_proto;
 
@@ -339,25 +557,27 @@ void NetworkServer(int port, int onceonly)
   if (is_daemon)
   {
     /* become a daemon, breaking all ties with the controlling terminal */
-    verbose = 0;
+    options.verbose = 0;
     for (i=0; i<255; i++)
     {
       if (i != lfd)
        close(i);
     }
+
     if (fork())
       exit(0);
     setsid();
     if (fork())
       exit(0);
     chdir("/");
+
     /* open a fake stdin, stdout, stderr, just in case */
     open("/dev/null", O_RDONLY);
     open("/dev/null", O_WRONLY);
     open("/dev/null", O_WRONLY);
   }
 
-  if (verbose)
+  if (options.verbose)
   {
     printf("rocksndiamonds network server: started up, listening on port %d\n",
           port);
@@ -369,14 +589,16 @@ void NetworkServer(int port, int onceonly)
   {
     interrupt = 0;
 
+    /*
     if (timetoplay && time(NULL) >= timetoplay)
     {
       buf[0] = 0;
       do_play();
-      if (verbose)
+      if (options.verbose)
        printf("RND_SERVER: everyone lost... restarting game\n");
       timetoplay = 0;
     }
+    */
 
     for (u=user0; u; u=u->next)
       flushuser(u);
@@ -404,7 +626,7 @@ void NetworkServer(int port, int onceonly)
 
     if (clients > 0 && clients == bots)
     {
-      if (verbose)
+      if (options.verbose)
        printf("RND_SERVER: only bots left... dropping all bots\n");
       while (user0)
        dropuser(user0);
@@ -446,7 +668,7 @@ void NetworkServer(int port, int onceonly)
        r = read(u->fd, u->readbuf + u->nread, MAX_BUFFER_SIZE - u->nread);
        if (r <= 0)
        {
-         if (verbose)
+         if (options.verbose)
            printf("RND_SERVER: EOF from client %d (%s)\n", u->number, u->nick);
          dropuser(u);
          interrupt = 1;
@@ -458,7 +680,7 @@ void NetworkServer(int port, int onceonly)
          len = u->readbuf[3];
          if (u->readbuf[0] || u->readbuf[1] || u->readbuf[2])
          {
-           if (verbose)
+           if (options.verbose)
              printf("RND_SERVER: crap from client %d (%s)\n", u->number, u->nick);
            write(u->fd, "\033]50;kanji24\007\033#8\033(0", 19);
            dropuser(u);
@@ -467,12 +689,12 @@ void NetworkServer(int port, int onceonly)
          }
          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)
          {
-           if (verbose)
+           if (options.verbose)
              printf("RND_SERVER: !(client %d)->introduced && buf[1]==%d (expected OP_NICKNAME)\n", buf[0], buf[1]);
 
            dropuser(u);
@@ -483,64 +705,35 @@ void NetworkServer(int port, int onceonly)
          switch(buf[1])
          {
            case OP_NICKNAME:
-             if (len>16)
-               len=16;
-             memcpy(u->nick, &buf[2], len-2);
-             u->nick[len-2] = 0;
-             for (i=0; i<len-2; i++)
-             {
-               if (u->nick[i] < ' ' || 
-                   (u->nick[i] > 0x7e && u->nick[i] <= 0xa0))
-               {
-                 u->nick[i] = 0;
-                 break;
-               }
-             }
+             Handle_OP_NICKNAME(u, len);
+             break;
 
-             if (!u->introduced)
-             {
-               buf[0] = u->number;
-               buf[1] = OP_PLAYER_CONNECTED;
-               broadcast(u, 2, 0);
-             }
-             
-             if (verbose)
-               printf("RND_SERVER: client %d calls itself \"%s\"\n", u->number, u->nick);
-             buf[1] = OP_NICKNAME;
-             broadcast(u, len, 0);
+           case OP_PROTOCOL_VERSION:
+             Handle_OP_PROTOCOL_VERSION(u, len);
+             break;
 
-             if (!u->introduced)
-             {
-               for (v=user0; v; v=v->next)
-               {
-                 if (v != u && v->introduced)
-                 {
-                   buf[0] = v->number;
-                   buf[1] = OP_PLAYER_CONNECTED;
-                   buf[2] = (v->games >> 8);
-                   buf[3] = (v->games & 0xff);
-                   sendtoone(u, 4);
-                   buf[1] = OP_NICKNAME;
-                   memcpy(&buf[2], v->nick, 14);
-                   sendtoone(u, 2+strlen(v->nick));
-                 }
-               }
-               if (level != 5)
-               {
-                 buf[0] = 0;
-                 buf[1] = OP_LEVEL;
-                 buf[2] = level;
-                 sendtoone(u, 3);
-               }
-               if (mode >= 0)
-               {
-                 buf[1] = OP_MODE;
-                 buf[2] = mode;
-                 sendtoone(u, 3);
-               }
-             }
+           case OP_NUMBER_WANTED:
+             Handle_OP_NUMBER_WANTED(u);
+             break;
+
+           case OP_START_PLAYING:
+             Handle_OP_START_PLAYING(u);
+             break;
+
+           case OP_PAUSE_PLAYING:
+             Handle_OP_PAUSE_PLAYING(u);
+             break;
+
+           case OP_CONTINUE_PLAYING:
+             Handle_OP_CONTINUE_PLAYING(u);
+             break;
+
+           case OP_STOP_PLAYING:
+             Handle_OP_STOP_PLAYING(u);
+             break;
 
-             u->introduced = 1;
+           case OP_MOVE_FIGURE:
+             Handle_OP_MOVE_FIGURE(u);
              break;
 
            case OP_KILL:
@@ -553,7 +746,7 @@ void NetworkServer(int port, int onceonly)
              {
                if (v->isbot)
                {
-                 if (verbose)
+                 if (options.verbose)
                    printf("RND_SERVER: client %d (%s) kills bot %d (%s)\n", u->number, u->nick, v->number, v->nick);
 
                  dropuser(v);
@@ -562,113 +755,30 @@ void NetworkServer(int port, int onceonly)
                }
                else
                {
-                 if (verbose)
+                 if (options.verbose)
                    printf("RND_SERVER: client %d (%s) attempting to kill non-bot %d (%s)\n", u->number, u->nick, v->number, v->nick);
                }
              }
              break;
 
-           case OP_START_PLAYING:
-             if (verbose)
-               printf("RND_SERVER: client %d (%s) starts game [level %d from levedir %d (%s)]\n",
-                      u->number, u->nick,
-                      (buf[2] << 8) + buf[3],
-                      (buf[4] << 8) + buf[5],
-                      &buf[6]);
-             timetoplay = 0;
-             do_play();
-             break;
-
-           case OP_MOVE_FIGURE:
-           {
-             int actions_complete = 1;
-             int last_client_nr = 0;
-
-             /* store player action */
-             for (v=user0; v; v=v->next)
-             {
-               if (v->number == u->number)
-               {
-                 v->action = buf[2];
-                 v->action_received = 1;
-               }
-             }
-
-             /* check if server received action from each player */
-             for (v=user0; v; v=v->next)
-             {
-               if (!v->action_received)
-               {
-                 actions_complete = 0;
-                 break;
-               }
-             }
-
-             if (!actions_complete)
-               break;
-
-             /* broadcast actions of all players to all players */
-             for (v=user0; v; v=v->next)
-             {
-               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);
-             buf[3] = (unsigned char)((frame_counter >> 16) & 0xff);
-             buf[4] = (unsigned char)((frame_counter >>  8) & 0xff);
-             buf[5] = (unsigned char)((frame_counter >>  0) & 0xff);
-
-             broadcast(NULL, 6 + last_client_nr, 0);
-
-             frame_counter++;
-
-             /*
-             if (verbose)
-               printf("RND_SERVER: frame %d: client %d (%s) moves player [0x%02x]\n",
-                      frame_counter,
-                      u->number, u->nick, buf[2]);
-             */
-
-             break;
-           }
-           
            case OP_MODE:
              mode = buf[2];
-             if (verbose)
+             if (options.verbose)
                printf("RND_SERVER: client %d (%s) sets mode %d (%s)\n", u->number, u->nick, buf[2], buf[2] == 0 ? "normal" : (buf[2] == 1 ? "fun" : "unknown"));
              broadcast(NULL, 3, 0);
              break;
 
-           case OP_PAUSE:
-             if (verbose)
-               printf("RND_SERVER: client %d (%s) pauses game\n", u->number, u->nick);
-             broadcast(NULL, 2, 0);
-             paused = 1;
-             break;
-
-           case OP_CONT:
-             if (verbose)
-               printf("RND_SERVER: client %d (%s) continues game\n", u->number, u->nick);
-             broadcast(NULL, 2, 0);
-             paused = 0;
-             break;
-
            case OP_BOT:
              if (!u->isbot)
                bots++;
              u->isbot = 1;
-             if (verbose)
+             if (options.verbose)
                printf("RND_SERVER: client %d (%s) declares itself to be a bot\n", u->number, u->nick);
              break;
            
            case OP_LEVEL:
-             level = buf[2];
-             if (verbose)
+             levelnr = buf[2];
+             if (options.verbose)
                printf("RND_SERVER: client %d (%s) sets level %d\n", u->number, u->nick, buf[2]);
              broadcast(NULL, 3, 0);
              break;
@@ -677,7 +787,7 @@ void NetworkServer(int port, int onceonly)
              {
                struct user *won = NULL;
 
-               if (verbose)
+               if (options.verbose)
                  printf("RND_SERVER: client %d (%s) has lost\n", u->number, u->nick);
                u->playing = 0;
                broadcast(u, 2, 1);
@@ -727,7 +837,7 @@ void NetworkServer(int port, int onceonly)
            
            case OP_ZERO:
              broadcast(NULL, 2, 0);
-             if (verbose)
+             if (options.verbose)
                printf("RND_SERVER: client %d (%s) resets the game counters\n", u->number, u->nick);
              for (v=user0; v; v=v->next)
                v->games = 0;
@@ -740,81 +850,15 @@ void NetworkServer(int port, int onceonly)
 
            case OP_MSG:
              buf[len] = '\0';
-             if (verbose)
+             if (options.verbose)
                printf("RND_SERVER: client %d (%s) sends message: %s\n", u->number, u->nick, &buf[2]);
              broadcast(u, len, 0);
              break;
 
-           case OP_NUMBER_WANTED:
-           {
-             int nr_wanted = buf[2];
-             int nr_is_free = 1;
-
-             if (verbose)
-               printf("RND_SERVER: client %d (%s) wants to switch to # %d\n",
-                      u->number, u->nick, nr_wanted);
-
-             for (v=user0; v; v=v->next)
-             {
-               if (v->number == nr_wanted)
-               {
-                 nr_is_free = 0;
-                 break;
-               }
-             }
-
-             if (verbose)
-             {
-               if (nr_is_free)
-                 printf("RND_SERVER: client %d (%s) switches to # %d\n",
-                        u->number, u->nick, nr_wanted);
-               else if (u->number == nr_wanted)
-                 printf("RND_SERVER: client %d (%s) still has # %d\n",
-                        u->number, u->nick, nr_wanted);
-               else
-                 printf("RND_SERVER: client %d (%s) cannot switch (client %d still exists)\n",
-                        u->number, u->nick, nr_wanted);
-             }
-
-             if (nr_is_free)
-               u->number = nr_wanted;
-
-             buf[0] = 0;
-             buf[1] = OP_NUMBER_WANTED;
-             buf[2] = nr_wanted;
-             buf[3] = u->number;
-             sendtoone(u, 4);
-             break;
-           }
-
-           case OP_PROTOCOL_VERSION:
-             if (len != 5 || buf[2] != PROT_VERS_1 || buf[3] != PROT_VERS_2)
-             {
-               if (verbose)
-                 printf("RND_SERVER: client %d (%s) has wrong protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]);
-
-               buf[0] = 0;
-               buf[1] = OP_BADVERS;
-               buf[2] = PROT_VERS_1;
-               buf[3] = PROT_VERS_2;
-               buf[4] = PROT_VERS_3;
-               sendtoone(u, 5);
-               flushuser(u);
-
-               dropuser(u);
-               interrupt = 1;
-             }
-             else
-             {
-               if (verbose)
-                 printf("RND_SERVER: client %d (%s) uses protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]);
-             }
-             break;
-
            case OP_LINES:
              if (len != 3)
              {
-               if (verbose)
+               if (options.verbose)
                  printf("RND_SERVER: client %d (%s) sends crap for an OP_LINES\n", u->number, u->nick);
 
                dropuser(u);
@@ -823,7 +867,7 @@ void NetworkServer(int port, int onceonly)
              }
              if (u->nextvictim)
              {
-               if (verbose)
+               if (options.verbose)
                  printf("RND_SERVER: client %d (%s) sends %d %s to client %d (%s)\n", u->number, u->nick, (int)buf[2], buf[2] == 1 ? "line" : "lines", u->nextvictim->number, u->nextvictim->nick);
                sendtoone(u->nextvictim, 3);
                buf[3] = u->nextvictim->number;
@@ -838,12 +882,12 @@ void NetworkServer(int port, int onceonly)
                  }
                }
              }
-             else if (verbose)
+             else if (options.verbose)
                printf("RND_SERVER: client %d (%s) makes %d %s but has no victim\n", u->number, u->nick, (int)buf[2], buf[2] == 1 ? "line" : "lines");
              break;
            
            default:
-             if (verbose)
+             if (options.verbose)
                printf("RND_SERVER: opcode %d from client %d (%s) not understood\n", buf[0], u->number, u->nick);
          }
        }