fixed bot user handling (bot should only have a user when connected)
[NeonServV5.git] / src / ClientSocket.c
index f9faf44807eaf8b7f896704409ef8dc2e529e738..1a3d94984279b477265f42dd5a3d8eec55df0582 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,8 @@
 #include "IRCParser.h"
 #include "UserNode.h"
 #include "IRCQueue.h"
+#include "WHOHandler.h"
+#include "HandleInfoHandler.h"
 
 struct socket_list {
     struct ClientSocket *data;
@@ -40,7 +42,7 @@ static void init_sockets() {
     sockets->count = 0;
 }
 
-struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user) {
+struct ClientSocket* create_socket(char *host, int port, char *pass, char *nick, char *ident, char *realname) {
     if(sockets == NULL) init_sockets();
     struct ClientSocket *client = malloc(sizeof(*client));
     if (!client)
@@ -52,7 +54,10 @@ struct ClientSocket* create_socket(char *host, int port, char *pass, struct User
     client->port = port;
     printf("Connect: %s:%d\n", client->host, client->port);
     client->pass = (pass == NULL ? NULL : strdup(pass));
-    client->user = user;
+    client->nick = strdup(nick);
+    client->ident = strdup(ident);
+    client->realname = strdup(realname);
+    client->user = NULL;
     client->flags = 0;
     client->bufferpos = 0;
     client->traffic_in = 0;
@@ -61,6 +66,10 @@ 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->handleinfo_first = NULL;
+    client->handleinfo_last = NULL;
     client->next = sockets->data;
     sockets->data = client;
     return client;
@@ -109,9 +118,9 @@ int connect_socket(struct ClientSocket *client) {
         len = sprintf(sendBuf, "PASS :%s\n", client->pass);
         write_socket(client, sendBuf, len);
     }
-    len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->user->ident, client->user->realname);
+    len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->ident, client->realname);
     write_socket(client, sendBuf, len);
-    len = sprintf(sendBuf, "NICK %s\n", client->user->nick);
+    len = sprintf(sendBuf, "NICK %s\n", client->nick);
     write_socket(client, sendBuf, len);
 
     return 1;
@@ -158,15 +167,15 @@ int connect_socket(struct ClientSocket *client) {
     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);
     }
-    len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->user->ident, client->user->realname);
+    len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->ident, client->realname);
     write_socket(client, sendBuf, len);
-    len = sprintf(sendBuf, "NICK %s\n", client->user->nick);
+    len = sprintf(sendBuf, "NICK %s\n", client->nick);
     write_socket(client, sendBuf, len);
-
+    
     return 1;
 }
 
@@ -189,6 +198,10 @@ int close_socket(struct ClientSocket *client) {
     }
     if(client->queue)
         queue_destroy(client);
+    if(client->whoqueue_first)
+        clear_whoqueue(client);
+    if(client->handleinfo_first)
+        clear_handleinfoqueue(client);
     free(client->host);
     free(client->pass);
     free(client);