]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanserv.c
3 * The main chanserv core file.
7 #include "../core/hooks.h"
8 #include "../core/schedule.h"
13 int chanserv_init_status
;
17 const flag rcflags
[] = {
18 { 'a', QCFLAG_AUTOOP
},
19 { 'b', QCFLAG_BITCH
},
20 { 'c', QCFLAG_AUTOLIMIT
},
21 { 'e', QCFLAG_ENFORCE
},
22 { 'f', QCFLAG_FORCETOPIC
},
23 { 'g', QCFLAG_AUTOVOICE
},
25 { 'j', QCFLAG_JOINED
},
26 { 'k', QCFLAG_KNOWNONLY
},
27 { 'p', QCFLAG_PROTECT
},
28 { 's', QCFLAG_SPAMPROT
},
29 { 't', QCFLAG_TOPICSAVE
},
30 { 'v', QCFLAG_VOICEALL
},
31 { 'w', QCFLAG_WELCOME
},
32 { 'z', QCFLAG_SUSPENDED
},
35 const flag rcuflags
[] = {
36 { 'a', QCUFLAG_AUTOOP
},
37 { 'b', QCUFLAG_BANNED
},
38 { 'd', QCUFLAG_DENY
},
39 { 'g', QCUFLAG_AUTOVOICE
},
40 { 'i', QCUFLAG_HIDEINFO
},
41 { 'j', QCUFLAG_AUTOINVITE
},
42 { 'k', QCUFLAG_KNOWN
},
43 { 'm', QCUFLAG_MASTER
},
44 { 'n', QCUFLAG_OWNER
},
46 { 'p', QCUFLAG_PROTECT
},
47 { 'q', QCUFLAG_QUIET
},
48 { 's', QCUFLAG_SPAMCON
},
49 { 't', QCUFLAG_TOPIC
},
50 { 'v', QCUFLAG_VOICE
},
51 { 'w', QCUFLAG_HIDEWELCOME
},
54 const flag ruflags
[] = {
55 { 'a', QUFLAG_ADMIN
},
57 { 'g', QUFLAG_GLINE
},
58 { 'G', QUFLAG_DELAYEDGLINE
},
59 { 'h', QUFLAG_HELPER
},
61 { 'l', QUFLAG_NEEDAUTH
},
62 { 'L', QUFLAG_NOAUTHLIMIT
},
63 { 'n', QUFLAG_NOTICE
},
65 { 'p', QUFLAG_PROTECT
},
66 { 'r', QUFLAG_RESTRICTED
},
67 { 'z', QUFLAG_SUSPENDED
},
70 void chanservfreestuff();
71 void chanservfinishinit(int hooknum
, void *arg
);
73 void chanservdumpstuff(void *arg
) {
74 dumplastjoindata("lastjoin.dump");
78 /* Register the extension */
79 chanservext
=registerchanext("chanserv");
80 chanservnext
=registernickext("nickserv");
82 if (chanservext
!=-1 && chanservnext
!=-1) {
83 /* Set up the chantypes */
84 chantypes
=(sstring
**)malloc(CHANTYPES
*sizeof(sstring
*));
85 chantypes
[0]=getsstring("(unspecified)",20);
86 chantypes
[1]=getsstring("clan",20);
87 chantypes
[2]=getsstring("league",20);
88 chantypes
[3]=getsstring("private",20);
89 chantypes
[4]=getsstring("special",20);
90 chantypes
[5]=getsstring("gamesite",20);
91 chantypes
[6]=getsstring("game",20);
93 /* Set up the allocators and the hashes */
97 /* And the messages */
100 /* And the log system */
103 /* Now load the database */
104 chanserv_init_status
= CS_INIT_DB
;
107 /* Set up the command handler, and built in commands */
108 chanservcommandinit();
109 chanservaddcommand("showcommands", 0, 1, cs_doshowcommands
, "Lists available commands.");
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.");
113 chanservaddcommand("help", 0, 1, cs_dohelp
, "Displays help on a specific command.");
115 chanservaddctcpcommand("ping",cs_doctcpping
);
116 chanservaddctcpcommand("version",cs_doctcpversion
);
117 chanservaddctcpcommand("gender",cs_doctcpgender
);
119 registerhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
123 void chanservfinishinit(int hooknum
, void *arg
) {
124 Error("chanserv",ERR_INFO
,"Database loaded, finishing initialisation.");
126 deregisterhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
128 readlastjoindata("lastjoin.dump");
130 /* Schedule the dumps */
131 schedulerecurring(time(NULL
)+DUMPINTERVAL
,0,DUMPINTERVAL
,chanservdumpstuff
,NULL
);
133 chanserv_init_status
= CS_INIT_NOUSER
;
135 /* Register the user */
136 scheduleoneshot(time(NULL
)+1,&chanservreguser
,NULL
);
139 void chanserv_finalinit() {
144 for (i
=0;i
<NICKHASHSIZE
;i
++)
145 for (np
=nicktable
[i
];np
;np
=np
->next
)
148 /* Register core hooks */
149 registerhook(HOOK_NICK_NEWNICK
, cs_handlenick
);
150 registerhook(HOOK_NICK_ACCOUNT
, cs_handlenick
);
151 registerhook(HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
152 registerhook(HOOK_NICK_SETHOST
, cs_handlesethost
);
153 registerhook(HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
154 registerhook(HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
155 registerhook(HOOK_CHANNEL_JOIN
, cs_handlejoin
);
156 registerhook(HOOK_CHANNEL_CREATE
, cs_handlejoin
);
157 registerhook(HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
158 registerhook(HOOK_CHANNEL_BURST
, cs_handleburst
);
159 registerhook(HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
160 registerhook(HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
164 deleteallschedules(cs_timerfunc
);
165 deleteallschedules(chanservreguser
);
166 deleteallschedules(chanservdumpstuff
);
167 deleteallschedules(chanservdgline
);
169 if (chanservext
>-1 && chanservnext
>-1) {
171 for (i
=0;i
<CHANTYPES
;i
++)
172 freesstring(chantypes
[i
]);
179 /* Free everything */
180 if (chanservext
!=-1) {
181 releasechanext(chanservext
);
184 if (chanservnext
!=-1) {
185 releasenickext(chanservnext
);
189 deregisterlocaluser(chanservnick
, "Leaving");
191 deregisterhook(HOOK_NICK_NEWNICK
, cs_handlenick
);
192 deregisterhook(HOOK_NICK_ACCOUNT
, cs_handlenick
);
193 deregisterhook(HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
194 deregisterhook(HOOK_NICK_SETHOST
, cs_handlesethost
);
195 deregisterhook(HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
196 deregisterhook(HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
197 deregisterhook(HOOK_CHANNEL_JOIN
, cs_handlejoin
);
198 deregisterhook(HOOK_CHANNEL_CREATE
, cs_handlejoin
);
199 deregisterhook(HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
200 deregisterhook(HOOK_CHANNEL_BURST
, cs_handleburst
);
201 deregisterhook(HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
202 deregisterhook(HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
203 /* deregisterhook(HOOK_CHANNEL_OPPED, cs_handleopchange);
204 deregisterhook(HOOK_CHANNEL_DEOPPED, cs_handleopchange);
205 deregisterhook(HOOK_CHANNEL_DEVOICED, cs_handleopchange);
206 deregisterhook(HOOK_CHANNEL_BANSET, cs_handlenewban); */
207 deregisterhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
); /* for safety */
209 chanservremovecommand("showcommands", cs_doshowcommands
);
210 chanservremovecommand("quit", cs_doquit
);
211 chanservremovecommand("rename", cs_dorename
);
212 chanservremovecommand("rehash", cs_dorehash
);
213 chanservremovecommand("help", cs_dohelp
);
214 chanservremovectcpcommand("ping",cs_doctcpping
);
215 chanservremovectcpcommand("version",cs_doctcpversion
);
216 chanservremovectcpcommand("gender",cs_doctcpgender
);
217 chanservcommandclose();
225 void chanservfreestuff() {
227 chanindex
*cip
, *ncip
;
233 for (i
=0;i
<REGUSERHASHSIZE
;i
++) {
234 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
) {
235 freesstring(rup
->email
);
236 freesstring(rup
->lastuserhost
);
237 freesstring(rup
->suspendreason
);
238 freesstring(rup
->comment
);
239 freesstring(rup
->info
);
241 for (rcup
=rup
->knownon
;rcup
;rcup
=rcup
->nextbyuser
)
242 freesstring(rcup
->info
);
246 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
247 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
249 if ((rcp
=cip
->exts
[chanservext
])) {
250 freesstring(rcp
->welcome
);
251 freesstring(rcp
->topic
);
252 freesstring(rcp
->key
);
253 freesstring(rcp
->suspendreason
);
254 freesstring(rcp
->comment
);
255 for (rbp
=rcp
->bans
;rbp
;rbp
=rbp
->next
) {
256 freesstring(rbp
->reason
);
257 freechanban(rbp
->cbp
);
259 cip
->exts
[chanservext
]=NULL
;
260 releasechanindex(cip
);