]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanservstdcmds.c
bc1a1b97667b050e3590af83c5368fefa040ea32
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]);
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];
95 n
=getcommandlist(cscommands
, cmdlist
, 200);
96 rup
=getreguserfromnick(sender
);
101 lang
=rup
->languageid
;
103 chanservstdmessage(sender
, QM_COMMANDLIST
);
107 if (cargc
>0 && !match2strings(cargv
[0],cmdlist
[i
]->command
->content
))
110 /* Don't list aliases */
111 if (cmdlist
[i
]->level
& QCMD_ALIAS
)
114 /* Check that this user can use this command.. */
115 if ((cmdlist
[i
]->level
& QCMD_AUTHED
) && !rup
)
118 if ((cmdlist
[i
]->level
& QCMD_NOTAUTHED
) && rup
)
121 if ((cmdlist
[i
]->level
& QCMD_HELPER
) &&
122 (!rup
|| !UHasHelperPriv(rup
)))
125 if ((cmdlist
[i
]->level
& QCMD_OPER
) &&
126 (!rup
|| !UHasOperPriv(rup
) || !IsOper(sender
)))
129 if ((cmdlist
[i
]->level
& QCMD_ADMIN
) &&
130 (!rup
|| !UHasAdminPriv(rup
) || !IsOper(sender
)))
133 if ((cmdlist
[i
]->level
& QCMD_DEV
) &&
134 (!rup
|| !UIsDev(rup
) || !IsOper(sender
)))
137 summary
=(cmdsummary
*)cmdlist
[i
]->ext
;
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
);
149 sprintf(cmdbuf
," %s",cmdlist
[i
]->command
->content
);
153 ct
=cmdlist
[i
]->command
->content
;
156 if (summary
->bylang
[lang
]) {
157 message
=summary
->bylang
[lang
]->content
;
158 } else if (summary
->bylang
[0]) {
159 message
=summary
->bylang
[0]->content
;
161 message
=summary
->def
->content
;
164 chanservsendmessage(sender
, "%-20s %s",ct
, message
);
167 chanservstdmessage(sender
, QM_ENDOFLIST
);
172 int cs_sendhelp(nick
*sender
, char *thecmd
, int oneline
) {
177 if (!(cmd
=findcommandintree(cscommands
, thecmd
, 1))) {
178 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
182 /* Disable database help for now - splidge
183 csdb_dohelp(sender, cmd); */
185 rup
=getreguserfromnick(sender
);
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
);
198 if (sum
->defhelp
&& *(sum
->defhelp
)) {
200 chanservsendmessageoneline(sender
, sum
->defhelp
);
202 chanservsendmessage(sender
, sum
->defhelp
);
206 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
213 int cs_dohelp(void *source
, int cargc
, char **cargv
) {
217 return cs_doshowcommands(source
,cargc
,cargv
);
219 return cs_sendhelp(sender
, cargv
[0], 0);
223 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
224 char *nullbuf
="\001";
226 sendnoticetouser(chanservnick
, source
, "%cPING %s",
227 1, cargc
?cargv
[0]:nullbuf
);
232 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
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");
239 int cs_doversion(void *source
, int cargc
, char **cargv
) {
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.");
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");
251 void csdb_dohelp_real(DBConn
*, void *);
254 unsigned int numeric
;
255 sstring
*commandname
;
260 void csdb_dohelp(nick
*np
, Command
*cmd
) {
261 struct helpinfo
*hip
;
263 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
265 hip
->numeric
=np
->numeric
;
266 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
269 q9asyncquery(csdb_dohelp_real
, (void *)hip
,
270 "SELECT languageID, fullinfo from chanserv.help where lower(command)=lower('%s')",cmd
->command
->content
);
273 void csdb_dohelp_real(DBConn
*dbconn
, void *arg
) {
274 struct helpinfo
*hip
=arg
;
275 nick
*np
=getnickbynumeric(hip
->numeric
);
282 freesstring(hip
->commandname
);
287 pgres
=dbgetresult(dbconn
);
289 if (!dbquerysuccessful(pgres
)) {
290 Error("chanserv",ERR_ERROR
,"Error loading help text.");
291 freesstring(hip
->commandname
);
296 if (dbnumfields(pgres
)!=2) {
297 Error("chanserv",ERR_ERROR
,"Help text format error.");
299 freesstring(hip
->commandname
);
306 freesstring(hip
->commandname
);
311 if ((rup
=getreguserfromnick(np
)))
312 lang
=rup
->languageid
;
316 while(dbfetchrow(pgres
)) {
317 j
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
318 if ((j
==0 && result
==NULL
) || (j
==lang
)) {
319 result
=dbgetvalue(pgres
,1);
320 if(strlen(result
)==0)
326 chanservsendmessage(np
, result
);
328 cmdsummary
*sum
=hip
->cmd
->ext
;
329 if (sum
->defhelp
&& *(sum
->defhelp
)) {
330 chanservsendmessage(np
, sum
->defhelp
);
332 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
336 freesstring(hip
->commandname
);