]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/users.c
3 * CMDLEVEL: QCMD_AUTHED
5 * CMDDESC: Displays a list of users on the channel.
7 * CMDPROTO: int csc_dousers(void *source, int cargc, char **cargv);
8 * CMDHELP: Usage: USERS <channel>
9 * CMDHELP: Displays a list of users on the named channel along with their usernames and flags
10 * CMDHELP: on the channel, where:
11 * CMDHELP: channel - channel to use
12 * CMDHELP: USERS requires operator (+o) access on the named channel.
15 #include "../chanserv.h"
16 #include "../../nick/nick.h"
17 #include "../../lib/flags.h"
18 #include "../../lib/irc_string.h"
19 #include "../../channel/channel.h"
20 #include "../../parser/parser.h"
21 #include "../../irc/irc.h"
22 #include "../../localuser/localuserchannel.h"
26 #define ISQ 0x40000000
27 #define ISOP 0x20000000
28 #define ISV 0x10000000
31 unsigned int flags
; /* Something that sorts nicely */
37 static int comparetheflags(const void *a
, const void *b
) {
38 const struct chanuserrec
*ra
=a
, *rb
=b
;
40 return rb
->flags
-ra
->flags
;
43 int csc_dousers(void *source
, int cargc
, char **cargv
) {
44 nick
*sender
=source
, *np
;
47 struct chanuserrec
*theusers
;
51 char *flagbuf
, *unbuf
, modechar
;
52 char uhbuf
[USERLEN
+HOSTLEN
+2];
54 unsigned int ops
,voices
,users
,flags
,qops
,masters
;
57 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "users");
61 if (!(cip
=cs_checkaccess(sender
, cargv
[0], CA_OPPRIV
,
62 NULL
, "users", QPRIV_VIEWFULLCHANLEV
, 0)))
65 rcp
=cip
->exts
[chanservext
];
67 if (!(cp
=cip
->channel
)) {
68 chanservstdmessage(sender
,QM_EMPTYCHAN
,cip
->name
->content
);
72 if (!cs_privcheck(QPRIV_VIEWFULLCHANLEV
, sender
) && !getnumerichandlefromchanhash(cip
->channel
->users
,sender
->numeric
)) {
73 chanservstdmessage(sender
,QM_NOTONCHAN
,cip
->name
->content
);
77 theusers
=malloc(cp
->users
->totalusers
* sizeof(struct chanuserrec
));
78 memset(theusers
,0,cp
->users
->totalusers
* sizeof(struct chanuserrec
));
80 for (i
=0,j
=0;i
<cp
->users
->hashsize
;i
++) {
81 if (cp
->users
->content
[i
]==nouser
)
84 if (!(np
=getnickbynumeric(cp
->users
->content
[i
])))
89 theusers
[j
].flags
=(cp
->users
->content
[i
]>>2) & 0x30000000;
91 if (np
==chanservnick
) {
92 theusers
[j
].flags
|=0x40000000;
95 theusers
[j
].rup
=getreguserfromnick(np
);
96 if (theusers
[j
].rup
) {
97 theusers
[j
].rcup
=findreguseronchannel(rcp
, theusers
[j
].rup
);
99 theusers
[j
].flags
|= theusers
[j
].rcup
->flags
;
104 qsort(theusers
, j
, sizeof(struct chanuserrec
), comparetheflags
);
106 chanservstdmessage(sender
,QM_USERSHEADER
, cip
->name
->content
);
108 flagmask
=QCUFLAGS_PUBLIC
;
109 ops
=voices
=users
=flags
=qops
=masters
=0;
110 if (cs_checkaccess(sender
, NULL
, CA_MASTERPRIV
, cip
, "users", 0, 1))
111 flagmask
|= QCUFLAGS_PUNISH
;
113 if (cs_privcheck(QPRIV_VIEWFULLCHANLEV
, sender
))
114 flagmask
= QCUFLAG_ALL
;
117 if (theusers
[i
].flags
& ISOP
) {
120 } else if (theusers
[i
].flags
& ISV
) {
128 if (theusers
[i
].flags
& ISQ
) {
133 if (theusers
[i
].rup
) {
134 unbuf
=theusers
[i
].rup
->username
;
139 rcup
=theusers
[i
].rcup
;
143 if (CUHasOpPriv(rcup
))
146 if (CUIsMaster(rcup
) || CUIsOwner(rcup
))
150 if (theusers
[i
].rcup
&& (theusers
[i
].rcup
->flags
& flagmask
)) {
151 flagbuf
=printflags((flagmask
| (theusers
[i
].np
==sender
?QCUFLAGS_PERSONAL
:0)) & theusers
[i
].rcup
->flags
, rcuflags
);
157 chanservsendmessage(sender
, "%c%-15s %-15s %-12s (%s)",modechar
,np
->nick
,unbuf
,flagbuf
,visibleuserhost(np
, uhbuf
));
161 chanservstdmessage(sender
, QM_ENDOFLIST
);
162 chanservstdmessage(sender
, QM_USERSSUMMARY
, j
, ops
, voices
, users
, flags
, qops
, masters
);