1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
package Service;
use strict;
use Utils;
use Parser;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(init_sock init_service senddata);
my $sock;
sub init_sock
{
$sock = IO::Socket::INET->new(PeerHost => getconf("ip"),
PeerPort => getconf("port"),
Proto => 'TCP');
die "Can't connect to server: $!" unless $sock;
$sock->autoflush(1);
init_service();
while (defined(my $line = <$sock>))
{
chomp $line;
my @fields = split /\s+/, $line;
if (@fields>0)
{
parse_sockmsg($line);
}
}
}
sub init_service
{
# link to server & listen sock
senddata("SERVER ".getconf("service")." ".getconf("pass")." 0 :".getconf("desc")."");
senddata("BURST");
senddata(":".getconf("service")." NICK ".time." ".getconf("nick")." ".getconf("host")." ".getconf("host")." ".getconf("ident")." ".getconf("modes")." 0.0.0.0 :".getconf("name")."");
senddata(":".getconf("nick")." OPERTYPE Services");
senddata(":".getconf("service")." FJOIN ".getconf("chan")." ".time()." :@,".getconf("nick")."");
senddata("ENDOFBURST");
}
sub senddata
{
my $line = shift;
my $send = "$line\r\n";
syswrite($sock, $send, length($send));
#print "Sent: $line\n" if $nofork;
}
1; |