]>
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; | |
c86edd1d Q |
94 | |
95 | n=getcommandlist(cscommands, cmdlist, 200); | |
96 | rup=getreguserfromnick(sender); | |
97 | ||
98 | if (!rup) | |
99 | lang=0; | |
100 | else | |
101 | lang=rup->languageid; | |
102 | ||
103 | chanservstdmessage(sender, QM_COMMANDLIST); | |
104 | ||
105 | for (i=0;i<n;i++) { | |
43583524 | 106 | |
c86edd1d Q |
107 | if (cargc>0 && !match2strings(cargv[0],cmdlist[i]->command->content)) |
108 | continue; | |
109 | ||
110 | /* Don't list aliases */ | |
111 | if (cmdlist[i]->level & QCMD_ALIAS) | |
112 | continue; | |
113 | ||
114 | /* Check that this user can use this command.. */ | |
115 | if ((cmdlist[i]->level & QCMD_AUTHED) && !rup) | |
116 | continue; | |
117 | ||
118 | if ((cmdlist[i]->level & QCMD_NOTAUTHED) && rup) | |
119 | continue; | |
120 | ||
7be5f783 CP |
121 | if ((cmdlist[i]->level & QCMD_STAFF) && |
122 | (!rup || !UHasStaffPriv(rup))) | |
123 | continue; | |
124 | ||
c86edd1d Q |
125 | if ((cmdlist[i]->level & QCMD_HELPER) && |
126 | (!rup || !UHasHelperPriv(rup))) | |
127 | continue; | |
128 | ||
129 | if ((cmdlist[i]->level & QCMD_OPER) && | |
130 | (!rup || !UHasOperPriv(rup) || !IsOper(sender))) | |
131 | continue; | |
132 | ||
133 | if ((cmdlist[i]->level & QCMD_ADMIN) && | |
134 | (!rup || !UHasAdminPriv(rup) || !IsOper(sender))) | |
135 | continue; | |
136 | ||
137 | if ((cmdlist[i]->level & QCMD_DEV) && | |
138 | (!rup || !UIsDev(rup) || !IsOper(sender))) | |
139 | continue; | |
140 | ||
141 | summary=(cmdsummary *)cmdlist[i]->ext; | |
142 | ||
372e4f1d | 143 | if (rup && UHasStaffPriv(rup)) { |
50ec21f3 | 144 | if (cmdlist[i]->level & QCMD_DEV) { |
145 | sprintf(cmdbuf,"+d %s",cmdlist[i]->command->content); | |
146 | } else if(cmdlist[i]->level & QCMD_ADMIN) { | |
147 | sprintf(cmdbuf,"+a %s",cmdlist[i]->command->content); | |
148 | } else if(cmdlist[i]->level & QCMD_OPER) { | |
149 | sprintf(cmdbuf,"+o %s",cmdlist[i]->command->content); | |
150 | } else if(cmdlist[i]->level & QCMD_HELPER) { | |
151 | sprintf(cmdbuf,"+h %s",cmdlist[i]->command->content); | |
7be5f783 CP |
152 | } else if(cmdlist[i]->level & QCMD_STAFF) { |
153 | sprintf(cmdbuf,"+q %s",cmdlist[i]->command->content); | |
50ec21f3 | 154 | } else { |
155 | sprintf(cmdbuf," %s",cmdlist[i]->command->content); | |
156 | } | |
157 | ct=cmdbuf; | |
43583524 | 158 | } else { |
50ec21f3 | 159 | ct=cmdlist[i]->command->content; |
43583524 | 160 | } |
161 | ||
c86edd1d Q |
162 | if (summary->bylang[lang]) { |
163 | message=summary->bylang[lang]->content; | |
164 | } else if (summary->bylang[0]) { | |
165 | message=summary->bylang[0]->content; | |
166 | } else { | |
167 | message=summary->def->content; | |
168 | } | |
169 | ||
50ec21f3 | 170 | chanservsendmessage(sender, "%-20s %s",ct, message); |
c86edd1d Q |
171 | } |
172 | ||
173 | chanservstdmessage(sender, QM_ENDOFLIST); | |
174 | ||
175 | return CMD_OK; | |
176 | } | |
177 | ||
dd258305 | 178 | int cs_sendhelp(nick *sender, char *thecmd, int oneline) { |
c86edd1d | 179 | Command *cmd; |
dd258305 | 180 | cmdsummary *sum; |
f2c13059 | 181 | reguser *rup; |
182 | ||
dd258305 | 183 | if (!(cmd=findcommandintree(cscommands, thecmd, 1))) { |
184 | chanservstdmessage(sender, QM_UNKNOWNCMD, thecmd); | |
c86edd1d Q |
185 | return CMD_ERROR; |
186 | } | |
dd258305 | 187 | |
188 | /* Disable database help for now - splidge | |
189 | csdb_dohelp(sender, cmd); */ | |
f2c13059 | 190 | |
191 | rup=getreguserfromnick(sender); | |
192 | ||
193 | /* Don't showhelp for privileged users to others.. */ | |
372e4f1d CP |
194 | if (((cmd->level & QCMD_STAFF) && (!rup || !UHasStaffPriv(rup))) || |
195 | ((cmd->level & QCMD_HELPER) && (!rup || !UHasHelperPriv(rup))) || | |
f2c13059 | 196 | ((cmd->level & QCMD_OPER) && (!rup || !UHasOperPriv(rup))) || |
197 | ((cmd->level & QCMD_ADMIN) && (!rup || !UHasAdminPriv(rup))) || | |
198 | ((cmd->level & QCMD_DEV) && (!rup || !UIsDev(rup)))) { | |
199 | chanservstdmessage(sender, QM_NOHELP, cmd->command->content); | |
200 | return CMD_OK; | |
201 | } | |
dd258305 | 202 | |
203 | sum=cmd->ext; | |
c86edd1d | 204 | |
dd258305 | 205 | if (sum->defhelp && *(sum->defhelp)) { |
206 | if (oneline) { | |
207 | chanservsendmessageoneline(sender, sum->defhelp); | |
208 | } else { | |
209 | chanservsendmessage(sender, sum->defhelp); | |
210 | } | |
211 | } else { | |
212 | if (!oneline) | |
213 | chanservstdmessage(sender, QM_NOHELP, cmd->command->content); | |
214 | } | |
4ad1cf7a CP |
215 | |
216 | return CMD_OK; | |
c86edd1d Q |
217 | } |
218 | ||
219 | ||
dd258305 | 220 | int cs_dohelp(void *source, int cargc, char **cargv) { |
221 | nick *sender=source; | |
222 | ||
223 | if (cargc==0) | |
224 | return cs_doshowcommands(source,cargc,cargv); | |
225 | ||
226 | return cs_sendhelp(sender, cargv[0], 0); | |
227 | } | |
228 | ||
229 | ||
c86edd1d Q |
230 | int cs_doctcpping(void *source, int cargc, char **cargv) { |
231 | char *nullbuf="\001"; | |
232 | ||
233 | sendnoticetouser(chanservnick, source, "%cPING %s", | |
234 | 1, cargc?cargv[0]:nullbuf); | |
235 | ||
236 | return CMD_OK; | |
237 | } | |
238 | ||
239 | int cs_doctcpversion(void *source, int cargc, char **cargv) { | |
3e224d3f | 240 | sendnoticetouser(chanservnick, source, "\01VERSION Q9 version %s (Compiled on " __DATE__ ") (C) 2002-8 David Mansell (splidge) and others.\01", QVERSION); |
241 | sendnoticetouser(chanservnick, source, "\01VERSION Built on newserv. (C) 2002-8 David Mansell (splidge) and others.\01"); | |
c86edd1d Q |
242 | |
243 | return CMD_OK; | |
244 | } | |
245 | ||
64f17f02 | 246 | int cs_doversion(void *source, int cargc, char **cargv) { |
3e224d3f | 247 | chanservsendmessage((nick *)source, "Q9 version %s (Compiled on " __DATE__ ") (C) 2002-8 David Mansell (splidge) and others.", QVERSION); |
248 | chanservsendmessage((nick *)source, "Built on newserv. (C) 2002-8 David Mansell (splidge) and others."); | |
64f17f02 P |
249 | return CMD_OK; |
250 | } | |
251 | ||
c86edd1d Q |
252 | int cs_doctcpgender(void *source, int cargc, char **cargv) { |
253 | sendnoticetouser(chanservnick, source, "\1GENDER Anyone who has a bitch mode has to be female ;)\1"); | |
254 | ||
255 | return CMD_OK; | |
256 | } | |
257 | ||
ee8cd7d0 | 258 | void csdb_dohelp_real(DBConn *, void *); |
b263aa79 | 259 | |
260 | struct helpinfo { | |
261 | unsigned int numeric; | |
262 | sstring *commandname; | |
1f0d7c8b | 263 | Command *cmd; |
b263aa79 | 264 | }; |
265 | ||
266 | /* Help stuff */ | |
267 | void csdb_dohelp(nick *np, Command *cmd) { | |
268 | struct helpinfo *hip; | |
269 | ||
270 | hip=(struct helpinfo *)malloc(sizeof(struct helpinfo)); | |
271 | ||
272 | hip->numeric=np->numeric; | |
273 | hip->commandname=getsstring(cmd->command->content, cmd->command->length); | |
1f0d7c8b | 274 | hip->cmd=cmd; |
b263aa79 | 275 | |
b3565978 | 276 | q9asyncquery(csdb_dohelp_real, (void *)hip, |
522e2b8c | 277 | "SELECT languageID, fullinfo from chanserv.help where lower(command)=lower('%s')",cmd->command->content); |
b263aa79 | 278 | } |
279 | ||
ee8cd7d0 | 280 | void csdb_dohelp_real(DBConn *dbconn, void *arg) { |
b263aa79 | 281 | struct helpinfo *hip=arg; |
282 | nick *np=getnickbynumeric(hip->numeric); | |
283 | reguser *rup; | |
284 | char *result; | |
ee8cd7d0 CP |
285 | DBResult *pgres; |
286 | int j,lang=0; | |
b263aa79 | 287 | |
b3565978 CP |
288 | if(!dbconn) { |
289 | freesstring(hip->commandname); | |
290 | free(hip); | |
291 | return; | |
292 | } | |
293 | ||
ee8cd7d0 | 294 | pgres=dbgetresult(dbconn); |
b263aa79 | 295 | |
ee8cd7d0 | 296 | if (!dbquerysuccessful(pgres)) { |
b263aa79 | 297 | Error("chanserv",ERR_ERROR,"Error loading help text."); |
c34af51f CP |
298 | freesstring(hip->commandname); |
299 | free(hip); | |
b263aa79 | 300 | return; |
301 | } | |
302 | ||
ee8cd7d0 | 303 | if (dbnumfields(pgres)!=2) { |
b263aa79 | 304 | Error("chanserv",ERR_ERROR,"Help text format error."); |
ee8cd7d0 | 305 | dbclear(pgres); |
c34af51f CP |
306 | freesstring(hip->commandname); |
307 | free(hip); | |
b263aa79 | 308 | return; |
309 | } | |
310 | ||
b263aa79 | 311 | if (!np) { |
ee8cd7d0 | 312 | dbclear(pgres); |
b263aa79 | 313 | freesstring(hip->commandname); |
314 | free(hip); | |
315 | return; | |
316 | } | |
317 | ||
318 | if ((rup=getreguserfromnick(np))) | |
319 | lang=rup->languageid; | |
320 | ||
321 | result=NULL; | |
322 | ||
ee8cd7d0 CP |
323 | while(dbfetchrow(pgres)) { |
324 | j=strtoul(dbgetvalue(pgres,0),NULL,10); | |
b263aa79 | 325 | if ((j==0 && result==NULL) || (j==lang)) { |
ee8cd7d0 | 326 | result=dbgetvalue(pgres,1); |
b263aa79 | 327 | if(strlen(result)==0) |
328 | result=NULL; | |
329 | } | |
330 | } | |
331 | ||
1f0d7c8b | 332 | if (result) { |
b263aa79 | 333 | chanservsendmessage(np, result); |
1f0d7c8b | 334 | } else { |
335 | cmdsummary *sum=hip->cmd->ext; | |
336 | if (sum->defhelp && *(sum->defhelp)) { | |
337 | chanservsendmessage(np, sum->defhelp); | |
338 | } else { | |
339 | chanservstdmessage(np, QM_NOHELP, hip->commandname->content); | |
340 | } | |
341 | } | |
b263aa79 | 342 | |
343 | freesstring(hip->commandname); | |
344 | free(hip); | |
ee8cd7d0 | 345 | dbclear(pgres); |
b263aa79 | 346 | } |