]>
Commit | Line | Data |
---|---|---|
c96aa815 P |
1 | /* oper commands for the splitlist */ |
2 | ||
3 | #include "../lib/irc_string.h" | |
4 | #include "../irc/irc.h" | |
5 | #include "../splitlist/splitlist.h" | |
6 | #include "../control/control.h" | |
7 | ||
8 | int spcmd_splitlist(void *source, int cargc, char **cargv); | |
9 | int spcmd_splitdel(void *source, int cargc, char **cargv); | |
10 | ||
11 | void _init(void) { | |
cc3fea75 | 12 | registercontrolhelpcmd("splitlist", NO_STAFF, 0, &spcmd_splitlist, "Usage: splitlist\nLists servers currently split from the netowkr"); |
c96aa815 P |
13 | registercontrolcmd("splitdel", 10, 1, &spcmd_splitdel); |
14 | } | |
15 | ||
16 | void _fini(void) { | |
17 | deregistercontrolcmd("splitlist", &spcmd_splitlist); | |
18 | deregistercontrolcmd("splitdel", &spcmd_splitdel); | |
19 | } | |
20 | ||
21 | /* todo: add RELINK status */ | |
22 | int spcmd_splitlist(void *source, int cargc, char **cargv) { | |
23 | nick *np = (nick*)source; | |
24 | int i; | |
25 | splitserver srv; | |
26 | ||
27 | if (splitlist.cursi == 0) { | |
28 | controlreply(np, "There currently aren't any registered splits."); | |
29 | ||
30 | return CMD_OK; | |
31 | } | |
32 | ||
33 | controlreply(np, "Server Status Split for"); | |
34 | ||
35 | for (i = 0; i < splitlist.cursi; i++) { | |
36 | srv = ((splitserver*)splitlist.content)[i]; | |
37 | ||
38 | controlreply(np, "%s M.I.A. %s", srv.name->content, longtoduration(getnettime() - srv.ts, 1)); | |
39 | } | |
40 | ||
41 | controlreply(np, "--- End of splitlist"); | |
42 | ||
43 | return CMD_OK; | |
44 | } | |
45 | ||
46 | int spcmd_splitdel(void *source, int cargc, char **cargv) { | |
47 | nick *np = (nick*)source; | |
48 | int i, count; | |
49 | splitserver srv; | |
50 | ||
51 | if (cargc < 1) { | |
52 | controlreply(np, "Syntax: splitdel <pattern>"); | |
53 | ||
54 | return CMD_ERROR; | |
55 | } | |
56 | ||
57 | count = 0; | |
58 | ||
59 | for (i = splitlist.cursi - 1; i >= 0; i--) { | |
60 | srv = ((splitserver*)splitlist.content)[i]; | |
61 | ||
62 | if (match2strings(cargv[0], srv.name->content)) { | |
63 | sp_deletesplit(srv.name->content); /* inefficient .. but it doesn't matter */ | |
64 | count++; | |
65 | } | |
66 | } | |
67 | ||
68 | controlreply(np, "%d %s deleted.", count, count != 1 ? "splits" : "split"); | |
69 | ||
70 | return CMD_OK; | |
71 | } |