X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=alliances.pl;h=4cfa2d51f46ea61e884a8665a2953a064153f851;hb=ccf38f8bef1adef7c1ef8797d8c84e477bc82305;hp=101f2db12a9caf69664041cc55b5d3a81ef4afa5;hpb=38ca8c5683ec02a62badb6a0150e60a9a9338580;p=ndwebbie.git diff --git a/alliances.pl b/alliances.pl index 101f2db..4cfa2d5 100644 --- a/alliances.pl +++ b/alliances.pl @@ -18,6 +18,8 @@ #**************************************************************************/ use strict; +use warnings FATAL => 'all'; +no warnings qw(uninitialized); use POSIX; our $BODY; our $DBH; @@ -33,12 +35,31 @@ if (param('alliance') =~ /^(\d+)$/){ my $query = $DBH->prepare(q{SELECT id,name, relationship FROM alliances WHERE id = ?}); $alliance = $DBH->selectrow_hashref($query,undef,$1); } -if ($alliance && param ('cmd') eq 'coords'){ - $DBH->begin_work; - $DBH->commit or $error .= "

Something went wrong: ".$DBH->errstr."

"; -} if ($alliance && param ('cmd') eq 'change'){ $DBH->begin_work; + if (param('crelationship')){ + my $value = escapeHTML(param('relationship')); + if ($DBH->do(q{UPDATE alliances SET relationship = ? WHERE id =?} + ,undef,$value,$alliance->{id})){ + $alliance->{relationship} = $value; + $LOG->execute($ND::UID,"HC set alliance: $alliance->{id} relationship: $value"); + }else{ + $error .= "

Something went wrong: ".$DBH->errstr."

"; + } + } + my $coords = param('coords'); + my $addplanet = $DBH->prepare(q{ +UPDATE planets SET alliance_id = ?, nick = coalesce(?,nick) +WHERE id = (SELECT id FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?); + }); + while ($coords =~ m/(\d+):(\d+):(\d+)(?:\s+nick=\s*(\S+))?/g){ + if ($addplanet->execute($alliance->{id},$4,$1,$2,$3)){ + $error .= "

Added planet $1:$2:$3 (nick $4) to this alliance

"; + $LOG->execute($ND::UID,"HC Added planet $1:$2:$3 (nick $4) to alliance: $alliance->{id}"); + }else{ + $error .= "

Something went wrong: ".$DBH->errstr."

"; + } + } $DBH->commit or $error .= "

Something went wrong: ".$DBH->errstr."

"; } @@ -65,9 +86,9 @@ ORDER BY $order}); $members->execute($alliance->{id}); my $i = 0; while (my $member = $members->fetchrow_hashref){ + $i++; $member->{ODD} = $i % 2; push @members,$member; - $i++; } $BODY->param(Members => \@members); @@ -79,16 +100,16 @@ ORDER BY $order}); $query->execute($alliance->{id},$alliance->{id},$alliance->{id},$alliance->{id}) or $error .= $DBH->errstr; my @intel; - my $i = 0; + $i = 0; while (my $intel = $query->fetchrow_hashref){ if ($intel->{ingal}){ $intel->{missionclass} = 'ingal'; }else{ $intel->{missionclass} = $intel->{mission}; } + $i++; $intel->{ODD} = $i % 2; push @intel,$intel; - $i++; } $BODY->param(Intel => \@intel); }else{ @@ -112,10 +133,10 @@ ORDER BY $order my @alliances; my $i = 0; while (my $alliance = $query->fetchrow_hashref){ + $i++; next if ($alliance->{score} < 1 && $alliance->{kscore} < 1); $alliance->{ODD} = $i % 2; push @alliances, $alliance; - $i++; } $BODY->param(Alliances => \@alliances); }