From 47d0502d6aeba04af55d3fee19a6754d3465fc9b Mon Sep 17 00:00:00 2001 From: Darin McBride Date: Mon, 21 Dec 2015 14:51:55 -0700 Subject: [PATCH] Add back view_authorized_sitters, bump version, add empire info for all bodies --- docs/Empire.pod | 26 ++++++++++++++++---- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Empire.pm | 6 +++-- lib/Lacuna/RPC/Empire.pm | 44 +++++++++++++++++++++++++++------- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/docs/Empire.pod b/docs/Empire.pod index 4b93e82c..6fcfedcc 100644 --- a/docs/Empire.pod +++ b/docs/Empire.pod @@ -217,15 +217,15 @@ B You should probably B call this method directly, as it is a wast "bodies" : { "colonies" : [ # bodies are provided sorted by name already. - { "id" : "xxxx", "name" : "...", "x": "#", "y": "#" }, + { "id" : "xxxx", "name" : "...", "x": "#", "y": "#", "orbit": #, "empire_name": "your name", "empire_id": 12345 }, ... ], "mystations" : [ - { "id" : "xxxx", "name" : "...", "x": "#", "y": "#" }, + { "id" : "xxxx", "name" : "...", "x": "#", "y": "#", "orbit": #, "empire_name": "your name", "empire_id": 12345 }, ... ], "ourstations" : [ - { "id" : "xxxx", "name" : "...", "x": "#", "y": "#" }, + { "id" : "xxxx", "name" : "...", "x": "#", "y": "#", "orbit": #, "empire_name": "their name", "empire_id": 12346 }, ... ], "babies" : { @@ -234,7 +234,7 @@ B You should probably B call this method directly, as it is a wast "id" : 12355, # empire ID "has_new_messages" : 30, "bodies" : [ - { "id" : "xxxx", "name" : "...", "x": "#", "y": "#" }, + { "id" : "xxxx", "name" : "...", "x": "#", "y": "#", "orbit": #, "empire_name": "their name", "empire_id": 12346 }, ... ], }, @@ -242,7 +242,7 @@ B You should probably B call this method directly, as it is a wast "has_new_messages" : 30, "id" : 12884, "bodies" : [ - { "id" : "xxxx", "name" : "...", "x": "#", "y": "#" }, + { "id" : "xxxx", "name" : "...", "x": "#", "y": "#", "orbit": #, "empire_name": "their name too", "empire_id": 12347 }, ... ], } @@ -996,6 +996,22 @@ Returns an array ref of species templates that can be used to help the user popu ... ] +=head2 view_authorized_sitters + +Returns the currently authorized sitters for this baby. + + { + "status" : { ... }, + "sitters" : [ + { + "id" : 12345, + "name" : "Some Empire", + "expiry" : "2015-10-10 17:20:03" + }, + ... + ] + } + =head2 authorize_sitters ( session_id, options ) Authorizes other empires to babysit your account. Each authorisation will diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 30a0e144..dedaabf6 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0917; +our $VERSION = 3.0918; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 98bccce5..36df11c6 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -589,10 +589,10 @@ sub get_status { if ($self->alliance_id) { $planet_rs = Lacuna->db->resultset('Map::Body')-> search( - { -or => { empire_id => $real_empire->id, alliance_id => $real_empire->alliance_id } }, + { -or => { 'me.empire_id' => $real_empire->id, 'me.alliance_id' => $real_empire->alliance_id } }, ); } - $planet_rs = $planet_rs->search({},{ prefetch => 'star', order_by => 'me.name' }); + $planet_rs = $planet_rs->search({},{ prefetch => ['empire','star'], order_by => 'me.name' }); my %planets; my %stations; my %colonies; @@ -610,6 +610,8 @@ sub get_status { orbit => $planet->orbit, x => $planet->x, y => $planet->y, #,,, + empire_name => $planet->empire->name, + empire_id => $planet->empire_id, } }; diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index f00be1a5..ea50e96a 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -1154,13 +1154,42 @@ sub get_species_templates { ] } +sub view_authorized_sitters +{ + my ($self, $session_id) = @_; + my $session = $self->get_session($session_id); + my $baby = $session->current_empire(); + + my $rs = $baby->sitters() + ->search( + { expiry => { '>' => \q[UTC_TIMESTAMP()] } }, + { + '+select' => [ 'me.expiry' ], + '+as' => [ 'expiry' ], + order_by => 'sitter.name', + } + ); + + my @auths; + while (my $e = $rs->next) + { + push @auths, { + id => $e->id, + name => $e->name, + expiry => $e->get_column('expiry'), + }; + } + + return { status => $self->format_status($session->empire), sitters => \@auths }; +} + sub authorize_sitters { my ($self, $session_id, $opts) = @_; my $session = $self->get_session({session_id => $session_id}); $session->check_captcha; - my $baby = $self->get_empire_by_session($session); + my $baby = $session->current_empire; my $baby_id = $session->empire_id; my $rs = $baby->sitters; my $auths = Lacuna->db->resultset('SitterAuths'); @@ -1223,10 +1252,9 @@ sub authorize_sitters } } - return { - status => $self->format_status($session), - rejected_ids => \@bad_ids, - }; + my $rc = $self->view_authorized_sitters($session); + $rc->{rejected_ids} = \@bad_ids; + return $rc; } sub deauthorize_sitters @@ -1249,9 +1277,7 @@ sub deauthorize_sitters $rs->search({baby_id => $baby_id, sitter_id => { in => $opts->{empires} }}) ->update({expiry => $now}); - return { - status => $self->format_status($session), - }; + return $self->view_authorized_sitters($session); } __PACKAGE__->register_rpc_method_names( @@ -1278,7 +1304,7 @@ __PACKAGE__->register_rpc_method_names( get_full_status get_status boost_building boost_storage boost_water boost_energy boost_ore boost_food boost_happiness boost_spy_training view_boosts - authorize_sitters deauthorize_sitters + view_authorized_sitters authorize_sitters deauthorize_sitters ), ); -- 2.51.2