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