]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/voice.c
Two argument op/voice commands now require you to be a master (eg ops can't now silen...
[irc/quakenet/newserv.git] / chanserv / chancmds / voice.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: voice
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 20
7 * CMDDESC: Voices you or other users on channel(s).
8 * CMDFUNC: csc_dovoice
9 * CMDPROTO: int csc_dovoice(void *source, int cargc, char **cargv);
10 */
11
12 #include "../chanserv.h"
13 #include "../../nick/nick.h"
14 #include "../../lib/flags.h"
15 #include "../../lib/irc_string.h"
16 #include "../../channel/channel.h"
17 #include "../../parser/parser.h"
18 #include "../../irc/irc.h"
19 #include "../../localuser/localuserchannel.h"
20 #include <string.h>
21 #include <stdio.h>
22
23 int csc_dovoice(void *source, int cargc, char **cargv) {
24 nick *sender=source, *np;
25 reguser *rup=getreguserfromnick(sender);
26 chanindex *cip;
27 regchan *rcp=NULL;
28 regchanuser *rcup;
29 channel **ca;
30 unsigned long *lp;
31 int i;
32 modechanges changes;
33
34 if (!rup)
35 return CMD_ERROR;
36
37 if (cargc==0) {
38 /* No args: "voice me on every channel you can */
39 ca=sender->channels->content;
40 for (i=0;i<sender->channels->cursi;i++) {
41 if ((rcp=ca[i]->index->exts[chanservext]) && !CIsSuspended(rcp)) {
42 /* It's a Q channel */
43 if (!(*(getnumerichandlefromchanhash(ca[i]->users, sender->numeric)) &
44 (CUMODE_OP|CUMODE_VOICE))) {
45 /* They're not opped or voiced */
46 rcup=findreguseronchannel(rcp, rup);
47 if ((!rcup || !CUIsQuiet(rcup)) &&
48 ((rcup && CUHasVoicePriv(rcup)) ||
49 (CIsVoiceAll(rcp)))) {
50 /* And they have voice priv on the chan (or it's autovoice):
51 * voice them */
52 localsetmodeinit(&changes, ca[i], chanservnick);
53 localdosetmode_nick(&changes, sender, MC_VOICE);
54 localsetmodeflush(&changes,1);
55 }
56 }
57 }
58 }
59
60 chanservstdmessage(sender, QM_DONE);
61 return CMD_OK;
62 }
63
64 /* If there is at least one arg, the first is a channel */
65
66 if (!(cip=cs_checkaccess(sender, cargv[0], CA_VOICEPRIV, NULL, "voice", 0, 0)))
67 return CMD_ERROR;
68
69 if (cargc==1) {
70 /* Only one arg: "voice me" */
71 if (!cs_checkaccess(sender, NULL, CA_VOICEPRIV | CA_DEVOICED, cip,
72 "voice", 0, 0))
73 return CMD_ERROR;
74
75 localsetmodeinit(&changes, cip->channel, chanservnick);
76 localdosetmode_nick(&changes, sender, MC_VOICE);
77 localsetmodeflush(&changes,1);
78
79 chanservstdmessage(sender, QM_DONE);
80 return CMD_OK;
81 }
82
83 /* You've got to be a master to 'silently' voice other people */
84 if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "voice", 0, 0))
85 return CMD_ERROR;
86
87 rcp=cip->exts[chanservext];
88
89 /* Set up the modes */
90 localsetmodeinit(&changes, cip->channel, chanservnick);
91
92 for(i=1;i<cargc;i++) {
93 if (!(np=getnickbynick(cargv[i]))) {
94 chanservstdmessage(sender, QM_UNKNOWNUSER, cargv[i]);
95 continue;
96 }
97
98 if (!(lp=getnumerichandlefromchanhash(cip->channel->users, np->numeric))) {
99 chanservstdmessage(sender, QM_USERNOTONCHAN, np->nick, cip->name->content);
100 continue;
101 }
102
103 if (*lp & CUMODE_VOICE) {
104 chanservstdmessage(sender, QM_USERVOICEDONCHAN, np->nick, cip->name->content);
105 continue;
106 }
107
108 if ((rup=getreguserfromnick(np)) && (rcup=findreguseronchannel(rcp, rup)) && CUIsQuiet(rcup)) {
109 chanservstdmessage(sender, QM_CANTVOICE, np->nick, cip->name->content);
110 continue;
111 }
112
113 localdosetmode_nick(&changes, np, MC_VOICE);
114 }
115
116 localsetmodeflush(&changes, 1);
117 chanservstdmessage(sender, QM_DONE);
118
119 return CMD_OK;
120 }