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