]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/chancmds/tempban.c
Ported requestowner from an old branch and removed some of it's former cretinism.
[irc/quakenet/newserv.git] / chanserv / chancmds / tempban.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: tempban
5 * CMDLEVEL: QCMD_AUTHED
6 * CMDARGS: 4
7 * CMDDESC: Bans a hostmask on a channel for a specified time period.
8 * CMDFUNC: csc_dotempban
9 * CMDPROTO: int csc_dotempban(void *source, int cargc, char **cargv);
1e32d528 10 * CMDHELP: Usage: TEMPBAN <channel> <hostmask> <duration> [<reason>]
11 * CMDHELP: Temporarily 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. When the time
14 * CMDHELP: expires the ban will be removed automatically. Bans set with the PERMBAN
15 * CMDHELP: command can be removed via BANCLEAR or BANDEL. Any users matching the hostmask
16 * CMDHELP: 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: duration - length of time to apply the ban for. Suffixes m (minutes), h (hours),
21 * CMDHELP: d (days), w (weeks), M (months) and y (years) can be used to specify
22 * CMDHELP: the duration, for example 3d, 5h, 1h30m, 1M.
23 * CMDHELP: reason - reason for the ban. This will be used in kick messages when kicking
24 * CMDHELP: users matching the ban. If this is not provided the generic message
25 * CMDHELP: \"Banned.\" will be used.
26 * CMDHELP: TEMPBAN requires master (+m) access on the named channel.
1dd6d55d 27 */
28
29#include "../chanserv.h"
30#include "../../nick/nick.h"
31#include "../../lib/flags.h"
32#include "../../lib/irc_string.h"
33#include "../../channel/channel.h"
34#include "../../parser/parser.h"
35#include "../../irc/irc.h"
36#include "../../localuser/localuserchannel.h"
37#include <string.h>
38#include <stdio.h>
39
40int csc_dotempban(void *source, int cargc, char **cargv) {
41 nick *sender=source;
42 chanindex *cip;
189772f2 43 regban *rbp, *toreplace = NULL;
1dd6d55d 44 regchan *rcp;
45 reguser *rup=getreguserfromnick(sender);
46 unsigned int duration;
3fbc2554 47 struct chanban *b;
1dd6d55d 48
49 if (cargc<3) {
50 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "tempban");
51 return CMD_ERROR;
52 }
53
54 if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, NULL, "tempban",0, 0)))
55 return CMD_ERROR;
56
57 rcp=cip->exts[chanservext];
58
59 duration=durationtolong(cargv[2]);
cabd7271 60 if (duration > 400000000) {
61 chanservstdmessage(sender, QM_DURATIONTOOLONG, cargv[2]);
62 return CMD_ERROR;
63 }
189772f2
CP
64 duration+=time(NULL);
65
3fbc2554
CP
66 b=makeban(cargv[1]);
67 for(rbp=rcp->bans;rbp;rbp=rbp->next) {
68 if(banequal(b,rbp->cbp)) {
189772f2
CP
69 if(rbp->expiry && (duration > rbp->expiry)) {
70 if(toreplace) { /* shouldn't happen */
71 chanservsendmessage(sender, "Internal error, duplicate bans found on banlist.");
72 } else {
73 toreplace=rbp;
74 continue;
75 }
76 } else {
77 chanservstdmessage(sender, QM_NOTREPLACINGBANLDURATION);
78 }
3fbc2554
CP
79 } else if(banoverlap(rbp->cbp,b)) {
80 chanservstdmessage(sender, QM_NEWBANALREADYBANNED, bantostring(rbp->cbp));
81 } else if(banoverlap(b,rbp->cbp)) {
82 chanservstdmessage(sender, QM_NEWBANOVERLAPS, bantostring(rbp->cbp), cargv[1]);
83 } else {
84 continue;
85 }
86
87 freechanban(b);
88 return CMD_ERROR;
89 }
90
189772f2
CP
91 if(toreplace) {
92 freechanban(b);
93 chanservstdmessage(sender, QM_REPLACINGBANSDURATION);
94 rbp=toreplace;
95 if(rbp->reason)
96 freesstring(toreplace->reason);
97 } else {
98 rbp=getregban();
99 rbp->ID=++lastbanID;
100 rbp->cbp=b;
101
102 rbp->next=rcp->bans;
103 rcp->bans=rbp;
104 }
105
1dd6d55d 106 rbp->setby=rup->ID;
189772f2 107 rbp->expiry=duration;
1dd6d55d 108 if (cargc>3)
109 rbp->reason=getsstring(cargv[3],200);
110 else
111 rbp->reason=NULL;
1dd6d55d 112
113 cs_setregban(cip, rbp);
189772f2
CP
114 if(toreplace) {
115 csdb_updateban(rcp, rbp);
116 } else {
117 csdb_createban(rcp, rbp);
118 }
1dd6d55d 119
120 chanservstdmessage(sender, QM_DONE);
121 return CMD_OK;
122}