From e978e5763ae37cfb7c4d6812633c87ce80eb36a6 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 10 Mar 2011 14:06:36 -0600 Subject: [PATCH] add space stations to alliance member's planet list --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Alliance.pm | 2 ++ lib/Lacuna/DB/Result/Empire.pm | 3 +++ lib/Lacuna/DB/Result/Map/Body.pm | 2 ++ lib/Lacuna/RPC.pm | 6 ++++++ var/upgrades/3.000.sql | 2 ++ var/www/public/changes.txt | 3 ++- 7 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 var/upgrades/3.000.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 2015e380..10816b36 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 2.4800; +our $VERSION = 3.0000; 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/Alliance.pm b/lib/Lacuna/DB/Result/Alliance.pm index 3c5b473b..86412c89 100644 --- a/lib/Lacuna/DB/Result/Alliance.pm +++ b/lib/Lacuna/DB/Result/Alliance.pm @@ -22,6 +22,8 @@ __PACKAGE__->add_columns( __PACKAGE__->belongs_to('leader', 'Lacuna::DB::Result::Empire', 'leader_id', { on_delete => 'set null' }); __PACKAGE__->has_many('members', 'Lacuna::DB::Result::Empire', 'alliance_id'); __PACKAGE__->has_many('invites', 'Lacuna::DB::Result::AllianceInvite', 'alliance_id'); +__PACKAGE__->has_many('stations', 'Lacuna::DB::Result::Map::Body', 'alliance_id'); + sub date_created_formatted { diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index f6dc2765..58e2c80f 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -275,6 +275,9 @@ has rpc_count => ( sub get_status { my ($self) = @_; my $planet_rs = $self->planets; + if ($self->alliance_id) { + $planet_rs = $planet_rs->search({-or => { alliance_id => $self->alliance_id }}); + } my %planets; my @planet_ids; while (my $planet = $planet_rs->next) { diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index fce926f7..76f64b41 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -9,6 +9,7 @@ __PACKAGE__->load_components('DynamicSubclass'); __PACKAGE__->table('body'); __PACKAGE__->add_columns( star_id => { data_type => 'int', is_nullable => 0 }, + alliance_id => { data_type => 'int', is_nullable => 1 }, orbit => { data_type => 'int', default_value => 0 }, class => { data_type => 'varchar', size => 255, is_nullable => 0 }, size => { data_type => 'int', default_value => 0 }, @@ -182,6 +183,7 @@ __PACKAGE__->typecast_map(class => { # RELATIONSHIPS __PACKAGE__->belongs_to('star', 'Lacuna::DB::Result::Map::Star', 'star_id'); +__PACKAGE__->belongs_to('alliance', 'Lacuna::DB::Result::Alliance', 'alliance_id', { on_delete => 'set null' }); __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); __PACKAGE__->has_many('buildings','Lacuna::DB::Result::Building','body_id'); diff --git a/lib/Lacuna/RPC.pm b/lib/Lacuna/RPC.pm index 79cbeeab..b6d60411 100644 --- a/lib/Lacuna/RPC.pm +++ b/lib/Lacuna/RPC.pm @@ -58,6 +58,12 @@ sub get_body { # makes for uniform error handling, and prevents staleness confess [1002, 'Body does not exist.', $body_id]; } unless ($body->empire_id eq $empire->id) { + if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) { + if ($body->empire->alliance_id eq $empire->alliance_id) { + $body->tick; + return $body; + } + } confess [1010, "Can't manipulate a planet you don't inhabit."]; } $body->empire($empire); diff --git a/var/upgrades/3.000.sql b/var/upgrades/3.000.sql new file mode 100644 index 00000000..a1aef4fc --- /dev/null +++ b/var/upgrades/3.000.sql @@ -0,0 +1,2 @@ +alter table body add column alliance_id int; +alter table body add foreign key body_fk_alliance_id (alliance_id) references alliance (id) on delete set null; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 3e5ada0f..ea72b788 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,7 +1,8 @@ -2.4800 +3.0000 - Rule: Added Space Station Lab building, which will eventually allow building space station modules. - Rule: Allow building space station hulls. - Rule: Added Station Command Center, Parliament, Warehouse, and IBS modules for space stations. + - Rule: Members of an alliance have alliance controlled stations added to their planet list. - API: Sending ships that trigger defenses requires the new captchas. - API: Sending spies requires the new captchas. - API: Running spy missions require the new captchas. -- 2.51.2