3 * The main chanserv core file.
8 #include "../core/hooks.h"
9 #include "../core/schedule.h"
10 #include "../lib/version.h"
12 MODULE_VERSION(QVERSION
);
16 int chanserv_init_status
;
20 const flag rcflags
[] = {
21 { 'a', QCFLAG_AUTOOP
},
22 { 'b', QCFLAG_BITCH
},
23 { 'c', QCFLAG_AUTOLIMIT
},
24 { 'e', QCFLAG_ENFORCE
},
25 { 'f', QCFLAG_FORCETOPIC
},
26 { 'g', QCFLAG_AUTOVOICE
},
28 { 'j', QCFLAG_JOINED
},
29 { 'k', QCFLAG_KNOWNONLY
},
30 { 'p', QCFLAG_PROTECT
},
31 { 's', QCFLAG_NOINFO
},
32 { 't', QCFLAG_TOPICSAVE
},
33 { 'v', QCFLAG_VOICEALL
},
34 { 'w', QCFLAG_WELCOME
},
35 { 'z', QCFLAG_SUSPENDED
},
38 const flag rcuflags
[] = {
39 { 'a', QCUFLAG_AUTOOP
},
40 { 'b', QCUFLAG_BANNED
},
41 { 'd', QCUFLAG_DENY
},
42 { 'g', QCUFLAG_AUTOVOICE
},
43 { 'i', QCUFLAG_INFO
},
44 { 'j', QCUFLAG_AUTOINVITE
},
45 { 'k', QCUFLAG_KNOWN
},
46 { 'm', QCUFLAG_MASTER
},
47 { 'n', QCUFLAG_OWNER
},
49 { 'p', QCUFLAG_PROTECT
},
50 { 'q', QCUFLAG_QUIET
},
51 { 's', QCUFLAG_NOINFO
},
52 { 't', QCUFLAG_TOPIC
},
53 { 'v', QCUFLAG_VOICE
},
54 { 'w', QCUFLAG_HIDEWELCOME
},
57 const flag ruflags
[] = {
58 { 'a', QUFLAG_ADMIN
},
60 { 'D', QUFLAG_CLEANUPEXEMPT
},
61 { 'g', QUFLAG_GLINE
},
62 { 'G', QUFLAG_DELAYEDGLINE
},
63 { 'h', QUFLAG_HELPER
},
65 { 'L', QUFLAG_NOAUTHLIMIT
},
66 { 'n', QUFLAG_NOTICE
},
68 { 'p', QUFLAG_PROTECT
},
69 { 's', QUFLAG_NOINFO
},
70 { 'T', QUFLAG_TRUST
},
71 { 'z', QUFLAG_SUSPENDED
},
74 const flag mdflags
[] = {
75 { 'l', MDFLAG_LIMIT
},
76 { 'b', MDFLAG_BANNED
},
77 { 'u', MDFLAG_ACTLIMIT
},
80 void chanservfreestuff();
81 void chanservfinishinit(int hooknum
, void *arg
);
83 PQModuleIdentifier q9pqid
;
85 void chanservdumpstuff(void *arg
) {
86 dumplastjoindata("lastjoin.dump");
90 /* Register the nick extension - the others are registered in the db module */
91 chanservnext
=registernickext("nickserv");
98 if (chanservext
!=-1 && chanservnext
!=-1 && chanservaext
!=-1) {
99 /* Set up the chantypes */
100 chantypes
=(sstring
**)malloc(CHANTYPES
*sizeof(sstring
*));
101 chantypes
[0]=getsstring("(unspecified)",20);
102 chantypes
[1]=getsstring("clan",20);
103 chantypes
[2]=getsstring("league",20);
104 chantypes
[3]=getsstring("private",20);
105 chantypes
[4]=getsstring("special",20);
106 chantypes
[5]=getsstring("gamesite",20);
107 chantypes
[6]=getsstring("game",20);
108 chantypes
[7]=getsstring("upgrade",20);
110 /* And the log system */
113 /* Set up the command handler, and built in commands */
114 chanservcommandinit();
115 chanservaddcommand("showcommands", 0, 1, cs_doshowcommands
, "Lists available commands.","Usage: SHOWCOMMANDS [<mask>]\nPrints a list of commands currently available to you, where:\nmask - Mask of commands to list (* or ? are wildcards). If no mask is specified,\n all available commands are displayed.");
116 chanservaddcommand("quit", QCMD_DEV
, 1, cs_doquit
, "Makes the bot QUIT and \"reconnect\".","");
117 chanservaddcommand("rename", QCMD_DEV
, 1, cs_dorename
, "Changes the bot's name.","");
118 chanservaddcommand("rehash", QCMD_DEV
, 0, cs_dorehash
, "Reloads all text from database.","");
119 /* Make "HELP" take 2 arguments so things like "HELP chanflags #channel" work. Any junk after the command will go into arg 2 and be ignored. */
120 chanservaddcommand("help", 0, 2, cs_dohelp
, "Displays help on a specific command.","Usage: HELP <command>\nShows help for a command, where:\ncommand - the command to show help for.\nFor a list of available commands, see SHOWCOMMANDS.\n");
121 chanservaddcommand("version", 0, 1, cs_doversion
, "Show Version.","Usage: VERSION\nShows the version number of the running bot.");
123 chanservaddctcpcommand("ping",cs_doctcpping
);
124 chanservaddctcpcommand("version",cs_doctcpversion
);
125 chanservaddctcpcommand("gender",cs_doctcpgender
);
127 registerhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
129 /* Now that the database is in a separate module it might be loaded already. */
130 if (chanservdb_ready
)
131 chanservfinishinit(HOOK_CHANSERV_DBLOADED
, NULL
);
135 void chanservfinishinit(int hooknum
, void *arg
) {
136 Error("chanserv",ERR_INFO
,"Database loaded, finishing initialisation.");
138 deregisterhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
140 readlastjoindata("lastjoin.dump");
142 /* Schedule the dumps */
143 schedulerecurring(time(NULL
)+DUMPINTERVAL
,0,DUMPINTERVAL
,chanservdumpstuff
,NULL
);
145 chanserv_init_status
= CS_INIT_NOUSER
;
147 /* Register the user */
148 scheduleoneshot(time(NULL
)+1,&chanservreguser
,NULL
);
151 void chanserv_finalinit() {
156 for (i
=0;i
<NICKHASHSIZE
;i
++)
157 for (np
=nicktable
[i
];np
;np
=np
->next
)
160 /* Register core hooks */
161 registerhook(HOOK_NICK_NEWNICK
, cs_handlenick
);
162 registerhook(HOOK_NICK_ACCOUNT
, cs_handlenick
);
163 registerhook(HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
164 registerhook(HOOK_NICK_SETHOST
, cs_handlesethost
);
165 registerhook(HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
166 registerhook(HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
167 registerhook(HOOK_CHANNEL_JOIN
, cs_handlejoin
);
168 registerhook(HOOK_CHANNEL_CREATE
, cs_handlejoin
);
169 registerhook(HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
170 registerhook(HOOK_CHANNEL_BURST
, cs_handleburst
);
171 registerhook(HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
172 registerhook(HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
174 chanserv_init_status
= CS_INIT_READY
;
175 triggerhook(HOOK_CHANSERV_RUNNING
, NULL
);
176 Error("chanserv",ERR_INFO
,"Ready to roll.");
182 deleteallschedules(cs_timerfunc
);
183 deleteallschedules(chanservreguser
);
184 deleteallschedules(chanservdumpstuff
);
185 deleteallschedules(chanservdgline
);
187 if (chanservext
>-1 && chanservnext
>-1 && chanservaext
>-1) {
189 for (i
=0;i
<CHANTYPES
;i
++)
190 freesstring(chantypes
[i
]);
195 /* Free everything */
196 if (chanservnext
!=-1) {
197 releasenickext(chanservnext
);
201 deregisterlocaluser(chanservnick
, "Leaving");
203 deregisterhook(HOOK_NICK_NEWNICK
, cs_handlenick
);
204 deregisterhook(HOOK_NICK_ACCOUNT
, cs_handlenick
);
205 deregisterhook(HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
206 deregisterhook(HOOK_NICK_SETHOST
, cs_handlesethost
);
207 deregisterhook(HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
208 deregisterhook(HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
209 deregisterhook(HOOK_CHANNEL_JOIN
, cs_handlejoin
);
210 deregisterhook(HOOK_CHANNEL_CREATE
, cs_handlejoin
);
211 deregisterhook(HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
212 deregisterhook(HOOK_CHANNEL_BURST
, cs_handleburst
);
213 deregisterhook(HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
214 deregisterhook(HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
215 /* deregisterhook(HOOK_CHANNEL_OPPED, cs_handleopchange);
216 deregisterhook(HOOK_CHANNEL_DEOPPED, cs_handleopchange);
217 deregisterhook(HOOK_CHANNEL_DEVOICED, cs_handleopchange);
218 deregisterhook(HOOK_CHANNEL_BANSET, cs_handlenewban); */
219 deregisterhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
); /* for safety */
221 chanservremovecommand("showcommands", cs_doshowcommands
);
222 chanservremovecommand("quit", cs_doquit
);
223 chanservremovecommand("rename", cs_dorename
);
224 chanservremovecommand("rehash", cs_dorehash
);
225 chanservremovecommand("help", cs_dohelp
);
226 chanservremovecommand("version", cs_doversion
);
227 chanservremovectcpcommand("ping",cs_doctcpping
);
228 chanservremovectcpcommand("version",cs_doctcpversion
);
229 chanservremovectcpcommand("gender",cs_doctcpgender
);
230 chanservcommandclose();
233 chanservcryptofree();