]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/permban.c
Implement --help parameter.
[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 freechanban(b);
89 chanservstdmessage(sender, QM_TOOMANYBANS);
90 return CMD_ERROR;
91 }
92
93 if(toreplace) {
94 freechanban(b);
95 chanservstdmessage(sender, QM_REPLACINGTEMPBAN);
96
97 rbp=toreplace;
98 if(rbp->reason)
99 freesstring(toreplace->reason);
100 } else {
101 rbp=getregban();
102 rbp->ID=++lastbanID;
103 rbp->cbp=b;
104
105 rbp->next=rcp->bans;
106 rcp->bans=rbp;
107 }
108
109 rbp->setby=rup->ID;
110 rbp->expiry=0;
111 if (cargc>2)
112 rbp->reason=getsstring(cargv[2],200);
113 else
114 rbp->reason=NULL;
115
116 cs_setregban(cip, rbp);
117 if(toreplace) {
118 csdb_updateban(rcp, rbp);
119 } else {
120 csdb_createban(rcp, rbp);
121 }
122 chanservstdmessage(sender, QM_DONE);
123 return CMD_OK;
124 }