From 6cfff39fa25a0aa2f1ee918844457bdc1a0d7666 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 30 Sep 2010 21:07:15 -0500 Subject: [PATCH] don't give back empire id if password is incorrect --- bin/util/benchmark.pl | 33 ++++++++++++++++++++++++++++----- lib/Lacuna/RPC/Empire.pm | 12 ++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/bin/util/benchmark.pl b/bin/util/benchmark.pl index 374c616d..d96d65ee 100644 --- a/bin/util/benchmark.pl +++ b/bin/util/benchmark.pl @@ -4,24 +4,45 @@ use JSON qw(to_json from_json); use 5.010; use Getopt::Long; use Time::HiRes; +use HTTP::Request::Common; my $empire_name; my $password; my $server; +my $ping; GetOptions( - 'empire-name=s' => \$empire_name, - 'password=s' => \$password, - 'server=s' => \$server, + 'empire-name=s' => \$empire_name, + 'password=s' => \$password, + 'server=s' => \$server, + 'ping' => \$ping, ); +my $ua = LWP::UserAgent->new; +$ua->timeout(30); +$ua->get('https://www.google.com/'); # prime it + + + +if ($ping) { + my $t = [Time::HiRes::gettimeofday]; + die 'nginx failed' unless $ua->get('https://'.$server.'/nginx_ping.txt')->is_success; + my $nginx_time = Time::HiRes::tv_interval($t); + $t = [Time::HiRes::gettimeofday]; + die 'starman failed' unless $ua->get('https://'.$server.'/starman_ping')->is_success; + my $starman_time = Time::HiRes::tv_interval($t); + say "Nginx: ".$nginx_time; + say "Starman: ". $starman_time; + say "Difference: ".($starman_time - $nginx_time); + exit; +} + + unless ($empire_name && $password && $server) { say "Usage: $0 --empire-name=xxx --password=xxx --server=us1.lacunaexpanse.com"; exit; } my $t = [Time::HiRes::gettimeofday]; -my $ua = LWP::UserAgent->new; -$ua->timeout(30); my $content = { jsonrpc => '2.0', id => 1, @@ -48,3 +69,5 @@ say "External Time = ".($total_time - $internal_time); say "Total Time = ".$total_time; + + diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index cfca6846..1eab8590 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -71,10 +71,15 @@ sub login { unless (defined $empire) { confess [1002, 'Empire does not exist.', $name]; } - if ($empire->stage eq 'new') { - confess [1100, "Your empire has not been completely created. You must complete it in order to play the game.", { empire_id => $empire->id } ]; + if ($empire->is_password_valid($password)) { + if ($empire->stage eq 'new') { + confess [1100, "Your empire has not been completely created. You must complete it in order to play the game.", { empire_id => $empire->id } ]; + } + else { + return { session_id => $empire->start_session({ api_key => $api_key, request => $plack_request })->id, status => $self->format_status($empire) }; + } } - unless ($empire->is_password_valid($password)) { + else { if ($password ne '' && $empire->sitter_password eq $password) { return { session_id => $empire->start_session({ api_key => $api_key, request => $plack_request, is_sitter => 1 })->id, status => $self->format_status($empire) }; } @@ -82,7 +87,6 @@ sub login { confess [1004, 'Password incorrect.', $password]; } } - return { session_id => $empire->start_session({ api_key => $api_key, request => $plack_request })->id, status => $self->format_status($empire) }; } -- 2.51.2