I have dropped by at #poe, but they didn't know either.
below is the main file
I hope it gets through as it should...
The try function is called in the irc::irc_public() function
This is the third version I'm building of ReaperBot. The first one could
only do one thing at a time. Then I build the second one, which uses
forking, but sometimes the database gets fucked up cause different
processes read/write the same file, so here I am, writing it in POE and
got stuck :(
thanks
Bart
------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use POE qw (Session Component::IRC);
use Time::HiRes qw (gettimeofday);
use try;
my $nickname = 'ReaprBot2';
my $username = 'ReaperBot';
my $ircname = 'ReaperBot, by daReaper';
my $server = 'irc.scholieren.com';
my $port = 6667;
my $channel = '#ftp4RB';
our @database;
my @leeches;
readDB();
sub irc::_start {
my ($kernel, $object) = @_[KERNEL, OBJECT];
$kernel->post('irc', 'register', 'all');
$kernel->post('irc', 'connect', {
Debug => 1,
Nick => $nickname,
Server => $server,
Port => $port,
Username => $username,
Ircname => $ircname,
} );
}
sub irc::irc_001 {
my $kernel = $_[KERNEL];
$kernel->post('irc', 'join', "$channel");
}
sub irc::irc_connect {
print "Connected to server\n";
}
sub irc::irc_public {
my ($kernel, $who, $chan, $msg) = @_[KERNEL, ARG0 .. ARG2];
if ($msg =~ /^\[#?FTP4Warez\]/i) {
addAd($kernel, $msg, $who);
}
if ($msg =~ /\@try ?(.+)?/i) {
if ($1) {
try->try($kernel, $1, $who);
}
}
}
POE::Component::IRC->new('irc') or die "noooo! $!\n";
POE::Session->new('irc' => [qw(_start irc_001 irc_public irc_connect)]);
$poe_kernel->run();
sub readDB {
open (DATABASE, "ftp4db.txt");
my $counter = 0;
while (<DATABASE>) {
chomp;
my @entry = split (/\t/);
for (my $x = 0; $x < @entry; $x++) {
$database[$counter][$x] = $entry[$x];
}
$counter ++;
}
close DATABASE;
}
sub writeDB {
open (DATABASE, ">ftp4db.txt");
for (my $x = 0; $x < @database; $x++) {
for (my $y = 0; $y < @{$database[$x]}; $y++) {
print DATABASE "$database[$x][$y]\t";
}
print DATABASE "\n";
}
close (DATABASE);
}
sub addAd {
my ($kernel, $msg, $who) = @_;
my ($nick, $ident, $host) = split(/!|@/, $who);
my @ftpsite;
while ($msg =~ /]]+/) {
$msg =~ s/]]+/]/;
}
while ($msg =~ /\[\[+/) {
$msg =~ s/\[\[+/\[/;
}
while ($msg) {
if ($msg =~ s/[^[]*\[([^\]]*)\]//) {
push @ftpsite, $1;
}
else {
$msg =~ s/ ?\[?//;
push @ftpsite, $msg;
$msg = "";
}
}
my %ftp = getInfo(@ftpsite);
if ($ftp{download}[0] && $ftp{look}[0] && $ftp{address} &&
$ftp{port}) {
if (!$ftp{request}) { $ftp{request} = "-" }
if (!$ftp{other}) { $ftp{other} = "-" }
if (!$ftp{upload}) { $ftp{upload}[0] = "-";
$ftp{upload}[1] = "-" }
$ftp{owner} = $nick;
insertDB(%ftp);
}
}
sub getInfo {
my @ftpsite = @_;
my %info;
my $counter = 0;
shift @ftpsite;
foreach(@ftpsite) {
if ($counter == 0) {
$info{name} = $_;
}
elsif (/^(port(:)?( )?)?(\d*)$/i) {
$info{port} = $4;
}
elsif (/^(([^ ]*)|({?your nick}?))\/(([^ ]*)|({?your
nick}?))$/i) {
my $user = $1;
my $pass = $4;
if ($user =~ /upload/i || $pass =~ /upload/i) {
$info{upload}[0] = $user;
$info{upload}[1] = $pass;
}
elsif ($user =~ /look|browse/i || $pass =~
/look|browse/i) {
$info{look}[0] = $user;
$info{look}[1] = $pass;
}
elsif (!$info{download}[0]) {
$info{download}[0] = $user;
$info{download}[1] = $pass;
}
}
elsif (/^(ip:[ ]?)?(.+\..+\..+[\..+]*)$/i &&
!$info{address}) {
$info{address} = $2;
}
elsif (/^req(uest)?(ing)?(s)?(:)?\s*(.*)/i) {
$info{request} = $5;
}
elsif (!$info{other}) {
$info{other} = $_;
}
$counter++;
}
return %info;
}
sub getAdByName {
my ($name) = @_;
for (my $x = 0; $x < scalar(@database); $x++) {
if ($database[$x][0] eq $name) {
return $x;
}
}
return -1;
}
sub getAdByOwner {
my ($owner) = @_;
for (my $x = 0; $x < $#database; $x++) {
if ($database[$x][1] eq $owner) {
return $x;
}
}
return -1;
}
sub insertDB {
my (%info) = @_;
#
0. Name
1. Owner
my @ftpsite = ( $info{name}, $info{owner},
# 2. IP 3. Port
$info{address}, $info{port},
#
4. Download User 5. Download Pass
$info{download}[0], $info{download}[1], #
7. Upload User 7. Upload Pass
$info{upload}[0], $info{upload}[1],
#
8. Look User 9. Look Pass
$info{look}[0], $info{look}[1], #
10. Requests 11. Other
$info{request}, $info{other},
#
12. Status 13. Last Check
"NOCHK", "0",
# 14. Last time ad seen 15. Last login
time, "0",
#
16. Login OK ? 17. Total FTP Size
"0", "0",
);
if (getAdByName($info{name}) == -1) {
push (@database, [@ftpsite]);
}
else {
my $ad = getAdByName($info{name});
foreach(12, 13, 15, 16, 17) {
$ftpsite[$_] = $database[$ad][$_];
}
$ftpsite[14] = time;
$database[$ad] = [@ftpsite];
}
writeDB();
}
------------------------------------------------------------------------
Erick Calder wrote:
> grr.. I keep hitting "reply" and I keep getting the messages bounced back to
> me.
>
> you should post the code so we know what you're doing. I suggest you drop
> by #poe on EFNET or feel free to contact me on AIM/YM: svekkis or ICQ
> 1005378