From 873cdab011ca4fd2ddf3d3a67e4882030dd7252f Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 8 Jul 2012 15:52:35 -0600 Subject: [PATCH 1/8] Fixed Scows dumping on planets. --- lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm | 7 ++++++- var/www/public/changes.txt | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm b/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm index 38c1bfa3..cf53c137 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm @@ -23,7 +23,12 @@ after handle_arrival_procedures => sub { $self->delete; confess [-1]; } - $body_attacked->add_waste($self->hold_size); + my $payload = $self->payload; + my $waste_dumped = 0; + if (defined($payload->{resources})) { + $waste_dumped = $payload->{resources}{waste} if defined($payload->{resources}{waste}); + } + $body_attacked->add_waste($waste_dumped); $body_attacked->update; unless ($self->body->empire->skip_attack_messages) { diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 9730949e..e6e2ee9f 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0860: + - Fix: Scows deliver the amount of waste in their payload, not capacity. + 3.0859: - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go - Mod: Spies now have a higher chance of stealing or destroying a 'useful' plan -- 2.51.2 From 3875b55f86a0d9d0fd717aa74c032bf4f4425bfa Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 9 Jul 2012 12:02:07 -0600 Subject: [PATCH 2/8] Space Station Command fix. --- lib/Lacuna/RPC/Building/StationCommand.pm | 29 ++++++++++------------- var/www/public/changes.txt | 1 + 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/Lacuna/RPC/Building/StationCommand.pm b/lib/Lacuna/RPC/Building/StationCommand.pm index 27c0b4ec..feccf7ba 100644 --- a/lib/Lacuna/RPC/Building/StationCommand.pm +++ b/lib/Lacuna/RPC/Building/StationCommand.pm @@ -21,6 +21,8 @@ around 'view' => sub { my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); $out->{planet} = $building->body->get_status($empire); + $out->{ore} = $building->body->get_ore_status; + $out->{food} = $building->body->get_food_status; $out->{next_colony_cost} = $empire->next_colony_cost; return $out; }; @@ -29,28 +31,21 @@ sub view_plans { my ($self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - my $item_hash; - my $plans = $building->body->plans; - while (my $plan = $plans->next) { - my $key = sprintf("%s-%s-%s", $plan->class->name, $plan->level, $plan->extra_build_level); - if (defined($item_hash->{$key})) { - $item_hash->{$key}->{quantity}++; - } - else { - $item_hash->{$key} = { - quantity => 1, - name => $plan->class->name, - level => $plan->level, - extra_build_level => $plan->extra_build_level, + my @out; + my $sorted_plans = $building->body->sorted_plans; + foreach my $plan (@$sorted_plans) { + my $item = { + quantity => $plan->quantity, + name => $plan->class->name, + level => $plan->level, + extra_build_level => $plan->extra_build_level, }; - } + push @out, $item; } - my $out; - @{$out} = sort {$a->{name} cmp $b->{name} || $a->{level} <=> $b->{level} || $b->{extra_build_level} <=> $a->{extra_build_level} } values %{$item_hash}; return { status => $self->format_status($empire, $building->body), - plans => $out, + plans => \@out, } } diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index e6e2ee9f..5627dc45 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,5 +1,6 @@ 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. + - Fix: Space Station Command accessible via UI. 3.0859: - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go -- 2.51.2 From b4106fc74194b4b077dc5db1d2d092f2b2ad3994 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 9 Jul 2012 17:58:41 -0600 Subject: [PATCH 3/8] Updated API docs. --- docs/Archaeology.pod | 2 +- docs/Trade.pod | 82 +++++++++++--------------------------- lib/Lacuna.pm | 2 +- var/www/public/changes.txt | 8 ++++ 4 files changed, 34 insertions(+), 60 deletions(-) diff --git a/docs/Archaeology.pod b/docs/Archaeology.pod index 1fce7466..33b86395 100644 --- a/docs/Archaeology.pod +++ b/docs/Archaeology.pod @@ -60,7 +60,7 @@ Returns a summary of all glyphs that may be assembled in this archaeology minist "glyphs" : [ { "id" : "id-goes-here", - "type: : "bauxite", + "name: : "bauxite", "type" : "bauxite", "quantity" : 2 }, diff --git a/docs/Trade.pod b/docs/Trade.pod index 763ddfdf..d0ea4cb0 100644 --- a/docs/Trade.pod +++ b/docs/Trade.pod @@ -90,19 +90,14 @@ The number of glyphs of type C that you want to trade =item plans -The hash reference for plans can look like this: +The hash reference for plans looks like this: { "type" : "plan", - "plan_id" : "id-goes-here" - } - -Or it can look like this - - { - "type" : "plan", - "plan_type" : "Malcud Field", - " + "plan_type" : "Permanent_AlgaePond", + "level" : 1, + "extra_build_level" : 5, + "quantity" : 4, } @@ -112,9 +107,21 @@ Or it can look like this Must be exactly C. -=item plan_id +=item plan_type + +Same as returned by get_plan_summary. + +=item level + +Level of the plan being added. + +=item extra_build_level + +Level of plus to plan. Note this will be 0 except possibly when the base level is 1. + +=item quantity -The unique id of the plan that you want to trade. See the C method for a list of your plans. +Number of plans to add. =back @@ -238,30 +245,7 @@ The unique id of this building. =head2 get_plans ( session_id, building_id ) -Returns a list of plans that may be traded. Used with the C method. - - { - "plans" : [ - { - "id" : "id-goes-here", - "name" : "Intelligence Ministry", - "level" : "7", - "extra_build_level" : "0" # some special plans will build a building from their level all the way to this number - }, - ... - ], - "cargo_space_used_each" : 10000, - "status" : { ... } - } - -=head3 session_id - -A session id. - -=head3 building_id - -The unique id of this building. - +Deprecated Method. Please use get_plan_summary instead =head2 get_plan_summary ( session_id, building_id ) @@ -272,6 +256,7 @@ Used with the C method. "plans" : [ { "name" : "Intelligence Ministry", + "plan_type" : "Intelligence", "level" : "7", "extra_build_level" : "0", "quantity" : "2" @@ -293,27 +278,7 @@ The unique id of this building =head2 get_glyphs ( session_id, building_id ) -Returns a list of glyphs that may be traded. Used with the C method. - - { - "glyphs" : [ - { - "id" : "id-goes-here", - "type" : "bauxite" - }, - ... - ], - "cargo_space_used_each" : 100, - "status" : { ... } - } - -=head3 session_id - -A session id. - -=head3 building_id - -The unique id of this building. +This API call is now deprecated, please use get_glyph_summary instead. =head2 get_glyph_summary ( session_id, building_id ) @@ -322,12 +287,13 @@ Returns a summary of all glyphs that may be traded. Used with the C m { "glyphs" : [ { + "id" : "id-goes-here", + "name: : "bauxite", "type" : "bauxite", "quantity" : 2 }, ... ], - "cargo_space_used_each" : 100, "status" : { ... } } diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 4fe69b76..c9f91814 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0859; +our $VERSION = 3.0860; 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/var/www/public/changes.txt b/var/www/public/changes.txt index 5627dc45..39ed373a 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,6 +1,14 @@ 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. + - Fix: Updated API Docs for Trade, Archaeology, PCC, and SCC. + +3.0859: + - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go + - Mod: Spies now have a higher chance of stealing or destroying a 'useful' plan + - Mod: Spies may now steal or destroy more than one plan of a type + - Mod: Missions that require a plan, now take the lowest level/extra that meet the criteria + - Mod: Improved efficiency on planets with lots of glyphs and plans 3.0859: - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go -- 2.51.2 From ee5d319c45d098c7d5d227d4d3eb587b7aa93fd0 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 9 Jul 2012 18:32:41 -0600 Subject: [PATCH 4/8] Trade API needed more changes. --- docs/Trade.pod | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/docs/Trade.pod b/docs/Trade.pod index d0ea4cb0..1e46b831 100644 --- a/docs/Trade.pod +++ b/docs/Trade.pod @@ -854,7 +854,8 @@ The hash reference for glyphs looks like: { "type" : "glyph", - "glyph_id" : "id-goes-here" + "name : "bauxite", + "quantity" : 3 } =over @@ -863,30 +864,54 @@ The hash reference for glyphs looks like: Must be exactly C. -=item glyph_id +=item name + +The type of glyph you want to trade (must be an ore type name). + +=item quantity + +The number of glyphs of type C that you want to push. + +See the C method for a list of your glyphs. -The unique id of the glyph you want to push. See the C method for a list of your glyphs. - =back =item plans -The hash reference for plans looks like: +The hash reference for plans looks like this: { "type" : "plan", - "plan_id" : "id-goes-here" + "plan_type" : "Permanent_AlgaePond", + "level" : 1, + "extra_build_level" : 5, + "quantity" : 4, } + =over =item type Must be exactly C. -=item plan_id +=item plan_type + +Same as returned by get_plan_summary. + +=item level + +Level of the plan being pushed. + +=item extra_build_level + +Level of plus to plan. Note this will be 0 except possibly when the base level is 1. + +=item quantity + +The number of plans of that you want to push. -The unique id of the plan that you want to push. See the C method for a list of your plans. +See the C method for a list of your plans. =back -- 2.51.2 From 99838c0016f25ac4f3f1cf6edf2bd7fd31b9dec9 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Wed, 11 Jul 2012 11:53:50 -0400 Subject: [PATCH 5/8] Added logging of an empires RPC and rate-limited RPC per day --- bin/record_rpc.pl | 75 +++++++++++++++++++++++++++ lib/Lacuna/DB/Result/Empire.pm | 14 ++++- lib/Lacuna/DB/Result/Log/EmpireRPC.pm | 16 ++++++ lib/Lacuna/RPC.pm | 1 + lib/Lacuna/RPC/Empire.pm | 1 + var/upgrades/3.0860.sql | 13 +++++ 6 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 bin/record_rpc.pl create mode 100644 lib/Lacuna/DB/Result/Log/EmpireRPC.pm create mode 100644 var/upgrades/3.0860.sql diff --git a/bin/record_rpc.pl b/bin/record_rpc.pl new file mode 100644 index 00000000..9a77a5ab --- /dev/null +++ b/bin/record_rpc.pl @@ -0,0 +1,75 @@ +use 5.010; +use strict; +use feature "switch"; +use lib '/data/Lacuna-Server/lib'; +use Lacuna::DB; +use Lacuna; +use Lacuna::Util qw(format_date); +use Getopt::Long; +$|=1; +our $quiet; +GetOptions( + 'quiet' => \$quiet, +); + +out('Started'); +my $start = DateTime->now; + +out('Loading DB'); +our $db = Lacuna->db; +my $empire_rs = $db->resultset('Empire'); + +out('Recording each empires previous day RPC count.'); +# this assumes that this task runs before noon each day and that +# the memcache for the previous day has not yet expired. +my $now = DateTime->now; +my $yesterday = DateTime->now->subtract( hours => 12 ); +my $yesterday_formatted = format_date($yesterday,'%d'); +out ("Now is $now yesterday is $yesterday"); + +my $total_rpc = 0; +my $total_limits = 0; + +while (my $empire = $empire_rs->next) { + my $rpc = Lacuna->cache->get('rpc_count_'.$yesterday_formatted, $empire->id) || 0; + my $limits = Lacuna->cache->get('rpc_limit_'.$yesterday_formatted, $empire->id) || 0; + + out("Empire [".$empire->name."] had [$rpc] RPC and [$limits] rate limits yesterday"); + my $log = $db->resultset('Log::EmpireRPC')->create({ + date_stamp => $now, + empire_id => $empire->id, + empire_name => $empire->name, + rpc => $rpc, + limits => $limits, + }); + $total_rpc += $rpc; + $total_limits += $limits; +} +$db->resultset('Log::EmpireRPC')->create({ + date_stamp => $now, + empire_id => 0, + empire_name => 'totals', + rpc => $total_rpc, + limits => $total_limits, +}); + + +out("Total Empire wide had [$total_rpc] RPC and [$total_limits] rate limits yesterday"); + +my $finish = time; +out('Finished'); +out((($finish - $start->epoch)/60)." minutes have elapsed"); + + +############### +## SUBROUTINES +############### + +sub out { + my $message = shift; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} + + diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index e68ef212..0425eb3b 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -299,15 +299,27 @@ sub get_latest_message_id { return $message_id; } +# The number if times a RPC has been made to this empire has rpc_count => ( is => 'ro', lazy => 1, default => sub { my $self = shift; - return Lacuna->cache->increment('rpc_count_'.format_date(undef,'%d'), $self->id, 1, 60 * 60 * 26); + return Lacuna->cache->increment('rpc_count_'.format_date(undef,'%d'), $self->id, 1, 60 * 60 * 30); } ); +# The number of times the rate limit has been exceeded +has rpc_limit => ( + is => 'ro', + lazy => 1, + default => sub { + my ($self) = @_; + return Lacuna->cache->get('rpc_count_'.format_date(undef,'%d'), $self->id, 1, 60 * 60 * 30); + } +); + +# The one minute RPC rate has rpc_rate => ( is => 'ro', lazy => 1, diff --git a/lib/Lacuna/DB/Result/Log/EmpireRPC.pm b/lib/Lacuna/DB/Result/Log/EmpireRPC.pm new file mode 100644 index 00000000..81b5fe87 --- /dev/null +++ b/lib/Lacuna/DB/Result/Log/EmpireRPC.pm @@ -0,0 +1,16 @@ +package Lacuna::DB::Result::Log::EmpireRPC; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Log::WithEmpire'; +use Lacuna::Util; + +__PACKAGE__->table('empire_rpc_log'); +__PACKAGE__->add_columns( + rpc => { data_type => 'int', size => 11, is_nullable => 0, default => 0 }, + limits => { data_type => 'int', size => 11, is_nullable => 0, default => 0 }, +); + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC.pm b/lib/Lacuna/RPC.pm index d4ebb24f..600c73db 100644 --- a/lib/Lacuna/RPC.pm +++ b/lib/Lacuna/RPC.pm @@ -35,6 +35,7 @@ sub get_empire_by_session { if (defined $empire) { my $throttle = Lacuna->config->get('rpc_throttle') || 30; if ($empire->rpc_rate > $throttle) { + Lacuna->cache->increment('rpc_limit_'.format_date(undef,'%d'), $self->id, 1, 60 * 60 * 30); confess [1010, 'Slow down! No more than '.$throttle.' requests per minute.']; } my $max = Lacuna->config->get('rpc_limit') || 2500; diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 4c73053a..60e33691 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -75,6 +75,7 @@ sub login { } my $throttle = Lacuna->config->get('rpc_throttle') || 30; if ($empire->rpc_rate > $throttle) { + Lacuna->cache->increment('rpc_limit_'.format_date(undef,'%d'), $self->id, 1, 60 * 60 * 30); confess [1010, 'Slow down! No more than '.$throttle.' requests per minute.']; } my $max = Lacuna->config->get('rpc_limit') || 2500; diff --git a/var/upgrades/3.0860.sql b/var/upgrades/3.0860.sql new file mode 100644 index 00000000..3eac26dd --- /dev/null +++ b/var/upgrades/3.0860.sql @@ -0,0 +1,13 @@ +create table empire_rpc_log ( + id int(11) not null auto_increment, + date_stamp datetime not null, + empire_id int(11) not null, + empire_name varchar(30) not null, + rpc int(11) not null default 0, + limits int(11) not null default 0, + primary key (id), + key erl_idx_empire_id (empire_id), + key erl_idx_date_stamp (date_stamp), + constraint wc_erl_empire_id foreign key (empire_id) references empire (id) +); + -- 2.51.2 From 06d7314df748754990050b49111f283162c8f091 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Wed, 11 Jul 2012 12:03:21 -0400 Subject: [PATCH 6/8] Updated changes.txt --- var/www/public/changes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 39ed373a..31118ead 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,7 @@ - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. - Fix: Updated API Docs for Trade, Archaeology, PCC, and SCC. + - Add: Record each Empire's daily RPC use and RPC-throttles for later 'name and shame' reports 3.0859: - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go -- 2.51.2 From c5d7aeef2825c5d4acf00013858d890405ed774a Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Thu, 12 Jul 2012 02:51:14 -0400 Subject: [PATCH 7/8] Removed objection to having a 'total' --- var/upgrades/3.0860.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/var/upgrades/3.0860.sql b/var/upgrades/3.0860.sql index 3eac26dd..559d044e 100644 --- a/var/upgrades/3.0860.sql +++ b/var/upgrades/3.0860.sql @@ -7,7 +7,5 @@ create table empire_rpc_log ( limits int(11) not null default 0, primary key (id), key erl_idx_empire_id (empire_id), - key erl_idx_date_stamp (date_stamp), - constraint wc_erl_empire_id foreign key (empire_id) references empire (id) + key erl_idx_date_stamp (date_stamp) ); - -- 2.51.2 From 73134d3bbc376471948636160c07863902c57484 Mon Sep 17 00:00:00 2001 From: Brad Gilbert Date: Sat, 14 Jul 2012 08:58:27 -0500 Subject: [PATCH 8/8] Remove unsupported dump method from docs/WaterProduction.pod --- docs/WaterProduction.pod | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/docs/WaterProduction.pod b/docs/WaterProduction.pod index 288bb28d..82c7721f 100644 --- a/docs/WaterProduction.pod +++ b/docs/WaterProduction.pod @@ -4,27 +4,4 @@ Water Production is accessible via the URL C. The list of methods below represents changes and additions to the methods that all L share. - - -=head2 dump ( session_id, building_id, amount ) - -Converts water into waste. - - { - "status" : { ... } - } - -=head3 session_id - -A session id. - -=head3 building_id - -The unique id of the building. - -=head3 amount - -An integer representing the amount to dump. - - =cut -- 2.51.2