]>
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"
12 int chanserv_init_status
;
16 const flag rcflags
[] = {
17 { 'a', QCFLAG_AUTOOP
},
18 { 'b', QCFLAG_BITCH
},
19 { 'c', QCFLAG_AUTOLIMIT
},
20 { 'e', QCFLAG_ENFORCE
},
21 { 'f', QCFLAG_FORCETOPIC
},
22 { 'g', QCFLAG_AUTOVOICE
},
24 { 'j', QCFLAG_JOINED
},
25 { 'k', QCFLAG_KNOWNONLY
},
26 { 'p', QCFLAG_PROTECT
},
27 { 's', QCFLAG_SPAMPROT
},
28 { 't', QCFLAG_TOPICSAVE
},
29 { 'v', QCFLAG_VOICEALL
},
30 { 'w', QCFLAG_WELCOME
},
31 { 'z', QCFLAG_SUSPENDED
},
34 const flag rcuflags
[] = {
35 { 'a', QCUFLAG_AUTOOP
},
36 { 'b', QCUFLAG_BANNED
},
37 { 'd', QCUFLAG_DENY
},
38 { 'g', QCUFLAG_AUTOVOICE
},
39 { 'i', QCUFLAG_HIDEINFO
},
40 { 'j', QCUFLAG_AUTOINVITE
},
41 { 'k', QCUFLAG_KNOWN
},
42 { 'm', QCUFLAG_MASTER
},
43 { 'n', QCUFLAG_OWNER
},
45 { 'p', QCUFLAG_PROTECT
},
46 { 'q', QCUFLAG_QUIET
},
47 { 's', QCUFLAG_SPAMCON
},
48 { 't', QCUFLAG_TOPIC
},
49 { 'v', QCUFLAG_VOICE
},
50 { 'w', QCUFLAG_HIDEWELCOME
},
53 const flag ruflags
[] = {
54 { 'a', QUFLAG_ADMIN
},
56 { 'g', QUFLAG_GLINE
},
57 { 'G', QUFLAG_DELAYEDGLINE
},
58 { 'h', QUFLAG_HELPER
},
60 { 'l', QUFLAG_NEEDAUTH
},
61 { 'L', QUFLAG_NOAUTHLIMIT
},
62 { 'n', QUFLAG_NOTICE
},
64 { 'p', QUFLAG_PROTECT
},
65 { 'r', QUFLAG_RESTRICTED
},
66 { 'z', QUFLAG_SUSPENDED
},
69 void chanservfreestuff();
70 void chanservfinishinit(int hooknum
, void *arg
);
72 void chanservdumpstuff(void *arg
) {
73 dumplastjoindata("lastjoin.dump");
77 /* Register the nick extension - the others are registered in the db module */
78 chanservnext
=registernickext("nickserv");
80 if (chanservext
!=-1 && chanservnext
!=-1 && chanservaext
!=-1) {
81 /* Set up the chantypes */
82 chantypes
=(sstring
**)malloc(CHANTYPES
*sizeof(sstring
*));
83 chantypes
[0]=getsstring("(unspecified)",20);
84 chantypes
[1]=getsstring("clan",20);
85 chantypes
[2]=getsstring("league",20);
86 chantypes
[3]=getsstring("private",20);
87 chantypes
[4]=getsstring("special",20);
88 chantypes
[5]=getsstring("gamesite",20);
89 chantypes
[6]=getsstring("game",20);
91 /* And the log system */
94 /* Set up the command handler, and built in commands */
95 chanservcommandinit();
96 chanservaddcommand("showcommands", 0, 1, cs_doshowcommands
, "Lists available commands.");
97 chanservaddcommand("quit", QCMD_DEV
, 1, cs_doquit
, "Makes the bot QUIT and \"reconnect\".");
98 chanservaddcommand("rename", QCMD_DEV
, 1, cs_dorename
, "Changes the bot's name.");
99 chanservaddcommand("rehash", QCMD_DEV
, 0, cs_dorehash
, "Reloads all text from database.");
100 chanservaddcommand("help", 0, 1, cs_dohelp
, "Displays help on a specific command.");
102 chanservaddctcpcommand("ping",cs_doctcpping
);
103 chanservaddctcpcommand("version",cs_doctcpversion
);
104 chanservaddctcpcommand("gender",cs_doctcpgender
);
106 registerhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
108 /* Now that the database is in a separate module it might be loaded already. */
109 if (chanservdb_ready
)
110 chanservfinishinit(HOOK_CHANSERV_DBLOADED
, NULL
);
114 void chanservfinishinit(int hooknum
, void *arg
) {
115 Error("chanserv",ERR_INFO
,"Database loaded, finishing initialisation.");
117 deregisterhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
119 readlastjoindata("lastjoin.dump");
121 /* Schedule the dumps */
122 schedulerecurring(time(NULL
)+DUMPINTERVAL
,0,DUMPINTERVAL
,chanservdumpstuff
,NULL
);
124 chanserv_init_status
= CS_INIT_NOUSER
;
126 /* Register the user */
127 scheduleoneshot(time(NULL
)+1,&chanservreguser
,NULL
);
130 void chanserv_finalinit() {
135 for (i
=0;i
<NICKHASHSIZE
;i
++)
136 for (np
=nicktable
[i
];np
;np
=np
->next
)
139 /* Register core hooks */
140 registerhook(HOOK_NICK_NEWNICK
, cs_handlenick
);
141 registerhook(HOOK_NICK_ACCOUNT
, cs_handlenick
);
142 registerhook(HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
143 registerhook(HOOK_NICK_SETHOST
, cs_handlesethost
);
144 registerhook(HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
145 registerhook(HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
146 registerhook(HOOK_CHANNEL_JOIN
, cs_handlejoin
);
147 registerhook(HOOK_CHANNEL_CREATE
, cs_handlejoin
);
148 registerhook(HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
149 registerhook(HOOK_CHANNEL_BURST
, cs_handleburst
);
150 registerhook(HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
151 registerhook(HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
153 Error("chanserv",ERR_INFO
,"Ready to roll.");
157 deleteallschedules(cs_timerfunc
);
158 deleteallschedules(chanservreguser
);
159 deleteallschedules(chanservdumpstuff
);
160 deleteallschedules(chanservdgline
);
162 if (chanservext
>-1 && chanservnext
>-1 && chanservaext
>-1) {
164 for (i
=0;i
<CHANTYPES
;i
++)
165 freesstring(chantypes
[i
]);
170 /* Free everything */
171 if (chanservnext
!=-1) {
172 releasenickext(chanservnext
);
176 deregisterlocaluser(chanservnick
, "Leaving");
178 deregisterhook(HOOK_NICK_NEWNICK
, cs_handlenick
);
179 deregisterhook(HOOK_NICK_ACCOUNT
, cs_handlenick
);
180 deregisterhook(HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
181 deregisterhook(HOOK_NICK_SETHOST
, cs_handlesethost
);
182 deregisterhook(HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
183 deregisterhook(HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
184 deregisterhook(HOOK_CHANNEL_JOIN
, cs_handlejoin
);
185 deregisterhook(HOOK_CHANNEL_CREATE
, cs_handlejoin
);
186 deregisterhook(HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
187 deregisterhook(HOOK_CHANNEL_BURST
, cs_handleburst
);
188 deregisterhook(HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
189 deregisterhook(HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
190 /* deregisterhook(HOOK_CHANNEL_OPPED, cs_handleopchange);
191 deregisterhook(HOOK_CHANNEL_DEOPPED, cs_handleopchange);
192 deregisterhook(HOOK_CHANNEL_DEVOICED, cs_handleopchange);
193 deregisterhook(HOOK_CHANNEL_BANSET, cs_handlenewban); */
194 deregisterhook(HOOK_CHANSERV_DBLOADED
, chanservfinishinit
); /* for safety */
196 chanservremovecommand("showcommands", cs_doshowcommands
);
197 chanservremovecommand("quit", cs_doquit
);
198 chanservremovecommand("rename", cs_dorename
);
199 chanservremovecommand("rehash", cs_dorehash
);
200 chanservremovecommand("help", cs_dohelp
);
201 chanservremovectcpcommand("ping",cs_doctcpping
);
202 chanservremovectcpcommand("version",cs_doctcpversion
);
203 chanservremovectcpcommand("gender",cs_doctcpgender
);
204 chanservcommandclose();