fixed renameAccount function (merging mode)
[NeonServV5.git] / src / ClientSocket.c
index cca4bcd7e2890727fef168b13dfa8b84ab393668..eb11d88fc131558ff1bb698f883c37bd91144188 100644 (file)
@@ -14,7 +14,7 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
-
+#include "main.h"
 #include "ClientSocket.h"
 #include "IRCParser.h"
 #include "UserNode.h"
@@ -24,6 +24,7 @@
 #include "ConfigParser.h"
 #include "version.h"
 #include "IOHandler.h"
+#include "IRCEvents.h"
 
 struct socket_list {
     struct ClientSocket *data;
@@ -221,13 +222,15 @@ static IOHANDLER_CALLBACK(socket_callback) {
     #ifdef HAVE_THREADS
     unsigned int tid;
     #endif
+    if(process_state.running == 0)
+        return; //just ignore the event (shutdown sequence)
     switch(event->type) {
     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:
@@ -284,13 +287,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;
 }