From 6f92721c7f925398e67da1b8b29ea48e175e178c Mon Sep 17 00:00:00 2001 From: Darin McBride Date: Wed, 3 Feb 2016 08:35:50 -0700 Subject: [PATCH] Security sweep improvements. - noempty option for omitting empty emails - subject line to indicate number of spies found --- docs/Intelligence.pod | 16 ++++++++++++ lib/Lacuna.pm | 2 +- lib/Lacuna/AI.pm | 2 +- lib/Lacuna/DB/Result/Spies.pm | 46 +++++++++++++++++++++-------------- var/www/public/changes.txt | 4 +++ 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/docs/Intelligence.pod b/docs/Intelligence.pod index 72cf2b4b..5cd0622e 100644 --- a/docs/Intelligence.pod +++ b/docs/Intelligence.pod @@ -311,6 +311,14 @@ The unique id of the spy you wish to assign. =head3 assignment +This can be either a hash (object) or a string. If it's a string, it is +treated as a hash whose sole key is C and the value is the string +given. If it's a hash, it accepts the following keys: + +=over 4 + +=item assignment + A string containing the new assignment name. These are the possible assignments: =over @@ -423,4 +431,12 @@ Steal a planet. B You can do bad things to allies using these assignments. +=item noempty + +For Cs, a true value here indicates that you do not want +an email when there are no spies found. Emails when spies are found, or +when the mission fails will still be posted. + +=back + =cut diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 361c914f..22f33efb 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0919; +our $VERSION = 3.0920; 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/AI.pm b/lib/Lacuna/AI.pm index 70181e90..e6aec5d0 100644 --- a/lib/Lacuna/AI.pm +++ b/lib/Lacuna/AI.pm @@ -518,7 +518,7 @@ sub set_defenders { if ($spy_result->{message_id}) { my $message = Lacuna->db->resultset('Lacuna::DB::Result::Message')->find($spy_result->{message_id}); say "message: ".$message->subject; - if ($message && $message->subject eq "Spy Report") { + if ($message && $message->subject =~ /^Spy Report/) { $on_sweep += 10; #No spies to find say " spy report, no more sweeps."; } diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 6c13e8f0..1127e04d 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -660,7 +660,11 @@ my @class_failures = ( ); sub assign { - my ($self, $assignment) = @_; + my ($self, $assignment_options) = @_; + $assignment_options = { + assignment => $assignment_options + } unless ref $assignment_options eq 'HASH'; + my $assignment = $assignment_options->{assignment}; my $is_available = $self->is_available; @@ -731,7 +735,7 @@ sub assign { } } elsif ($assignment eq 'Security Sweep') { - return $self->run_security_sweep($mission); + return $self->run_security_sweep($mission, $assignment_options); } elsif ($assignment eq 'Bugout') { return $self->bugout($mission); @@ -973,7 +977,7 @@ sub run_mission { } sub run_security_sweep { - my $self = shift; + my $self = shift; # calculate success, failure, or bounce my $mission_skill = 'intel_xp'; @@ -3471,7 +3475,8 @@ sub surface_report { } sub spy_report { - my ($self, $defender) = @_; + my ($self, $defender, $assignment_options) = @_; + $assignment_options ||= {}; my @peeps = (['Name','From','Assignment','Level']); my %planets = ( $self->on_body->id => $self->on_body->name ); my $spies = Lacuna->db @@ -3486,21 +3491,26 @@ sub spy_report { } push @peeps, [$spook->name, $planets{$spook->from_body_id}, $spook->task, $spook->level]; } - unless (scalar @peeps > 1) { - $peeps[0] = ["No", "Enemy", "Spies", "Found" ]; + if (@peeps <= 1 and $assignment_options->{noempty}) { + return; + } else { + unless (scalar @peeps > 1) { + $peeps[0] = ["No", "Enemy", "Spies", "Found" ]; + } + my $title = sprintf "Spy Report (%d)", $#peeps; + return $self->empire->send_predefined_message( + tags => ['Intelligence'], + filename => 'intel_report.txt', + params => [$title, + $self->on_body->x, + $self->on_body->y, + $self->on_body->name, + $self->name, + $self->from_body->id, + $self->from_body->name], + attachments=> { table => \@peeps}, + )->id; } - return $self->empire->send_predefined_message( - tags => ['Intelligence'], - filename => 'intel_report.txt', - params => ['Spy Report', - $self->on_body->x, - $self->on_body->y, - $self->on_body->name, - $self->name, - $self->from_body->id, - $self->from_body->name], - attachments=> { table => \@peeps}, - )->id; } sub economic_report { diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 46c6682e..aede414d 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,7 @@ +3.0920: + - Mod: Security Sweep reports give number of found spies in subject line. + - Add: Security Sweep API allows bypassing of empty emails. + 3.0919: - Add: Adding docker support. - Fix: Emails to GG owners during fissure explosion were missing numbers. -- 2.51.2