]>
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" | |
b263aa79 | 8 | #include "../pqsql/pqsql.h" |
c86edd1d Q |
9 | |
10 | #include <string.h> | |
11 | ||
12 | int cs_dorehash(void *source, int cargc, char **cargv) { | |
13 | nick *sender=source; | |
14 | Command *cmdlist[200]; | |
15 | int i,n; | |
16 | ||
17 | /* Reload the response text first */ | |
18 | loadmessages(); | |
19 | ||
20 | /* Now the commands */ | |
21 | n=getcommandlist(cscommands, cmdlist, 200); | |
22 | ||
23 | for(i=0;i<n;i++) | |
24 | loadcommandsummary(cmdlist[i]); | |
25 | ||
26 | chanservstdmessage(sender, QM_DONE); | |
27 | ||
28 | return CMD_OK; | |
29 | } | |
30 | ||
31 | int cs_doquit(void *source, int cargc, char **cargv) { | |
32 | char *reason="Leaving"; | |
33 | nick *sender=(nick *)source; | |
34 | ||
35 | if (cargc>0) { | |
36 | reason=cargv[0]; | |
37 | } | |
38 | ||
39 | chanservstdmessage(sender, QM_DONE); | |
40 | ||
41 | deregisterlocaluser(chanservnick, reason); | |
42 | scheduleoneshot(time(NULL)+1,&chanservreguser,NULL); | |
43 | ||
44 | return CMD_OK; | |
45 | } | |
46 | ||
47 | int cs_dorename(void *source, int cargc, char **cargv) { | |
48 | char newnick[NICKLEN+1]; | |
49 | nick *sender=source; | |
50 | ||
51 | if (cargc<1) { | |
52 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "rename"); | |
53 | return CMD_ERROR; | |
54 | } | |
55 | ||
56 | strncpy(newnick,cargv[0],NICKLEN); | |
57 | newnick[NICKLEN]='\0'; | |
58 | ||
59 | renamelocaluser(chanservnick, newnick); | |
60 | chanservstdmessage(sender, QM_DONE); | |
61 | ||
62 | return CMD_OK; | |
63 | } | |
64 | ||
65 | int cs_doshowcommands(void *source, int cargc, char **cargv) { | |
66 | nick *sender=source; | |
67 | reguser *rup; | |
68 | Command *cmdlist[200]; | |
69 | int i,n; | |
70 | int lang; | |
71 | char *message; | |
72 | cmdsummary *summary; | |
50ec21f3 | 73 | char cmdbuf[50]; |
74 | char *ct; | |
c86edd1d Q |
75 | |
76 | n=getcommandlist(cscommands, cmdlist, 200); | |
77 | rup=getreguserfromnick(sender); | |
78 | ||
79 | if (!rup) | |
80 | lang=0; | |
81 | else | |
82 | lang=rup->languageid; | |
83 | ||
84 | chanservstdmessage(sender, QM_COMMANDLIST); | |
85 | ||
86 | for (i=0;i<n;i++) { | |
43583524 | 87 | |
c86edd1d Q |
88 | if (cargc>0 && !match2strings(cargv[0],cmdlist[i]->command->content)) |
89 | continue; | |
90 | ||
91 | /* Don't list aliases */ | |
92 | if (cmdlist[i]->level & QCMD_ALIAS) | |
93 | continue; | |
94 | ||
95 | /* Check that this user can use this command.. */ | |
96 | if ((cmdlist[i]->level & QCMD_AUTHED) && !rup) | |
97 | continue; | |
98 | ||
99 | if ((cmdlist[i]->level & QCMD_NOTAUTHED) && rup) | |
100 | continue; | |
101 | ||
102 | if ((cmdlist[i]->level & QCMD_HELPER) && | |
103 | (!rup || !UHasHelperPriv(rup))) | |
104 | continue; | |
105 | ||
106 | if ((cmdlist[i]->level & QCMD_OPER) && | |
107 | (!rup || !UHasOperPriv(rup) || !IsOper(sender))) | |
108 | continue; | |
109 | ||
110 | if ((cmdlist[i]->level & QCMD_ADMIN) && | |
111 | (!rup || !UHasAdminPriv(rup) || !IsOper(sender))) | |
112 | continue; | |
113 | ||
114 | if ((cmdlist[i]->level & QCMD_DEV) && | |
115 | (!rup || !UIsDev(rup) || !IsOper(sender))) | |
116 | continue; | |
117 | ||
118 | summary=(cmdsummary *)cmdlist[i]->ext; | |
119 | ||
50ec21f3 | 120 | if (rup && UHasHelperPriv(rup)) { |
121 | if (cmdlist[i]->level & QCMD_DEV) { | |
122 | sprintf(cmdbuf,"+d %s",cmdlist[i]->command->content); | |
123 | } else if(cmdlist[i]->level & QCMD_ADMIN) { | |
124 | sprintf(cmdbuf,"+a %s",cmdlist[i]->command->content); | |
125 | } else if(cmdlist[i]->level & QCMD_OPER) { | |
126 | sprintf(cmdbuf,"+o %s",cmdlist[i]->command->content); | |
127 | } else if(cmdlist[i]->level & QCMD_HELPER) { | |
128 | sprintf(cmdbuf,"+h %s",cmdlist[i]->command->content); | |
129 | } else { | |
130 | sprintf(cmdbuf," %s",cmdlist[i]->command->content); | |
131 | } | |
132 | ct=cmdbuf; | |
43583524 | 133 | } else { |
50ec21f3 | 134 | ct=cmdlist[i]->command->content; |
43583524 | 135 | } |
136 | ||
c86edd1d Q |
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 | ||
50ec21f3 | 145 | chanservsendmessage(sender, "%-20s %s",ct, message); |
c86edd1d Q |
146 | } |
147 | ||
148 | chanservstdmessage(sender, QM_ENDOFLIST); | |
149 | ||
150 | return CMD_OK; | |
151 | } | |
152 | ||
dd258305 | 153 | int cs_sendhelp(nick *sender, char *thecmd, int oneline) { |
c86edd1d | 154 | Command *cmd; |
dd258305 | 155 | cmdsummary *sum; |
f2c13059 | 156 | reguser *rup; |
157 | ||
dd258305 | 158 | if (!(cmd=findcommandintree(cscommands, thecmd, 1))) { |
159 | chanservstdmessage(sender, QM_UNKNOWNCMD, thecmd); | |
c86edd1d Q |
160 | return CMD_ERROR; |
161 | } | |
dd258305 | 162 | |
163 | /* Disable database help for now - splidge | |
164 | csdb_dohelp(sender, cmd); */ | |
f2c13059 | 165 | |
166 | rup=getreguserfromnick(sender); | |
167 | ||
168 | /* Don't showhelp for privileged users to others.. */ | |
169 | if (((cmd->level & QCMD_HELPER) && (!rup || !UHasHelperPriv(rup))) || | |
170 | ((cmd->level & QCMD_OPER) && (!rup || !UHasOperPriv(rup))) || | |
171 | ((cmd->level & QCMD_ADMIN) && (!rup || !UHasAdminPriv(rup))) || | |
172 | ((cmd->level & QCMD_DEV) && (!rup || !UIsDev(rup)))) { | |
173 | chanservstdmessage(sender, QM_NOHELP, cmd->command->content); | |
174 | return CMD_OK; | |
175 | } | |
dd258305 | 176 | |
177 | sum=cmd->ext; | |
c86edd1d | 178 | |
dd258305 | 179 | if (sum->defhelp && *(sum->defhelp)) { |
180 | if (oneline) { | |
181 | chanservsendmessageoneline(sender, sum->defhelp); | |
182 | } else { | |
183 | chanservsendmessage(sender, sum->defhelp); | |
184 | } | |
185 | } else { | |
186 | if (!oneline) | |
187 | chanservstdmessage(sender, QM_NOHELP, cmd->command->content); | |
188 | } | |
4ad1cf7a CP |
189 | |
190 | return CMD_OK; | |
c86edd1d Q |
191 | } |
192 | ||
193 | ||
dd258305 | 194 | int cs_dohelp(void *source, int cargc, char **cargv) { |
195 | nick *sender=source; | |
196 | ||
197 | if (cargc==0) | |
198 | return cs_doshowcommands(source,cargc,cargv); | |
199 | ||
200 | return cs_sendhelp(sender, cargv[0], 0); | |
201 | } | |
202 | ||
203 | ||
c86edd1d Q |
204 | int cs_doctcpping(void *source, int cargc, char **cargv) { |
205 | char *nullbuf="\001"; | |
206 | ||
207 | sendnoticetouser(chanservnick, source, "%cPING %s", | |
208 | 1, cargc?cargv[0]:nullbuf); | |
209 | ||
210 | return CMD_OK; | |
211 | } | |
212 | ||
213 | int cs_doctcpversion(void *source, int cargc, char **cargv) { | |
64f17f02 | 214 | sendnoticetouser(chanservnick, source, "\01VERSION Q9 version %s (Compiled on " __DATE__ ") (C) 2002-3 David Mansell (splidge)\01", QVERSION); |
c86edd1d Q |
215 | sendnoticetouser(chanservnick, source, "\01VERSION Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)\01"); |
216 | ||
217 | return CMD_OK; | |
218 | } | |
219 | ||
64f17f02 P |
220 | int cs_doversion(void *source, int cargc, char **cargv) { |
221 | chanservsendmessage((nick *)source, "Q9 version %s (Compiled on " __DATE__ ") (C) 2002-3 David Mansell (splidge)", QVERSION); | |
222 | chanservsendmessage((nick *)source, "Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)"); | |
223 | return CMD_OK; | |
224 | } | |
225 | ||
c86edd1d Q |
226 | int cs_doctcpgender(void *source, int cargc, char **cargv) { |
227 | sendnoticetouser(chanservnick, source, "\1GENDER Anyone who has a bitch mode has to be female ;)\1"); | |
228 | ||
229 | return CMD_OK; | |
230 | } | |
231 | ||
b263aa79 | 232 | void csdb_dohelp_real(PGconn *, void *); |
233 | ||
234 | struct helpinfo { | |
235 | unsigned int numeric; | |
236 | sstring *commandname; | |
1f0d7c8b | 237 | Command *cmd; |
b263aa79 | 238 | }; |
239 | ||
240 | /* Help stuff */ | |
241 | void csdb_dohelp(nick *np, Command *cmd) { | |
242 | struct helpinfo *hip; | |
243 | ||
244 | hip=(struct helpinfo *)malloc(sizeof(struct helpinfo)); | |
245 | ||
246 | hip->numeric=np->numeric; | |
247 | hip->commandname=getsstring(cmd->command->content, cmd->command->length); | |
1f0d7c8b | 248 | hip->cmd=cmd; |
b263aa79 | 249 | |
b3565978 | 250 | q9asyncquery(csdb_dohelp_real, (void *)hip, |
b263aa79 | 251 | "SELECT languageID, fullinfo from help where lower(command)=lower('%s')",cmd->command->content); |
252 | } | |
253 | ||
254 | void csdb_dohelp_real(PGconn *dbconn, void *arg) { | |
255 | struct helpinfo *hip=arg; | |
256 | nick *np=getnickbynumeric(hip->numeric); | |
257 | reguser *rup; | |
258 | char *result; | |
259 | PGresult *pgres; | |
260 | int i,j,num,lang=0; | |
261 | ||
b3565978 CP |
262 | if(!dbconn) { |
263 | freesstring(hip->commandname); | |
264 | free(hip); | |
265 | return; | |
266 | } | |
267 | ||
b263aa79 | 268 | pgres=PQgetResult(dbconn); |
269 | ||
270 | if (PQresultStatus(pgres) != PGRES_TUPLES_OK) { | |
271 | Error("chanserv",ERR_ERROR,"Error loading help text."); | |
c34af51f CP |
272 | freesstring(hip->commandname); |
273 | free(hip); | |
b263aa79 | 274 | return; |
275 | } | |
276 | ||
277 | if (PQnfields(pgres)!=2) { | |
278 | Error("chanserv",ERR_ERROR,"Help text format error."); | |
c34af51f CP |
279 | PQclear(pgres); |
280 | freesstring(hip->commandname); | |
281 | free(hip); | |
b263aa79 | 282 | return; |
283 | } | |
284 | ||
285 | num=PQntuples(pgres); | |
286 | ||
287 | if (!np) { | |
288 | PQclear(pgres); | |
289 | freesstring(hip->commandname); | |
290 | free(hip); | |
291 | return; | |
292 | } | |
293 | ||
294 | if ((rup=getreguserfromnick(np))) | |
295 | lang=rup->languageid; | |
296 | ||
297 | result=NULL; | |
298 | ||
299 | for (i=0;i<num;i++) { | |
300 | j=strtoul(PQgetvalue(pgres,i,0),NULL,10); | |
301 | if ((j==0 && result==NULL) || (j==lang)) { | |
302 | result=PQgetvalue(pgres,i,1); | |
303 | if(strlen(result)==0) | |
304 | result=NULL; | |
305 | } | |
306 | } | |
307 | ||
1f0d7c8b | 308 | if (result) { |
b263aa79 | 309 | chanservsendmessage(np, result); |
1f0d7c8b | 310 | } else { |
311 | cmdsummary *sum=hip->cmd->ext; | |
312 | if (sum->defhelp && *(sum->defhelp)) { | |
313 | chanservsendmessage(np, sum->defhelp); | |
314 | } else { | |
315 | chanservstdmessage(np, QM_NOHELP, hip->commandname->content); | |
316 | } | |
317 | } | |
b263aa79 | 318 | |
319 | freesstring(hip->commandname); | |
320 | free(hip); | |
321 | } |