]> jfr.im git - irc/quakenet/newserv.git/blob - usercount/usercount.c
Fix more warnings.
[irc/quakenet/newserv.git] / usercount / usercount.c
1 #include <string.h>
2
3 #include "../nick/nick.h"
4 #include "../core/hooks.h"
5 #include "usercount.h"
6
7 int servercount[MAXSERVERS];
8
9 static void uc_newserver(int hook, void *arg);
10 static void uc_newnick(int hook, void *arg);
11 static void uc_lostnick(int hook, void *arg);
12
13 void _init(void) {
14 nick *np;
15 int i;
16
17 memset(servercount, 0, sizeof(servercount));
18
19 for(i=0;i<NICKHASHSIZE;i++)
20 for(np=nicktable[i];np;np=np->next)
21 servercount[homeserver(np->numeric)]++;
22
23 registerhook(HOOK_SERVER_NEWSERVER, uc_newserver);
24 registerhook(HOOK_NICK_NEWNICK, uc_newnick);
25 registerhook(HOOK_NICK_LOSTNICK, uc_lostnick);
26 }
27
28 void _fini(void) {
29 deregisterhook(HOOK_SERVER_NEWSERVER, uc_newserver);
30 deregisterhook(HOOK_NICK_NEWNICK, uc_newnick);
31 deregisterhook(HOOK_NICK_LOSTNICK, uc_lostnick);
32 }
33
34 static void uc_newserver(int hook, void *arg) {
35 long num = (long)arg;
36
37 servercount[num] = 0;
38 }
39
40 static void uc_newnick(int hook, void *arg) {
41 nick *np = (nick *)arg;
42
43 if(np)
44 servercount[homeserver(np->numeric)]++;
45 }
46
47 static void uc_lostnick(int hook, void *arg) {
48 nick *np = (nick *)arg;
49
50 if(np)
51 servercount[homeserver(np->numeric)]--;
52 }