]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add usercount.
authorChris Porter <redacted>
Thu, 10 Apr 2008 02:30:07 +0000 (03:30 +0100)
committerChris Porter <redacted>
Thu, 10 Apr 2008 02:30:07 +0000 (03:30 +0100)
usercount/Makefile.in [new file with mode: 0644]
usercount/usercount.c [new file with mode: 0644]
usercount/usercount.h [new file with mode: 0644]

diff --git a/usercount/Makefile.in b/usercount/Makefile.in
new file mode 100644 (file)
index 0000000..1c84ac4
--- /dev/null
@@ -0,0 +1,6 @@
+@include@ @includel@../build.mk@includel@
+
+.PHONY: all
+all: usercount.so
+
+usercount.so: usercount.o
diff --git a/usercount/usercount.c b/usercount/usercount.c
new file mode 100644 (file)
index 0000000..f032b0f
--- /dev/null
@@ -0,0 +1,41 @@
+#include "../nick/nick.h"
+#include "../core/hooks.h"
+#include "usercount.h"
+
+int servercount[MAXSERVERS];
+
+static void uc_newserver(int hook, void *arg);
+static void uc_newnick(int hook, void *arg);
+static void uc_lostnick(int hook, void *arg);
+
+void _init(void) {
+  registerhook(HOOK_SERVER_NEWSERVER, uc_newserver);
+  registerhook(HOOK_NICK_NEWNICK, uc_newnick);
+  registerhook(HOOK_NICK_LOSTNICK, uc_lostnick);
+}
+
+void _fini(void) {
+  deregisterhook(HOOK_SERVER_NEWSERVER, uc_newserver);
+  deregisterhook(HOOK_NICK_NEWNICK, uc_newnick);
+  deregisterhook(HOOK_NICK_LOSTNICK, uc_lostnick);
+}
+
+static void uc_newserver(int hook, void *arg) {
+  long num = (long)arg;
+
+  servercount[num] = 0;
+}
+
+static void uc_newnick(int hook, void *arg) {
+  nick *np = (nick *)arg;
+
+  if(np)
+    servercount[homeserver(np->numeric)]++;
+}
+
+static void uc_lostnick(int hook, void *arg) {
+  nick *np = (nick *)arg;
+
+  if(np)
+    servercount[homeserver(np->numeric)]--;
+}
diff --git a/usercount/usercount.h b/usercount/usercount.h
new file mode 100644 (file)
index 0000000..b61662b
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __USERCOUNT_H
+#define __USERCOUNT_H
+
+#include "../server/server.h"
+
+extern int servercount[MAXSERVERS];
+
+#endif