From bbc5ae0252db9991d28195a6f1065a50723d64b8 Mon Sep 17 00:00:00 2001 From: novgorodschi catalin Date: Fri, 4 Sep 2026 07:36:42 +0300 Subject: [PATCH] Some important fixes --- .../Database/DatabaseAllianceQueries.php | 20 ++++++++++++++++--- .../Database/DatabaseStatisticsQueries.php | 7 ++++++- Templates/Message/sent.tpl | 11 ++++++++-- nachrichten.php | 2 +- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/GameEngine/Database/DatabaseAllianceQueries.php b/GameEngine/Database/DatabaseAllianceQueries.php index 846491c2..f7c7be66 100644 --- a/GameEngine/Database/DatabaseAllianceQueries.php +++ b/GameEngine/Database/DatabaseAllianceQueries.php @@ -244,8 +244,17 @@ trait DatabaseAllianceQueries { list($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8) = $this->escape_input($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8); - $q = "INSERT into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')"; - mysqli_query($this->dblink,$q); + $q = "INSERT IGNORE into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')"; + // BUG FIXED (fatal, log 3 sep): acceptInvite() in Alliance.php checks + // $session->alliance == 0 before calling this, but a double-submitted request + // (double-click / two near-simultaneous requests) can pass that check twice + // before either commits - ali_permission has a UNIQUE KEY on (uid, alliance), + // so the second INSERT threw an uncaught "Duplicate entry" mysqli_sql_exception, + // killing the whole request. INSERT IGNORE makes the (rare) duplicate a silent + // no-op instead: the first request's row already has correct, freshly-created + // permissions, so there's nothing meaningful to overwrite. Routed through + // $this->query() too, for the deadlock/connection-loss retry already there. + $this->query($q); // update cache $insertID = mysqli_insert_id($this->dblink); @@ -294,7 +303,12 @@ trait DatabaseAllianceQueries { self::$alliancePermissionsCache[ $uid . $aid ]['opt5'] = $opt5; self::$alliancePermissionsCache[ $uid . $aid ]['opt6'] = $opt6; self::$alliancePermissionsCache[ $uid . $aid ]['opt7'] = $opt7; - self::$alliancePermissionsCache[ $uid . $aid ]['opt8'] = $opt8; + // BUG FIXED: this function has no $opt8 parameter (only opt1..opt7 - see + // signature above and the UPDATE below, which also never touches the opt8 + // column) - "self::...['opt8'] = $opt8" referenced an undefined variable on + // every call. Line removed entirely rather than inventing an opt8 param none + // of the 4 call sites pass: the DB column is untouched by this function, so + // leaving the cached opt8 value alone is what actually matches the DB. } $q = "UPDATE " . TB_PREFIX . "ali_permission SET `rank` = '$rank',opt1 = '$opt1', opt2 = '$opt2', opt3 = '$opt3', opt4 = '$opt4', opt5 = '$opt5', opt6 = '$opt6', opt7 = '$opt7' WHERE uid = $uid AND alliance = $aid LIMIT 1"; $result = mysqli_query($this->dblink, $q); diff --git a/GameEngine/Database/DatabaseStatisticsQueries.php b/GameEngine/Database/DatabaseStatisticsQueries.php index ad58419b..e75ee3b6 100644 --- a/GameEngine/Database/DatabaseStatisticsQueries.php +++ b/GameEngine/Database/DatabaseStatisticsQueries.php @@ -198,7 +198,12 @@ trait DatabaseStatisticsQueries { } $q = "SELECT count(id) FROM " . TB_PREFIX . "users where id > 5"; - $result = mysqli_query($this->dblink,$q); + // BUG FIXED (fatal, log 2 sep): raw mysqli_query() bypassed $this->query() (the + // only place with reconnect/retry). This is called on every automation tick via + // procNewClimbers() -> Ranking::procRankArray() -> countUser() - when the + // connection dropped between cron ticks, "MySQL server has gone away" (2006) + // killed the whole tick. Same fix already applied to getOasisEnforce(). + $result = $this->query($q); $row = mysqli_fetch_row($result); self::$usersCountCache[0] = $row[0]; diff --git a/Templates/Message/sent.tpl b/Templates/Message/sent.tpl index 7413ebd4..3b6a3bb8 100644 --- a/Templates/Message/sent.tpl +++ b/Templates/Message/sent.tpl @@ -137,8 +137,15 @@ for ($i = (1 + $s); $i <= (10 + $s); $i++) { if ( !$support_messages || - ($support_messages && $message->inbox1[$i - 1]['target'] != 1) || - ($multihunter_messages && $message->inbox1[$i - 1]['target'] != 5) + // BUG FIXED (warning only): $message->inbox1[$i - 1] intentionally kept as-is + // (see "IMPORTANT: păstrăm bug original inbox1" above) - inbox1 is a different, + // differently-sized array than sent1, so these indices commonly don't exist. + // Null-coalescing gives the exact same result as before (undefined key/null + // offset both evaluated to NULL, and NULL != 1 / NULL != 5 are both true) - + // just without the "Undefined array key" + "array offset on null" warning + // pair firing on every one of the up to 10 rows on this page. + ($support_messages && ($message->inbox1[$i - 1]['target'] ?? null) != 1) || + ($multihunter_messages && ($message->inbox1[$i - 1]['target'] ?? null) != 5) ) { $sent_as_text = ""; diff --git a/nachrichten.php b/nachrichten.php index 95e280a1..7d5cf669 100644 --- a/nachrichten.php +++ b/nachrichten.php @@ -35,7 +35,7 @@ if(isset($_GET['newdid'])){ if(isset($_GET['t'])){ header("Location: ".$_SERVER['PHP_SELF']."?t=".$_GET['t']); exit(); - }else if($_GET['id'] != 0){ + }else if(isset($_GET['id']) && $_GET['id'] != 0){ header("Location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']); exit(); }else{