diff --git a/docs/Parliament.pod b/docs/Parliament.pod index f74d7c03..7dc14b28 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -446,6 +446,88 @@ A 140 character string that cannot contain special characters or profanity. +=head2 propose_induct_member ( session_id, building_id, empire_id, [ message ] ) + +Induct a new member into the alliance. Once passed, an alliance invitation will be sent. Only works with Parliament 10 and higher. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Induct Member", + "description" : "Induct The Romulans as a new member of The Federation.", + "votes_needed" : 7, + "votes_yes" : 0, + "votes_no" : 0, + "status" : "Pending", + "date_ends" : "01 31 2010 13:09:05 +0600", + "proposed_by" : { + "id" : "id-goes-here", + "name" : "Klingons", + } + } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 empire_id + +The unique id of an empire proposed for membership in the alliance. + +=head3 message + +Optional. A personalized welcome message that will be included in the invitation. + + + + +=head2 propose_expel_member ( session_id, building_id, empire_id, [ message ] ) + +Expel a member from the alliance. Once passed, the member will be removed from the alliance. Only works with Parliament 10 and higher. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Expel Member", + "description" : "Expel The Romulans from The Federation.", + "votes_needed" : 7, + "votes_yes" : 0, + "votes_no" : 0, + "status" : "Pending", + "date_ends" : "01 31 2010 13:09:05 +0600", + "proposed_by" : { + "id" : "id-goes-here", + "name" : "Klingons", + } + } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 empire_id + +The unique id of an empire proposed for removal from the alliance. + +=head3 message + +An optional message about why you're removing them from the alliance. Cannot contain restricted characters or profanity. + + + + =head2 propose_elect_new_leader ( session_id, building_id, to_empire_id ) Elect a new leader of the alliance. Only works with Parliament 11 and higher. diff --git a/lib/Lacuna/DB/Result/Propositions.pm b/lib/Lacuna/DB/Result/Propositions.pm index fc262957..edb801d5 100644 --- a/lib/Lacuna/DB/Result/Propositions.pm +++ b/lib/Lacuna/DB/Result/Propositions.pm @@ -31,7 +31,9 @@ __PACKAGE__->typecast_map(type => { EnactWrit => 'Lacuna::DB::Result::Propositions::EnactWrit', ElectNewLeader => 'Lacuna::DB::Result::Propositions::ElectNewLeader', EvictMiningPlatform => 'Lacuna::DB::Result::Propositions::EvictMiningPlatform', + ExpelMember => 'Lacuna::DB::Result::Propositions::ExpelMember', FireBfg => 'Lacuna::DB::Result::Propositions::FireBfg', + InductMember => 'Lacuna::DB::Result::Propositions::InductMember', InstallModule => 'Lacuna::DB::Result::Propositions::InstallModule', MembersOnlyColonization => 'Lacuna::DB::Result::Propositions::MembersOnlyColonization', MembersOnlyMiningRights => 'Lacuna::DB::Result::Propositions::MembersOnlyMiningRights', diff --git a/lib/Lacuna/DB/Result/Propositions/ExpelMember.pm b/lib/Lacuna/DB/Result/Propositions/ExpelMember.pm new file mode 100644 index 00000000..0d45213d --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/ExpelMember.pm @@ -0,0 +1,33 @@ +package Lacuna::DB::Result::Propositions::ExpelMember; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $alliance = $station->alliance; + my $empire_to_remove = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($self->scratch->{empire_id}); + if (defined $empire_to_remove) { + if ($empire_to_remove->alliance_id == $alliance->id) { + $alliance->remove_member($empire_to_remove); + $empire_to_remove->send_predefined_message( + from => $alliance->leader, + tags => ['Correspondence'], + filename => 'alliance_expelled.txt', + params => [$alliance->id, $alliance->name, $self->scratch->{message}, $alliance->name], + ); + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the empire to expel was no longer a member of the alliance, effectively nullifying the vote.'); + } + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the empire to expel no longer existed, effectively nullifying the vote.'); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/InductMember.pm b/lib/Lacuna/DB/Result/Propositions/InductMember.pm new file mode 100644 index 00000000..439d1ba4 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/InductMember.pm @@ -0,0 +1,29 @@ +package Lacuna::DB::Result::Propositions::InductMember; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $station = $self->station; + my $alliance = $station->alliance; + my $invite_empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($self->scratch->{empire_id}); + if (defined $invite_empire) { + my $count = $alliance->members->count; + $count += $alliance->invites->count; + if ($count < $self->max_members ) { + $alliance->send_invite($invite_empire, $self->scratch->{message}); + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the alliance had reached maximum membership, effectively nullifying the vote.'); + } + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the empire of the proposed new member no longer existed, effectively nullifying the vote.'); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index 3ed9f5c4..4457ee9d 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -604,8 +604,89 @@ sub propose_elect_new_leader { }; } +sub propose_induct_member { + my ($self, $session_id, $building_id, $empire_id, $message) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 10) { + confess [1013, 'Parliament must be level 10 to induct a new alliance member.',10]; + } + my $alliance = $self->alliance; + my $count = $alliance->members->count; + $count += $alliance->invites->count; + if ($count >= $self->max_members ) { + confess [1009, 'You may only have '.$self->max_members.' in or invited to this alliance.']; + } + unless ($empire_id) { + confess [1002, 'Must specify an empire id to induct a new alliance member.']; + } + my $invite_empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($empire_id); + unless (defined $invite_empire) { + confess [1002, 'Could not find the empire of the proposed new alliance member.']; + } + Lacuna::Verify->new(content=>\$message, throws=>[1005,'Message must not contain restricted characters or profanity.', 'message']) + ->no_tags + ->no_profanity; + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'InductMember', + name => 'Induct Member', + description => 'Induct {Empire '.$invite_empire->id.' '.$invite_empire->name.'} as a new member of {Alliance '.$building->body->alliance_id.' '.$building->body->alliance->name.'}.', + scratch => { empire_id => $invite_empire->id, message => $message }, + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} + +sub propose_expel_member { + my ($self, $session_id, $building_id, $empire_id, $message) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 10) { + confess [1013, 'Parliament must be level 10 to expel an alliance member.',10]; + } + unless ($empire_id) { + confess [1002, 'Must specify an empire id to expel an alliance member.']; + } + my $empire_to_remove = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($empire_id); + unless (defined $empire_to_remove) { + confess [1002, 'Could not find the empire of the proposed member to expel.']; + } + unless ($empire_to_remove->alliance_id == $empire->alliance_id) { + confess [1009, 'That empire is not a member of your alliance.']; + } + Lacuna::Verify->new(content=>\$message, throws=>[1005,'Message must not contain restricted characters or profanity.', 'message']) + ->no_tags + ->no_profanity; + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'ExpelMember', + name => 'Expel Member', + description => 'Expel {Empire '.$empire_to_remove->id.' '.$empire_to_remove->name.'} from {Alliance '.$building->body->alliance_id.' '.$building->body->alliance->name.'}.', + scratch => { empire_id => $empire_to_remove->id, message => $message }, + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} + -__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_members_only_colonization propose_rename_asteroid propose_rename_uninhabited propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ propose_elect_new_leader)); +__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_members_only_colonization propose_rename_asteroid propose_rename_uninhabited propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ propose_elect_new_leader propose_induct_member propose_expel_member)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index e6232f57..48f98dcf 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,4 +1,6 @@ 3.0500 + - API: Added proposing induction of new alliance members at Parliament level 10. + - API: Added proposing expulstion of alliance members at Parliament level 10. - API: Added proposing election of a new alliance leader at Parliament level 11. - API: Added proposing renaming uninhabited planets at Parliament level 17. - API: Added proposing members only colonization at Parliament level 18.