From 72a2365d17b0e1f25a703464fc60db399b8cf546 Mon Sep 17 00:00:00 2001 From: novgorodschi catalin Date: Wed, 5 Aug 2026 13:59:24 +0300 Subject: [PATCH] Fix bug autocomplete Fix bug autocomplete --- .../Database/DatabaseVillageQueries.php | 49 ++++++++++++++++++- GameEngine/Units.php | 8 +-- Templates/Build/17.tpl | 3 +- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/GameEngine/Database/DatabaseVillageQueries.php b/GameEngine/Database/DatabaseVillageQueries.php index 1163e1ae..809956d1 100644 --- a/GameEngine/Database/DatabaseVillageQueries.php +++ b/GameEngine/Database/DatabaseVillageQueries.php @@ -1988,7 +1988,54 @@ trait DatabaseVillageQueries { mysqli_query($this->dblink, $q); } - function getVillageByName($name, $use_cache = true) { + function getVillageByName($name, $use_cache = true, $uid = 0) { + + /** + * BUG REPARAT: numele de sate NU sunt unice. + * + * Cele 13 sate de Minune ale Natarilor se numesc toate "WW village". + * Cand un jucator cucerea unul si il pastra cu acelasi nume, apoi scria + * "WW village" ca destinatie, interogarea "WHERE name = ... LIMIT 1" + * returna primul rand gasit - de obicei un sat al Natarilor, nu al lui. + * Resursele plecau in alta parte, fara niciun avertisment. + * + * Acum cautam in ordinea in care se gandeste jucatorul: + * 1. satele LUI + * 2. satele colegilor de alianta + * 3. orice alt sat cu numele acela + * + * Fara $uid, comportamentul ramane cel vechi, deci apelantii care nu + * stiu de jucator nu se strica. + */ + $uid = (int) $uid; + + if ($uid > 0) { + $safeName = $this->escape($name); + + // 1. satele proprii + $q = "SELECT wref FROM " . TB_PREFIX . "vdata + WHERE `name` = '" . $safeName . "' AND owner = " . $uid . " LIMIT 1"; + $r = mysqli_query($this->dblink, $q); + + if ($r && ($row = mysqli_fetch_assoc($r))) { + return $row['wref']; + } + + // 2. satele aliantei + $q = "SELECT v.wref FROM " . TB_PREFIX . "vdata v + JOIN " . TB_PREFIX . "users u ON u.id = v.owner + JOIN " . TB_PREFIX . "users me ON me.id = " . $uid . " + WHERE v.`name` = '" . $safeName . "' + AND me.alliance > 0 AND u.alliance = me.alliance + LIMIT 1"; + $r = mysqli_query($this->dblink, $q); + + if ($r && ($row = mysqli_fetch_assoc($r))) { + return $row['wref']; + } + } + + // 3. cautarea initiala, ca rezerva return $this->getVillage($name, 1, $use_cache)['wref']; } diff --git a/GameEngine/Units.php b/GameEngine/Units.php index 734eaf57..828e1863 100755 --- a/GameEngine/Units.php +++ b/GameEngine/Units.php @@ -77,7 +77,7 @@ class Units { */ public function checkErrors(&$post){ - global $database, $generator; + global $database, $generator, $session; if(($error = $this->parseCoordinates($post)) !== "") return $error; @@ -95,7 +95,8 @@ class Units { if(!empty($post['dname']) && $post['x'] != "" && $post['y'] != "") return "Insert name or coordinates"; if(isset($post['dname']) && !empty($post['dname'])) { - $id = $database->getVillageByName(stripslashes($post['dname'])); + $id = $database->getVillageByName(stripslashes($post['dname']), true, + (int) ($session->uid ?? 0)); // preferam satele jucatorului if (!isset($id)) return "Village doesn't exist"; else $coor = $database->getCoor($id); @@ -164,7 +165,8 @@ class Units { $vid = $database->getVilWref($post['x'], $post['y']); unset($post['dname']); } - else if(isset($post['dname']) && !empty($post['dname'])) $vid = $database->getVillageByName(stripslashes($post['dname'])); + else if(isset($post['dname']) && !empty($post['dname'])) $vid = $database->getVillageByName(stripslashes($post['dname']), true, + (int) ($session->uid ?? 0)); // preferam satele jucatorului if (!empty($vid)) { if($isOasis = $database->isVillageOases($vid)){ diff --git a/Templates/Build/17.tpl b/Templates/Build/17.tpl index 285d5c43..20a00341 100644 --- a/Templates/Build/17.tpl +++ b/Templates/Build/17.tpl @@ -46,7 +46,8 @@ if ($x!== '' && $y!== '' && is_numeric($x) && is_numeric($y)) { $getwref = (int)$database->getVilWref((int)$x, (int)$y); $checkexist = $database->checkVilExist($getwref); } elseif ($dname!== '') { - $getwref = (int)$database->getVillageByName($dname); + // Preferam satele jucatorului: numele NU sunt unice (vezi getVillageByName). + $getwref = (int) $database->getVillageByName($dname, true, (int) ($session->uid ?? 0)); $checkexist = $database->checkVilExist($getwref); }