]> jfr.im git - irc/quakenet/newserv.git/blob - countusers/countusers.c
Began manual merge.
[irc/quakenet/newserv.git] / countusers / countusers.c
1 #include "../control/control.h"
2 #include "../nick/nick.h"
3 #include "../channel/channel.h"
4 #include "../lib/irc_string.h"
5 #include <string.h>
6
7 int do_countusers(void *source, int cargc, char **cargv) {
8 nick *sender=(nick *)source, *np;
9 host *hp;
10 unsigned int count=0;
11 char *chp,*host,*ident;
12
13 if (cargc<1)
14 return CMD_USAGE;
15
16 for (chp=cargv[0]; ;chp++) {
17 if (*chp=='@') {
18 /* found @, so it's user@host */
19 ident=cargv[0];
20 *chp='\0';
21 host=chp+1;
22 break;
23 } else if (*chp=='\0') {
24 /* found NULL, so just host */
25 host=cargv[0];
26 ident=NULL;
27 break;
28 }
29 }
30
31 if ((hp=findhost(host))==NULL) {
32 controlreply(sender,"0 users match %s%s%s",ident?ident:"",ident?"@":"",host);
33 return CMD_OK;
34 }
35
36 if (!ident) {
37 /* We want *@host, so it's just the clonecount we have for free */
38 controlreply(sender,"%d users match %s",hp->clonecount,host);
39 } else {
40 /* Do it the slow way */
41 for (np=hp->nicks;np;np=np->nextbyhost) {
42 if (!ircd_strcmp(np->ident,ident))
43 count++;
44 }
45 controlreply(sender,"%d users match %s@%s",count,ident,host);
46 }
47
48 return CMD_OK;
49 }
50
51 void _init() {
52 registercontrolhelpcmd("countusers", NO_OPER, 1, do_countusers, "Usage: countusers <hostmask>\nReturns users on specified hostmask.");
53 }
54
55 void _fini() {
56 deregistercontrolcmd("countusers", do_countusers);
57 }