]>
jfr.im git - irc/SurrealServices/srsv.git/blob - branches/0.5.0/SrSv/IRCd/IO.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
::IO
;
21 use Exporter
'import';
22 BEGIN { our @EXPORT_OK = qw(ircd_connect ircd_disconnect ircsendimm ircsend ircd_flush_queue ) }
30 use SrSv
::Conf
'main';
31 use SrSv
::Process
::InParent
qw(irc_connect ircsend ircsendimm ircd_flush_queue);
32 use SrSv
::Process
::Worker
qw(ima_worker);
34 use SrSv
::IRCd
::State
qw($ircline $ircline_real $ircd_ready);
35 use SrSv
::IRCd
::Event
qw(callfuncs);
36 use SrSv
::Unreal
::Tokens
qw( :tokens );
37 use SrSv
::IRCd
::Parse
qw(parse_line);
38 use SrSv
::RunLevel
qw(emerg_shutdown);
39 use SrSv
::Log
qw( write_log );
46 print "IRC connection failed", ($_[0] ? ": $_[0]\n" : ".\n");
55 while($r = $irc_sock->sysread(my $part, 4096) > 0) {
59 irc_error
($!) if($r <= 0 and not $!{EAGAIN
});
61 my @lines = split(/\015\012/, $in);
63 $lines[0] = $partial . $lines[0];
64 if($in =~ /\015\012$/s) {
67 $partial = pop @lines;
70 foreach my $line (@lines) {
71 $ircline_real++ unless $line =~ /^(?:8|PING)/;
72 write_log
('netdump', '', $line) if main
::NETDUMP
();
73 print ">> $ircline_real $line\n" if DEBUG_ANY
;
74 foreach my $ev (parse_line
($line)) {
86 sub ircd_connect
($$) {
87 my ($remote, $port) = @_;
89 print "Connecting..." if DEBUG
;
90 $irc_sock = IO
::Socket
::INET-
>new(
95 ) or die("Could not connect to IRC server ($remote:$port): $!");
96 $irc_sock->blocking(0);
97 print " done\n" if DEBUG
;
99 $irc_sock->autoflush(1);
101 $watcher = Event-
>io(
108 sub ircd_disconnect
() {
116 print "ircsendimm() ima_worker: ", ima_worker
(), "\n" if DEBUG
;
118 if(defined $flood_queue) {
119 print "FLOOD QUEUE ACTIVE\n" if DEBUG
;
120 push @$flood_queue, @_;
124 while(my $line = shift @_) {
127 my $len = length($line) + 2;
128 write_log
('netdump', '', split(NL
, $line))
131 $r = $irc_sock->syswrite($line . NL
, undef, $bytes);
132 $bytes += $r if $r > 0;
134 if($r <= 0 or $r < $len) {
135 if($!{EAGAIN
} or ($r > 0 and $r < $len)) {
136 # Hold off to avoid flooding off
137 print "FLOOD QUEUE ACTIVE\n" if DEBUG
;
141 push @$flood_queue, substr($line, $bytes) unless $bytes == $len;
142 push @$flood_queue, @_;
148 cb
=> \
&flush_flood_queue
158 last if($bytes == $len);
160 print "<< $line\n" if DEBUG_ANY
;
165 print "ircsend() ima_worker: ", ima_worker
(), "\n" if DEBUG
;
168 print "<< $ircline $x\n";
176 if($x =~ /^@{[TOK_NICK]}/) {
185 sub ircd_flush_queue
() {
190 sub flush_flood_queue
() {
191 my $q = $flood_queue;