added first helpserv functions
[NeonServV5.git] / src / ClientSocket.h
1 /* ClientSocket.h - NeonServ v5.3
2  * Copyright (C) 2011-2012  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 #define SOCKET_FLAG_SSL       0x40
29 #define SOCKET_FLAG_HAVE_SSL  0x80
30 #define SOCKET_FLAG_QUITTED   0x100
31 #define SOCKET_FLAG_FAST_JUMP 0x200
32
33 #define SOCKET_HAVE_BOTCLASSVALUE1 0x10000000
34 #define SOCKET_HAVE_BOTCLASSVALUE2 0x20000000
35 #define SOCKET_HAVE_BOTCLASSVALUE3 0x40000000
36
37 #define BUF_SIZ 512
38
39 struct UserNode;
40 struct trigger_cache;
41 struct SSLConnection;
42
43 struct ClientSocket {
44     int sock;
45     unsigned int flags;
46     char buffer[BUF_SIZ*2]; //we need to store up to 2 full commands at once
47     unsigned int bufferpos;
48     char *host;
49     int port;
50     char *bind;
51     char *pass;
52     char *nick;
53     char *ident;
54     char *realname;
55     struct UserNode *user;
56     unsigned long traffic_in;
57     unsigned long traffic_out;
58     time_t connection_time;
59     struct SSLConnection *sslconn;
60     
61     struct BotQueue *queue;
62     
63     struct WHOQueueEntry *whoqueue_first;
64     struct WHOQueueEntry *whoqueue_last;
65     
66     struct HandleInfoQueueEntry *handleinfo_first;
67     struct HandleInfoQueueEntry *handleinfo_last;
68         
69         int botid : 16;
70     int clientid : 16;
71     
72     void *botclassvalue1;
73     void *botclassvalue2;
74     void *botclassvalue3;
75     
76     struct ClientSocket *next;
77 };
78
79 struct ClientSocket* create_socket(char *host, int port, char *bindto, char *pass, char *nick, char *ident, char *realname);
80 int connect_socket(struct ClientSocket *client);
81 int close_socket(struct ClientSocket *client);
82 int disconnect_socket(struct ClientSocket *client);
83 int write_socket_force(struct ClientSocket *client, char* msg, int len);
84 int write_socket(struct ClientSocket *client, char* msg, int len);
85 void socket_loop(int timeout_seconds);
86 void putsock(struct ClientSocket *client, const char *text, ...) PRINTF_LIKE(2, 3);
87 struct ClientSocket* getBots(int flags, struct ClientSocket* last_bot);
88 void free_sockets();
89
90 #endif