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 52 53 54 55 56 57 58 59 60
|
package Service;
use strict;
use Utils;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(sock_init);
my %socket;
my $CONNECT = 0;
sub sock_init
{
my $sock = IO::Socket::INET->new(PeerHost => getconf("ip"),
PeerPort => getconf("port"),
Proto => 'TCP');
die "Can't connect to server: $!" unless $sock;
$sock->autoflush(1);
$socket{"id"} = $sock;
# link to server
&send("SERVER ".getconf("service")." ".getconf("pass")." 0 :".getconf("desc")."");
&send("BURST");
$CONNECT = 1;
# bot creation
&init_bot if $CONNECT;
# listen and parse
&parse_line($sock);
}
sub init_bot
{
&send(":".getconf("service")." NICK ".time." ".getconf("nick")." ".getconf("host")." ".getconf("host")." ".getconf("ident")." ".getconf("modes")." 0.0.0.0 :".getconf("name")."");
&send(":".getconf("nick")." OPERTYPE Services");
&send(":".getconf("service")." FJOIN ".getconf("chan")." ".time()." :@,".getconf("nick")."");
&send("ENDOFBURST");
}
sub parse_line
{
my $sock = shift;
while (defined(my $line = <$sock>))
{
chomp $line;
print "-> $line\n";
}
}
sub send
{
my $line = shift;
my $send = "$line\r\n";
syswrite($socket{"id"}, $send, length($send));
}
1; |
Partager