]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/usercmds/listflags.c
CHANSERV: listflags fixes
[irc/quakenet/newserv.git] / chanserv / usercmds / listflags.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: listflags
5 * CMDLEVEL: QCMD_OPER
6 * CMDARGS: 1
7 * CMDDESC: List users with the specified user flags.
8 * CMDFUNC: csu_dolistflags
9 * CMDPROTO: int csu_dolistflags(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: listflags <flags>
11 * CMDHELP: Shows a list of all users with the specified user flags.
12 */
13
14 #include "../chanserv.h"
15 #include "../../lib/irc_string.h"
16 #include <stdio.h>
17 #include <string.h>
18
19 int csu_dolistflags(void *source, int cargc, char **cargv) {
20 nick *sender=source;
21 reguser *rup=getreguserfromnick(sender);
22 reguser *dbrup;
23 flag_t matchflags = 0;
24 char *ch;
25 int i, j;
26 unsigned int count=0;
27
28 if (!rup)
29 return CMD_ERROR;
30
31 if (cargc < 1) {
32 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "listflags");
33 return CMD_ERROR;
34 }
35
36 ch=cargv[0][0]=='+'?cargv[0]+1:cargv[0];
37
38 for (i=0; ch[i]; i++) {
39 for (j = 0; ruflags[j].flagchar; j++) {
40 if (ruflags[j].flagchar == ch[i]) {
41 matchflags|=ruflags[j].flagbit;
42 break;
43 }
44 }
45 }
46
47 if (!matchflags || (matchflags == QUFLAG_NOTICE)) {
48 chanservsendmessage(sender, "Error: no flags selected");
49 return CMD_ERROR;
50 }
51
52 chanservstdmessage(sender, QM_LISTFLAGSHEADER);
53 for (i=0;i<REGUSERHASHSIZE;i++) {
54 for (dbrup=regusernicktable[i]; dbrup; dbrup=dbrup->nextbyname) {
55 if ((dbrup->flags & matchflags) == matchflags) {
56 char tbuf[TIMELEN], *tdata;
57
58 if (dbrup->lastemailchange) {
59 q9strftime(tbuf, sizeof(tbuf), dbrup->lastemailchange);
60 tdata = tbuf;
61 } else {
62 tdata = "(none)";
63 }
64
65 char *email;
66 if (dbrup->email && dbrup->email->content[0]) {
67 email = dbrup->email->content;
68 } else {
69 email = "(none)";
70 }
71
72 chanservsendmessage(sender, " %-15s %-17s %-30s %-15s", dbrup->username, printflags(dbrup->flags, ruflags), email, tdata);
73 count++;
74 if (count >= 2000) {
75 chanservstdmessage(sender, QM_TOOMANYRESULTS, 2000, "users");
76 return CMD_ERROR;
77 }
78 }
79 }
80 }
81 chanservstdmessage(sender, QM_RESULTCOUNT, count, "user", (count==1)?"":"s");
82
83 return CMD_OK;
84 }