Don't count detached users in server local user count.
[silc.git] / apps / silcd / packet_receive.c
index 06e5bcd9161431a807f2b264523c292a9198875a..5a49ca314e2cc1bd7fdd2eb7091a417955f26211 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "serverincludes.h"
 #include "server_internal.h"
-#include <assert.h>
 
 /* Received notify packet. Server can receive notify packets from router.
    Server then relays the notify messages to clients if needed. */
@@ -327,7 +326,7 @@ static void silc_server_notify_process(SilcServer server,
       tmp_len = 128;
 
     /* Update statistics */
-       assert(server->stat.clients > 0);
+    SILC_VERIFY(server->stat.clients > 0);
     server->stat.clients--;
     if (server->stat.cell_clients)
       server->stat.cell_clients--;
@@ -1247,7 +1246,7 @@ static void silc_server_notify_process(SilcServer server,
            }
 
            /* Update statistics */
-               assert(server->stat.clients > 0);
+           SILC_VERIFY(server->stat.clients > 0);
            server->stat.clients--;
            if (server->stat.cell_clients)
              server->stat.cell_clients--;
@@ -1493,7 +1492,7 @@ static void silc_server_notify_process(SilcServer server,
       }
 
       /* Update statistics */
-         assert(server->stat.clients > 0);
+      SILC_VERIFY(server->stat.clients > 0);
       server->stat.clients--;
       if (server->stat.cell_clients)
        server->stat.cell_clients--;
@@ -3735,9 +3734,13 @@ void silc_server_resume_client(SilcServer server,
       silc_server_check_watcher_list(server, detached_client, NULL,
                                     SILC_NOTIFY_TYPE_UMODE_CHANGE);
 
-    /* Delete this current client entry since we're resuming to old one. */
-    server->stat.my_clients--;
-       assert(server->stat.clients > 0);
+    /* Delete this current client entry since we're resuming to old one.
+       We decrement clients/cell_clients as we are getting rid of the
+       current client and replacing it with the detached one.  We keep the
+       server user count as-is (incremented by the current client entry) as
+       we decremented the count already during detach, thus we'd be undoing
+       that operation. */
+    SILC_VERIFY(server->stat.clients > 0);
     server->stat.clients--;
     if (server->stat.cell_clients)
       server->stat.cell_clients--;