Authentication appears to work

This commit is contained in:
Ryan Voots 2011-10-23 20:07:53 -04:00
parent ca6348ea06
commit b634c19983
2 changed files with 25 additions and 9 deletions

View file

@ -7,13 +7,14 @@ package POE::Component::Minecraft;
use POE; use POE;
use POE::Component::Client::TCP; use POE::Component::Client::TCP;
use POE::Component::Client::HTTP; use POE::Component::Client::HTTP;
use POE::Component::SSLify; # i don't need to use this, BUT I do need to see it in the requirements
use HTTP::Request; use HTTP::Request;
use Data::Dumper;
our $client_version = 12; # current launcher version as of October 23rd 2011, package variable to allow monkey patching to new required versions our $client_version = 12; # current launcher version as of October 23rd 2011, package variable to allow monkey patching to new required versions
sub new { sub new {
my $class = shift; my $class = shift;
my $self = bless { }, $class;
my %opts = (username => undef, my %opts = (username => undef,
password => undef, password => undef,
@ -27,11 +28,12 @@ sub new {
); );
if (@_ > 1) { # do we have more than one argument left? if (@_ > 1) { # do we have more than one argument left?
%opts = @_; # we're given a hash if so %opts = (%opts, @_); # we're given a hash if so
} elsif (@_ == 1) { # exactly one, must be a hashref } elsif (@_ == 1) { # exactly one, must be a hashref
%opts = %$_[0]; %opts = (%opts, %{$_[0]});
} }
$alias = "resolver" unless $alias;
my $self = bless \%opts, $class;
$self->{_session} = POE::Session->create( $self->{_session} = POE::Session->create(
object_states => [ object_states => [
@ -39,13 +41,14 @@ sub new {
_start => "_poe_start", _start => "_poe_start",
login => "_poe_login", login => "_poe_login",
login_response => "_poe_login_response", login_response => "_poe_login_response",
connect => "_poe_connect",
}, },
], ],
); );
$self->{_http} = POE::Component::Client::HTTP->spawn( $self->{_http} = POE::Component::Client::HTTP->spawn(
Agent => 'Minecraft Bot 2387', # defaults to something long Agent => 'Minecraft Bot 2387', # defaults to something long
Alias => 'ua', # defaults to 'weeble' Alias => $self->{alias}.'UA', # defaults to 'weeble'
From => 'simcop2387@simcop2387.info', # defaults to undef (no header) From => 'simcop2387@simcop2387.info', # defaults to undef (no header)
Timeout => 60, # defaults to 180 seconds Timeout => 60, # defaults to 180 seconds
FollowRedirects => 2, # defaults to 0 (off) FollowRedirects => 2, # defaults to 0 (off)
@ -56,13 +59,15 @@ sub new {
sub _poe_start { sub _poe_start {
my $self = $_[OBJECT]; my $self = $_[OBJECT];
$_[KERNEL]->alias_set("$_[OBJECT]"); $_[KERNEL]->alias_set($_[OBJECT]->{alias});
} }
sub _poe_login { sub _poe_login {
my $self = $_[OBJECT]; my $self = $_[OBJECT];
my $to = $self->{_http}->ID(); print "Doing login\n";
my $to = $self->{alias}.'UA';
my $req = HTTP::Request->new(POST => 'https://login.minecraft.net/'); my $req = HTTP::Request->new(POST => 'https://login.minecraft.net/');
$req->content_type('application/x-www-form-urlencoded'); $req->content_type('application/x-www-form-urlencoded');
@ -75,6 +80,11 @@ sub _poe_login_response {
my $self = $_[OBJECT]; my $self = $_[OBJECT];
my ($req, $res) = @_[ARG0, ARG1]; my ($req, $res) = @_[ARG0, ARG1];
$res = $res->[0];
$req = $req->[0];
print "Got back login : ",$res->is_success(),"\n";
if ($res->is_success) if ($res->is_success)
{ {
print $res->content, "\n"; print $res->content, "\n";
@ -107,8 +117,9 @@ sub login {
if (defined($self->{username}) && defined($self->{password}) && if (defined($self->{username}) && defined($self->{password}) &&
defined($self->{server}) && defined($self->{port})) { defined($self->{server}) && defined($self->{port})) {
$poe_kernel->call($_[SESSION], login); $poe_kernel->call($self->{alias}, "login");
} else { } else {
print Dumper $self;
die "No Server or credentials"; die "No Server or credentials";
} }
} }

View file

@ -2,6 +2,7 @@
use lib 'lib'; use lib 'lib';
use POE qw/Component::Minecraft/; use POE qw/Component::Minecraft/;
use Data::Dumper;
my $username = $ARGV[0]; my $username = $ARGV[0];
my $password = $ARGV[1]; my $password = $ARGV[1];
@ -12,11 +13,15 @@ my $mc = POE::Component::Minecraft->new({
server => "mythmaster", server => "mythmaster",
}); });
print Dumper $mc;
POE::Session->create( POE::Session->create(
inline_states => { inline_states => {
_start => sub { _start => sub {
$mc->login(sub {print "woo!\n"}) $poe_kernel->delay(tick => 5);
$mc->login(sub {print "woo!\n"});
}, },
tick => sub {$poe_kernel->delay(tick => 5); print "tick\n";}
}, },
); );