]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/chanflags.c
Merge chanserv-live into default.
[irc/quakenet/newserv.git] / chanserv / chancmds / chanflags.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: chanflags
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 2
7 * CMDDESC: Shows or changes the flags on a channel.
8 * CMDFUNC: csc_dochanflags
9 * CMDPROTO: int csc_dochanflags(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: CHANFLAGS <channel> [<changes>]
11 * CMDHELP: Shows or changes the status of channel flags, where:
12 * CMDHELP: channel - channel to use
13 * CMDHELP: changes - changes to apply to the channel flags in the usual +/- format, e.g. +c
14 * CMDHELP: to set +c and -c to remove it.
15 * CMDHELP: Viewing the current flags requires operator (+o) access on the named channel.
16 * CMDHELP: Changing the flags requires master (+m) access on the named channel.
17 * CMDHELP: Valid channel flags are:
18 * CMDHELP: +a AUTOOP Automatically ops any user who has op access when they join the
19 * CMDHELP: channel. Same effect as giving all ops the +a chanlev flag.
20 * CMDHELP: +b BITCH Prevents users who don't have operator access on the channel
21 * CMDHELP: from being opped (automatically deops them)
22 * CMDHELP: +c AUTOLIMIT Enables automatic limit feature - updates the channel limit at
23 * CMDHELP: regular intervals to keep a certain number of free spaces. This
24 * CMDHELP: can mitigate the effect of join floods. See AUTOLIMIT.
25 * CMDHELP: +e ENFORCE Enforces bans on the channel. Any user who is banned will be
26 * CMDHELP: kicked automatically.
27 * CMDHELP: +f FORCETOPIC Prevents channel ops from changing the topic. The SETTOPIC
28 * CMDHELP: command must be used instead.
29 * CMDHELP: +g AUTOVOICE Automatically voices any user who has voice access when they join
30 * CMDHELP: the channel. Same effect as giving all voices the +g chanlev flag.
31 * CMDHELP: +h ACH'MENTS Display achievement announcements in channel.
32 * CMDHELP: +j JOINED Causes Q to remain on the channel. Cannot be removed.
33 * CMDHELP: +k KNOWNONLY Any user who joins the channel who is not known (+k) will be kicked.
34 * CMDHELP: Unless channel mode +i is set they will be banned as well.
35 * CMDHELP: +p PROTECT Any user with voice (+v) or operator (+o) access will have that
36 * CMDHELP: status enforced on the channel at all times. Same effect as giving
37 * CMDHELP: all ops and voices the +p chanlev flag.
38 * CMDHELP: +t TOPICSAVE Saves the topic when it changes. Such saved topics can be restored
39 * CMDHELP: via settopic, or when the bot rejoins when a channel has been left
40 * CMDHELP: empty.
41 * CMDHELP: +v VOICEALL Automatically grants voice (+v) on the channel to any user who enters,
42 * CMDHELP: unless they have quiet (+q) chanlev flag.
43 * CMDHELP: +w WELCOME Sends the welcome message to users joining the channel. See WELCOME.
44 * CMDHELP: Note: Previous versions of Q included the facility to enforce limits and keys using
45 * CMDHELP: +k and +l chanflags. This functionality is now available via the CHANMODE command.
46 */
47
48 #include "../chanserv.h"
49 #include "../../nick/nick.h"
50 #include "../../lib/flags.h"
51 #include "../../lib/irc_string.h"
52 #include "../../channel/channel.h"
53 #include "../../parser/parser.h"
54 #include "../../irc/irc.h"
55 #include "../../localuser/localuserchannel.h"
56 #include <string.h>
57 #include <stdio.h>
58
59 int csc_dochanflags(void *source, int cargc, char **cargv) {
60 regchan *rcp;
61 nick *sender=source;
62 reguser *rup=getreguserfromnick(sender);
63 chanindex *cip;
64 flag_t oldflags,changemask;
65 char flagbuf[20];
66
67 if (cargc<1) {
68 chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"chanflags");
69 return CMD_ERROR;
70 }
71
72 if (!(cip=cs_checkaccess(sender, cargv[0], CA_OPPRIV, NULL,
73 "chanflags", QPRIV_VIEWCHANFLAGS, 0)))
74 return CMD_ERROR;
75
76 rcp=cip->exts[chanservext];
77
78 if (cargc>1) {
79 if (!cs_checkaccess(sender, NULL, CA_MASTERPRIV, cip, "chanflags",
80 QPRIV_CHANGECHANFLAGS, 0))
81 return CMD_ERROR;
82
83 oldflags=rcp->flags;
84 changemask=QCFLAG_USERCONTROL;
85
86 /* Disable achievements flag before April 1 */
87 if (time(NULL) < ACHIEVEMENTS_START)
88 changemask &= ~QCFLAG_ACHIEVEMENTS;
89
90 /* Developer override! */
91 if (UIsDev(rup)) {
92 changemask=QCFLAG_ALL;
93 }
94 setflags(&rcp->flags, changemask, cargv[1], rcflags, REJECT_NONE);
95
96 /* We might need to do things in response to the flag changes.. */
97 if (cip->channel) {
98 if ((oldflags ^ rcp->flags) & (QCFLAG_JOINED | QCFLAG_SUSPENDED)) {
99 chanservjoinchan(cip->channel);
100 rcp->status |= (QCSTAT_OPCHECK | QCSTAT_MODECHECK | QCSTAT_BANCHECK);
101 rcp->lastbancheck=0;
102 cs_timerfunc(cip);
103 } else {
104 if (CIsEnforce(rcp)) {
105 rcp->lastbancheck=0;
106 cs_checkbans(cip->channel);
107 }
108
109 if (CIsProtect(rcp) || CIsBitch(rcp) || CIsAutoOp(rcp) || CIsAutoVoice(rcp) || CIsKnownOnly(rcp)) {
110 rcp->status |= QCSTAT_OPCHECK;
111 cs_timerfunc(cip);
112 }
113 }
114 }
115
116 if (CIsAutoLimit(rcp) && !(oldflags & QCFLAG_AUTOLIMIT)) {
117 rcp->forcemodes |= CHANMODE_LIMIT;
118 rcp->denymodes &= ~CHANMODE_LIMIT;
119 rcp->limit=0;
120 cs_timerfunc(cip);
121 }
122
123 if (!CIsAutoLimit(rcp) && (oldflags & QCFLAG_AUTOLIMIT)) {
124 rcp->forcemodes &= ~CHANMODE_LIMIT;
125 if (cip->channel)
126 cs_checkchanmodes(cip->channel);
127 }
128
129 /* If nothing has changed, say so and don't do anything else */
130 if (rcp->flags == oldflags) {
131 chanservstdmessage(sender, QM_CHANLEVNOCHANGE);
132 return CMD_OK;
133 }
134
135 strcpy(flagbuf,printflags(oldflags, rcflags));
136 cs_log(sender,"CHANFLAGS %s %s (%s -> %s)",cip->name->content,cargv[1],flagbuf,printflags(rcp->flags,rcflags));
137 chanservstdmessage(sender, QM_DONE);
138 csdb_updatechannel(rcp);
139 }
140
141 chanservstdmessage(sender,QM_CURCHANFLAGS,cip->name->content,printflags(rcp->flags, rcflags));
142 return CMD_OK;
143 }