]> jfr.im git - irc/SurrealServices/srsv.git/blame - branches/erry-devel/modules/services.pm
My work on this so far....
[irc/SurrealServices/srsv.git] / branches / erry-devel / modules / services.pm
CommitLineData
5975999e 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
16package services;
17use strict;
2eef9154 18use Data::Dumper;
5975999e 19use SrSv::Conf::Parameters services => [
20 [noexpire => undef],
21 [nickexpire => 21],
22 [vacationexpire => 90],
23 [nearexpire => 7],
24 [chanexpire => 21],
25 [validate_email => undef],
26 [validate_expire => 1],
27 [clone_limit => 3],
28 [chankilltime => 86400],
29
30 [default_protect => 'normal'],
31 [default_chanbot => undef],
32 [old_user_age => 300],
33
34 [log_overrides => 0],
35
36 [botserv => undef],
37 [nickserv => undef],
38 [chanserv => undef],
39 [memoserv => undef],
40 [adminserv => undef],
41 [operserv => undef],
42 [hostserv => undef],
43];
44
45use DBI;
46use SrSv::MySQL qw($dbh);
47use SrSv::Conf qw(main services sql);
48use SrSv::Conf2Consts qw(main services sql);
49use SrSv::Timer qw(add_timer);
50use SrSv::Agent;
51use SrSv::IRCd::Event qw(addhandler);
52use SrSv::Log;
53use SrSv::User qw( :flood __flood_expire );
54
55use modules::serviceslibs::adminserv;
56use modules::serviceslibs::nickserv;
57use modules::serviceslibs::chanserv;
58use modules::serviceslibs::operserv;
59use modules::serviceslibs::botserv;
60use modules::serviceslibs::memoserv;
61use modules::serviceslibs::hostserv;
62
63*conf = \%services_conf; # only used in some help docs
64
65our @agents = (
66 [$nickserv::nsnick_default, '+opqzBHS', 'Nick Registration Agent'],
67 [$chanserv::csnick_default, '+pqzBS', 'Channel Registration Agent'],
68 [$operserv::osnick_default, '+opqzBHS', 'Operator Services Agent'],
69 [$memoserv::msnick_default, '+pqzBS', 'Memo Exchange Agent'],
70 [$botserv::bsnick_default, '+pqzBS', 'Channel Bot Control Agent'],
71 [$adminserv::asnick_default, '+pqzBS', 'Services\' Administration Agent'],
72 [$hostserv::hsnick_default, '+pqzBS', 'vHost Agent']
73);
74if(services_conf_nickserv) {
75 push @agents, [services_conf_nickserv, '+opqzBHS', 'Nick Registration Agent'];
76 $nickserv::nsnick = services_conf_nickserv;
77}
78if(services_conf_chanserv) {
79 push @agents, [services_conf_chanserv, '+pqzBS', 'Channel Registration Agent'];
80 $chanserv::csnick = services_conf_nickserv;
81}
82if(services_conf_operserv) {
83 push @agents, [services_conf_operserv, '+opqzBHS', 'Operator Services Agent'];
84 $operserv::osnick = services_conf_operserv;
85}
86if(services_conf_memoserv) {
87 push @agents, [services_conf_memoserv, '+pqzBS', 'Memo Exchange Agent'];
88 $memoserv::msnick = services_conf_memoserv;
89}
90if(services_conf_botserv) {
91 push @agents, [services_conf_botserv, '+pqzBS', 'Channel Bot Control Agent'];
92 $botserv::bsnick = services_conf_botserv;
93}
94if(services_conf_adminserv) {
95 push @agents, [services_conf_adminserv, '+pqzBS', 'Services\' Administration Agent'];
96 $adminserv::asnick = services_conf_adminserv;
97}
98if(services_conf_hostserv) {
99 push @agents, [services_conf_hostserv, '+pqzBS', 'vHost Agent'];
100 $hostserv::hsnick = services_conf_hostserv;
101}
102
103our $qlreason = 'Reserved for Services';
104
105foreach my $a (@agents) {
2eef9154 106 print "AGENT " . Dumper($a);
5975999e 107 agent_connect($a->[0], 'services', undef, $a->[1], $a->[2]);
108 ircd::sqline($a->[0], $qlreason);
109 agent_join($a->[0], main_conf_diag);
2eef9154 110 my $rsUser = { NICK => $main::rsnick, ID => ircd::getUuid($main::rsnick) };
111 my $agent = { NICK => $a->[0], ID => ircd::getUuid ($a->[0]) };
112 ircd::setmode($agent, main_conf_diag, '+o', $agent);
5975999e 113}
114
115addhandler('ENDBURST', undef, undef, 'services::ev_connect');
116sub ev_connect {
117 botserv::eos();
118 nickserv::cleanup_users();
119 nickserv::fix_vhosts();
120 chanserv::eos();
121 operserv::expire();
122}
123
124addhandler('ENDBURST', undef, undef, 'services::eos');
125sub eos {
126 chanserv::eos($_[0]);
127}
128
129addhandler('KILL', undef, undef, 'nickserv::killhandle');
130
131addhandler('NICKCONN', undef, undef, 'services::ev_nickconn');
132sub ev_nickconn {
133 nickserv::nick_create(@_[0,2..4,8,5..7,9,10,11]);
134}
135
136# NickServ
137addhandler('NICKCHANGE', undef, undef, 'nickserv::nick_change');
138addhandler('QUIT', undef, undef, 'nickserv::nick_delete');
139addhandler('UMODE', undef, undef, 'nickserv::umode');
140addhandler('CHGHOST', undef, undef, 'nickserv::chghost');
141addhandler('CHGIDENT', undef, undef, 'nickserv::chgident');
142addhandler('USERIP', undef, undef, 'nickserv::userip');
143addhandler('SQUIT', undef, undef, 'nickserv::squit') if ircd::NOQUIT();
2eef9154 144addhandler("OPERUP", undef, undef, 'nickserv::handle_oper');
145addhandler('PRIVMSG', undef, undef, 'nickserv::dispatch');
5975999e 146addhandler('PRIVMSG', undef, lc services_conf_nickserv, 'nickserv::dispatch') if services_conf_nickserv;
147
148addhandler('BACK', undef, undef, 'nickserv::notify_auths');
149
150# ChanServ
151addhandler('JOIN', undef, undef, 'chanserv::user_join');
152addhandler('SJOIN', undef, undef, 'chanserv::handle_sjoin');
153addhandler('PART', undef, undef, 'chanserv::user_part');
154addhandler('KICK', undef, undef, 'chanserv::process_kick');
155addhandler('MODE', undef, qr/^#/, 'chanserv::chan_mode');
156addhandler('TOPIC', undef, undef, 'chanserv::chan_topic');
157
2eef9154 158addhandler('PRIVMSG', undef, undef, 'chanserv::dispatch');
5975999e 159addhandler('PRIVMSG', undef, lc services_conf_chanserv, 'chanserv::dispatch') if services_conf_chanserv;
160
161# OperServ
2eef9154 162addhandler('PRIVMSG', undef, undef, 'operserv::dispatch');
5975999e 163addhandler('PRIVMSG', undef, lc services_conf_operserv, 'operserv::dispatch') if services_conf_operserv;
164
165add_timer('flood_expire', 10, __PACKAGE__, 'services::flood_expire');
166
167sub flood_expire(;$) {
168 add_timer('flood_expire', 10, __PACKAGE__, 'services::flood_expire');
169 __flood_expire();
170}
171
172# MemoServ
2eef9154 173addhandler('PRIVMSG', undef, undef, 'memoserv::dispatch');
5975999e 174addhandler('PRIVMSG', undef, lc services_conf_memoserv, 'memoserv::dispatch') if services_conf_memoserv;
175addhandler('BACK', undef, undef, 'memoserv::notify');
176
177# BotServ
178addhandler('PRIVMSG', undef, undef, 'botserv::dispatch');
179# botserv takes all PRIVMSG and NOTICEs, so no special dispatch is needed.
180addhandler('NOTICE', undef, qr/^#/, 'botserv::chan_msg');
181
182# AdminServ
2eef9154 183addhandler('PRIVMSG', undef, undef, 'adminserv::dispatch');
5975999e 184addhandler('PRIVMSG', undef, lc services_conf_adminserv, 'adminserv::dispatch') if services_conf_adminserv;
185
186add_timer('', 30, __PACKAGE__, 'services::maint');
187#add_timer('', 20, __PACKAGE__, 'nickserv::cleanup_users');
188add_timer('', 60, __PACKAGE__, 'nickserv::expire_silence_timed');
189
190# HostServ
2eef9154 191addhandler('PRIVMSG', undef, undef, 'hostserv::dispatch');
5975999e 192addhandler('PRIVMSG', undef, lc services_conf_hostserv, 'hostserv::dispatch') if services_conf_hostserv;
193
194# $nick should be a registered root nick, if applicable
195# $src is the nick or nickid that sent the command
196sub ulog($$$$;$$) {
197 my ($service, $level, $text) = splice(@_, 0, 3);
198
199 my $hostmask = nickserv::get_hostmask($_[0]);
200
201 # TODO - Record this in the database
202
203 wlog($service, $level, "$hostmask - $text");
204}
205
206sub maint {
207 wlog($main::rsnick, LOG_INFO(), " -- Running maintenance routines.");
208 add_timer('', 3600, __PACKAGE__, 'services::maint');
209
210 nickserv::expire();
211 chanserv::expire();
212
213 wlog($main::rsnick, LOG_INFO(), " -- Maintenance routines complete.");
214}
215
216sub init {
217 my $tmpdbh = DBI->connect("DBI:mysql:".sql_conf_mysql_db, sql_conf_mysql_user, sql_conf_mysql_pass, { AutoCommit => 1, RaiseError => 1 });
218
219 $tmpdbh->do("TRUNCATE TABLE chanuser");
220 $tmpdbh->do("TRUNCATE TABLE nickchg");
221 $tmpdbh->do("TRUNCATE TABLE chan");
222 $tmpdbh->do("TRUNCATE TABLE chanban");
223 $tmpdbh->do("UPDATE user SET online=0, quittime=".time());
224
225 $tmpdbh->disconnect;
226}
227
228sub begin {
229 nickserv::init();
230 chanserv::init();
231 operserv::init();
232 botserv::init();
233 adminserv::init();
234 memoserv::init();
235 hostserv::init();
236}
237
238sub end {
239 $dbh->disconnect;
240}
241
242sub unload { }
243
2441;