X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FClientSocket.c;h=7160014d36c18b089720ddf1e05f74743f4f9724;hb=3ed0a4b0f4ce4dc94ae52dcbd2a18770083241ce;hp=cb40cc7dc9eb1afe311919d685ca16de153846e7;hpb=f28a6cf114ec097583236a82aab0dbf52c4852c4;p=NeonServV5.git diff --git a/src/ClientSocket.c b/src/ClientSocket.c index cb40cc7..7160014 100644 --- a/src/ClientSocket.c +++ b/src/ClientSocket.c @@ -1,4 +1,4 @@ -/* ClientSocket.c - NeonServ v5.5 +/* ClientSocket.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "ConfigParser.h" #include "version.h" #include "IOHandler.h" +#include "IRCEvents.h" struct socket_list { struct ClientSocket *data; @@ -136,6 +137,7 @@ int destroy_socket(struct ClientSocket *client) { } else last_sock = sock; } + event_freeclient(client); free(client->host); if(client->bind) free(client->bind); @@ -217,14 +219,16 @@ int clientsocket_parseorder_top(unsigned int tid) { static IOHANDLER_CALLBACK(socket_callback) { struct ClientSocket *client = event->iofd->data; + #ifdef HAVE_THREADS unsigned int tid; + #endif 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: @@ -245,6 +249,7 @@ static IOHANDLER_CALLBACK(socket_callback) { tid = (unsigned int) pthread_self_tid(); clientsocket_start_of_recv(tid); #endif + client->traffic_in += strlen(event->data.recv_str); parse_line(client, event->data.recv_str); #ifdef HAVE_THREADS clientsocket_end_of_recv(tid); @@ -280,13 +285,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; }