]>
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
);
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_dohelp(void *source
, int cargc
, char **cargv
) {
138 return cs_doshowcommands(source
,cargc
,cargv
);
140 if (!(cmd
=findcommandintree(cscommands
, cargv
[0], 1))) {
141 chanservstdmessage(sender
, QM_UNKNOWNCMD
, cargv
[0]);
145 csdb_dohelp(sender
, cmd
);
151 int cs_doctcpping(void *source
, int cargc
, char **cargv
) {
152 char *nullbuf
="\001";
154 sendnoticetouser(chanservnick
, source
, "%cPING %s",
155 1, cargc
?cargv
[0]:nullbuf
);
160 int cs_doctcpversion(void *source
, int cargc
, char **cargv
) {
161 sendnoticetouser(chanservnick
, source
, "\01VERSION Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)\01", QVERSION
);
162 sendnoticetouser(chanservnick
, source
, "\01VERSION Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)\01");
167 int cs_doversion(void *source
, int cargc
, char **cargv
) {
168 chanservsendmessage((nick
*)source
, "Q9 version %s (Compiled on " __DATE__
") (C) 2002-3 David Mansell (splidge)", QVERSION
);
169 chanservsendmessage((nick
*)source
, "Built on newserv version 1.00. (C) 2002-3 David Mansell (splidge)");
173 int cs_doctcpgender(void *source
, int cargc
, char **cargv
) {
174 sendnoticetouser(chanservnick
, source
, "\1GENDER Anyone who has a bitch mode has to be female ;)\1");
179 void csdb_dohelp_real(PGconn
*, void *);
182 unsigned int numeric
;
183 sstring
*commandname
;
187 void csdb_dohelp(nick
*np
, Command
*cmd
) {
188 struct helpinfo
*hip
;
190 hip
=(struct helpinfo
*)malloc(sizeof(struct helpinfo
));
192 hip
->numeric
=np
->numeric
;
193 hip
->commandname
=getsstring(cmd
->command
->content
, cmd
->command
->length
);
195 pqasyncquery(csdb_dohelp_real
, (void *)hip
,
196 "SELECT languageID, fullinfo from help where lower(command)=lower('%s')",cmd
->command
->content
);
199 void csdb_dohelp_real(PGconn
*dbconn
, void *arg
) {
200 struct helpinfo
*hip
=arg
;
201 nick
*np
=getnickbynumeric(hip
->numeric
);
207 pgres
=PQgetResult(dbconn
);
209 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
210 Error("chanserv",ERR_ERROR
,"Error loading help text.");
214 if (PQnfields(pgres
)!=2) {
215 Error("chanserv",ERR_ERROR
,"Help text format error.");
219 num
=PQntuples(pgres
);
223 freesstring(hip
->commandname
);
228 if ((rup
=getreguserfromnick(np
)))
229 lang
=rup
->languageid
;
233 for (i
=0;i
<num
;i
++) {
234 j
=strtoul(PQgetvalue(pgres
,i
,0),NULL
,10);
235 if ((j
==0 && result
==NULL
) || (j
==lang
)) {
236 result
=PQgetvalue(pgres
,i
,1);
237 if(strlen(result
)==0)
243 chanservstdmessage(np
, QM_NOHELP
, hip
->commandname
->content
);
245 chanservsendmessage(np
, result
);
247 freesstring(hip
->commandname
);