From 610aa63899777247036fa48916e1d0ef8fefaf8c Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 5 Jan 2007 09:57:37 +0000 Subject: [PATCH] intel_log --- ND/Include.pm | 11 +++++++++-- alliances.pl | 11 +++++++---- intel.pl | 5 +++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ND/Include.pm b/ND/Include.pm index 8aa2bd4..889c97d 100644 --- a/ND/Include.pm +++ b/ND/Include.pm @@ -25,7 +25,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/min max log_message/; +our @EXPORT = qw/min max log_message intel_log/; sub min { my ($x,$y) = @_; @@ -41,7 +41,14 @@ sub log_message { my ($uid, $message) = @_; my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES( (SELECT ftid FROM forum_threads WHERE log_uid = $1),$1,$2)}); - $log->execute($uid,$message); + $log->execute($uid,$message) or $ND::ERROR .= p($ND::DBH->errstr); +} + +sub intel_log { + my ($uid,$planet, $message) = @_; + my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES( + (SELECT ftid FROM forum_threads WHERE planet = $3),$1,$2)}); + $log->execute($uid,$message,$planet) or $ND::ERROR .= p($ND::DBH->errstr); } 1; diff --git a/alliances.pl b/alliances.pl index b78d5ff..4f89a48 100644 --- a/alliances.pl +++ b/alliances.pl @@ -22,6 +22,7 @@ use warnings FATAL => 'all'; use ND::Include; our $BODY; our $DBH; +our $ERROR; my $error; $ND::TEMPLATE->param(TITLE => 'Alliances'); @@ -46,16 +47,18 @@ if ($alliance && defined param('cmd') && param ('cmd') eq 'change'){ } } my $coords = param('coords'); + my $findplanet = $DBH->prepare(q{SELECT id FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?}); 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 = ?); +UPDATE planets SET alliance_id = $2, nick = coalesce($3,nick) +WHERE id = $1; }); while ($coords =~ m/(\d+):(\d+):(\d+)(?:\s+nick=\s*(\S+))?/g){ - if ($addplanet->execute($alliance->{id},$4,$1,$2,$3)){ + my ($id) = $DBH->selectrow_array($findplanet,undef,$1,$2,$3) or $ERROR .= p $DBH->errstr; + if ($addplanet->execute($id,$alliance->{id},$4)){ my $nick = ''; $nick = '(nick $4)' if defined $4; $error .= "

Added planet $1:$2:$3 $nick to this alliance

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

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

"; } diff --git a/intel.pl b/intel.pl index 9ab5864..e538411 100644 --- a/intel.pl +++ b/intel.pl @@ -20,6 +20,7 @@ use strict; use warnings FATAL => 'all'; use ND::Web::Forum; +use ND::Include; our $BODY; our $DBH; @@ -85,6 +86,7 @@ if ($planet && defined param('cmd')){ my $value = escapeHTML(param('nick')); if ($DBH->do(q{UPDATE planets SET nick = ? WHERE id =?} ,undef,$value,$planet->{id})){ + intel_log $ND::UID,$planet->{id},"Set nick to: $value"; $planet->{nick} = $value; }else{ $error .= "

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

"; @@ -94,6 +96,7 @@ if ($planet && defined param('cmd')){ my $value = escapeHTML(param('channel')); if ($DBH->do(q{UPDATE planets SET channel = ? WHERE id =?} ,undef,$value,$planet->{id})){ + intel_log $ND::UID,$planet->{id},"Set channel to: $value"; $planet->{channel} = $value; }else{ $error .= "

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

"; @@ -103,6 +106,7 @@ if ($planet && defined param('cmd')){ my $value = escapeHTML(param('status')); if ($DBH->do(q{UPDATE planets SET planet_status = ? WHERE id =?} ,undef,$value,$planet->{id})){ + intel_log $ND::UID,$planet->{id},"Set planet_status to: $value"; $planet->{planet_status} = $value; }else{ $error .= "

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

"; @@ -111,6 +115,7 @@ if ($planet && defined param('cmd')){ if (param('calliance')){ if ($DBH->do(q{UPDATE planets SET alliance_id = NULLIF(?,-1) WHERE id =?} ,undef,param('alliance'),$planet->{id})){ + intel_log $ND::UID,$planet->{id},"Set alliance_id to: ".param('alliance'); $planet->{alliance_id} = param('alliance'); }else{ $error .= "

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

"; -- 2.39.2