]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanservstdcmds.c
58fdcd99fec2c64fdd274c8a261a3b4546b9b0c3
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];
74 n
=getcommandlist(cscommands
, cmdlist
, 200);
75 rup
=getreguserfromnick(sender
);
82 chanservstdmessage(sender
, QM_COMMANDLIST
);
85 if (cargc
>0 && !match2strings(cargv
[0],cmdlist
[i
]->command
->content
))
88 /* Don't list aliases */
89 if (cmdlist
[i
]->level
& QCMD_ALIAS
)
92 /* Check that this user can use this command.. */
93 if ((cmdlist
[i
]->level
& QCMD_AUTHED
) && !rup
)
96 if ((cmdlist
[i
]->level
& QCMD_NOTAUTHED
) && rup
)
99 if ((cmdlist
[i
]->level
& QCMD_HELPER
) &&
100 (!rup
|| !UHasHelperPriv(rup
)))
103 if ((cmdlist
[i
]->level
& QCMD_OPER
) &&
104 (!rup
|| !UHasOperPriv(rup
) || !IsOper(sender
)))
107 if ((cmdlist
[i
]->level
& QCMD_ADMIN
) &&
108 (!rup
|| !UHasAdminPriv(rup
) || !IsOper(sender
)))
111 if ((cmdlist
[i
]->level
& QCMD_DEV
) &&
112 (!rup
|| !UIsDev(rup
) || !IsOper(sender
)))
115 summary
=(cmdsummary
*)cmdlist
[i
]->ext
;
117 if (summary
->bylang
[lang
]) {
118 message
=summary
->bylang
[lang
]->content
;
119 } else if (summary
->bylang
[0]) {
120 message
=summary
->bylang
[0]->content
;
122 message
=summary
->def
->content
;
125 chanservsendmessage(sender
, "%-20s %s",cmdlist
[i
]->command
->content
, message
);
128 chanservstdmessage(sender
, QM_ENDOFLIST
);
133 int cs_sendhelp(nick
*sender
, char *thecmd
, int oneline
) {
138 if (!(cmd
=findcommandintree(cscommands
, thecmd
, 1))) {
139 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
143 /* Disable database help for now - splidge
144 csdb_dohelp(sender, cmd); */
146 rup
=getreguserfromnick(sender
);
148 /* Don't showhelp for privileged users to others.. */
149 if (((cmd
->level
& QCMD_HELPER
) && (!rup
|| !UHasHelperPriv(rup
))) ||
150 ((cmd
->level
& QCMD_OPER
) && (!rup
|| !UHasOperPriv(rup
))) ||
151 ((cmd
->level
& QCMD_ADMIN
) && (!rup
|| !UHasAdminPriv(rup
))) ||
152 ((cmd
->level
& QCMD_DEV
) && (!rup
|| !UIsDev(rup
)))) {
153 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
159 if (sum
->defhelp
&& *(sum
->defhelp
)) {
161 chanservsendmessageoneline(sender
, sum
->defhelp
);
163 chanservsendmessage(sender
, sum
->defhelp
);
167 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
174 int cs_dohelp(void *source
, int cargc
, char **cargv
) {
178 return cs_doshowcommands(source
,cargc
,cargv
);
180 return cs_sendhelp(sender
, cargv
[0], 0);
184 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
185 char *nullbuf
="\001";
187 sendnoticetouser(chanservnick
, source
, "%cPING %s",
188 1, cargc
?cargv
[0]:nullbuf
);
193 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
194 sendnoticetouser(chanservnick
, source
, "\01VERSION Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)\01", QVERSION
);
195 sendnoticetouser(chanservnick
, source
, "\01VERSION Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)\01");
200 int cs_doversion(void *source
, int cargc
, char **cargv
) {
201 chanservsendmessage((nick
*)source
, "Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)", QVERSION
);
202 chanservsendmessage((nick
*)source
, "Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)");
206 int cs_doctcpgender(void *source
, int cargc
, char **cargv
) {
207 sendnoticetouser(chanservnick
, source
, "\1GENDER Anyone who has a bitch mode has to be female ;)\1");
212 void csdb_dohelp_real(PGconn
*, void *);
215 unsigned int numeric
;
216 sstring
*commandname
;
221 void csdb_dohelp(nick
*np
, Command
*cmd
) {
222 struct helpinfo
*hip
;
224 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
226 hip
->numeric
=np
->numeric
;
227 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
230 q9asyncquery(csdb_dohelp_real
, (void *)hip
,
231 "SELECT languageID, fullinfo from help where lower(command)=lower('%s')",cmd
->command
->content
);
234 void csdb_dohelp_real(PGconn
*dbconn
, void *arg
) {
235 struct helpinfo
*hip
=arg
;
236 nick
*np
=getnickbynumeric(hip
->numeric
);
243 freesstring(hip
->commandname
);
248 pgres
=PQgetResult(dbconn
);
250 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
251 Error("chanserv",ERR_ERROR
,"Error loading help text.");
252 freesstring(hip
->commandname
);
257 if (PQnfields(pgres
)!=2) {
258 Error("chanserv",ERR_ERROR
,"Help text format error.");
260 freesstring(hip
->commandname
);
265 num
=PQntuples(pgres
);
269 freesstring(hip
->commandname
);
274 if ((rup
=getreguserfromnick(np
)))
275 lang
=rup
->languageid
;
279 for (i
=0;i
<num
;i
++) {
280 j
=strtoul(PQgetvalue(pgres
,i
,0),NULL
,10);
281 if ((j
==0 && result
==NULL
) || (j
==lang
)) {
282 result
=PQgetvalue(pgres
,i
,1);
283 if(strlen(result
)==0)
289 chanservsendmessage(np
, result
);
291 cmdsummary
*sum
=hip
->cmd
->ext
;
292 if (sum
->defhelp
&& *(sum
->defhelp
)) {
293 chanservsendmessage(np
, sum
->defhelp
);
295 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
299 freesstring(hip
->commandname
);