]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanservstdcmds.c
2 * This contains Q9's "built in" commands and CTCP handlers
6 #include "../core/schedule.h"
7 #include "../lib/irc_string.h"
8 #include "../dbapi/dbapi.h"
13 int cs_dorehash(void *source
, int cargc
, char **cargv
) {
15 Command
*cmdlist
[200];
18 /* Reload the response text first */
21 /* Now the commands */
22 n
=getcommandlist(cscommands
, cmdlist
, 200);
25 loadcommandsummary(cmdlist
[i
]);
27 chanservstdmessage(sender
, QM_DONE
);
32 int cs_doquit(void *source
, int cargc
, char **cargv
) {
33 char *reason
="Leaving";
34 nick
*sender
=(nick
*)source
;
40 chanservstdmessage(sender
, QM_DONE
);
42 deregisterlocaluser(chanservnick
, reason
);
43 scheduleoneshot(time(NULL
)+1,&chanservreguser
,NULL
);
48 int cs_dosetquitreason(void *source
, int cargc
, char **cargv
) {
49 nick
*sender
=(nick
*)source
;
52 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "setquitreason");
57 freesstring(cs_quitreason
);
59 cs_quitreason
=getsstring(cargv
[0], 250);
61 chanservstdmessage(sender
, QM_DONE
);
66 int cs_dorename(void *source
, int cargc
, char **cargv
) {
67 char newnick
[NICKLEN
+1];
71 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "rename");
75 strncpy(newnick
,cargv
[0],NICKLEN
);
76 newnick
[NICKLEN
]='\0';
78 renamelocaluser(chanservnick
, newnick
);
79 chanservstdmessage(sender
, QM_DONE
);
84 int cs_doshowcommands(void *source
, int cargc
, char **cargv
) {
87 Command
*cmdlist
[200];
94 unsigned int dumpcount
=0;
96 n
=getcommandlist(cscommands
, cmdlist
, 200);
97 rup
=getreguserfromnick(sender
);
102 lang
=rup
->languageid
;
104 chanservstdmessage(sender
, QM_COMMANDLIST
);
106 if (cargc
>0 && rup
&& UIsDev(rup
) && !ircd_strcmp(cargv
[0], "-v")) {
111 /* Generate the appropriate strings for the command name (including
112 * prefixes for privileged users) and the summary text.
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
;
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
);
130 sprintf(cmdbuf
," %s",cmdlist
[i
]->command
->content
);
134 ct
=cmdlist
[i
]->command
->content
;
137 if (summary
->bylang
[lang
]) {
138 message
=summary
->bylang
[lang
]->content
;
139 } else if (summary
->bylang
[0]) {
140 message
=summary
->bylang
[0]->content
;
142 message
=summary
->def
->content
;
146 chanservsendmessage(sender
,"%-20s %u", cmdbuf
, cmdlist
[i
]->calls
);
150 if (cargc
>0 && !match2strings(cargv
[0],cmdlist
[i
]->command
->content
))
153 /* Don't list aliases */
154 if (cmdlist
[i
]->level
& QCMD_ALIAS
)
157 /* Check that this user can use this command.. */
158 if ((cmdlist
[i
]->level
& QCMD_AUTHED
) && !rup
)
161 if ((cmdlist
[i
]->level
& QCMD_NOTAUTHED
) && rup
)
164 if ((cmdlist
[i
]->level
& QCMD_STAFF
) &&
165 (!rup
|| !UHasStaffPriv(rup
)))
168 if ((cmdlist
[i
]->level
& QCMD_HELPER
) &&
169 (!rup
|| !UHasHelperPriv(rup
)))
172 if ((cmdlist
[i
]->level
& QCMD_OPER
) &&
173 (!rup
|| !UHasOperPriv(rup
) || !IsOper(sender
)))
176 if ((cmdlist
[i
]->level
& QCMD_ADMIN
) &&
177 (!rup
|| !UHasAdminPriv(rup
) || !IsOper(sender
)))
180 if ((cmdlist
[i
]->level
& QCMD_DEV
) &&
181 (!rup
|| !UIsDev(rup
) || !IsOper(sender
)))
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
)
191 if ((time(NULL
) > ACHIEVEMENTS_END
) &&
192 !UIsAchievements(rup
))
196 /* Commands flagged QCMD_TITLES:
197 * Only valid on 01/04/2010. */
198 if ((cmdlist
[i
]->level
& QCMD_TITLES
) &&
199 ((time(NULL
) < ACHIEVEMENTS_START
) ||
200 (time(NULL
) > ACHIEVEMENTS_END
)))
203 /* We passed all the checks, send the message */
204 chanservsendmessage(sender
, "%-20s %s",ct
, message
);
207 chanservstdmessage(sender
, QM_ENDOFLIST
);
212 int cs_sendhelp(nick
*sender
, char *thecmd
, int oneline
) {
217 if (!(cmd
=findcommandintree(cscommands
, thecmd
, 1))) {
218 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
222 /* Disable database help for now - splidge
223 csdb_dohelp(sender, cmd); */
225 rup
=getreguserfromnick(sender
);
227 /* Don't showhelp for privileged users to others.. */
228 if (((cmd
->level
& QCMD_STAFF
) && (!rup
|| !UHasStaffPriv(rup
))) ||
229 ((cmd
->level
& QCMD_HELPER
) && (!rup
|| !UHasHelperPriv(rup
))) ||
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 ((cmd
->level
& (QCMD_TITLES
| QCMD_ACHIEVEMENTS
)) && (time(NULL
) < ACHIEVEMENTS_START
))) {
234 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
240 if (sum
->defhelp
&& *(sum
->defhelp
)) {
242 chanservsendmessageoneline(sender
, "%s", sum
->defhelp
);
244 chanservsendmessage(sender
, "%s", sum
->defhelp
);
248 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
255 int cs_dohelp(void *source
, int cargc
, char **cargv
) {
259 return cs_doshowcommands(source
,cargc
,cargv
);
261 return cs_sendhelp(sender
, cargv
[0], 0);
265 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
266 char *nullbuf
="\001";
268 sendnoticetouser(chanservnick
, source
, "%cPING %s",
269 1, cargc
?cargv
[0]:nullbuf
);
274 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
275 sendnoticetouser(chanservnick
, source
, "\01VERSION Q9 version %s (Compiled on " __DATE__
") (C) 2002-8 David Mansell (splidge) and others.\01", QVERSION
);
276 sendnoticetouser(chanservnick
, source
, "\01VERSION Built on newserv. (C) 2002-8 David Mansell (splidge) and others.\01");
281 int cs_doversion(void *source
, int cargc
, char **cargv
) {
282 chanservsendmessage((nick
*)source
, "Q9 version %s (Compiled on " __DATE__
") (C) 2002-8 David Mansell (splidge) and others.", QVERSION
);
283 chanservsendmessage((nick
*)source
, "Built on newserv. (C) 2002-8 David Mansell (splidge) and others.");
287 int cs_doctcpgender(void *source
, int cargc
, char **cargv
) {
288 sendnoticetouser(chanservnick
, source
, "\1GENDER Anyone who has a bitch mode has to be female ;)\1");
293 void csdb_dohelp_real(DBConn
*, void *);
296 unsigned int numeric
;
297 sstring
*commandname
;
302 void csdb_dohelp(nick
*np
, Command
*cmd
) {
303 struct helpinfo
*hip
;
305 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
307 hip
->numeric
=np
->numeric
;
308 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
311 q9asyncquery(csdb_dohelp_real
, (void *)hip
,
312 "SELECT languageID, fullinfo from chanserv.help where lower(command)=lower('%s')",cmd
->command
->content
);
315 void csdb_dohelp_real(DBConn
*dbconn
, void *arg
) {
316 struct helpinfo
*hip
=arg
;
317 nick
*np
=getnickbynumeric(hip
->numeric
);
324 freesstring(hip
->commandname
);
329 pgres
=dbgetresult(dbconn
);
331 if (!dbquerysuccessful(pgres
)) {
332 Error("chanserv",ERR_ERROR
,"Error loading help text.");
333 freesstring(hip
->commandname
);
338 if (dbnumfields(pgres
)!=2) {
339 Error("chanserv",ERR_ERROR
,"Help text format error.");
341 freesstring(hip
->commandname
);
348 freesstring(hip
->commandname
);
353 if ((rup
=getreguserfromnick(np
)))
354 lang
=rup
->languageid
;
358 while(dbfetchrow(pgres
)) {
359 j
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
360 if ((j
==0 && result
==NULL
) || (j
==lang
)) {
361 result
=dbgetvalue(pgres
,1);
362 if(strlen(result
)==0)
368 chanservsendmessage(np
, "%s", result
);
370 cmdsummary
*sum
=hip
->cmd
->ext
;
371 if (sum
->defhelp
&& *(sum
->defhelp
)) {
372 chanservsendmessage(np
, "%s", sum
->defhelp
);
374 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
378 freesstring(hip
->commandname
);