]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | /* |
2 | * This contains Q9's "built in" commands and CTCP handlers | |
3 | */ | |
4 | ||
5 | #include "chanserv.h" | |
6 | #include "../core/schedule.h" | |
7 | #include "../lib/irc_string.h" | |
ee8cd7d0 | 8 | #include "../dbapi/dbapi.h" |
c86edd1d Q |
9 | |
10 | #include <string.h> | |
ee8cd7d0 | 11 | #include <stdio.h> |
c86edd1d Q |
12 | |
13 | int cs_dorehash(void *source, int cargc, char **cargv) { | |
14 | nick *sender=source; | |
15 | Command *cmdlist[200]; | |
16 | int i,n; | |
17 | ||
18 | /* Reload the response text first */ | |
19 | loadmessages(); | |
20 | ||
21 | /* Now the commands */ | |
22 | n=getcommandlist(cscommands, cmdlist, 200); | |
23 | ||
24 | for(i=0;i<n;i++) | |
25 | loadcommandsummary(cmdlist[i]); | |
26 | ||
27 | chanservstdmessage(sender, QM_DONE); | |
28 | ||
29 | return CMD_OK; | |
30 | } | |
31 | ||
32 | int cs_doquit(void *source, int cargc, char **cargv) { | |
33 | char *reason="Leaving"; | |
34 | nick *sender=(nick *)source; | |
35 | ||
36 | if (cargc>0) { | |
37 | reason=cargv[0]; | |
38 | } | |
39 | ||
40 | chanservstdmessage(sender, QM_DONE); | |
41 | ||
42 | deregisterlocaluser(chanservnick, reason); | |
43 | scheduleoneshot(time(NULL)+1,&chanservreguser,NULL); | |
44 | ||
45 | return CMD_OK; | |
46 | } | |
47 | ||
9ecce0e8 | 48 | int cs_dosetquitreason(void *source, int cargc, char **cargv) { |
49 | nick *sender=(nick *)source; | |
50 | ||
51 | if (cargc<0) { | |
52 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "setquitreason"); | |
53 | return CMD_ERROR; | |
54 | } | |
55 | ||
56 | if (cs_quitreason) | |
57 | freesstring(cs_quitreason); | |
58 | ||
4c5a359a | 59 | cs_quitreason=getsstring(cargv[0], 250); |
9ecce0e8 | 60 | |
61 | chanservstdmessage(sender, QM_DONE); | |
62 | ||
63 | return CMD_OK; | |
64 | } | |
65 | ||
c86edd1d Q |
66 | int cs_dorename(void *source, int cargc, char **cargv) { |
67 | char newnick[NICKLEN+1]; | |
68 | nick *sender=source; | |
69 | ||
70 | if (cargc<1) { | |
71 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "rename"); | |
72 | return CMD_ERROR; | |
73 | } | |
74 | ||
75 | strncpy(newnick,cargv[0],NICKLEN); | |
76 | newnick[NICKLEN]='\0'; | |
77 | ||
78 | renamelocaluser(chanservnick, newnick); | |
79 | chanservstdmessage(sender, QM_DONE); | |
80 | ||
81 | return CMD_OK; | |
82 | } | |
83 | ||
84 | int cs_doshowcommands(void *source, int cargc, char **cargv) { | |
85 | nick *sender=source; | |
86 | reguser *rup; | |
87 | Command *cmdlist[200]; | |
88 | int i,n; | |
89 | int lang; | |
90 | char *message; | |
91 | cmdsummary *summary; | |
50ec21f3 | 92 | char cmdbuf[50]; |
93 | char *ct; | |
d0c8f269 | 94 | unsigned int dumpcount=0; |
c86edd1d Q |
95 | |
96 | n=getcommandlist(cscommands, cmdlist, 200); | |
97 | rup=getreguserfromnick(sender); | |
98 | ||
99 | if (!rup) | |
100 | lang=0; | |
101 | else | |
102 | lang=rup->languageid; | |
103 | ||
104 | chanservstdmessage(sender, QM_COMMANDLIST); | |
105 | ||
d0c8f269 | 106 | if (cargc>0 && rup && UIsDev(rup) && !ircd_strcmp(cargv[0], "-v")) { |
107 | dumpcount=1; | |
108 | } | |
109 | ||
c86edd1d | 110 | for (i=0;i<n;i++) { |
d0c8f269 | 111 | /* Generate the appropriate strings for the command name (including |
112 | * prefixes for privileged users) and the summary text. | |
113 | * | |
114 | * We do this before we're sure we will print the command to make things | |
115 | * easier when we are doing -v */ | |
116 | summary=(cmdsummary *)cmdlist[i]->ext; | |
117 | ||
118 | if (rup && UHasStaffPriv(rup)) { | |
119 | if (cmdlist[i]->level & QCMD_DEV) { | |
120 | sprintf(cmdbuf,"+d %s",cmdlist[i]->command->content); | |
121 | } else if(cmdlist[i]->level & QCMD_ADMIN) { | |
122 | sprintf(cmdbuf,"+a %s",cmdlist[i]->command->content); | |
123 | } else if(cmdlist[i]->level & QCMD_OPER) { | |
124 | sprintf(cmdbuf,"+o %s",cmdlist[i]->command->content); | |
125 | } else if(cmdlist[i]->level & QCMD_HELPER) { | |
126 | sprintf(cmdbuf,"+h %s",cmdlist[i]->command->content); | |
127 | } else if(cmdlist[i]->level & QCMD_STAFF) { | |
128 | sprintf(cmdbuf,"+q %s",cmdlist[i]->command->content); | |
129 | } else { | |
130 | sprintf(cmdbuf," %s",cmdlist[i]->command->content); | |
131 | } | |
132 | ct=cmdbuf; | |
133 | } else { | |
134 | ct=cmdlist[i]->command->content; | |
135 | } | |
136 | ||
137 | if (summary->bylang[lang]) { | |
138 | message=summary->bylang[lang]->content; | |
139 | } else if (summary->bylang[0]) { | |
140 | message=summary->bylang[0]->content; | |
141 | } else { | |
142 | message=summary->def->content; | |
143 | } | |
144 | ||
145 | if (dumpcount) { | |
146 | chanservsendmessage(sender,"%-20s %u", cmdbuf, cmdlist[i]->calls); | |
147 | continue; | |
148 | } | |
43583524 | 149 | |
c86edd1d Q |
150 | if (cargc>0 && !match2strings(cargv[0],cmdlist[i]->command->content)) |
151 | continue; | |
152 | ||
153 | /* Don't list aliases */ | |
154 | if (cmdlist[i]->level & QCMD_ALIAS) | |
155 | continue; | |
156 | ||
157 | /* Check that this user can use this command.. */ | |
158 | if ((cmdlist[i]->level & QCMD_AUTHED) && !rup) | |
159 | continue; | |
160 | ||
161 | if ((cmdlist[i]->level & QCMD_NOTAUTHED) && rup) | |
162 | continue; | |
163 | ||
7be5f783 CP |
164 | if ((cmdlist[i]->level & QCMD_STAFF) && |
165 | (!rup || !UHasStaffPriv(rup))) | |
166 | continue; | |
167 | ||
c86edd1d Q |
168 | if ((cmdlist[i]->level & QCMD_HELPER) && |
169 | (!rup || !UHasHelperPriv(rup))) | |
170 | continue; | |
171 | ||
172 | if ((cmdlist[i]->level & QCMD_OPER) && | |
173 | (!rup || !UHasOperPriv(rup) || !IsOper(sender))) | |
174 | continue; | |
175 | ||
176 | if ((cmdlist[i]->level & QCMD_ADMIN) && | |
177 | (!rup || !UHasAdminPriv(rup) || !IsOper(sender))) | |
178 | continue; | |
179 | ||
180 | if ((cmdlist[i]->level & QCMD_DEV) && | |
181 | (!rup || !UIsDev(rup) || !IsOper(sender))) | |
182 | continue; | |
183 | ||
9b7c9974 | 184 | /* Commands flagged QCMD_ACHIEVEMENTS: |
185 | * Always invalid before 01/04/2010. | |
186 | * Valid after 02/04/2010 only if you have the flag set */ | |
187 | if (cmdlist[i]->level & QCMD_ACHIEVEMENTS) { | |
188 | if (time(NULL) < ACHIEVEMENTS_START) | |
189 | continue; | |
190 | ||
58a9529d | 191 | if ((time(NULL) > ACHIEVEMENTS_END) && |
9b7c9974 | 192 | !UIsAchievements(rup)) |
193 | continue; | |
194 | } | |
195 | ||
196 | /* Commands flagged QCMD_TITLES: | |
197 | * Only valid on 01/04/2010. */ | |
198 | if ((cmdlist[i]->level & QCMD_TITLES) && | |
199 | ((time(NULL) < ACHIEVEMENTS_START) || | |
50ce416c | 200 | (time(NULL) > ACHIEVEMENTS_END))) |
9b7c9974 | 201 | continue; |
202 | ||
d0c8f269 | 203 | /* We passed all the checks, send the message */ |
50ec21f3 | 204 | chanservsendmessage(sender, "%-20s %s",ct, message); |
c86edd1d Q |
205 | } |
206 | ||
207 | chanservstdmessage(sender, QM_ENDOFLIST); | |
208 | ||
209 | return CMD_OK; | |
210 | } | |
211 | ||
dd258305 | 212 | int cs_sendhelp(nick *sender, char *thecmd, int oneline) { |
c86edd1d | 213 | Command *cmd; |
dd258305 | 214 | cmdsummary *sum; |
f2c13059 | 215 | reguser *rup; |
216 | ||
dd258305 | 217 | if (!(cmd=findcommandintree(cscommands, thecmd, 1))) { |
218 | chanservstdmessage(sender, QM_UNKNOWNCMD, thecmd); | |
c86edd1d Q |
219 | return CMD_ERROR; |
220 | } | |
dd258305 | 221 | |
222 | /* Disable database help for now - splidge | |
223 | csdb_dohelp(sender, cmd); */ | |
f2c13059 | 224 | |
225 | rup=getreguserfromnick(sender); | |
226 | ||
227 | /* Don't showhelp for privileged users to others.. */ | |
372e4f1d CP |
228 | if (((cmd->level & QCMD_STAFF) && (!rup || !UHasStaffPriv(rup))) || |
229 | ((cmd->level & QCMD_HELPER) && (!rup || !UHasHelperPriv(rup))) || | |
f2c13059 | 230 | ((cmd->level & QCMD_OPER) && (!rup || !UHasOperPriv(rup))) || |
231 | ((cmd->level & QCMD_ADMIN) && (!rup || !UHasAdminPriv(rup))) || | |
232 | ((cmd->level & QCMD_DEV) && (!rup || !UIsDev(rup)))) { | |
233 | chanservstdmessage(sender, QM_NOHELP, cmd->command->content); | |
234 | return CMD_OK; | |
235 | } | |
dd258305 | 236 | |
237 | sum=cmd->ext; | |
c86edd1d | 238 | |
dd258305 | 239 | if (sum->defhelp && *(sum->defhelp)) { |
240 | if (oneline) { | |
bc34a4bc | 241 | chanservsendmessageoneline(sender, "%s", sum->defhelp); |
dd258305 | 242 | } else { |
bc34a4bc | 243 | chanservsendmessage(sender, "%s", sum->defhelp); |
dd258305 | 244 | } |
245 | } else { | |
246 | if (!oneline) | |
247 | chanservstdmessage(sender, QM_NOHELP, cmd->command->content); | |
248 | } | |
4ad1cf7a CP |
249 | |
250 | return CMD_OK; | |
c86edd1d Q |
251 | } |
252 | ||
253 | ||
dd258305 | 254 | int cs_dohelp(void *source, int cargc, char **cargv) { |
255 | nick *sender=source; | |
256 | ||
257 | if (cargc==0) | |
258 | return cs_doshowcommands(source,cargc,cargv); | |
259 | ||
260 | return cs_sendhelp(sender, cargv[0], 0); | |
261 | } | |
262 | ||
263 | ||
c86edd1d Q |
264 | int cs_doctcpping(void *source, int cargc, char **cargv) { |
265 | char *nullbuf="\001"; | |
266 | ||
267 | sendnoticetouser(chanservnick, source, "%cPING %s", | |
268 | 1, cargc?cargv[0]:nullbuf); | |
269 | ||
270 | return CMD_OK; | |
271 | } | |
272 | ||
273 | int cs_doctcpversion(void *source, int cargc, char **cargv) { | |
3e224d3f | 274 | sendnoticetouser(chanservnick, source, "\01VERSION Q9 version %s (Compiled on " __DATE__ ") (C) 2002-8 David Mansell (splidge) and others.\01", QVERSION); |
275 | sendnoticetouser(chanservnick, source, "\01VERSION Built on newserv. (C) 2002-8 David Mansell (splidge) and others.\01"); | |
c86edd1d Q |
276 | |
277 | return CMD_OK; | |
278 | } | |
279 | ||
64f17f02 | 280 | int cs_doversion(void *source, int cargc, char **cargv) { |
3e224d3f | 281 | chanservsendmessage((nick *)source, "Q9 version %s (Compiled on " __DATE__ ") (C) 2002-8 David Mansell (splidge) and others.", QVERSION); |
282 | chanservsendmessage((nick *)source, "Built on newserv. (C) 2002-8 David Mansell (splidge) and others."); | |
64f17f02 P |
283 | return CMD_OK; |
284 | } | |
285 | ||
c86edd1d Q |
286 | int cs_doctcpgender(void *source, int cargc, char **cargv) { |
287 | sendnoticetouser(chanservnick, source, "\1GENDER Anyone who has a bitch mode has to be female ;)\1"); | |
288 | ||
289 | return CMD_OK; | |
290 | } | |
291 | ||
ee8cd7d0 | 292 | void csdb_dohelp_real(DBConn *, void *); |
b263aa79 | 293 | |
294 | struct helpinfo { | |
295 | unsigned int numeric; | |
296 | sstring *commandname; | |
1f0d7c8b | 297 | Command *cmd; |
b263aa79 | 298 | }; |
299 | ||
300 | /* Help stuff */ | |
301 | void csdb_dohelp(nick *np, Command *cmd) { | |
302 | struct helpinfo *hip; | |
303 | ||
304 | hip=(struct helpinfo *)malloc(sizeof(struct helpinfo)); | |
305 | ||
306 | hip->numeric=np->numeric; | |
307 | hip->commandname=getsstring(cmd->command->content, cmd->command->length); | |
1f0d7c8b | 308 | hip->cmd=cmd; |
b263aa79 | 309 | |
b3565978 | 310 | q9asyncquery(csdb_dohelp_real, (void *)hip, |
522e2b8c | 311 | "SELECT languageID, fullinfo from chanserv.help where lower(command)=lower('%s')",cmd->command->content); |
b263aa79 | 312 | } |
313 | ||
ee8cd7d0 | 314 | void csdb_dohelp_real(DBConn *dbconn, void *arg) { |
b263aa79 | 315 | struct helpinfo *hip=arg; |
316 | nick *np=getnickbynumeric(hip->numeric); | |
317 | reguser *rup; | |
318 | char *result; | |
ee8cd7d0 CP |
319 | DBResult *pgres; |
320 | int j,lang=0; | |
b263aa79 | 321 | |
b3565978 CP |
322 | if(!dbconn) { |
323 | freesstring(hip->commandname); | |
324 | free(hip); | |
325 | return; | |
326 | } | |
327 | ||
ee8cd7d0 | 328 | pgres=dbgetresult(dbconn); |
b263aa79 | 329 | |
ee8cd7d0 | 330 | if (!dbquerysuccessful(pgres)) { |
b263aa79 | 331 | Error("chanserv",ERR_ERROR,"Error loading help text."); |
c34af51f CP |
332 | freesstring(hip->commandname); |
333 | free(hip); | |
b263aa79 | 334 | return; |
335 | } | |
336 | ||
ee8cd7d0 | 337 | if (dbnumfields(pgres)!=2) { |
b263aa79 | 338 | Error("chanserv",ERR_ERROR,"Help text format error."); |
ee8cd7d0 | 339 | dbclear(pgres); |
c34af51f CP |
340 | freesstring(hip->commandname); |
341 | free(hip); | |
b263aa79 | 342 | return; |
343 | } | |
344 | ||
b263aa79 | 345 | if (!np) { |
ee8cd7d0 | 346 | dbclear(pgres); |
b263aa79 | 347 | freesstring(hip->commandname); |
348 | free(hip); | |
349 | return; | |
350 | } | |
351 | ||
352 | if ((rup=getreguserfromnick(np))) | |
353 | lang=rup->languageid; | |
354 | ||
355 | result=NULL; | |
356 | ||
ee8cd7d0 CP |
357 | while(dbfetchrow(pgres)) { |
358 | j=strtoul(dbgetvalue(pgres,0),NULL,10); | |
b263aa79 | 359 | if ((j==0 && result==NULL) || (j==lang)) { |
ee8cd7d0 | 360 | result=dbgetvalue(pgres,1); |
b263aa79 | 361 | if(strlen(result)==0) |
362 | result=NULL; | |
363 | } | |
364 | } | |
365 | ||
1f0d7c8b | 366 | if (result) { |
bc34a4bc | 367 | chanservsendmessage(np, "%s", result); |
1f0d7c8b | 368 | } else { |
369 | cmdsummary *sum=hip->cmd->ext; | |
370 | if (sum->defhelp && *(sum->defhelp)) { | |
bc34a4bc | 371 | chanservsendmessage(np, "%s", sum->defhelp); |
1f0d7c8b | 372 | } else { |
373 | chanservstdmessage(np, QM_NOHELP, hip->commandname->content); | |
374 | } | |
375 | } | |
b263aa79 | 376 | |
377 | freesstring(hip->commandname); | |
378 | free(hip); | |
ee8cd7d0 | 379 | dbclear(pgres); |
b263aa79 | 380 | } |