X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ClientSocket.c;h=78467a1c94b5d1d725d216ed4f57e261d6a4706e;hb=84fb65ee885f3f747b0a07eb07999395c0ae22f9;hp=0192b084fb97904eba1ce1462f5fe21ba97b3464;hpb=6e415e27feac22d80d613450b97cd372db0dd2a3;p=NeonServV5.git diff --git a/ClientSocket.c b/ClientSocket.c index 0192b08..78467a1 100644 --- a/ClientSocket.c +++ b/ClientSocket.c @@ -12,7 +12,7 @@ struct socket_list { static struct socket_list *sockets = NULL; static char buffer[BUF_SIZ]; -static void init() { +static void init_sockets() { sockets = malloc(sizeof(*sockets)); if (!sockets) { @@ -24,7 +24,7 @@ static void init() { } struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user) { - if(sockets == NULL) init(); + if(sockets == NULL) init_sockets(); struct ClientSocket *client = malloc(sizeof(*client)); if (!client) { @@ -38,7 +38,7 @@ struct ClientSocket* create_socket(char *host, int port, char *pass, struct User client->flags = 0; client->bufferpos = 0; client->botid = 0; - client->trigger = NULL; + client->clientid = 0; client->next = sockets->data; sockets->data = client; return client; @@ -202,3 +202,18 @@ struct ClientSocket* getBots(int flags, struct ClientSocket* last_bot) { } return NULL; } + +void free_sockets() { + if(!sockets) return; + struct ClientSocket *client, *next; + for (client = sockets->data; client; client = next) { + next = client->next; + if((client->flags & SOCKET_FLAG_CONNECTED)) + close(client->sock); + free(client->host); + free(client->pass); + free(client); + } + free(sockets); + sockets = NULL; +}