moving NeonServ into background by default; added a few startup parameters
[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 <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <ctype.h>
28 #ifdef WIN32
29 #include <windows.h>
30 #include <winsock2.h>
31 #include <malloc.h>
32 #else
33 #include <features.h>
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 #ifdef WIN32
49 #define pthread_self_tid() pthread_self().p
50 #else
51 #define pthread_self_tid() pthread_self()
52 #endif
53 #define THREAD_MUTEX_INIT(var) { \
54     pthread_mutexattr_t mutex_attr; \
55     pthread_mutexattr_init(&mutex_attr);\
56     pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_NP);\
57     pthread_mutex_init(&var, &mutex_attr); \
58 }
59 #define THREAD_MUTEX_INIT_TYPE(var, type) { \
60     pthread_mutexattr_t mutex_attr; \
61     pthread_mutexattr_init(&mutex_attr);\
62     pthread_mutexattr_settype(&mutex_attr, type);\
63     pthread_mutex_init(&var, &mutex_attr); \
64 }
65 #define SYNCHRONIZE(var) pthread_mutex_lock(&var)
66 #define SET_SYNCHRONIZE(var) pthread_mutex_trylock(&var)
67 #define DESYNCHRONIZE(var) pthread_mutex_unlock(&var)
68 #else
69 #define THREAD_MUTEX_INIT(var)
70 #define SYNCHRONIZE(var)
71 #define DESYNCHRONIZE(var)
72 #endif
73
74 #if __GNUC__
75 #define PRINTF_LIKE(M,N) __attribute__((format (printf, M, N)))
76 #else
77 #define PRINTF_LIKE(M,N)
78 #endif
79
80 #if __GNUC__ >= 2
81 #define UNUSED_ARG(ARG) ARG __attribute__((unused))
82 #elif defined(S_SPLINT_S)
83 #define UNUSED_ARG(ARG) /*@unused@*/ ARG
84 #define const /*@observer@*/ /*@temp@*/
85 #else
86 #define UNUSED_ARG(ARG) ARG
87 #endif
88
89 #define STRINGIFY_(x) #x
90 #define STRINGIFY(x) STRINGIFY_(x)
91  
92 #if defined(__GNUC__)
93 #if defined(__GNUC_PATCHLEVEL__)
94 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) "." STRINGIFY(__GNUC_PATCHLEVEL__)
95 #else
96 #define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__)
97 #endif
98 #elif defined (__IMAGECRAFT__)
99 #define COMPILER "ICCAVR"
100 #else
101 #define COMPILER "Unknown"
102 #endif
103
104 #ifdef ENABLE_MEMORY_DEBUG
105 #include "memoryDebug.h"
106 #endif
107
108 #define PID_FILE "neonserv.pid"
109 #define CONF_FILE "neonserv.conf"
110 #define LOG_FILE "neonserv.log"
111
112 #define SOCKET_SELECT_TIME    1
113 #define SOCKET_RECONNECT_TIME 20
114
115 #define NICKLEN         30
116 #define USERLEN         10
117 #define AUTHLEN         32
118 #define HOSTLEN         63
119 #define REALLEN         50
120 #define TOPICLEN        500
121 #define CHANNELLEN      200
122 #define MAXLEN          512
123 #define MAXLOGLEN       1024
124 #define TRIGGERLEN      50
125 #define MAXNUMPARAMS    200 /* maximum number of parameters in one line */
126 #define MAXLANGUAGES    5
127 #define MAXMODES        6
128 #define INVITE_TIMEOUT  30
129 #define BOTWAR_DETECTION_TIME 7
130 #define BOTWAR_DETECTION_EVENTS 6
131 #define REWHO_TIMEOUT   10 /* wait 10 seconds before WHO an unauthed user again */
132 #define TICKS_PER_SECOND 10
133
134 //valid nick chars
135 #define VALID_NICK_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890{|}~[\\]^-_`"
136 //the first char is a little bit different
137 //                              0        1         2         3         4         5          6
138 //                              1234567890123456789012345678901234567890123456789012345678 9012   62
139 #define VALID_NICK_CHARS_FIRST "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~[\\]^_`"
140 #define VALID_NICK_CHARS_FIRST_LEN 62
141
142 #define TEMPUSER_LIST_INDEX VALID_NICK_CHARS_FIRST_LEN
143
144 #define LOGLEVEL_INFO  0x01
145 #define LOGLEVEL_ERROR 0x02
146 #define LOGLEVEL_RAW   0x04
147 #define LOGLEVEL_MYSQL 0x08
148
149 #define timeval_is_bigger(x,y) ((x.tv_sec > y.tv_sec) || (x.tv_sec == y.tv_sec && x.tv_usec > y.tv_usec))
150
151 extern time_t start_time;
152 extern int statistics_enabled;
153 #ifdef HAVE_THREADS
154 extern int running_threads;
155 extern pthread_mutex_t cache_sync;
156 extern pthread_mutex_t whohandler_sync, whohandler_mass_sync;
157
158 int getCurrentThreadID();
159 #endif
160
161 void exit_daemon();
162
163 int stricmp (const char *s1, const char *s2);
164 int stricmplen (const char *s1, const char *s2, int len);
165
166 void restart_process();
167 void cleanup();
168 void restart_bot(int do_hard_restart);
169 void stop_bot();
170 void reload_config();
171
172 void statistics_update();
173
174 void putlog(int loglevel, const char *text, ...) PRINTF_LIKE(2, 3);
175
176 #define perror(errmsg) (putlog(LOGLEVEL_ERROR, "ERROR (%s:%d) %s", __FILE__, __LINE__, errmsg))
177
178 #endif