]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | /* |
2 | * chanserv.c: | |
3 | * The main chanserv core file. | |
4 | */ | |
5 | ||
6 | #include "chanserv.h" | |
dc9548f4 | 7 | #include "authlib.h" |
c86edd1d Q |
8 | #include "../core/hooks.h" |
9 | #include "../core/schedule.h" | |
b567a875 CP |
10 | #include "../lib/version.h" |
11 | ||
12 | MODULE_VERSION(QVERSION); | |
c86edd1d | 13 | |
c86edd1d Q |
14 | int chanservnext; |
15 | ||
16 | int chanserv_init_status; | |
17 | ||
18 | sstring **chantypes; | |
19 | ||
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 }, | |
27 | { 'i', QCFLAG_INFO }, | |
28 | { 'j', QCFLAG_JOINED }, | |
29 | { 'k', QCFLAG_KNOWNONLY }, | |
30 | { 'p', QCFLAG_PROTECT }, | |
c86edd1d Q |
31 | { 't', QCFLAG_TOPICSAVE }, |
32 | { 'v', QCFLAG_VOICEALL }, | |
33 | { 'w', QCFLAG_WELCOME }, | |
34 | { 'z', QCFLAG_SUSPENDED }, | |
35 | { '\0', 0 } }; | |
36 | ||
37 | const flag rcuflags[] = { | |
38 | { 'a', QCUFLAG_AUTOOP }, | |
39 | { 'b', QCUFLAG_BANNED }, | |
40 | { 'd', QCUFLAG_DENY }, | |
41 | { 'g', QCUFLAG_AUTOVOICE }, | |
42 | { 'i', QCUFLAG_HIDEINFO }, | |
43 | { 'j', QCUFLAG_AUTOINVITE }, | |
44 | { 'k', QCUFLAG_KNOWN }, | |
45 | { 'm', QCUFLAG_MASTER }, | |
46 | { 'n', QCUFLAG_OWNER }, | |
47 | { 'o', QCUFLAG_OP }, | |
48 | { 'p', QCUFLAG_PROTECT }, | |
49 | { 'q', QCUFLAG_QUIET }, | |
c86edd1d Q |
50 | { 't', QCUFLAG_TOPIC }, |
51 | { 'v', QCUFLAG_VOICE }, | |
52 | { 'w', QCUFLAG_HIDEWELCOME }, | |
53 | { '\0', 0 } }; | |
54 | ||
55 | const flag ruflags[] = { | |
56 | { 'a', QUFLAG_ADMIN }, | |
57 | { 'd', QUFLAG_DEV }, | |
7e0b37b0 | 58 | { 'D', QUFLAG_CLEANUPEXEMPT }, |
c86edd1d Q |
59 | { 'g', QUFLAG_GLINE }, |
60 | { 'G', QUFLAG_DELAYEDGLINE }, | |
61 | { 'h', QUFLAG_HELPER }, | |
62 | { 'i', QUFLAG_INFO }, | |
c86edd1d Q |
63 | { 'L', QUFLAG_NOAUTHLIMIT }, |
64 | { 'n', QUFLAG_NOTICE }, | |
65 | { 'o', QUFLAG_OPER }, | |
66 | { 'p', QUFLAG_PROTECT }, | |
67 | { 'r', QUFLAG_RESTRICTED }, | |
e58b744c | 68 | { 'T', QUFLAG_TRUST }, |
c86edd1d Q |
69 | { 'z', QUFLAG_SUSPENDED }, |
70 | { '\0', 0 } }; | |
71 | ||
e3805f60 P |
72 | const flag mdflags[] = { |
73 | { 'l', MDFLAG_LIMIT }, | |
74 | { 'b', MDFLAG_BANNED }, | |
75 | { 'u', MDFLAG_ACTLIMIT }, | |
76 | { '\0', 0 } }; | |
77 | ||
c86edd1d Q |
78 | void chanservfreestuff(); |
79 | void chanservfinishinit(int hooknum, void *arg); | |
80 | ||
81 | void chanservdumpstuff(void *arg) { | |
82 | dumplastjoindata("lastjoin.dump"); | |
83 | } | |
84 | ||
85 | void _init() { | |
b263aa79 | 86 | /* Register the nick extension - the others are registered in the db module */ |
c86edd1d Q |
87 | chanservnext=registernickext("nickserv"); |
88 | ||
45770ae6 | 89 | chanservcryptoinit(); |
dc9548f4 | 90 | csa_initregex(); |
45770ae6 | 91 | |
316959c1 | 92 | if (chanservext!=-1 && chanservnext!=-1 && chanservaext!=-1) { |
c86edd1d Q |
93 | /* Set up the chantypes */ |
94 | chantypes=(sstring **)malloc(CHANTYPES*sizeof(sstring *)); | |
95 | chantypes[0]=getsstring("(unspecified)",20); | |
96 | chantypes[1]=getsstring("clan",20); | |
97 | chantypes[2]=getsstring("league",20); | |
98 | chantypes[3]=getsstring("private",20); | |
99 | chantypes[4]=getsstring("special",20); | |
100 | chantypes[5]=getsstring("gamesite",20); | |
101 | chantypes[6]=getsstring("game",20); | |
af862bd5 | 102 | chantypes[7]=getsstring("upgrade",20); |
c86edd1d | 103 | |
c86edd1d Q |
104 | /* And the log system */ |
105 | cs_initlog(); | |
106 | ||
c86edd1d Q |
107 | /* Set up the command handler, and built in commands */ |
108 | chanservcommandinit(); | |
dd258305 | 109 | 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."); |
1f0d7c8b | 110 | chanservaddcommand("quit", QCMD_DEV, 1, cs_doquit, "Makes the bot QUIT and \"reconnect\".",""); |
111 | chanservaddcommand("rename", QCMD_DEV, 1, cs_dorename, "Changes the bot's name.",""); | |
112 | chanservaddcommand("rehash", QCMD_DEV, 0, cs_dorehash, "Reloads all text from database.",""); | |
96249709 | 113 | /* 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. */ |
114 | 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"); | |
634a5bfa | 115 | chanservaddcommand("version", 0, 1, cs_doversion, "Show Version.","Usage: VERSION\nShows the version number of the running bot."); |
64f17f02 | 116 | |
c86edd1d Q |
117 | chanservaddctcpcommand("ping",cs_doctcpping); |
118 | chanservaddctcpcommand("version",cs_doctcpversion); | |
119 | chanservaddctcpcommand("gender",cs_doctcpgender); | |
120 | ||
121 | registerhook(HOOK_CHANSERV_DBLOADED, chanservfinishinit); | |
b263aa79 | 122 | |
123 | /* Now that the database is in a separate module it might be loaded already. */ | |
124 | if (chanservdb_ready) | |
125 | chanservfinishinit(HOOK_CHANSERV_DBLOADED, NULL); | |
c86edd1d Q |
126 | } |
127 | } | |
128 | ||
129 | void chanservfinishinit(int hooknum, void *arg) { | |
130 | Error("chanserv",ERR_INFO,"Database loaded, finishing initialisation."); | |
131 | ||
132 | deregisterhook(HOOK_CHANSERV_DBLOADED, chanservfinishinit); | |
133 | ||
134 | readlastjoindata("lastjoin.dump"); | |
135 | ||
136 | /* Schedule the dumps */ | |
137 | schedulerecurring(time(NULL)+DUMPINTERVAL,0,DUMPINTERVAL,chanservdumpstuff,NULL); | |
138 | ||
139 | chanserv_init_status = CS_INIT_NOUSER; | |
140 | ||
141 | /* Register the user */ | |
142 | scheduleoneshot(time(NULL)+1,&chanservreguser,NULL); | |
143 | } | |
144 | ||
145 | void chanserv_finalinit() { | |
146 | int i; | |
147 | nick *np; | |
148 | ||
149 | /* Scan for users */ | |
150 | for (i=0;i<NICKHASHSIZE;i++) | |
151 | for (np=nicktable[i];np;np=np->next) | |
152 | cs_checknick(np); | |
153 | ||
154 | /* Register core hooks */ | |
155 | registerhook(HOOK_NICK_NEWNICK, cs_handlenick); | |
156 | registerhook(HOOK_NICK_ACCOUNT, cs_handlenick); | |
157 | registerhook(HOOK_NICK_LOSTNICK, cs_handlelostnick); | |
158 | registerhook(HOOK_NICK_SETHOST, cs_handlesethost); | |
159 | registerhook(HOOK_CHANNEL_NEWCHANNEL, cs_handlenewchannel); | |
160 | registerhook(HOOK_CHANNEL_LOSTCHANNEL, cs_handlelostchannel); | |
161 | registerhook(HOOK_CHANNEL_JOIN, cs_handlejoin); | |
162 | registerhook(HOOK_CHANNEL_CREATE, cs_handlejoin); | |
163 | registerhook(HOOK_CHANNEL_MODECHANGE, cs_handlemodechange); | |
164 | registerhook(HOOK_CHANNEL_BURST, cs_handleburst); | |
165 | registerhook(HOOK_CHANNEL_TOPIC, cs_handletopicchange); | |
166 | registerhook(HOOK_CHANNEL_LOSTNICK, cs_handlechanlostuser); | |
32562540 | 167 | |
168 | chanserv_init_status = CS_INIT_READY; | |
169 | triggerhook(HOOK_CHANSERV_RUNNING, NULL); | |
316959c1 | 170 | Error("chanserv",ERR_INFO,"Ready to roll."); |
c86edd1d Q |
171 | } |
172 | ||
173 | void _fini() { | |
174 | deleteallschedules(cs_timerfunc); | |
175 | deleteallschedules(chanservreguser); | |
176 | deleteallschedules(chanservdumpstuff); | |
177 | deleteallschedules(chanservdgline); | |
178 | ||
b263aa79 | 179 | if (chanservext>-1 && chanservnext>-1 && chanservaext>-1) { |
c86edd1d Q |
180 | int i; |
181 | for (i=0;i<CHANTYPES;i++) | |
182 | freesstring(chantypes[i]); | |
183 | ||
184 | free(chantypes); | |
185 | } | |
186 | ||
c86edd1d | 187 | /* Free everything */ |
c86edd1d Q |
188 | if (chanservnext!=-1) { |
189 | releasenickext(chanservnext); | |
190 | } | |
191 | ||
192 | if (chanservnick) | |
193 | deregisterlocaluser(chanservnick, "Leaving"); | |
194 | ||
195 | deregisterhook(HOOK_NICK_NEWNICK, cs_handlenick); | |
196 | deregisterhook(HOOK_NICK_ACCOUNT, cs_handlenick); | |
197 | deregisterhook(HOOK_NICK_LOSTNICK, cs_handlelostnick); | |
198 | deregisterhook(HOOK_NICK_SETHOST, cs_handlesethost); | |
199 | deregisterhook(HOOK_CHANNEL_NEWCHANNEL, cs_handlenewchannel); | |
200 | deregisterhook(HOOK_CHANNEL_LOSTCHANNEL, cs_handlelostchannel); | |
201 | deregisterhook(HOOK_CHANNEL_JOIN, cs_handlejoin); | |
202 | deregisterhook(HOOK_CHANNEL_CREATE, cs_handlejoin); | |
203 | deregisterhook(HOOK_CHANNEL_MODECHANGE, cs_handlemodechange); | |
204 | deregisterhook(HOOK_CHANNEL_BURST, cs_handleburst); | |
205 | deregisterhook(HOOK_CHANNEL_TOPIC, cs_handletopicchange); | |
206 | deregisterhook(HOOK_CHANNEL_LOSTNICK, cs_handlechanlostuser); | |
207 | /* deregisterhook(HOOK_CHANNEL_OPPED, cs_handleopchange); | |
208 | deregisterhook(HOOK_CHANNEL_DEOPPED, cs_handleopchange); | |
209 | deregisterhook(HOOK_CHANNEL_DEVOICED, cs_handleopchange); | |
210 | deregisterhook(HOOK_CHANNEL_BANSET, cs_handlenewban); */ | |
65f2c6a3 | 211 | deregisterhook(HOOK_CHANSERV_DBLOADED, chanservfinishinit); /* for safety */ |
c86edd1d Q |
212 | |
213 | chanservremovecommand("showcommands", cs_doshowcommands); | |
214 | chanservremovecommand("quit", cs_doquit); | |
215 | chanservremovecommand("rename", cs_dorename); | |
216 | chanservremovecommand("rehash", cs_dorehash); | |
217 | chanservremovecommand("help", cs_dohelp); | |
64f17f02 | 218 | chanservremovecommand("version", cs_doversion); |
c86edd1d Q |
219 | chanservremovectcpcommand("ping",cs_doctcpping); |
220 | chanservremovectcpcommand("version",cs_doctcpversion); | |
221 | chanservremovectcpcommand("gender",cs_doctcpgender); | |
222 | chanservcommandclose(); | |
223 | ||
dc9548f4 | 224 | csa_freeregex(); |
30a66d6c | 225 | chanservcryptofree(); |
dc9548f4 | 226 | |
c86edd1d | 227 | cs_closelog(); |
c86edd1d | 228 | } |