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