Re: :Component::Client::FTP problem

2002-09-18 Thread Bart van den Burg

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 n! $!\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:[ 

RE: :Component::Client::FTP problem

2002-09-18 Thread Erick Calder

 I have dropped by at #poe, but they didn't know either.

it's a good place to hang out anyway :)

I see the call to try but if I recall the error was with the try module, not
its caller, so that was the code you needed to show.  if Rocco's suggestion
didn't work then come back to #poe.

-Original Message-
From: Bart van den Burg [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 18, 2002 10:42 AM
To: [EMAIL PROTECTED]
Subject: Re: :Component::Client::FTP problem


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 n! $!\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

RE: :Component::Client::FTP problem

2002-09-17 Thread Erick Calder

Bart,

the session you are creating needs an alias set to try since you're
telling the ftp client to use try to send its events...

you can do it like this:

sub start {
$_[KERNEL]-alias_set(try);
print *** test\n;
}

dngnand was going to add an arg to the session create function so you could
name it at creation time... but I don't know if that's released yet.

- e

-Original Message-
From: Bart [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 17, 2002 3:04 AM
To: [EMAIL PROTECTED]
Subject: POE::Component::Client::FTP problem


Hi

I'm trying to run Poco::Client::FTP in a self-made module file, but somehow,
it's going wrong.
I execute the function try::try($kernel, $1, $who); somewhere in the main
..pl file. The try function searches for $adname ($1) in the database, and if
it can find it, it logs into the ftp with the host/ip user/pass for that
ftp. Everything is going fine, POE connects to the server, executes the
start function as it should (*** test gets printed) and logs in. Then, it
should execute the inline authenticated() function, but it doesn't. I have
absolutely no idea why this is. The other 2 functions won't get executed
either, when they should.
Does anyone have an idea of what's going wrong ?
Thanks
Bart

--

use strict;
use warnings;

sub POE::Component::Client::FTP::DEBUG () { 1 };

use POE qw (Session Component::Client::FTP);

package try;

return 1;

sub login_error {
print *** no login\n;
}
sub authenticated {
print *** yes\n;
}
sub connect_error {
print *** no connection\n;
}

sub start {
print *** test\n;
}

sub try {
my ($kernel, $adname, $who) = @_;
my $number = -1;
my $counter = 0;
my $ftp = main::getAdByName($adname);
while ($number  0) {
if (!$main::leeches[$counter]) {
$number = $counter;
}
$counter ++;
}

POE::Component::Client::FTP-spawn(
Alias = try,
Username = $main::database[$ftp][4],
Password = $main::database[$ftp][5],
RemoteAddr = $main::database[$ftp][2],
RemotePort = $main::database[$ftp][3],
Timeout = 5,
Events = [qw (authenticated login_error connect_error
cmd_connected) ]
);

POE::Session-create(
inline_states = {
authenticated = sub { print test; }, #DOES NOT
GET EXECUTED
_start = \start, # GETS EXECUTED 
login_error = \login_error, #DOES NOT GET EXECUTED
cmd_connected = sub { print CONNECTED
\n; }, #DOES NOT GET EXECUTED
connect_error = \connect_error, #DOES NOT GET
EXECUTED
}
);
}




Re: :Component::Client::FTP problem

2002-09-17 Thread Rocco Caputo

On Tue, Sep 17, 2002 at 10:52:08AM -0700, Erick Calder wrote:
 Bart,
 
 the session you are creating needs an alias set to try since you're
 telling the ftp client to use try to send its events...
 
 you can do it like this:
 
 sub start {
   $_[KERNEL]-alias_set(try);
   print *** test\n;
   }
 
 dngnand was going to add an arg to the session create function so you could
 name it at creation time... but I don't know if that's released yet.

It's not.  I'm restructuring POE::Kernel and the event loop bridges
right now.  Things should be a little cleaner when I'm done, and
unfortunately temporarily slower.

If you've been following efnet #poe, there is some interest in
implementing XS counterparts for parts of POE.  My current work should
make things easier for them.

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net