fixes for multi thread support
[NeonServV5.git] / src / main.h
1 /* main.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 _main_h
18 #define _main_h
19 #include "../config.h"
20
21 #define NEONSERV_VERSION "5.3"
22 #define VERSION_PATCHLEVEL 543
23
24 #include <features.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29 #ifdef WIN32
30 #include <windows.h>
31 #include <winsock2.h>
32 #include <malloc.h>
33 #else
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <netinet/tcp.h>
38 #include <arpa/inet.h>
39 #include <netdb.h>
40 #include <sys/wait.h>
41 #endif
42 #include <unistd.h>
43 #include <stdarg.h>
44 #include <sys/time.h>
45 #include <time.h>
46 #ifdef HAVE_THREADS
47 #include <pthread.h>
48 #include <sys/syscall.h>
49 #define THREAD_MUTEX_INIT(var) { \
50     pthread_mutexattr_t mutex_attr; \
51     pthread_mutexattr_init(&mutex_attr);\
52     pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);\
53     pthread_mutex_init(&var, &mutex_attr); \
54 }
55 #define SYNCHRONIZE(var) pthread_mutex_lock(&var)
56 #define DESYNCHRONIZE(var) pthread_mutex_unlock(&var)
57 #else
58 #define THREAD_MUTEX_INIT(var)
59 #define SYNCHRONIZE(var)
60 #define DESYNCHRONIZE(var)
61 #endif
62
63 #if __GNUC__
64 #define PRINTF_LIKE(M,N) __attribute__((format (printf, M, N)))
65 #else
66 #define PRINTF_LIKE(M,N)
67 #endif
68
69 #if __GNUC__ >= 2
70 #define UNUSED_ARG(ARG) ARG __attribute__((unused))
71 #elif defined(S_SPLINT_S)
72 #define UNUSED_ARG(ARG) /*@unused@*/ ARG
73 #define const /*@observer@*/ /*@temp@*/
74 #else
75 #define UNUSED_ARG(ARG) ARG
76 #endif
77
78 #define STRINGIFY_(x) #x
79 #define STRINGIFY(x) STRINGIFY_(x)
80  
81 #if defined(__GNUC__)
82 #if defined(__GNUC_PATCHLEVEL__)
83 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) "." STRINGIFY(__GNUC_PATCHLEVEL__)
84 #else
85 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__)
86 #endif
87 #elif defined (__IMAGECRAFT__)
88 #define COMPILER "ICCAVR"
89 #else
90 #define COMPILER "Unknown"
91 #endif
92
93 #define SOCKET_SELECT_TIME    1
94 #define SOCKET_RECONNECT_TIME 20
95
96 #define NICKLEN         30
97 #define USERLEN         10
98 #define AUTHLEN         32
99 #define HOSTLEN         63
100 #define REALLEN         50
101 #define TOPICLEN        500
102 #define CHANNELLEN      200
103 #define MAXLEN          512
104 #define TRIGGERLEN      50
105 #define MAXNUMPARAMS    200 /* maximum number of parameters in one line */
106 #define MAXLANGUAGES    5
107 #define MAXMODES        6
108 #define INVITE_TIMEOUT  30
109 #define BOTWAR_DETECTION_TIME 7
110 #define BOTWAR_DETECTION_EVENTS 6
111 #define REWHO_TIMEOUT   10 /* wait 10 seconds before WHO an unauthed user again */
112
113 //valid nick chars
114 #define VALID_NICK_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890{|}~[\\]^-_`"
115 //the first char is a little bit different
116 //                              0        1         2         3         4         5          6
117 //                              1234567890123456789012345678901234567890123456789012345678 9012   62
118 #define VALID_NICK_CHARS_FIRST "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~[\\]^_`"
119 #define VALID_NICK_CHARS_FIRST_LEN 62
120
121 #define TEMPUSER_LIST_INDEX VALID_NICK_CHARS_FIRST_LEN
122
123 extern time_t start_time;
124 extern int statistics_enabled;
125 #ifdef HAVE_THREADS
126 extern int running_threads;
127 #endif
128
129 int stricmp (const char *s1, const char *s2);
130 int stricmplen (const char *s1, const char *s2, int len);
131
132 void restart_bot(int do_hard_restart);
133 void stop_bot();
134 void reload_config();
135
136 void statistics_update();
137
138 #endif