]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 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); | |
ab721714 | 10 | * CMDHELP: Usage: VOICE [<channel> [<user1> [<user2> [...]]]] |
1e32d528 | 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. | |
1dd6d55d | 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; | |
1e32d528 | 47 | char buf[512]; |
48 | unsigned int bufpos=0,donotice=0; | |
1dd6d55d | 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 | ||
9b1b30fc | 85 | if (!cip->channel) { |
86 | chanservstdmessage(sender, QM_EMPTYCHAN, cip->name->content); | |
87 | return CMD_ERROR; | |
88 | } | |
89 | ||
1dd6d55d | 90 | if (cargc==1) { |
91 | /* Only one arg: "voice me" */ | |
92 | if (!cs_checkaccess(sender, NULL, CA_VOICEPRIV | CA_DEVOICED, cip, | |
93 | "voice", 0, 0)) | |
94 | return CMD_ERROR; | |
95 | ||
96 | localsetmodeinit(&changes, cip->channel, chanservnick); | |
97 | localdosetmode_nick(&changes, sender, MC_VOICE); | |
98 | localsetmodeflush(&changes,1); | |
99 | ||
100 | chanservstdmessage(sender, QM_DONE); | |
101 | return CMD_OK; | |
102 | } | |
103 | ||
1e32d528 | 104 | /* You've got to be an operator to voice other people */ |
105 | if (!cs_checkaccess(sender, NULL, CA_OPPRIV, cip, "voice", 0, 0)) | |
1dd6d55d | 106 | return CMD_ERROR; |
107 | ||
1e32d528 | 108 | /* You've got to be a master to 'silently' voice other people */ |
109 | if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "voice", 0, 1)) | |
110 | donotice=1; | |
111 | ||
1dd6d55d | 112 | rcp=cip->exts[chanservext]; |
113 | ||
114 | /* Set up the modes */ | |
115 | localsetmodeinit(&changes, cip->channel, chanservnick); | |
116 | ||
117 | for(i=1;i<cargc;i++) { | |
118 | if (!(np=getnickbynick(cargv[i]))) { | |
119 | chanservstdmessage(sender, QM_UNKNOWNUSER, cargv[i]); | |
120 | continue; | |
121 | } | |
122 | ||
123 | if (!(lp=getnumerichandlefromchanhash(cip->channel->users, np->numeric))) { | |
124 | chanservstdmessage(sender, QM_USERNOTONCHAN, np->nick, cip->name->content); | |
125 | continue; | |
126 | } | |
127 | ||
128 | if (*lp & CUMODE_VOICE) { | |
129 | chanservstdmessage(sender, QM_USERVOICEDONCHAN, np->nick, cip->name->content); | |
130 | continue; | |
131 | } | |
132 | ||
133 | if ((rup=getreguserfromnick(np)) && (rcup=findreguseronchannel(rcp, rup)) && CUIsQuiet(rcup)) { | |
134 | chanservstdmessage(sender, QM_CANTVOICE, np->nick, cip->name->content); | |
135 | continue; | |
136 | } | |
1e32d528 | 137 | |
138 | bufpos+=sprintf(buf+bufpos,"%s%s",bufpos?", ":"",np->nick); | |
1dd6d55d | 139 | localdosetmode_nick(&changes, np, MC_VOICE); |
140 | } | |
141 | ||
1e32d528 | 142 | if (donotice && bufpos) { |
16739dbe | 143 | sendopnoticetochannel(chanservnick, cip->channel, "%s voiced %s", sender->nick, buf); |
1e32d528 | 144 | } |
145 | ||
1dd6d55d | 146 | localsetmodeflush(&changes, 1); |
147 | chanservstdmessage(sender, QM_DONE); | |
148 | ||
149 | return CMD_OK; | |
150 | } |