]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/recover.c
Update README.
[irc/quakenet/newserv.git] / chanserv / chancmds / recover.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: recover
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 1
7 * CMDDESC: Recovers a channel (same as deopall, unbanall, clearchan).
8 * CMDFUNC: csc_dorecover
9 * CMDPROTO: int csc_dorecover(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: RECOVER <channel>
11 * CMDHELP: This command resets the named channel if undesired modes, bans or ops have been
12 * CMDHELP: set. This has the same effect as DEOPALL followed by UNBANALL followed by
13 * CMDHELP: CLEARCHAN on the channel, where:
14 * CMDHELP: channel - channel to recover
15 * CMDHELP: RECOVER requires master (+m) access on the named channel.
16 */
17
18 #include "../chanserv.h"
19 #include "../../nick/nick.h"
20 #include "../../lib/flags.h"
21 #include "../../lib/irc_string.h"
22 #include "../../channel/channel.h"
23 #include "../../parser/parser.h"
24 #include "../../irc/irc.h"
25 #include "../../localuser/localuserchannel.h"
26 #include <string.h>
27 #include <stdio.h>
28
29 static int nickmatchban_peerthroughhidehost(void *arg, struct chanban *ban) {
30 return nickmatchban(arg, ban, 0);
31 }
32
33 int csc_dorecover(void *source, int cargc, char **cargv) {
34 nick *sender=source,*np;
35 reguser *rup;
36 regchanuser *rcup;
37 regchan *rcp;
38 chanindex *cip;
39 unsigned long *lp;
40 int i;
41 modechanges changes;
42
43 if (cargc<1) {
44 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "recover");
45 return CMD_ERROR;
46 }
47
48 if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "recover",0, 0)))
49 return CMD_ERROR;
50
51 rcp=cip->exts[chanservext];
52
53 if (cip->channel) {
54 localsetmodeinit(&changes, cip->channel, chanservnick);
55
56 /* clearchan */
57 localdosetmode_key(&changes, NULL, MCB_DEL);
58 localdosetmode_simple(&changes, 0, cip->channel->flags);
59 cs_docheckchanmodes(cip->channel, &changes);
60
61 /* unbanall */
62 while (cip->channel->bans) {
63 localdosetmode_ban(&changes, bantostring(cip->channel->bans), MCB_DEL);
64 }
65
66 /* remove the registered bans that match on me */
67 cs_unbanfn(sender, cip, nickmatchban_peerthroughhidehost, sender, 1, 0);
68
69 /* deopall */
70 for (i=0,lp=cip->channel->users->content;
71 i<cip->channel->users->hashsize;i++,lp++) {
72 if (*lp!=nouser && (*lp & CUMODE_OP)) {
73 if (!(np=getnickbynumeric(*lp)) ||
74 (!IsService(np) && (!(rup=getreguserfromnick(np)) ||
75 !(rcup=findreguseronchannel(rcp, rup)) || !(CUHasOpPriv(rcup)) ||
76 !(CUIsProtect(rcup) || CIsProtect(rcp))))) {
77 localdosetmode_nick(&changes, np, MC_DEOP);
78 }
79 }
80 }
81
82 localsetmodeflush(&changes, 1);
83 }
84
85 cs_log(sender,"RECOVER %s",cip->name->content);
86 chanservstdmessage(sender, QM_DONE);
87 return CMD_OK;
88 }