fixed bot user handling (bot should only have a user when connected)
[NeonServV5.git] / src / ClientSocket.c
index b76e6f62c421c9af81e9cb6be9a629bf34ac425c..1a3d94984279b477265f42dd5a3d8eec55df0582 100644 (file)
@@ -42,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)
@@ -54,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;
@@ -115,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;
@@ -168,11 +171,11 @@ 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;
 }