]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/chancmds/op.c
Merge chanserv-live into default.
[irc/quakenet/newserv.git] / chanserv / chancmds / op.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: op
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 20
7 * CMDDESC: Ops you or other users on channel(s).
8 * CMDFUNC: csc_doop
9 * CMDPROTO: int csc_doop(void *source, int cargc, char **cargv);
ab721714 10 * CMDHELP: Usage: OP [<channel> [<user1> [<user2> [...]]]]
1e32d528 11 * CMDHELP: Ops you on one or more channels, or ops other named users on a given channel.
12 * CMDHELP: This command cannot be used to op users who are otherwise prevented from getting
13 * CMDHELP: ops, e.g. via the +d chanlev flag (see CHANLEV) or bitch mode (see CHANFLAGS).
14 * CMDHELP: Where:
15 * CMDHELP: channel - channel to use. If no channel is specified, you will be given ops on
16 * CMDHELP: every channel where you have appropriate access and are not already
17 * CMDHELP: opped.
18 * CMDHELP: user<n> - user(s) to op instead of yourself. Each user must be specified as the
19 * CMDHELP: current nickname of a user on the named channel.
20 * CMDHELP: OP requires operator access (+o) on the named channel. If this command is used
21 * CMDHELP: to op other users, a notice will be sent to other channel operators on the
22 * CMDHELP: channel identifying you, unless you have master (+m) access.
1dd6d55d 23 */
24
25#include "../chanserv.h"
26#include "../../nick/nick.h"
27#include "../../lib/flags.h"
28#include "../../lib/irc_string.h"
29#include "../../channel/channel.h"
30#include "../../parser/parser.h"
31#include "../../irc/irc.h"
32#include "../../localuser/localuserchannel.h"
33#include <string.h>
34#include <stdio.h>
35
36int csc_doop(void *source, int cargc, char **cargv) {
37 nick *sender=source, *np;
38 reguser *rup=getreguserfromnick(sender);
1482fb78 39 reguser *srup=rup;
1dd6d55d 40 chanindex *cip;
41 regchan *rcp=NULL;
42 regchanuser *rcup;
43 channel **ca;
44 unsigned long *lp;
45 int i;
46 modechanges changes;
95332d7b 47 int donotice=0, bufpos=0;
48 char buf[512];
1dd6d55d 49
50 if (!rup)
51 return CMD_ERROR;
52
53 if (cargc==0) {
54 /* No args: "op 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)) {
61 /* They're not opped */
62 if ((rcup=findreguseronchannel(rcp, rup)) && CUHasOpPriv(rcup) &&
63 !CUIsDeny(rcup)) {
64 /* And they have op priv on the chan: op them */
65 localsetmodeinit(&changes, ca[i], chanservnick);
66 localdosetmode_nick(&changes, sender, MC_OP);
67 localsetmodeflush(&changes,1);
1482fb78 68 cs_logchanop(rcp, sender->nick, rup);
1dd6d55d 69 }
70 }
71 }
72 }
73
74 chanservstdmessage(sender, QM_DONE);
75 return CMD_OK;
76 }
77
78 /* If there is at least one arg, the first is a channel */
79
80 if (!(cip=cs_checkaccess(sender, cargv[0], CA_OPPRIV, NULL, "op", 0, 0)))
81 return CMD_ERROR;
82
83 rcp=cip->exts[chanservext];
9b1b30fc 84
85 /* If the channel doesn't currently exist, forget it. */
86 if (!cip->channel) {
87 chanservstdmessage(sender, QM_EMPTYCHAN, cip->name->content);
88 return CMD_ERROR;
89 }
1dd6d55d 90
91 if (cargc==1) {
92 /* Only one arg: "op me" */
93 if (!cs_checkaccess(sender, NULL, CA_OPPRIV | CA_DEOPPED, cip, "op", 0, 0))
94 return CMD_ERROR;
95
96 localsetmodeinit(&changes, cip->channel, chanservnick);
97 localdosetmode_nick(&changes, sender, MC_OP);
98 localsetmodeflush(&changes,1);
1482fb78 99 cs_logchanop(rcp, sender->nick, srup);
1dd6d55d 100
101 chanservstdmessage(sender, QM_DONE);
102 return CMD_OK;
103 }
104
70f98cd3 105 /* You've got to be a master to 'silently' op other people */
cabd7271 106 if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "op", 0, 1))
107 donotice=1;
70f98cd3 108
1dd6d55d 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_OP) {
124 chanservstdmessage(sender, QM_USEROPPEDONCHAN, np->nick, cip->name->content);
125 continue;
126 }
127
128 rup=getreguserfromnick(np);
129 if (rup)
130 rcup=findreguseronchannel(rcp,rup);
131 else
132 rcup=NULL;
133
134 /* Bitch mode: check that this user is allowed to be opped.. */
135 if ((CIsBitch(rcp) && (!rcup || !CUHasOpPriv(rcup))) || (rcup && CUIsDeny(rcup))) {
136 chanservstdmessage(sender, QM_CANTOP, np->nick, cip->name->content);
137 continue;
138 }
139
cabd7271 140 bufpos += sprintf(buf+bufpos,"%s%s",bufpos?", ":"",np->nick);
1dd6d55d 141 localdosetmode_nick(&changes, np, MC_OP);
1482fb78 142 cs_logchanop(rcp, np->nick, srup);
1dd6d55d 143 }
144
cabd7271 145 if (donotice && bufpos) {
16739dbe 146 sendopnoticetochannel(chanservnick, cip->channel, "%s opped %s", sender->nick, buf);
cabd7271 147 }
148
1dd6d55d 149 localsetmodeflush(&changes, 1);
150 chanservstdmessage(sender, QM_DONE);
151
152 return CMD_OK;
153}