]>
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];
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_STAFF
) &&
122 (!rup
|| !UHasStaffPriv(rup
)))
125 if ((cmdlist
[i
]->level
& QCMD_HELPER
) &&
126 (!rup
|| !UHasHelperPriv(rup
)))
129 if ((cmdlist
[i
]->level
& QCMD_OPER
) &&
130 (!rup
|| !UHasOperPriv(rup
) || !IsOper(sender
)))
133 if ((cmdlist
[i
]->level
& QCMD_ADMIN
) &&
134 (!rup
|| !UHasAdminPriv(rup
) || !IsOper(sender
)))
137 if ((cmdlist
[i
]->level
& QCMD_DEV
) &&
138 (!rup
|| !UIsDev(rup
) || !IsOper(sender
)))
141 summary
=(cmdsummary
*)cmdlist
[i
]->ext
;
143 if (rup
&& UHasStaffPriv(rup
)) {
144 if (cmdlist
[i
]->level
& QCMD_DEV
) {
145 sprintf(cmdbuf
,"+d %s",cmdlist
[i
]->command
->content
);
146 } else if(cmdlist
[i
]->level
& QCMD_ADMIN
) {
147 sprintf(cmdbuf
,"+a %s",cmdlist
[i
]->command
->content
);
148 } else if(cmdlist
[i
]->level
& QCMD_OPER
) {
149 sprintf(cmdbuf
,"+o %s",cmdlist
[i
]->command
->content
);
150 } else if(cmdlist
[i
]->level
& QCMD_HELPER
) {
151 sprintf(cmdbuf
,"+h %s",cmdlist
[i
]->command
->content
);
152 } else if(cmdlist
[i
]->level
& QCMD_STAFF
) {
153 sprintf(cmdbuf
,"+q %s",cmdlist
[i
]->command
->content
);
155 sprintf(cmdbuf
," %s",cmdlist
[i
]->command
->content
);
159 ct
=cmdlist
[i
]->command
->content
;
162 if (summary
->bylang
[lang
]) {
163 message
=summary
->bylang
[lang
]->content
;
164 } else if (summary
->bylang
[0]) {
165 message
=summary
->bylang
[0]->content
;
167 message
=summary
->def
->content
;
170 chanservsendmessage(sender
, "%-20s %s",ct
, message
);
173 chanservstdmessage(sender
, QM_ENDOFLIST
);
178 int cs_sendhelp(nick
*sender
, char *thecmd
, int oneline
) {
183 if (!(cmd
=findcommandintree(cscommands
, thecmd
, 1))) {
184 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
188 /* Disable database help for now - splidge
189 csdb_dohelp(sender, cmd); */
191 rup
=getreguserfromnick(sender
);
193 /* Don't showhelp for privileged users to others.. */
194 if (((cmd
->level
& QCMD_STAFF
) && (!rup
|| !UHasStaffPriv(rup
))) ||
195 ((cmd
->level
& QCMD_HELPER
) && (!rup
|| !UHasHelperPriv(rup
))) ||
196 ((cmd
->level
& QCMD_OPER
) && (!rup
|| !UHasOperPriv(rup
))) ||
197 ((cmd
->level
& QCMD_ADMIN
) && (!rup
|| !UHasAdminPriv(rup
))) ||
198 ((cmd
->level
& QCMD_DEV
) && (!rup
|| !UIsDev(rup
)))) {
199 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
205 if (sum
->defhelp
&& *(sum
->defhelp
)) {
207 chanservsendmessageoneline(sender
, "%s", sum
->defhelp
);
209 chanservsendmessage(sender
, "%s", sum
->defhelp
);
213 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
220 int cs_dohelp(void *source
, int cargc
, char **cargv
) {
224 return cs_doshowcommands(source
,cargc
,cargv
);
226 return cs_sendhelp(sender
, cargv
[0], 0);
230 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
231 char *nullbuf
="\001";
233 sendnoticetouser(chanservnick
, source
, "%cPING %s",
234 1, cargc
?cargv
[0]:nullbuf
);
239 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
240 sendnoticetouser(chanservnick
, source
, "\01VERSION Q9 version %s (Compiled on " __DATE__
") (C) 2002-8 David Mansell (splidge) and others.\01", QVERSION
);
241 sendnoticetouser(chanservnick
, source
, "\01VERSION Built on newserv. (C) 2002-8 David Mansell (splidge) and others.\01");
246 int cs_doversion(void *source
, int cargc
, char **cargv
) {
247 chanservsendmessage((nick
*)source
, "Q9 version %s (Compiled on " __DATE__
") (C) 2002-8 David Mansell (splidge) and others.", QVERSION
);
248 chanservsendmessage((nick
*)source
, "Built on newserv. (C) 2002-8 David Mansell (splidge) and others.");
252 int cs_doctcpgender(void *source
, int cargc
, char **cargv
) {
253 sendnoticetouser(chanservnick
, source
, "\1GENDER Anyone who has a bitch mode has to be female ;)\1");
258 void csdb_dohelp_real(DBConn
*, void *);
261 unsigned int numeric
;
262 sstring
*commandname
;
267 void csdb_dohelp(nick
*np
, Command
*cmd
) {
268 struct helpinfo
*hip
;
270 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
272 hip
->numeric
=np
->numeric
;
273 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
276 q9asyncquery(csdb_dohelp_real
, (void *)hip
,
277 "SELECT languageID, fullinfo from chanserv.help where lower(command)=lower('%s')",cmd
->command
->content
);
280 void csdb_dohelp_real(DBConn
*dbconn
, void *arg
) {
281 struct helpinfo
*hip
=arg
;
282 nick
*np
=getnickbynumeric(hip
->numeric
);
289 freesstring(hip
->commandname
);
294 pgres
=dbgetresult(dbconn
);
296 if (!dbquerysuccessful(pgres
)) {
297 Error("chanserv",ERR_ERROR
,"Error loading help text.");
298 freesstring(hip
->commandname
);
303 if (dbnumfields(pgres
)!=2) {
304 Error("chanserv",ERR_ERROR
,"Help text format error.");
306 freesstring(hip
->commandname
);
313 freesstring(hip
->commandname
);
318 if ((rup
=getreguserfromnick(np
)))
319 lang
=rup
->languageid
;
323 while(dbfetchrow(pgres
)) {
324 j
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
325 if ((j
==0 && result
==NULL
) || (j
==lang
)) {
326 result
=dbgetvalue(pgres
,1);
327 if(strlen(result
)==0)
333 chanservsendmessage(np
, "%s", result
);
335 cmdsummary
*sum
=hip
->cmd
->ext
;
336 if (sum
->defhelp
&& *(sum
->defhelp
)) {
337 chanservsendmessage(np
, "%s", sum
->defhelp
);
339 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
343 freesstring(hip
->commandname
);