]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/removeuser.c
Merged default.
[irc/quakenet/newserv.git] / chanserv / chancmds / removeuser.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: removeuser
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 20
7 * CMDDESC: Removes one or more users from a channel.
8 * CMDFUNC: csc_doremoveuser
9 * CMDPROTO: int csc_doremoveuser(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: REMOVEUSER <channel> <user1> [<user2> [<user3> [...]]]
11 * CMDHELP: Removes any flags the named user(s) have on the channel. This command
12 * CMDHELP: cannot be used to remove owners (+n) from the channel, and cannot be used
13 * CMDHELP: to remove masters (+m) unless the user issuing the command is an owner.
14 * CMDHELP: Where:
15 * CMDHELP: channel - channel to use
16 * CMDHELP: user<n> - a user to remove. Can either be a nickname on the network
17 * CMDHELP: or #authname. Up to 18 users can be specified.
18 * CMDHELP: REMOVEUSER requires master (+m) access on the named channel.
19 */
20
21 #include "../chanserv.h"
22 #include "../../nick/nick.h"
23 #include "../../lib/flags.h"
24 #include "../../lib/irc_string.h"
25 #include "../../channel/channel.h"
26 #include "../../parser/parser.h"
27 #include "../../irc/irc.h"
28 #include "../../localuser/localuserchannel.h"
29 #include <string.h>
30 #include <stdio.h>
31
32 int csc_doremoveuser(void *source, int cargc, char **cargv) {
33 nick *sender=source;
34 chanindex *cip;
35 regchanuser *rcup;
36 regchan *rcp;
37 reguser *rup;
38 int isowner=0;
39 int removed=0;
40 int i;
41 void *args[3];
42 flag_t oldflags;
43
44 if (cargc<2) {
45 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "removeuser");
46 return CMD_ERROR;
47 }
48
49 if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "removeuser", QPRIV_CHANGECHANLEV, 0)))
50 return CMD_ERROR;
51
52 if (cs_checkaccess(sender, NULL, CA_OWNERPRIV, cip, "removeuser", QPRIV_CHANGECHANLEV, 1))
53 isowner=1;
54
55 rcp=cip->exts[chanservext];
56
57 for (i=1;i<cargc;i++) {
58 if (!(rup=findreguser(sender, cargv[i])))
59 continue;
60
61 if (!(rcup=findreguseronchannel(rcp, rup))) {
62 chanservstdmessage(sender, QM_CHANUSERUNKNOWN, cargv[i], cip->name->content);
63 continue;
64 }
65
66 if (CUIsOwner(rcup) && !cs_privcheck(QPRIV_CHANGECHANLEV, sender)) {
67 chanservstdmessage(sender, QM_CANNOTREMOVEOWNER, cargv[i], cip->name->content);
68 continue;
69 }
70
71 if (CUIsMaster(rcup) && !isowner && (rup != getreguserfromnick(sender))) {
72 chanservstdmessage(sender, QM_CANNOTREMOVEMASTER, cargv[i], cip->name->content);
73 continue;
74 }
75
76 cs_log(sender,"CHANLEV %s #%s -%s (%s -> +)",cip->name->content,rup->username,
77 printflags_noprefix(rcup->flags, rcuflags), printflags(rcup->flags, rcuflags));
78
79 oldflags=rcup->flags;
80 rcup->flags=0;
81
82 args[0]=sender;
83 args[1]=rcup;
84 args[2]=(void *)oldflags;
85
86 triggerhook(HOOK_CHANSERV_CHANLEVMOD, args);
87
88 csdb_deletechanuser(rcup);
89 delreguserfromchannel(rcp, rup);
90 csdb_chanlevhistory_insert(rcp, sender, rcup->user, rcup->flags, 0);
91 removed++;
92 }
93
94 rcp->status |= QCSTAT_OPCHECK;
95 cs_timerfunc(cip);
96
97 if (removed) {
98 if (cs_removechannelifempty(sender, rcp)) {
99 chanservstdmessage(sender, QM_CHANLEVEMPTIEDCHANNEL);
100 } else {
101 chanservstdmessage(sender, QM_DONE);
102 }
103 }
104
105 return CMD_OK;
106 }