]>
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 "../pqsql/pqsql.h"
12 int cs_dorehash(void *source
, int cargc
, char **cargv
) {
14 Command
*cmdlist
[200];
17 /* Reload the response text first */
20 /* Now the commands */
21 n
=getcommandlist(cscommands
, cmdlist
, 200);
24 loadcommandsummary(cmdlist
[i
]);
26 chanservstdmessage(sender
, QM_DONE
);
31 int cs_doquit(void *source
, int cargc
, char **cargv
) {
32 char *reason
="Leaving";
33 nick
*sender
=(nick
*)source
;
39 chanservstdmessage(sender
, QM_DONE
);
41 deregisterlocaluser(chanservnick
, reason
);
42 scheduleoneshot(time(NULL
)+1,&chanservreguser
,NULL
);
47 int cs_dorename(void *source
, int cargc
, char **cargv
) {
48 char newnick
[NICKLEN
+1];
52 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "rename");
56 strncpy(newnick
,cargv
[0],NICKLEN
);
57 newnick
[NICKLEN
]='\0';
59 renamelocaluser(chanservnick
, newnick
);
60 chanservstdmessage(sender
, QM_DONE
);
65 int cs_doshowcommands(void *source
, int cargc
, char **cargv
) {
68 Command
*cmdlist
[200];
76 n
=getcommandlist(cscommands
, cmdlist
, 200);
77 rup
=getreguserfromnick(sender
);
84 chanservstdmessage(sender
, QM_COMMANDLIST
);
88 if (cargc
>0 && !match2strings(cargv
[0],cmdlist
[i
]->command
->content
))
91 /* Don't list aliases */
92 if (cmdlist
[i
]->level
& QCMD_ALIAS
)
95 /* Check that this user can use this command.. */
96 if ((cmdlist
[i
]->level
& QCMD_AUTHED
) && !rup
)
99 if ((cmdlist
[i
]->level
& QCMD_NOTAUTHED
) && rup
)
102 if ((cmdlist
[i
]->level
& QCMD_HELPER
) &&
103 (!rup
|| !UHasHelperPriv(rup
)))
106 if ((cmdlist
[i
]->level
& QCMD_OPER
) &&
107 (!rup
|| !UHasOperPriv(rup
) || !IsOper(sender
)))
110 if ((cmdlist
[i
]->level
& QCMD_ADMIN
) &&
111 (!rup
|| !UHasAdminPriv(rup
) || !IsOper(sender
)))
114 if ((cmdlist
[i
]->level
& QCMD_DEV
) &&
115 (!rup
|| !UIsDev(rup
) || !IsOper(sender
)))
118 summary
=(cmdsummary
*)cmdlist
[i
]->ext
;
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
);
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
;
145 chanservsendmessage(sender
, "%-20s %s",ct
, message
);
148 chanservstdmessage(sender
, QM_ENDOFLIST
);
153 int cs_sendhelp(nick
*sender
, char *thecmd
, int oneline
) {
158 if (!(cmd
=findcommandintree(cscommands
, thecmd
, 1))) {
159 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
163 /* Disable database help for now - splidge
164 csdb_dohelp(sender, cmd); */
166 rup
=getreguserfromnick(sender
);
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
);
179 if (sum
->defhelp
&& *(sum
->defhelp
)) {
181 chanservsendmessageoneline(sender
, sum
->defhelp
);
183 chanservsendmessage(sender
, sum
->defhelp
);
187 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
194 int cs_dohelp(void *source
, int cargc
, char **cargv
) {
198 return cs_doshowcommands(source
,cargc
,cargv
);
200 return cs_sendhelp(sender
, cargv
[0], 0);
204 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
205 char *nullbuf
="\001";
207 sendnoticetouser(chanservnick
, source
, "%cPING %s",
208 1, cargc
?cargv
[0]:nullbuf
);
213 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
214 sendnoticetouser(chanservnick
, source
, "\01VERSION Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)\01", QVERSION
);
215 sendnoticetouser(chanservnick
, source
, "\01VERSION Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)\01");
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)");
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");
232 void csdb_dohelp_real(PGconn
*, void *);
235 unsigned int numeric
;
236 sstring
*commandname
;
241 void csdb_dohelp(nick
*np
, Command
*cmd
) {
242 struct helpinfo
*hip
;
244 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
246 hip
->numeric
=np
->numeric
;
247 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
250 q9asyncquery(csdb_dohelp_real
, (void *)hip
,
251 "SELECT languageID, fullinfo from help where lower(command)=lower('%s')",cmd
->command
->content
);
254 void csdb_dohelp_real(PGconn
*dbconn
, void *arg
) {
255 struct helpinfo
*hip
=arg
;
256 nick
*np
=getnickbynumeric(hip
->numeric
);
263 freesstring(hip
->commandname
);
268 pgres
=PQgetResult(dbconn
);
270 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
271 Error("chanserv",ERR_ERROR
,"Error loading help text.");
272 freesstring(hip
->commandname
);
277 if (PQnfields(pgres
)!=2) {
278 Error("chanserv",ERR_ERROR
,"Help text format error.");
280 freesstring(hip
->commandname
);
285 num
=PQntuples(pgres
);
289 freesstring(hip
->commandname
);
294 if ((rup
=getreguserfromnick(np
)))
295 lang
=rup
->languageid
;
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)
309 chanservsendmessage(np
, result
);
311 cmdsummary
*sum
=hip
->cmd
->ext
;
312 if (sum
->defhelp
&& *(sum
->defhelp
)) {
313 chanservsendmessage(np
, sum
->defhelp
);
315 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
319 freesstring(hip
->commandname
);