added some code
[NextIRCd.git] / src / ircd_sock.c
index 5e750082ca75ab57fb46a865ac15a53d7f3e43b0..a61686f5a22b089034b2b2d935f142e7b2d2fa62 100644 (file)
@@ -19,6 +19,7 @@
 #include "ircd_sock.h"
 #include "ircd_client.h"
 #include "ircd_parse.h"
+#include "ircd_auth.h"
 #include "struct_connection.h"
 
 #include "IOHandler/IOSockets.h"
@@ -135,7 +136,7 @@ static void sockets_accept_client(struct IOSocket *new_client, struct Connection
     new_client->data = connection;
     sockets_append_list(connection);
     
-    client_connected(connection);
+    auth_new(connection);
 }
 
 static CONFRELOAD_CALLBACK(sockets_config_reload) {
@@ -180,9 +181,13 @@ static IOSOCKET_CALLBACK(sockets_iohandler_callback) {
         sockets_remove_list(connection);
         if(connection->server) {
         
+        } else if(connection->authed) {
+                       connection->data.client->conn = NULL;
+            client_exit(connection->data.client, "Client disconnected.");
         } else {
-            client_disconnected(connection);
-        }
+                       connection->data.auth->conn = NULL;
+                       auth_abort(connection->data.auth);
+               }
         sockets_free_connection(connection);
         break;
     
@@ -197,12 +202,12 @@ static IOSOCKET_CALLBACK(sockets_iohandler_callback) {
         break;
     
     case IOSOCKETEVENT_RECV:
-               if(!connection->authed)
-                       parse_unauth_data(connection->data.auth, event->data.recv_str);
-        else if(connection->server)
+        if(connection->server)
             parse_server_data(connection->data.server, event->data.recv_buf);
-        else
+        else if(connection->authed)
             parse_client_data(connection->data.client, event->data.recv_str);
+        else
+                       parse_unauth_data(connection->data.auth, event->data.recv_str);
         break;
     
     default:
@@ -214,6 +219,25 @@ void socket_send(struct Connection *conn, char *data, int len) {
     iosocket_send(conn->socket, data, len);
 }
 
+void socket_printf(struct Connection *conn, const char *text, ...) {
+    va_list arg_list;
+       char sendBuf[512];
+       int pos;
+       sendBuf[0] = '\0';
+       va_start(arg_list, text);
+       pos = vsnprintf(sendBuf, 512 - 2, text, arg_list);
+       va_end(arg_list);
+       if (pos < 0 || pos > (512 - 2)) pos = CLIENT_MAXLEN - 2;
+       sendBuf[pos] = '\n';
+    sendBuf[pos+1] = '\0';
+       iosocket_send(conn->socket, sendBuf, pos+1);
+}
+
+void socket_close(struct Connection *conn) {
+    iosocket_close(conn->socket);
+    sockets_free_connection(conn);
+}
+
 void socket_set_server(struct Connection *conn) {
        struct IOSocket *iosock = conn->socket;
        iosock->parse_delimiter = 0;