]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/usercmds/suspenduser.c
CHANSERV: tidy up suspend/unsuspend wall/log messages.
[irc/quakenet/newserv.git] / chanserv / usercmds / suspenduser.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: suspenduser
5 * CMDLEVEL: QCMD_OPER
6 * CMDARGS: 1
7 * CMDDESC: Suspend/delay GLINE/instantly GLINE a user.
8 * CMDFUNC: csu_dosuspenduser
9 * CMDPROTO: int csu_dosuspenduser(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: suspenduser <username> [<duration>] <reason>
11 * CMDHELP: -nokill <username> [<duration>] <reason>
12 * CMDHELP: -gline <username> [<duration>] <reason>
13 * CMDHELP: -instantgline <username> [<duration>] <reason>
14 * CMDHELP: Suspends the user with the specified username.
15 * CMDHELP: By default the user will be immediately disconnected unless
16 * CMDHELP: nokill is specified.
17 * CMDHELP: gline will gline the user at some random period of time after
18 * CMDHELP: they auth, instantgline will gline them the moment they auth.
19 */
20
21 #include "../chanserv.h"
22 #include "../../lib/irc_string.h"
23 #include <stdio.h>
24 #include <string.h>
25
26 static int killtheusers(nick *sender, reguser *rup) {
27 int count=0;
28 authname *anp;
29
30 if (!(anp=findauthname(rup->ID)))
31 return 0;
32
33 while (anp->nicks) {
34 chanservstdmessage(sender, QM_DISCONNECTINGUSER, anp->nicks->nick, rup->username);
35 chanservkillstdmessage(anp->nicks, QM_SUSPENDKILL);
36 count++;
37 }
38
39 return count;
40 }
41
42 int csu_dosuspenduser(void *source, int cargc, char **cargv) {
43 nick *sender=source;
44 reguser *rup=getreguserfromnick(sender);
45 reguser *vrup;
46 char *flag;
47 char *victim;
48 char *dur_p;
49 char *reason, *stype;
50 int kill=1, gline=0;
51 time_t expires=0;
52 int duration=0;
53 char expiresbuf[TIMELEN]="";
54 int dgwait;
55
56 if (!rup)
57 return CMD_ERROR;
58
59 if (cargc < 1) {
60 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser");
61 return CMD_ERROR;
62 }
63
64 if (cargv[0][0] == '-') {
65 flag=cargv[0];
66 if (!(victim=strchr(flag, ' '))) {
67 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser");
68 return CMD_ERROR;
69 }
70 *(victim++)='\0';
71 if (!(dur_p=strchr(victim, ' '))) {
72 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser");
73 return CMD_ERROR;
74 }
75 *(dur_p++)='\0';
76 if ((reason=strchr(dur_p, ' '))) {
77 *(reason++)='\0';
78 if ((duration=durationtolong(dur_p))) {
79 if ((duration < 86400) || (duration > 2592000)) {
80 chanservstdmessage(sender, QM_INVALIDDURATION);
81 return CMD_ERROR;
82 }
83 expires=time(0)+duration;
84 }
85 else {
86 *(reason-1)=' ';
87 reason=dur_p;
88 expires=0;
89 }
90 }
91 else {
92 reason=dur_p;
93 expires=0;
94 }
95
96 if (!ircd_strcmp(flag, "-nokill")) {
97 kill=0;
98 }
99 else if (!ircd_strcmp(flag, "-gline")) {
100 gline=1;
101 }
102 else if (!ircd_strcmp(flag, "-instantgline")) {
103 gline=2;
104 }
105 else {
106 chanservstdmessage(sender, QM_INVALIDCHANLEVCHANGE);
107 return CMD_ERROR;
108 }
109 }
110 else {
111 victim=cargv[0];
112 if (!(dur_p=strchr(victim, ' '))) {
113 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser");
114 return CMD_ERROR;
115 }
116 *(dur_p++)='\0';
117 if ((reason=strchr(dur_p, ' '))) {
118 *(reason++)='\0';
119 if ((duration=durationtolong(dur_p))) {
120 if ((duration < 86400) || (duration > 2592000)) {
121 chanservstdmessage(sender, QM_INVALIDDURATION);
122 return CMD_ERROR;
123 }
124 expires=time(0)+duration;
125 }
126 else {
127 *(reason-1)=' ';
128 reason=dur_p;
129 expires=0;
130 }
131 }
132 else {
133 reason=dur_p;
134 expires=0;
135 }
136 }
137
138 if(!checkreason(sender, reason))
139 return CMD_ERROR;
140
141 if (expires)
142 q9strftime(expiresbuf,sizeof(expiresbuf),expires);
143
144 if (!(vrup=findreguser(sender, victim)))
145 return CMD_ERROR;
146
147 if (!ircd_strcmp(vrup->username, rup->username)) {
148 chanservsendmessage(sender, "You can't suspend yourself, silly.");
149 return CMD_ERROR;
150 }
151
152 if (UHasSuspension(vrup)) {
153 chanservstdmessage(sender, QM_USERALREADYSUSPENDED);
154 return CMD_ERROR;
155 }
156
157 if (UHasStaffPriv(vrup)) {
158 char buf[200];
159 snprintf(buf, sizeof(buf), "suspenduser on %s (reason: %s)", vrup->username, reason);
160 chanservstdmessage(sender, QM_NOACCESS, buf);
161 chanservwallmessage("%s (%s) FAILED to SUSPENDUSER %s (reason: %s)", sender->nick, rup->username, vrup->username, reason);
162 return CMD_ERROR;
163 }
164
165 if (gline == 2)
166 vrup->flags|=QUFLAG_GLINE;
167 else if (gline == 1)
168 vrup->flags|=QUFLAG_DELAYEDGLINE;
169 else
170 vrup->flags|=QUFLAG_SUSPENDED;
171 vrup->suspendby=rup->ID;
172 vrup->suspendexp=expires;
173 vrup->suspendtime=time(NULL);
174 vrup->suspendreason=getsstring(reason, strlen(reason)+1);
175
176 stype = (gline)?((gline == 2)?"instant gline":"delayed gline"):"normal";
177
178 chanservwallmessage("%s (%s) used SUSPENDUSER on %s, type: %s, expires: %s, reason: %s", sender->nick, rup->username, vrup->username, stype, expires?expiresbuf:"never", reason);
179 cs_log(sender, "SUSPENDUSER %s (%s, expires: %s, reason: %s)", vrup->username, stype, expires?expiresbuf:"never", reason);
180
181 if (gline) {
182 dgwait=(gline==2)?0:rand()%900;
183 chanservsendmessage(sender, "Scheduling delayed GLINE for account %s in %d %s",
184 vrup->username, (dgwait>60)?(dgwait/60):dgwait, (dgwait>60)?"minutes":"seconds");
185 deleteschedule(NULL, &chanservdgline, (void*)vrup);
186 scheduleoneshot(time(NULL)+dgwait, &chanservdgline, (void*)vrup);
187 }
188 else if (kill) {
189 killtheusers(sender,vrup);
190 }
191
192 csdb_updateuser(vrup);
193
194 return CMD_OK;
195 }