]>
Commit | Line | Data |
---|---|---|
aecfa1fd | 1 | # This file is part of SurrealServices. |
2 | # | |
3 | # SurrealServices is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # SurrealServices is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with SurrealServices; if not, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | package services; | |
17 | use strict; | |
5e682044 | 18 | use Data::Dumper; |
aecfa1fd | 19 | use SrSv::Conf::services; |
20 | ||
21 | use SrSv::MySQL qw($dbh); | |
22 | use SrSv::Conf qw(main services sql); | |
23 | use SrSv::Conf2Consts qw(main services sql); | |
24 | use SrSv::Timer qw(add_timer); | |
25 | use SrSv::Agent; | |
26 | use SrSv::IRCd::Event qw(addhandler); | |
27 | use SrSv::Log; | |
28 | use SrSv::User qw( :flood __flood_expire ); | |
29 | ||
30 | use modules::serviceslibs::adminserv; | |
31 | use modules::serviceslibs::nickserv; | |
32 | use modules::serviceslibs::chanserv; | |
33 | use modules::serviceslibs::operserv; | |
34 | use modules::serviceslibs::botserv; | |
35 | use modules::serviceslibs::memoserv; | |
36 | use modules::serviceslibs::hostserv; | |
7b3a5814 | 37 | use modules::nullserv; |
aecfa1fd | 38 | *conf = \%services_conf; # only used in some help docs |
39 | ||
40 | our @agents = ( | |
41 | [$nickserv::nsnick_default, '+opqzBHS', 'Nick Registration Agent'], | |
42 | [$chanserv::csnick_default, '+pqzBS', 'Channel Registration Agent'], | |
43 | [$operserv::osnick_default, '+opqzBHS', 'Operator Services Agent'], | |
44 | [$memoserv::msnick_default, '+pqzBS', 'Memo Exchange Agent'], | |
45 | [$botserv::bsnick_default, '+pqzBS', 'Channel Bot Control Agent'], | |
46 | [$adminserv::asnick_default, '+pqzBS', 'Services\' Administration Agent'], | |
47 | [$hostserv::hsnick_default, '+pqzBS', 'vHost Agent'] | |
48 | ); | |
49 | if(services_conf_nickserv) { | |
50 | push @agents, [services_conf_nickserv, '+opqzBHS', 'Nick Registration Agent']; | |
51 | $nickserv::nsnick = services_conf_nickserv; | |
52 | } | |
53 | if(services_conf_chanserv) { | |
54 | push @agents, [services_conf_chanserv, '+pqzBS', 'Channel Registration Agent']; | |
55 | $chanserv::csnick = services_conf_chanserv; | |
56 | } | |
57 | if(services_conf_operserv) { | |
58 | push @agents, [services_conf_operserv, '+opqzBHS', 'Operator Services Agent']; | |
59 | $operserv::osnick = services_conf_operserv; | |
60 | } | |
61 | if(services_conf_memoserv) { | |
62 | push @agents, [services_conf_memoserv, '+pqzBS', 'Memo Exchange Agent']; | |
63 | $memoserv::msnick = services_conf_memoserv; | |
64 | } | |
65 | if(services_conf_botserv) { | |
66 | push @agents, [services_conf_botserv, '+pqzBS', 'Channel Bot Control Agent']; | |
67 | $botserv::bsnick = services_conf_botserv; | |
68 | } | |
69 | if(services_conf_adminserv) { | |
70 | push @agents, [services_conf_adminserv, '+pqzBS', 'Services\' Administration Agent']; | |
71 | $adminserv::asnick = services_conf_adminserv; | |
72 | } | |
73 | if(services_conf_hostserv) { | |
74 | push @agents, [services_conf_hostserv, '+pqzBS', 'vHost Agent']; | |
75 | $hostserv::hsnick = services_conf_hostserv; | |
76 | } | |
77 | ||
78 | our $qlreason = 'Reserved for Services'; | |
79 | ||
80 | foreach my $a (@agents) { | |
81 | agent_connect($a->[0], 'services', undef, $a->[1], $a->[2]); | |
82 | ircd::sqline($a->[0], $qlreason); | |
83 | agent_join($a->[0], main_conf_diag); | |
026939ee | 84 | my $rsUser = { NICK => $main::rsnick, ID => 1 }; |
85 | my $agent = { NICK => $a->[0], ID => 2 }; | |
5e682044 | 86 | ircd::setmode($agent, main_conf_diag, '+o', $agent); |
aecfa1fd | 87 | } |
88 | ||
5e682044 | 89 | addhandler('ENDBURST', undef, undef, 'services::ev_connect'); |
aecfa1fd | 90 | sub ev_connect { |
91 | botserv::eos(); | |
92 | nickserv::cleanup_users(); | |
93 | nickserv::fix_vhosts(); | |
94 | chanserv::eos(); | |
95 | operserv::expire(); | |
96 | } | |
97 | ||
5e682044 | 98 | addhandler('ENDBURST', undef, undef, 'services::eos'); |
aecfa1fd | 99 | sub eos { |
100 | chanserv::eos($_[0]); | |
101 | } | |
102 | ||
103 | addhandler('KILL', undef, undef, 'nickserv::killhandle'); | |
104 | ||
105 | addhandler('NICKCONN', undef, undef, 'services::ev_nickconn'); | |
106 | sub ev_nickconn { | |
7b3a5814 | 107 | print "NICKCONN\n"; |
aecfa1fd | 108 | nickserv::nick_create(@_[0,2..4,8,5..7,9,10,11]); |
109 | } | |
110 | ||
111 | # NickServ | |
112 | addhandler('NICKCHANGE', undef, undef, 'nickserv::nick_change'); | |
113 | addhandler('QUIT', undef, undef, 'nickserv::nick_delete'); | |
114 | addhandler('UMODE', undef, undef, 'nickserv::umode'); | |
115 | addhandler('CHGHOST', undef, undef, 'nickserv::chghost'); | |
116 | addhandler('CHGIDENT', undef, undef, 'nickserv::chgident'); | |
117 | addhandler('USERIP', undef, undef, 'nickserv::userip'); | |
118 | addhandler('SQUIT', undef, undef, 'nickserv::squit') if ircd::NOQUIT(); | |
5e682044 | 119 | addhandler("OPERUP", undef, undef, 'nickserv::handle_oper'); |
92c29160 | 120 | addhandler('PRIVMSG', undef, undef, 'core::dispatch'); |
5e682044 | 121 | addhandler('PRIVMSG', undef, undef, 'nickserv::dispatch'); |
aecfa1fd | 122 | addhandler('PRIVMSG', undef, lc services_conf_nickserv, 'nickserv::dispatch') if services_conf_nickserv; |
123 | ||
124 | addhandler('BACK', undef, undef, 'nickserv::notify_auths'); | |
125 | ||
126 | # ChanServ | |
127 | addhandler('JOIN', undef, undef, 'chanserv::user_join'); | |
128 | addhandler('SJOIN', undef, undef, 'chanserv::handle_sjoin'); | |
129 | addhandler('PART', undef, undef, 'chanserv::user_part'); | |
130 | addhandler('KICK', undef, undef, 'chanserv::process_kick'); | |
131 | addhandler('MODE', undef, qr/^#/, 'chanserv::chan_mode'); | |
132 | addhandler('TOPIC', undef, undef, 'chanserv::chan_topic'); | |
133 | ||
5e682044 | 134 | addhandler('PRIVMSG', undef, undef, 'chanserv::dispatch'); |
aecfa1fd | 135 | addhandler('PRIVMSG', undef, lc services_conf_chanserv, 'chanserv::dispatch') if services_conf_chanserv; |
136 | ||
137 | # OperServ | |
5e682044 | 138 | addhandler('PRIVMSG', undef, undef, 'operserv::dispatch'); |
aecfa1fd | 139 | addhandler('PRIVMSG', undef, lc services_conf_operserv, 'operserv::dispatch') if services_conf_operserv; |
140 | ||
141 | add_timer('flood_expire', 10, __PACKAGE__, 'services::flood_expire'); | |
142 | ||
143 | sub flood_expire(;$) { | |
144 | add_timer('flood_expire', 10, __PACKAGE__, 'services::flood_expire'); | |
145 | __flood_expire(); | |
146 | } | |
147 | ||
148 | # MemoServ | |
5e682044 | 149 | addhandler('PRIVMSG', undef, undef, 'memoserv::dispatch'); |
aecfa1fd | 150 | addhandler('PRIVMSG', undef, lc services_conf_memoserv, 'memoserv::dispatch') if services_conf_memoserv; |
151 | addhandler('BACK', undef, undef, 'memoserv::notify'); | |
152 | ||
153 | # BotServ | |
154 | addhandler('PRIVMSG', undef, undef, 'botserv::dispatch'); | |
155 | # botserv takes all PRIVMSG and NOTICEs, so no special dispatch is needed. | |
156 | addhandler('NOTICE', undef, qr/^#/, 'botserv::chan_msg'); | |
157 | ||
158 | # AdminServ | |
5e682044 | 159 | addhandler('PRIVMSG', undef, undef, 'adminserv::dispatch'); |
aecfa1fd | 160 | addhandler('PRIVMSG', undef, lc services_conf_adminserv, 'adminserv::dispatch') if services_conf_adminserv; |
161 | ||
162 | add_timer('', 30, __PACKAGE__, 'services::maint'); | |
163 | #add_timer('', 20, __PACKAGE__, 'nickserv::cleanup_users'); | |
164 | add_timer('', 60, __PACKAGE__, 'nickserv::expire_silence_timed'); | |
165 | ||
166 | # HostServ | |
5e682044 | 167 | addhandler('PRIVMSG', undef, undef, 'hostserv::dispatch'); |
aecfa1fd | 168 | addhandler('PRIVMSG', undef, lc services_conf_hostserv, 'hostserv::dispatch') if services_conf_hostserv; |
169 | ||
170 | # $nick should be a registered root nick, if applicable | |
171 | # $src is the nick or nickid that sent the command | |
172 | sub ulog($$$$;$$) { | |
86a50b12 | 173 | |
aecfa1fd | 174 | my ($service, $level, $text) = splice(@_, 0, 3); |
175 | ||
176 | my $hostmask = nickserv::get_hostmask($_[0]); | |
aecfa1fd | 177 | # TODO - Record this in the database |
178 | ||
179 | wlog($service, $level, "$hostmask - $text"); | |
180 | } | |
181 | ||
182 | sub maint { | |
183 | wlog($main::rsnick, LOG_INFO(), " -- Running maintenance routines."); | |
184 | add_timer('', 3600, __PACKAGE__, 'services::maint'); | |
185 | ||
186 | nickserv::expire(); | |
187 | chanserv::expire(); | |
188 | ||
189 | wlog($main::rsnick, LOG_INFO(), " -- Maintenance routines complete."); | |
190 | } | |
191 | ||
192 | sub init { | |
193 | return if main::COMPILE_ONLY(); | |
194 | my $tmpdbh = DBI->connect("DBI:mysql:".sql_conf_mysql_db, sql_conf_mysql_user, sql_conf_mysql_pass, { AutoCommit => 1, RaiseError => 1 }); | |
195 | ||
196 | $tmpdbh->do("TRUNCATE TABLE chanuser"); | |
197 | $tmpdbh->do("TRUNCATE TABLE nickchg"); | |
198 | $tmpdbh->do("TRUNCATE TABLE chan"); | |
199 | $tmpdbh->do("TRUNCATE TABLE chanban"); | |
200 | $tmpdbh->do("UPDATE user SET online=0, quittime=".time()); | |
201 | ||
202 | $tmpdbh->disconnect; | |
203 | } | |
204 | ||
205 | sub begin { | |
206 | nickserv::init(); | |
207 | chanserv::init(); | |
208 | operserv::init(); | |
209 | botserv::init(); | |
210 | adminserv::init(); | |
211 | memoserv::init(); | |
212 | hostserv::init(); | |
213 | } | |
214 | ||
215 | sub end { | |
216 | $dbh->disconnect; | |
217 | } | |
218 | ||
219 | sub unload { } | |
220 | ||
221 | 1; |