]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/op.c
Merge.
[irc/quakenet/newserv.git] / chanserv / chancmds / op.c
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);
10 * CMDHELP: Usage: OP [<channel> [<user1> [<user2> [...]]]
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.
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
36 int csc_doop(void *source, int cargc, char **cargv) {
37 nick *sender=source, *np;
38 reguser *rup=getreguserfromnick(sender);
39 reguser *srup=rup;
40 chanindex *cip;
41 regchan *rcp=NULL;
42 regchanuser *rcup;
43 channel **ca;
44 unsigned long *lp;
45 int i;
46 modechanges changes;
47 int donotice=0, bufpos=0;
48 char buf[512];
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);
68 cs_logchanop(rcp, sender->nick, rup);
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];
84
85 if (cargc==1) {
86 /* Only one arg: "op me" */
87 if (!cs_checkaccess(sender, NULL, CA_OPPRIV | CA_DEOPPED, cip, "op", 0, 0))
88 return CMD_ERROR;
89
90 localsetmodeinit(&changes, cip->channel, chanservnick);
91 localdosetmode_nick(&changes, sender, MC_OP);
92 localsetmodeflush(&changes,1);
93 cs_logchanop(rcp, sender->nick, srup);
94
95 chanservstdmessage(sender, QM_DONE);
96 return CMD_OK;
97 }
98
99 /* You've got to be a master to 'silently' op other people */
100 if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "op", 0, 1))
101 donotice=1;
102
103 /* Set up the modes */
104 localsetmodeinit(&changes, cip->channel, chanservnick);
105
106 for(i=1;i<cargc;i++) {
107 if (!(np=getnickbynick(cargv[i]))) {
108 chanservstdmessage(sender, QM_UNKNOWNUSER, cargv[i]);
109 continue;
110 }
111
112 if (!(lp=getnumerichandlefromchanhash(cip->channel->users, np->numeric))) {
113 chanservstdmessage(sender, QM_USERNOTONCHAN, np->nick, cip->name->content);
114 continue;
115 }
116
117 if (*lp & CUMODE_OP) {
118 chanservstdmessage(sender, QM_USEROPPEDONCHAN, np->nick, cip->name->content);
119 continue;
120 }
121
122 rup=getreguserfromnick(np);
123 if (rup)
124 rcup=findreguseronchannel(rcp,rup);
125 else
126 rcup=NULL;
127
128 /* Bitch mode: check that this user is allowed to be opped.. */
129 if ((CIsBitch(rcp) && (!rcup || !CUHasOpPriv(rcup))) || (rcup && CUIsDeny(rcup))) {
130 chanservstdmessage(sender, QM_CANTOP, np->nick, cip->name->content);
131 continue;
132 }
133
134 bufpos += sprintf(buf+bufpos,"%s%s",bufpos?", ":"",np->nick);
135 localdosetmode_nick(&changes, np, MC_OP);
136 cs_logchanop(rcp, np->nick, srup);
137 }
138
139 if (donotice && bufpos) {
140 sendopnoticetochannel(chanservnick, cip->channel, "%s opped %s", sender, buf);
141 }
142
143 localsetmodeflush(&changes, 1);
144 chanservstdmessage(sender, QM_DONE);
145
146 return CMD_OK;
147 }