]>
Commit | Line | Data |
---|---|---|
c96aa815 P |
1 | /* shroud's splitlist */ |
2 | ||
3 | #include <string.h> | |
4 | #include "../irc/irc.h" | |
5 | #include "splitlist.h" | |
6 | #include "../core/hooks.h" | |
df3bf970 | 7 | #include "../lib/version.h" |
c96aa815 | 8 | |
ef7154fb P |
9 | MODULE_VERSION(""); |
10 | ||
c96aa815 P |
11 | array splitlist; |
12 | ||
13 | void sphook_newserver(int hook, void *arg); | |
14 | void sphook_lostserver(int hook, void *arg); | |
15 | ||
16 | void _init(void) { | |
17 | registerhook(HOOK_SERVER_NEWSERVER, &sphook_newserver); | |
18 | registerhook(HOOK_SERVER_LOSTSERVER, &sphook_lostserver); | |
19 | ||
20 | array_init(&splitlist, sizeof(splitserver)); | |
21 | array_setlim1(&splitlist, 5); | |
22 | array_setlim2(&splitlist, 5); | |
23 | ||
24 | sp_addsplit("default.split.quakenet.org", getnettime()); | |
25 | } | |
26 | ||
27 | void _fini(void) { | |
28 | int i; | |
29 | ||
30 | deregisterhook(HOOK_SERVER_NEWSERVER, &sphook_newserver); | |
31 | deregisterhook(HOOK_SERVER_LOSTSERVER, &sphook_lostserver); | |
32 | ||
33 | for (i = 0; i < splitlist.cursi; i++) { | |
34 | freesstring(((splitserver*)splitlist.content)[i].name); | |
35 | } | |
36 | ||
37 | array_free(&splitlist); | |
38 | } | |
39 | ||
40 | void sphook_newserver(int hook, void *arg) { | |
c3db6f7e | 41 | sp_deletesplit(serverlist[(long)arg].name->content); |
c96aa815 P |
42 | } |
43 | ||
44 | void sphook_lostserver(int hook, void *arg) { | |
c3db6f7e | 45 | sp_addsplit(serverlist[(long)arg].name->content, getnettime()); |
c96aa815 P |
46 | } |
47 | ||
48 | int sp_countsplitservers(void) { | |
49 | return splitlist.cursi; | |
50 | } | |
51 | ||
52 | int sp_issplitserver(const char *name) { | |
53 | int i; | |
54 | ||
55 | for (i = 0; i < splitlist.cursi; i++) { | |
56 | if (strcmp(name, ((splitserver*)splitlist.content)[i].name->content) == 0) | |
57 | return 1; | |
58 | } | |
59 | ||
60 | return 0; | |
61 | } | |
62 | ||
63 | void sp_deletesplit(const char *name) { | |
64 | int i; | |
65 | ||
66 | if (splitlist.cursi == 0) | |
67 | return; | |
68 | ||
69 | for (i = splitlist.cursi - 1; i >= 0; i--) { | |
70 | if (strcmp(name, ((splitserver*)splitlist.content)[i].name->content) == 0) { | |
71 | freesstring(((splitserver*)splitlist.content)[i].name); | |
72 | array_delslot(&splitlist, i); | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
77 | void sp_addsplit(const char *name, time_t ts) { | |
78 | int slot; | |
79 | splitserver *srv; | |
80 | ||
81 | slot = array_getfreeslot(&splitlist); | |
82 | ||
83 | srv = &(((splitserver*)splitlist.content)[slot]); | |
84 | ||
85 | srv->name = getsstring(name, HOSTLEN); | |
86 | srv->ts = ts; | |
87 | } |