]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/voice.c
Merge.
[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 * CMDHELP: Usage: VOICE [<channel> [<user1> [<user2> [...]]]]
11 * CMDHELP: Grants voice to you on one or more channels, or grants voice to one or more
12 * CMDHELP: other users on a particular channel. This command cannot be used to grant
13 * CMDHELP: voice to users who would otherwise be prevented from obtaining voice, e.g.
14 * CMDHELP: the quiet (+q) chanlev flag. Where:
15 * CMDHELP: channel - channel to use. If no channel is specified, you will be granted voice
16 * CMDHELP: on every channel where you have appropriate access and are not already
17 * CMDHELP: voiced.
18 * CMDHELP: user<n> - other users to grant voice to. Must be specified as the nickname
19 * CMDHELP: of users who are on the named channel.
20 * CMDHELP: Voicing yourself requires voice (+v) access on the relevant channels.
21 * CMDHELP: Voicing other users requires operator (+o) access on the named channel. If this
22 * CMDHELP: command is used to voice other users, a notice will be sent to channel operators
23 * CMDHELP: on the channel identifying you, unless you have master (+m) access.
24 */
25
26 #include "../chanserv.h"
27 #include "../../nick/nick.h"
28 #include "../../lib/flags.h"
29 #include "../../lib/irc_string.h"
30 #include "../../channel/channel.h"
31 #include "../../parser/parser.h"
32 #include "../../irc/irc.h"
33 #include "../../localuser/localuserchannel.h"
34 #include <string.h>
35 #include <stdio.h>
36
37 int csc_dovoice(void *source, int cargc, char **cargv) {
38 nick *sender=source, *np;
39 reguser *rup=getreguserfromnick(sender);
40 chanindex *cip;
41 regchan *rcp=NULL;
42 regchanuser *rcup;
43 channel **ca;
44 unsigned long *lp;
45 int i;
46 modechanges changes;
47 char buf[512];
48 unsigned int bufpos=0,donotice=0;
49
50 if (!rup)
51 return CMD_ERROR;
52
53 if (cargc==0) {
54 /* No args: "voice me on every channel you can */
55 ca=sender->channels->content;
56 for (i=0;i<sender->channels->cursi;i++) {
57 if ((rcp=ca[i]->index->exts[chanservext]) && !CIsSuspended(rcp)) {
58 /* It's a Q channel */
59 if (!(*(getnumerichandlefromchanhash(ca[i]->users, sender->numeric)) &
60 (CUMODE_OP|CUMODE_VOICE))) {
61 /* They're not opped or voiced */
62 rcup=findreguseronchannel(rcp, rup);
63 if ((!rcup || !CUIsQuiet(rcup)) &&
64 ((rcup && CUHasVoicePriv(rcup)) ||
65 (CIsVoiceAll(rcp)))) {
66 /* And they have voice priv on the chan (or it's autovoice):
67 * voice them */
68 localsetmodeinit(&changes, ca[i], chanservnick);
69 localdosetmode_nick(&changes, sender, MC_VOICE);
70 localsetmodeflush(&changes,1);
71 }
72 }
73 }
74 }
75
76 chanservstdmessage(sender, QM_DONE);
77 return CMD_OK;
78 }
79
80 /* If there is at least one arg, the first is a channel */
81
82 if (!(cip=cs_checkaccess(sender, cargv[0], CA_VOICEPRIV, NULL, "voice", 0, 0)))
83 return CMD_ERROR;
84
85 if (cargc==1) {
86 /* Only one arg: "voice me" */
87 if (!cs_checkaccess(sender, NULL, CA_VOICEPRIV | CA_DEVOICED, cip,
88 "voice", 0, 0))
89 return CMD_ERROR;
90
91 localsetmodeinit(&changes, cip->channel, chanservnick);
92 localdosetmode_nick(&changes, sender, MC_VOICE);
93 localsetmodeflush(&changes,1);
94
95 chanservstdmessage(sender, QM_DONE);
96 return CMD_OK;
97 }
98
99 /* You've got to be an operator to voice other people */
100 if (!cs_checkaccess(sender, NULL, CA_OPPRIV, cip, "voice", 0, 0))
101 return CMD_ERROR;
102
103 /* You've got to be a master to 'silently' voice other people */
104 if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "voice", 0, 1))
105 donotice=1;
106
107 rcp=cip->exts[chanservext];
108
109 /* Set up the modes */
110 localsetmodeinit(&changes, cip->channel, chanservnick);
111
112 for(i=1;i<cargc;i++) {
113 if (!(np=getnickbynick(cargv[i]))) {
114 chanservstdmessage(sender, QM_UNKNOWNUSER, cargv[i]);
115 continue;
116 }
117
118 if (!(lp=getnumerichandlefromchanhash(cip->channel->users, np->numeric))) {
119 chanservstdmessage(sender, QM_USERNOTONCHAN, np->nick, cip->name->content);
120 continue;
121 }
122
123 if (*lp & CUMODE_VOICE) {
124 chanservstdmessage(sender, QM_USERVOICEDONCHAN, np->nick, cip->name->content);
125 continue;
126 }
127
128 if ((rup=getreguserfromnick(np)) && (rcup=findreguseronchannel(rcp, rup)) && CUIsQuiet(rcup)) {
129 chanservstdmessage(sender, QM_CANTVOICE, np->nick, cip->name->content);
130 continue;
131 }
132
133 bufpos+=sprintf(buf+bufpos,"%s%s",bufpos?", ":"",np->nick);
134 localdosetmode_nick(&changes, np, MC_VOICE);
135 }
136
137 if (donotice && bufpos) {
138 sendopnoticetochannel(chanservnick, cip->channel, "%s voiced %s", sender, buf);
139 }
140
141 localsetmodeflush(&changes, 1);
142 chanservstdmessage(sender, QM_DONE);
143
144 return CMD_OK;
145 }