]>
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"
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 { 't' , QCFLAG_TOPICSAVE
},
32 { 'v' , QCFLAG_VOICEALL
},
33 { 'w' , QCFLAG_WELCOME
},
34 { 'z' , QCFLAG_SUSPENDED
},
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
},
48 { 'p' , QCUFLAG_PROTECT
},
49 { 'q' , QCUFLAG_QUIET
},
50 { 't' , QCUFLAG_TOPIC
},
51 { 'v' , QCUFLAG_VOICE
},
52 { 'w' , QCUFLAG_HIDEWELCOME
},
55 const flag ruflags
[] = {
56 { 'a' , QUFLAG_ADMIN
},
58 { 'D' , QUFLAG_CLEANUPEXEMPT
},
59 { 'g' , QUFLAG_GLINE
},
60 { 'G' , QUFLAG_DELAYEDGLINE
},
61 { 'h' , QUFLAG_HELPER
},
63 { 'L' , QUFLAG_NOAUTHLIMIT
},
64 { 'n' , QUFLAG_NOTICE
},
66 { 'p' , QUFLAG_PROTECT
},
67 { 'r' , QUFLAG_RESTRICTED
},
68 { 'T' , QUFLAG_TRUST
},
69 { 'z' , QUFLAG_SUSPENDED
},
72 const flag mdflags
[] = {
73 { 'l' , MDFLAG_LIMIT
},
74 { 'b' , MDFLAG_BANNED
},
75 { 'u' , MDFLAG_ACTLIMIT
},
78 void chanservfreestuff ();
79 void chanservfinishinit ( int hooknum
, void * arg
);
81 void chanservdumpstuff ( void * arg
) {
82 dumplastjoindata ( "lastjoin.dump" );
86 /* Register the nick extension - the others are registered in the db module */
87 chanservnext
= registernickext ( "nickserv" );
92 if ( chanservext
!=- 1 && chanservnext
!=- 1 && chanservaext
!=- 1 ) {
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 );
102 chantypes
[ 7 ]= getsstring ( "upgrade" , 20 );
104 /* And the log system */
107 /* Set up the command handler, and built in commands */
108 chanservcommandinit ();
109 chanservaddcommand ( "showcommands" , 0 , 1 , cs_doshowcommands
, "Lists available commands." , "Usage: SHOWCOMMANDS [<mask>] \n Prints a list of commands currently available to you, where: \n mask - Mask of commands to list (* or ? are wildcards). If no mask is specified, \n all available commands are displayed." );
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 /* 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> \n Shows help for a command, where: \n command - the command to show help for. \n For a list of available commands, see SHOWCOMMANDS. \n " );
115 chanservaddcommand ( "version" , 0 , 1 , cs_doversion
, "Show Version." , "Usage: VERSION \n Shows the version number of the running bot." );
117 chanservaddctcpcommand ( "ping" , cs_doctcpping
);
118 chanservaddctcpcommand ( "version" , cs_doctcpversion
);
119 chanservaddctcpcommand ( "gender" , cs_doctcpgender
);
121 registerhook ( HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
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
);
129 void chanservfinishinit ( int hooknum
, void * arg
) {
130 Error ( "chanserv" , ERR_INFO
, "Database loaded, finishing initialisation." );
132 deregisterhook ( HOOK_CHANSERV_DBLOADED
, chanservfinishinit
);
134 readlastjoindata ( "lastjoin.dump" );
136 /* Schedule the dumps */
137 schedulerecurring ( time ( NULL
)+ DUMPINTERVAL
, 0 , DUMPINTERVAL
, chanservdumpstuff
, NULL
);
139 chanserv_init_status
= CS_INIT_NOUSER
;
141 /* Register the user */
142 scheduleoneshot ( time ( NULL
)+ 1 ,& chanservreguser
, NULL
);
145 void chanserv_finalinit () {
150 for ( i
= 0 ; i
< NICKHASHSIZE
; i
++)
151 for ( np
= nicktable
[ i
]; np
; np
= np
-> next
)
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
);
168 chanserv_init_status
= CS_INIT_READY
;
169 triggerhook ( HOOK_CHANSERV_RUNNING
, NULL
);
170 Error ( "chanserv" , ERR_INFO
, "Ready to roll." );
174 deleteallschedules ( cs_timerfunc
);
175 deleteallschedules ( chanservreguser
);
176 deleteallschedules ( chanservdumpstuff
);
177 deleteallschedules ( chanservdgline
);
179 if ( chanservext
>- 1 && chanservnext
>- 1 && chanservaext
>- 1 ) {
181 for ( i
= 0 ; i
< CHANTYPES
; i
++)
182 freesstring ( chantypes
[ i
]);
187 /* Free everything */
188 if ( chanservnext
!=- 1 ) {
189 releasenickext ( chanservnext
);
193 deregisterlocaluser ( chanservnick
, "Leaving" );
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); */
211 deregisterhook ( HOOK_CHANSERV_DBLOADED
, chanservfinishinit
); /* for safety */
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
);
218 chanservremovecommand ( "version" , cs_doversion
);
219 chanservremovectcpcommand ( "ping" , cs_doctcpping
);
220 chanservremovectcpcommand ( "version" , cs_doctcpversion
);
221 chanservremovectcpcommand ( "gender" , cs_doctcpgender
);
222 chanservcommandclose ();
225 chanservcryptofree ();