]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: permban | |
61f1d196 | 5 | * CMDALIASES: ban |
1dd6d55d | 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); | |
61f1d196 | 11 | * CMDHELP: Usage: @UCOMMAND@ <channel> <hostmask> [<reason>] |
1e32d528 | 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 | |
61f1d196 | 15 | * CMDHELP: set with the @UCOMMAND@ command can be removed with BANCLEAR or BANDEL. Any users |
1e32d528 | 16 | * CMDHELP: matching the hostmask will be kicked from the channel. |
17 | * CMDHELP: Where: | |
18 | * CMDHELP: channel - channel to set a ban on | |
3fbc2554 | 19 | * CMDHELP: hostmask - hostmask (nick!user@host) to ban. |
1e32d528 | 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. | |
61f1d196 | 23 | * CMDHELP: @UCOMMAND@ requires master (+m) access on the named channel. |
1dd6d55d | 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; | |
3fbc2554 | 40 | regban *rbp, *toreplace=NULL; |
1dd6d55d | 41 | regchan *rcp; |
42 | reguser *rup=getreguserfromnick(sender); | |
3fbc2554 | 43 | struct chanban *b; |
bccd3d6a | 44 | char banbuf[1024]; |
705542fa | 45 | unsigned int count = 0; |
1dd6d55d | 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 | ||
bccd3d6a | 57 | /* saves us having to do repeat a LOT more sanity checking *wink* *wink* */ |
3fbc2554 | 58 | b=makeban(cargv[1]); |
bccd3d6a CP |
59 | snprintf(banbuf,sizeof(banbuf),"%s",bantostring(b)); |
60 | freechanban(b); | |
61 | b=makeban(banbuf); | |
3fbc2554 CP |
62 | |
63 | for(rbp=rcp->bans;rbp;rbp=rbp->next) { | |
705542fa | 64 | count++; |
3fbc2554 CP |
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 */ | |
bccd3d6a | 79 | chanservstdmessage(sender, QM_NEWBANOVERLAPS, bantostring(rbp->cbp), banbuf); |
3fbc2554 CP |
80 | } else { |
81 | continue; | |
82 | } | |
83 | freechanban(b); | |
84 | return CMD_ERROR; | |
85 | } | |
86 | ||
705542fa CP |
87 | if(count >= MAXBANS) { |
88 | freechanban(b); | |
89 | chanservstdmessage(sender, QM_TOOMANYBANS); | |
90 | return CMD_ERROR; | |
91 | } | |
92 | ||
3fbc2554 CP |
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 | ||
1dd6d55d | 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; | |
1dd6d55d | 115 | |
116 | cs_setregban(cip, rbp); | |
3fbc2554 CP |
117 | if(toreplace) { |
118 | csdb_updateban(rcp, rbp); | |
119 | } else { | |
120 | csdb_createban(rcp, rbp); | |
121 | } | |
1dd6d55d | 122 | chanservstdmessage(sender, QM_DONE); |
123 | return CMD_OK; | |
124 | } |