]>
jfr.im git - irc/SurrealServices/srsv.git/blob - branches/erry-devel/SrSv/IRCd/Event.pm
1 # This file is part of SurrealServices.
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.
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.
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
17 package SrSv
::IRCd
::Event
;
21 use Exporter
'import';
22 BEGIN { our @EXPORT_OK = qw(addhandler callfuncs) }
26 use SrSv
::IRCd
::Queue
qw(ircd_enqueue);
27 use SrSv
::IRCd
::State
qw($ircline $ircline_real synced initial_synced);
29 use SrSv
::Message
qw(add_callback message);
40 sub addhandler
($$$$;$) {
41 my ($type, $src, $dst, $cb, $po) = @_;
44 $cb = caller() . "::$cb";
47 print "Adding callback: $cb\n" if DEBUG
;
49 my @cond = ( CLASS
=> 'IRCD', TYPE
=> $type );
50 push @cond, ( SRC
=> $src ) if($src);
51 push @cond, ( DST
=> $dst ) if($dst);
55 TRIGGER_COND
=> { @cond },
56 CALL
=> 'SrSv::IRCd::Event::_realcall',
63 my ($args, $sync, $wf, $message);
79 SRC
=> (defined($_[1]) ? $args->[$_[1]] : undef),
80 DST
=> (defined($_[2]) ? $args->[$_[2]] : undef),
82 IRCLINE
=> ($sync ? $ircline : $ircline_real),
84 ON_FINISH
=> ($sync ? undef : 'SrSv::IRCd::Queue::finished'), # FIXME
85 SYNCED
=> [synced
, initial_synced
],
91 ircd_enqueue
($message);
98 my ($message, $callback) = @_;
100 print "Calling ", $callback->{REALCALL
}, " ", join(',', @{$message->{ARGS
}}), "\n" if DEBUG
();
101 $ircline = $message->{IRCLINE
};
103 local $SrSv::IRCd
::State
::synced
= $message->{SYNCED
}[0]; # XXX This is questionable.
104 local $SrSv::IRCd
::State
::initial_synced
= $message->{SYNCED
}[1];
106 print "IRCLINE is $ircline synced is $SrSv::IRCd::State::synced initial_synced is $SrSv::IRCd::State::initial_synced\n" if DEBUG
();
108 &{$callback->{REALCALL
}}(@{$message->{ARGS
}});
109 ircd
::flushmodes
() unless $message->{SYNC
}; # FIXME
110 print "Finished with $ircline\n" if DEBUG
();