completely rebuild WHOHander ticket management
[NeonServV5.git] / src / ClientSocket.c
index cda3ee76adeb93b82501db4b305fc05322ef7aa1..5e790dac4e3b2de07d61dc3f15057f6d6fe7ea5e 100644 (file)
@@ -1,4 +1,4 @@
-/* ClientSocket.c - NeonServ v5.1
+/* ClientSocket.c - NeonServ v5.2
  * Copyright (C) 2011  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -19,6 +19,7 @@
 #include "IRCParser.h"
 #include "UserNode.h"
 #include "IRCQueue.h"
+#include "WHOHandler.h"
 
 struct socket_list {
     struct ClientSocket *data;
@@ -61,6 +62,8 @@ struct ClientSocket* create_socket(char *host, int port, char *pass, struct User
        client->botid = 0;
     client->clientid = 0;
     client->queue = NULL;
+    client->whoqueue_first = NULL;
+    client->whoqueue_last = NULL;
     client->next = sockets->data;
     sockets->data = client;
     return client;
@@ -98,7 +101,7 @@ int connect_socket(struct ClientSocket *client) {
     }
 
     client->sock = sock;
-    client->flags |= SOCKET_FLAG_CONNECTED;
+    client->flags |= SOCKET_FLAG_CONNECTED | SOCKET_FLAG_RECONNECT;
     client->connection_time = time(0);
 
     //send the IRC Headers
@@ -151,14 +154,14 @@ int connect_socket(struct ClientSocket *client) {
     }
 
     client->sock = sock;
-    client->flags |= SOCKET_FLAG_CONNECTED;
+    client->flags |= SOCKET_FLAG_CONNECTED | SOCKET_FLAG_RECONNECT;
     client->connection_time = time(0);
 
     //send the IRC Headers
     char sendBuf[512];
     int len;
 
-    if(client->pass) {
+    if(client->pass && strcmp(client->pass, "")) {
         len = sprintf(sendBuf, "PASS :%s\n", client->pass);
         write_socket(client, sendBuf, len);
     }
@@ -189,6 +192,8 @@ int close_socket(struct ClientSocket *client) {
     }
     if(client->queue)
         queue_destroy(client);
+    if(client->whoqueue_first)
+        clear_whoqueue(client);
     free(client->host);
     free(client->pass);
     free(client);
@@ -275,6 +280,10 @@ void socket_loop(int timeout_seconds) {
                     sock->bufferpos -= used;
                 }
             }
+        } else if(!(sock->flags & SOCKET_FLAG_CONNECTED) && (sock->flags & SOCKET_FLAG_RECONNECT)) {
+            if(time(0) - sock->connection_time >= SOCKET_RECONNECT_TIME) {
+                connect_socket(sock);
+            }
         }
     }
 }