fixed small startup crash in main.c
[NeonServV5.git] / src / ClientSocket.c
index eaf43d46991b213ebc1021de875f21bfa74e53c1..7160014d36c18b089720ddf1e05f74743f4f9724 100644 (file)
@@ -226,9 +226,9 @@ static IOHANDLER_CALLBACK(socket_callback) {
     case IOEVENT_CONNECTED:
         client->flags |= SOCKET_FLAG_CONNECTED;
         if(client->pass && strcmp(client->pass, ""))
-            iohandler_printf(event->iofd, "PASS :%s", client->pass);
-        iohandler_printf(event->iofd, "USER %s 0 0 :%s", client->ident, client->realname);
-        iohandler_printf(event->iofd, "NICK %s", client->nick);
+            putsock(client, "PASS :%s", client->pass);
+        putsock(client, "USER %s 0 0 :%s", client->ident, client->realname);
+        putsock(client, "NICK %s", client->nick);
         break;
     case IOEVENT_NOTCONNECTED:
     case IOEVENT_CLOSED:
@@ -285,13 +285,19 @@ struct ClientSocket* getBots(int flags, struct ClientSocket* last_bot) {
     return NULL;
 }
 
-void free_sockets() {
+void free_sockets(int close_only) {
     if(!sockets) return;
     struct ClientSocket *client, *next;
     for (client = sockets->data; client; client = next) {
         next = client->next;
-        destroy_socket(client);
+        if(close_only) {
+            if((client->flags & SOCKET_FLAG_CONNECTED))
+                iohandler_printf(client->iofd, "QUIT :[NeonServ %s.%d] shutdown requested.\n", NEONSERV_VERSION, patchlevel);
+        } else
+            destroy_socket(client);
+    }
+    if(!close_only) {
+        free(sockets);
+        sockets = NULL;
     }
-    free(sockets);
-    sockets = NULL;
 }