Don't count detached users in server local user count.
[silc.git] / apps / silcd / command.c
index f35969ecf8968c3377595a04bd8fe7b84e63c50e..698b22657ac1c719dbfc455c7ae8e6a45ffb6a7f 100644 (file)
@@ -1472,12 +1472,19 @@ SILC_SERVER_CMD_FUNC(kill)
 
     /* Do normal signoff for the destination client */
     sock = remote_client->connection;
+
+    if (sock)
+      silc_packet_stream_ref(sock);
+
     silc_server_remove_from_channels(server, NULL, remote_client,
                                     TRUE, (char *)"Killed", TRUE, TRUE);
     silc_server_free_sock_user_data(server, sock, comment ? comment :
                                    (unsigned char *)"Killed");
-    if (sock)
+    if (sock) {
+      silc_packet_set_context(sock, NULL);
       silc_server_close_connection(server, sock);
+      silc_packet_stream_unref(sock);
+    }
   } else {
     /* Router operator killing */
 
@@ -4071,6 +4078,13 @@ SILC_TASK_CALLBACK(silc_server_command_detach_cb)
     client->router = NULL;
     client->connection = NULL;
     silc_server_close_connection(server, sock);
+
+    /*
+     * Decrement the user count; we'll increment it if the user resumes on our
+     * server.
+     */
+    SILC_VERIFY(&server->stat.my_clients > 0);
+    server->stat.my_clients--;
   }
 
   silc_free(client_id);