01a8eeeff3e7f2a985228209e742167ee4d0631b
[NeonServV5.git] / src / ClientSocket.h
1 /* ClientSocket.h - NeonServ v5.1
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17 #ifndef _ClientSocket_h
18 #define _ClientSocket_h
19
20 #include "main.h"
21
22 #define SOCKET_FLAG_DEAD      0x01
23 #define SOCKET_FLAG_CONNECTED 0x02
24 #define SOCKET_FLAG_READY     0x04
25 #define SOCKET_FLAG_PREFERRED 0x08 /* prefered bot to send datas to the IRC World (NOTICE's WHO's etc pp) */
26 #define SOCKET_FLAG_USE_QUEUE 0x10
27 #define SOCKET_FLAG_RECONNECT 0x20
28
29 #define BUF_SIZ 512
30
31 struct UserNode;
32 struct trigger_cache;
33
34 struct ClientSocket {
35     int sock;
36     unsigned char flags;
37     char buffer[BUF_SIZ*2]; //we need to store up to 2 full commands at once
38     unsigned int bufferpos;
39     char *host;
40     int port;
41     char *pass;
42     struct UserNode *user;
43     unsigned long traffic_in;
44     unsigned long traffic_out;
45     time_t connection_time;
46     
47     struct BotQueue *queue;
48         
49         int botid : 16;
50     int clientid : 16;
51     
52     struct ClientSocket *next;
53 };
54
55 struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user);
56 int connect_socket(struct ClientSocket *client);
57 int close_socket(struct ClientSocket *client);
58 int write_socket_force(struct ClientSocket *client, char* msg, int len);
59 int write_socket(struct ClientSocket *client, char* msg, int len);
60 void socket_loop(int timeout_seconds);
61 void putsock(struct ClientSocket *client, const char *text, ...) PRINTF_LIKE(2, 3);
62 struct ClientSocket* getBots(int flags, struct ClientSocket* last_bot);
63 void free_sockets();
64
65 #endif