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