Fix bug autocomplete

Fix bug autocomplete
This commit is contained in:
novgorodschi catalin
2026-08-05 13:59:24 +03:00
parent 146b96907c
commit 72a2365d17
3 changed files with 55 additions and 5 deletions
+48 -1
View File
@@ -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'];
}
+5 -3
View File
@@ -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)){
+2 -1
View File
@@ -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);
}