]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanserv.c
3 * The main chanserv core file.
8 #include "../core/hooks.h"
9 #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 { '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 { 't' , QCUFLAG_TOPIC
},
48 { 'v' , QCUFLAG_VOICE
},
49 { 'w' , QCUFLAG_HIDEWELCOME
},
52 const flag ruflags
[] = {
53 { 'a' , QUFLAG_ADMIN
},
55 { 'D' , QUFLAG_CLEANUPEXEMPT
},
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 const flag mdflags
[] = {
70 { 'l' , MDFLAG_LIMIT
},
71 { 'b' , MDFLAG_BANNED
},
72 { 'u' , MDFLAG_ACTLIMIT
},
75 void chanservfreestuff ();
76 void chanservfinishinit ( int hooknum
, void * arg
);
78 void chanservdumpstuff ( void * arg
) {
79 dumplastjoindata ( "lastjoin.dump" );
83 /* Register the nick extension - the others are registered in the db module */
84 chanservnext
= registernickext ( "nickserv" );
89 if ( chanservext
!=- 1 && chanservnext
!=- 1 && chanservaext
!=- 1 ) {
90 /* Set up the chantypes */
91 chantypes
=( sstring
**) malloc ( CHANTYPES
* sizeof ( sstring
*));
92 chantypes
[ 0 ]= getsstring ( "(unspecified)" , 20 );
93 chantypes
[ 1 ]= getsstring ( "clan" , 20 );
94 chantypes
[ 2 ]= getsstring ( "league" , 20 );
95 chantypes
[ 3 ]= getsstring ( "private" , 20 );
96 chantypes
[ 4 ]= getsstring ( "special" , 20 );
97 chantypes
[ 5 ]= getsstring ( "gamesite" , 20 );
98 chantypes
[ 6 ]= getsstring ( "game" , 20 );
100 /* And the log system */
103 /* Set up the command handler, and built in commands */
104 chanservcommandinit ();
105 chanservaddcommand ( "showcommands" , 0 , 1 , cs_doshowcommands
, "Lists available commands." , "Usage: showcommands \n\n Prints a list of all commands currently available to you. \n " );
106 chanservaddcommand ( "quit" , QCMD_DEV
, 1 , cs_doquit
, "Makes the bot QUIT and \" reconnect \" ." , "" );
107 chanservaddcommand ( "rename" , QCMD_DEV
, 1 , cs_dorename
, "Changes the bot's name." , "" );
108 chanservaddcommand ( "rehash" , QCMD_DEV
, 0 , cs_dorehash
, "Reloads all text from database." , "" );
109 chanservaddcommand ( "help" , 0 , 1 , cs_dohelp
, "Displays help on a specific command." , "" );
110 chanservaddcommand ( "version" , 0 , 1 , cs_doversion
, "Show Version." , "" );
112 chanservaddctcpcommand ( "ping" , cs_doctcpping
);
113 chanservaddctcpcommand ( "version" , cs_doctcpversion
);
114 chanservaddctcpcommand ( "gender" , cs_doctcpgender
);
116 registerhook ( HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
118 /* Now that the database is in a separate module it might be loaded already. */
119 if ( chanservdb_ready
)
120 chanservfinishinit ( HOOK_CHANSERV_DBLOADED
, NULL
);
124 void chanservfinishinit ( int hooknum
, void * arg
) {
125 Error ( "chanserv" , ERR_INFO
, "Database loaded, finishing initialisation." );
127 deregisterhook ( HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
129 readlastjoindata ( "lastjoin.dump" );
131 /* Schedule the dumps */
132 schedulerecurring ( time ( NULL
)+ DUMPINTERVAL
, 0 , DUMPINTERVAL
, chanservdumpstuff
, NULL
);
134 chanserv_init_status
= CS_INIT_NOUSER
;
136 /* Register the user */
137 scheduleoneshot ( time ( NULL
)+ 1 ,& chanservreguser
, NULL
);
140 void chanserv_finalinit () {
145 for ( i
= 0 ; i
< NICKHASHSIZE
; i
++)
146 for ( np
= nicktable
[ i
]; np
; np
= np
-> next
)
149 /* Register core hooks */
150 registerhook ( HOOK_NICK_NEWNICK
, cs_handlenick
);
151 registerhook ( HOOK_NICK_ACCOUNT
, cs_handlenick
);
152 registerhook ( HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
153 registerhook ( HOOK_NICK_SETHOST
, cs_handlesethost
);
154 registerhook ( HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
155 registerhook ( HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
156 registerhook ( HOOK_CHANNEL_JOIN
, cs_handlejoin
);
157 registerhook ( HOOK_CHANNEL_CREATE
, cs_handlejoin
);
158 registerhook ( HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
159 registerhook ( HOOK_CHANNEL_BURST
, cs_handleburst
);
160 registerhook ( HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
161 registerhook ( HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
163 chanserv_init_status
= CS_INIT_READY
;
164 triggerhook ( HOOK_CHANSERV_RUNNING
, NULL
);
165 Error ( "chanserv" , ERR_INFO
, "Ready to roll." );
169 deleteallschedules ( cs_timerfunc
);
170 deleteallschedules ( chanservreguser
);
171 deleteallschedules ( chanservdumpstuff
);
172 deleteallschedules ( chanservdgline
);
174 if ( chanservext
>- 1 && chanservnext
>- 1 && chanservaext
>- 1 ) {
176 for ( i
= 0 ; i
< CHANTYPES
; i
++)
177 freesstring ( chantypes
[ i
]);
182 /* Free everything */
183 if ( chanservnext
!=- 1 ) {
184 releasenickext ( chanservnext
);
188 deregisterlocaluser ( chanservnick
, "Leaving" );
190 deregisterhook ( HOOK_NICK_NEWNICK
, cs_handlenick
);
191 deregisterhook ( HOOK_NICK_ACCOUNT
, cs_handlenick
);
192 deregisterhook ( HOOK_NICK_LOSTNICK
, cs_handlelostnick
);
193 deregisterhook ( HOOK_NICK_SETHOST
, cs_handlesethost
);
194 deregisterhook ( HOOK_CHANNEL_NEWCHANNEL
, cs_handlenewchannel
);
195 deregisterhook ( HOOK_CHANNEL_LOSTCHANNEL
, cs_handlelostchannel
);
196 deregisterhook ( HOOK_CHANNEL_JOIN
, cs_handlejoin
);
197 deregisterhook ( HOOK_CHANNEL_CREATE
, cs_handlejoin
);
198 deregisterhook ( HOOK_CHANNEL_MODECHANGE
, cs_handlemodechange
);
199 deregisterhook ( HOOK_CHANNEL_BURST
, cs_handleburst
);
200 deregisterhook ( HOOK_CHANNEL_TOPIC
, cs_handletopicchange
);
201 deregisterhook ( HOOK_CHANNEL_LOSTNICK
, cs_handlechanlostuser
);
202 /* deregisterhook(HOOK_CHANNEL_OPPED, cs_handleopchange);
203 deregisterhook(HOOK_CHANNEL_DEOPPED, cs_handleopchange);
204 deregisterhook(HOOK_CHANNEL_DEVOICED, cs_handleopchange);
205 deregisterhook(HOOK_CHANNEL_BANSET, cs_handlenewban); */
206 deregisterhook ( HOOK_CHANSERV_DBLOADED
, chanservfinishinit
); /* for safety */
208 chanservremovecommand ( "showcommands" , cs_doshowcommands
);
209 chanservremovecommand ( "quit" , cs_doquit
);
210 chanservremovecommand ( "rename" , cs_dorename
);
211 chanservremovecommand ( "rehash" , cs_dorehash
);
212 chanservremovecommand ( "help" , cs_dohelp
);
213 chanservremovecommand ( "version" , cs_doversion
);
214 chanservremovectcpcommand ( "ping" , cs_doctcpping
);
215 chanservremovectcpcommand ( "version" , cs_doctcpversion
);
216 chanservremovectcpcommand ( "gender" , cs_doctcpgender
);
217 chanservcommandclose ();