]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/permban.c
CHANSERV: HACK: tempban/permban limits are now 20x normal if founder is an IRC operator
[irc/quakenet/newserv.git] / chanserv / chancmds / permban.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: permban
5 * CMDALIASES: ban
6 * CMDLEVEL: QCMD_AUTHED
7 * CMDARGS: 3
8 * CMDDESC: Permanently bans a hostmask on a channel.
9 * CMDFUNC: csc_dopermban
10 * CMDPROTO: int csc_dopermban(void *source, int cargc, char **cargv);
11 * CMDHELP: Usage: @UCOMMAND@ <channel> <hostmask> [<reason>]
12 * CMDHELP: Permanently bans the provided hostmask on the channel. If the ban is
13 * CMDHELP: removed from the channel e.g. by a channel op or the BANTIMER feature, the
14 * CMDHELP: ban will be reapplied if a matching user joins the channel. Bans
15 * CMDHELP: set with the @UCOMMAND@ command can be removed with BANCLEAR or BANDEL. Any users
16 * CMDHELP: matching the hostmask will be kicked from the channel.
17 * CMDHELP: Where:
18 * CMDHELP: channel - channel to set a ban on
19 * CMDHELP: hostmask - hostmask (nick!user@host) to ban.
20 * CMDHELP: reason - reason for the ban. This will be used in kick messages when kicking
21 * CMDHELP: users matching the ban. If this is not provided the generic message
22 * CMDHELP: \"Banned.\" will be used.
23 * CMDHELP: @UCOMMAND@ requires master (+m) access on the named channel.
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_dopermban(void *source, int cargc, char **cargv) {
38 nick *sender=source;
39 chanindex *cip;
40 regban *rbp, *toreplace=NULL;
41 regchan *rcp;
42 reguser *rup=getreguserfromnick(sender);
43 struct chanban *b;
44 char banbuf[1024];
45 unsigned int count = 0;
46
47 if (cargc<2) {
48 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "permban");
49 return CMD_ERROR;
50 }
51
52 if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "permban",0, 0)))
53 return CMD_ERROR;
54
55 rcp=cip->exts[chanservext];
56
57 /* saves us having to do repeat a LOT more sanity checking *wink* *wink* */
58 b=makeban(cargv[1]);
59 snprintf(banbuf,sizeof(banbuf),"%s",bantostring(b));
60 freechanban(b);
61 b=makeban(banbuf);
62
63 for(rbp=rcp->bans;rbp;rbp=rbp->next) {
64 count++;
65 if(banequal(b,rbp->cbp)) { /* if they're equal and one is temporary we just replace it */
66 if(rbp->expiry) {
67 if(toreplace) { /* shouldn't happen */
68 chanservsendmessage(sender, "Internal error, duplicate bans found on banlist.");
69 } else {
70 toreplace=rbp;
71 continue;
72 }
73 } else {
74 chanservstdmessage(sender, QM_PERMBANALREADYSET);
75 }
76 } else if(banoverlap(rbp->cbp,b)) { /* new ban is contained in an already existing one */
77 chanservstdmessage(sender, QM_NEWBANALREADYBANNED, bantostring(rbp->cbp));
78 }else if(banoverlap(b,rbp->cbp)) { /* existing ban is contained in new one */
79 chanservstdmessage(sender, QM_NEWBANOVERLAPS, bantostring(rbp->cbp), banbuf);
80 } else {
81 continue;
82 }
83 freechanban(b);
84 return CMD_ERROR;
85 }
86
87 if(count >= MAXBANS) {
88 /* HACK: oper founder channels have 20x the ban limit */
89 reguser *founder=findreguserbyID(rcp->founder);
90 if(!founder || !UHasOperPriv(founder) || count >= MAXBANS * 20) {
91 freechanban(b);
92 chanservstdmessage(sender, QM_TOOMANYBANS);
93 return CMD_ERROR;
94 }
95 }
96
97 if(toreplace) {
98 freechanban(b);
99 chanservstdmessage(sender, QM_REPLACINGTEMPBAN);
100
101 rbp=toreplace;
102 if(rbp->reason)
103 freesstring(toreplace->reason);
104 } else {
105 rbp=getregban();
106 rbp->ID=++lastbanID;
107 rbp->cbp=b;
108
109 rbp->next=rcp->bans;
110 rcp->bans=rbp;
111 }
112
113 rbp->setby=rup->ID;
114 rbp->expiry=0;
115 if (cargc>2)
116 rbp->reason=getsstring(cargv[2],200);
117 else
118 rbp->reason=NULL;
119
120 cs_setregban(cip, rbp);
121 if(toreplace) {
122 csdb_updateban(rcp, rbp);
123 } else {
124 csdb_createban(rcp, rbp);
125 }
126 chanservstdmessage(sender, QM_DONE);
127 return CMD_OK;
128 }