]>
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];
74 n
=getcommandlist(cscommands
, cmdlist
, 200);
75 rup
=getreguserfromnick(sender
);
82 chanservstdmessage(sender
, QM_COMMANDLIST
);
87 if (cargc
>0 && !match2strings(cargv
[0],cmdlist
[i
]->command
->content
))
90 /* Don't list aliases */
91 if (cmdlist
[i
]->level
& QCMD_ALIAS
)
94 /* Check that this user can use this command.. */
95 if ((cmdlist
[i
]->level
& QCMD_AUTHED
) && !rup
)
98 if ((cmdlist
[i
]->level
& QCMD_NOTAUTHED
) && rup
)
101 if ((cmdlist
[i
]->level
& QCMD_HELPER
) &&
102 (!rup
|| !UHasHelperPriv(rup
)))
105 if ((cmdlist
[i
]->level
& QCMD_OPER
) &&
106 (!rup
|| !UHasOperPriv(rup
) || !IsOper(sender
)))
109 if ((cmdlist
[i
]->level
& QCMD_ADMIN
) &&
110 (!rup
|| !UHasAdminPriv(rup
) || !IsOper(sender
)))
113 if ((cmdlist
[i
]->level
& QCMD_DEV
) &&
114 (!rup
|| !UIsDev(rup
) || !IsOper(sender
)))
117 summary
=(cmdsummary
*)cmdlist
[i
]->ext
;
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
);
128 sprintf(cmdbuf
," %s",cmdlist
[i
]->command
->content
);
131 if (summary
->bylang
[lang
]) {
132 message
=summary
->bylang
[lang
]->content
;
133 } else if (summary
->bylang
[0]) {
134 message
=summary
->bylang
[0]->content
;
136 message
=summary
->def
->content
;
139 chanservsendmessage(sender
, "%-20s %s",UHasHelperPriv(rup
)?cmdbuf
:cmdlist
[i
]->command
->content
, message
);
142 chanservstdmessage(sender
, QM_ENDOFLIST
);
147 int cs_sendhelp(nick
*sender
, char *thecmd
, int oneline
) {
152 if (!(cmd
=findcommandintree(cscommands
, thecmd
, 1))) {
153 chanservstdmessage(sender
, QM_UNKNOWNCMD
, thecmd
);
157 /* Disable database help for now - splidge
158 csdb_dohelp(sender, cmd); */
160 rup
=getreguserfromnick(sender
);
162 /* Don't showhelp for privileged users to others.. */
163 if (((cmd
->level
& QCMD_HELPER
) && (!rup
|| !UHasHelperPriv(rup
))) ||
164 ((cmd
->level
& QCMD_OPER
) && (!rup
|| !UHasOperPriv(rup
))) ||
165 ((cmd
->level
& QCMD_ADMIN
) && (!rup
|| !UHasAdminPriv(rup
))) ||
166 ((cmd
->level
& QCMD_DEV
) && (!rup
|| !UIsDev(rup
)))) {
167 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
173 if (sum
->defhelp
&& *(sum
->defhelp
)) {
175 chanservsendmessageoneline(sender
, sum
->defhelp
);
177 chanservsendmessage(sender
, sum
->defhelp
);
181 chanservstdmessage(sender
, QM_NOHELP
, cmd
->command
->content
);
188 int cs_dohelp(void *source
, int cargc
, char **cargv
) {
192 return cs_doshowcommands(source
,cargc
,cargv
);
194 return cs_sendhelp(sender
, cargv
[0], 0);
198 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
199 char *nullbuf
="\001";
201 sendnoticetouser(chanservnick
, source
, "%cPING %s",
202 1, cargc
?cargv
[0]:nullbuf
);
207 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
208 sendnoticetouser(chanservnick
, source
, "\01VERSION Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)\01", QVERSION
);
209 sendnoticetouser(chanservnick
, source
, "\01VERSION Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)\01");
214 int cs_doversion(void *source
, int cargc
, char **cargv
) {
215 chanservsendmessage((nick
*)source
, "Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)", QVERSION
);
216 chanservsendmessage((nick
*)source
, "Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)");
220 int cs_doctcpgender(void *source
, int cargc
, char **cargv
) {
221 sendnoticetouser(chanservnick
, source
, "\1GENDER Anyone who has a bitch mode has to be female ;)\1");
226 void csdb_dohelp_real(PGconn
*, void *);
229 unsigned int numeric
;
230 sstring
*commandname
;
235 void csdb_dohelp(nick
*np
, Command
*cmd
) {
236 struct helpinfo
*hip
;
238 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
240 hip
->numeric
=np
->numeric
;
241 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
244 q9asyncquery(csdb_dohelp_real
, (void *)hip
,
245 "SELECT languageID, fullinfo from help where lower(command)=lower('%s')",cmd
->command
->content
);
248 void csdb_dohelp_real(PGconn
*dbconn
, void *arg
) {
249 struct helpinfo
*hip
=arg
;
250 nick
*np
=getnickbynumeric(hip
->numeric
);
257 freesstring(hip
->commandname
);
262 pgres
=PQgetResult(dbconn
);
264 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
265 Error("chanserv",ERR_ERROR
,"Error loading help text.");
266 freesstring(hip
->commandname
);
271 if (PQnfields(pgres
)!=2) {
272 Error("chanserv",ERR_ERROR
,"Help text format error.");
274 freesstring(hip
->commandname
);
279 num
=PQntuples(pgres
);
283 freesstring(hip
->commandname
);
288 if ((rup
=getreguserfromnick(np
)))
289 lang
=rup
->languageid
;
293 for (i
=0;i
<num
;i
++) {
294 j
=strtoul(PQgetvalue(pgres
,i
,0),NULL
,10);
295 if ((j
==0 && result
==NULL
) || (j
==lang
)) {
296 result
=PQgetvalue(pgres
,i
,1);
297 if(strlen(result
)==0)
303 chanservsendmessage(np
, result
);
305 cmdsummary
*sum
=hip
->cmd
->ext
;
306 if (sum
->defhelp
&& *(sum
->defhelp
)) {
307 chanservsendmessage(np
, sum
->defhelp
);
309 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
313 freesstring(hip
->commandname
);