380e051951522ebaef2a5f602f23e9c67e52f493
[NeonServV5.git] / ClientSocket.h
1 #ifndef _ClientSocket_h
2 #define _ClientSocket_h
3
4 #include "main.h"
5
6 #define SOCKET_FLAG_DEAD      0x01
7 #define SOCKET_FLAG_CONNECTED 0x02
8 #define SOCKET_FLAG_READY     0x04
9 #define SOCKET_FLAG_PREFERRED  0x08 /* prefered bot to send datas to the IRC World (NOTICE's WHO's etc pp) */
10
11 #define BUF_SIZ 512
12
13 struct UserNode;
14 struct trigger_cache;
15
16 struct ClientSocket {
17     int sock;
18     unsigned char flags;
19     char buffer[BUF_SIZ*2]; //we need to store up to 2 full commands at once
20     unsigned int bufferpos;
21     char *host;
22     int port;
23     char *pass;
24     struct UserNode *user;
25     unsigned long traffic_in;
26     unsigned long traffic_out;
27     time_t connection_time;
28         
29         int botid : 16;
30     int clientid : 16;
31     
32     struct ClientSocket *next;
33 };
34
35 struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user);
36 int connect_socket(struct ClientSocket *client);
37 int close_socket(struct ClientSocket *client);
38 int write_socket(struct ClientSocket *client, char* msg, int len);
39 void socket_loop(int timeout_seconds);
40 void putsock(struct ClientSocket *client, const char *text, ...) PRINTF_LIKE(2, 3);
41 struct ClientSocket* getBots(int flags, struct ClientSocket* last_bot);
42 void free_sockets();
43
44 #endif