]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 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); | |
1e32d528 | 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 | |
3fbc2554 | 18 | * CMDHELP: hostmask - hostmask (nick!user@host) to ban. |
1e32d528 | 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. | |
1dd6d55d | 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; | |
3fbc2554 | 39 | regban *rbp, *toreplace=NULL; |
1dd6d55d | 40 | regchan *rcp; |
41 | reguser *rup=getreguserfromnick(sender); | |
3fbc2554 | 42 | struct chanban *b; |
1dd6d55d | 43 | |
44 | if (cargc<2) { | |
45 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "permban"); | |
46 | return CMD_ERROR; | |
47 | } | |
48 | ||
49 | if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "permban",0, 0))) | |
50 | return CMD_ERROR; | |
51 | ||
52 | rcp=cip->exts[chanservext]; | |
53 | ||
3fbc2554 CP |
54 | b=makeban(cargv[1]); |
55 | ||
56 | for(rbp=rcp->bans;rbp;rbp=rbp->next) { | |
57 | if(banequal(b,rbp->cbp)) { /* if they're equal and one is temporary we just replace it */ | |
58 | if(rbp->expiry) { | |
59 | if(toreplace) { /* shouldn't happen */ | |
60 | chanservsendmessage(sender, "Internal error, duplicate bans found on banlist."); | |
61 | } else { | |
62 | toreplace=rbp; | |
63 | continue; | |
64 | } | |
65 | } else { | |
66 | chanservstdmessage(sender, QM_PERMBANALREADYSET); | |
67 | } | |
68 | } else if(banoverlap(rbp->cbp,b)) { /* new ban is contained in an already existing one */ | |
69 | chanservstdmessage(sender, QM_NEWBANALREADYBANNED, bantostring(rbp->cbp)); | |
70 | }else if(banoverlap(b,rbp->cbp)) { /* existing ban is contained in new one */ | |
71 | chanservstdmessage(sender, QM_NEWBANOVERLAPS, bantostring(rbp->cbp), cargv[1]); | |
72 | } else { | |
73 | continue; | |
74 | } | |
75 | freechanban(b); | |
76 | return CMD_ERROR; | |
77 | } | |
78 | ||
79 | if(toreplace) { | |
80 | freechanban(b); | |
81 | chanservstdmessage(sender, QM_REPLACINGTEMPBAN); | |
82 | ||
83 | rbp=toreplace; | |
84 | if(rbp->reason) | |
85 | freesstring(toreplace->reason); | |
86 | } else { | |
87 | rbp=getregban(); | |
88 | rbp->ID=++lastbanID; | |
89 | rbp->cbp=b; | |
90 | ||
91 | rbp->next=rcp->bans; | |
92 | rcp->bans=rbp; | |
93 | } | |
94 | ||
1dd6d55d | 95 | rbp->setby=rup->ID; |
96 | rbp->expiry=0; | |
97 | if (cargc>2) | |
98 | rbp->reason=getsstring(cargv[2],200); | |
99 | else | |
100 | rbp->reason=NULL; | |
1dd6d55d | 101 | |
102 | cs_setregban(cip, rbp); | |
3fbc2554 CP |
103 | if(toreplace) { |
104 | csdb_updateban(rcp, rbp); | |
105 | } else { | |
106 | csdb_createban(rcp, rbp); | |
107 | } | |
1dd6d55d | 108 | chanservstdmessage(sender, QM_DONE); |
109 | return CMD_OK; | |
110 | } |