tried to reorder the program structure and build process
[NeonServV5.git] / src / main.c
1
2 #include "main.h"
3 #include "ClientSocket.h"
4 #include "UserNode.h"
5 #include "ChanNode.h"
6 #include "IRCEvents.h"
7 #include "IRCParser.h"
8 #include "modcmd.h"
9 #include "WHOHandler.h"
10 #include "bots.h"
11 #include "mysqlConn.h"
12 #include "HandleInfoHandler.h"
13 #include "lang.h"
14 #include "tools.h"
15 #include "timeq.h"
16 #include "EventLogger.h"
17 #include "ModeNode.h"
18
19 time_t start_time;
20
21 void cleanup() {
22     free_sockets();
23     free_parser();
24     free_UserNode();
25     free_ChanNode();
26     free_bind();
27     free_modcmd();
28     free_whoqueue();
29     free_bots();
30     free_mysql();
31     free_handleinfohandler();
32     free_lang();
33 }
34
35 int main(void)
36 {
37     start_time = time(0);
38     
39     init_mysql();
40     init_lang();
41     init_parser();
42     init_UserNode();
43     init_ChanNode();
44     init_ModeNode();
45     init_bind();
46         init_modcmd();
47     init_handleinfohandler();
48     init_tools();
49     init_bots();
50     
51     load_languages();
52     
53     time_t socket_wait;
54     while(1) {
55         socket_wait = time(0) + SOCKET_SELECT_TIME;
56         do {
57             socket_loop(SOCKET_SELECT_TIME);
58         } while(time(0) < socket_wait);
59         timeq_tick();
60         loop_bots();
61         clearTempUsers();
62         destroyEvents();
63     }
64 }
65
66 int stricmp (const char *s1, const char *s2)
67 {
68    if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
69    if (s2 == NULL) return *s1;
70    char c1, c2;
71    while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
72    {
73      if (*s1 == '\0') break;
74      ++s1; ++s2;
75    }
76    return c1 - c2;
77 }
78
79 int stricmplen (const char *s1, const char *s2, int len)
80 {
81    if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
82    if (s2 == NULL) return *s1;
83    char c1, c2;
84    int i = 0;
85    while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
86    {
87      i++;
88      if (*s1 == '\0') break;
89      ++s1; ++s2;
90      if(i == len) break;
91    }
92    return c1 - c2;
93 }
94