mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-09-18 08:07:18 +00:00
Fix bug autocomplete
Fix bug autocomplete
This commit is contained in:
@@ -1988,7 +1988,54 @@ trait DatabaseVillageQueries {
|
|||||||
mysqli_query($this->dblink, $q);
|
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'];
|
return $this->getVillage($name, 1, $use_cache)['wref'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class Units {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public function checkErrors(&$post){
|
public function checkErrors(&$post){
|
||||||
global $database, $generator;
|
global $database, $generator, $session;
|
||||||
|
|
||||||
if(($error = $this->parseCoordinates($post)) !== "") return $error;
|
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(!empty($post['dname']) && $post['x'] != "" && $post['y'] != "") return "Insert name or coordinates";
|
||||||
|
|
||||||
if(isset($post['dname']) && !empty($post['dname'])) {
|
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";
|
if (!isset($id)) return "Village doesn't exist";
|
||||||
else $coor = $database->getCoor($id);
|
else $coor = $database->getCoor($id);
|
||||||
@@ -164,7 +165,8 @@ class Units {
|
|||||||
$vid = $database->getVilWref($post['x'], $post['y']);
|
$vid = $database->getVilWref($post['x'], $post['y']);
|
||||||
unset($post['dname']);
|
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 (!empty($vid)) {
|
||||||
if($isOasis = $database->isVillageOases($vid)){
|
if($isOasis = $database->isVillageOases($vid)){
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ if ($x!== '' && $y!== '' && is_numeric($x) && is_numeric($y)) {
|
|||||||
$getwref = (int)$database->getVilWref((int)$x, (int)$y);
|
$getwref = (int)$database->getVilWref((int)$x, (int)$y);
|
||||||
$checkexist = $database->checkVilExist($getwref);
|
$checkexist = $database->checkVilExist($getwref);
|
||||||
} elseif ($dname!== '') {
|
} 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);
|
$checkexist = $database->checkVilExist($getwref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user