0aa1a1bb8b2bec5be0908f34ec345c7ccb5e78e4
[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     #ifdef WIN32
40     int res;
41     WSADATA wsadata;
42     // Start Windows Sockets.
43     res = WSAStartup(MAKEWORD(2, 0), &wsadata);
44     if (res)
45     {
46         perror("Unable to start Windows Sockets");
47         return 0;
48     }
49     #endif
50     
51     init_mysql();
52     init_lang();
53     init_parser();
54     init_UserNode();
55     init_ChanNode();
56     init_ModeNode();
57     init_bind();
58         init_modcmd();
59     init_handleinfohandler();
60     init_tools();
61     init_bots();
62     
63     load_languages();
64     
65     time_t socket_wait;
66     while(1) {
67         socket_wait = time(0) + SOCKET_SELECT_TIME;
68         do {
69             socket_loop(SOCKET_SELECT_TIME);
70         } while(time(0) < socket_wait);
71         timeq_tick();
72         loop_bots();
73         clearTempUsers();
74         destroyEvents();
75     }
76 }
77
78 int stricmp (const char *s1, const char *s2)
79 {
80    if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
81    if (s2 == NULL) return *s1;
82    char c1, c2;
83    while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
84    {
85      if (*s1 == '\0') break;
86      ++s1; ++s2;
87    }
88    return c1 - c2;
89 }
90
91 int stricmplen (const char *s1, const char *s2, int len)
92 {
93    if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
94    if (s2 == NULL) return *s1;
95    char c1, c2;
96    int i = 0;
97    while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
98    {
99      i++;
100      if (*s1 == '\0') break;
101      ++s1; ++s2;
102      if(i == len) break;
103    }
104    return c1 - c2;
105 }
106