diff --git a/GameEngine/Database/DatabaseUserQueries.php b/GameEngine/Database/DatabaseUserQueries.php
index 2d756cd3..d8f618c9 100644
--- a/GameEngine/Database/DatabaseUserQueries.php
+++ b/GameEngine/Database/DatabaseUserQueries.php
@@ -388,6 +388,19 @@ trait DatabaseUserQueries {
$q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED ." LIMIT 1";
$result = mysqli_query($this->dblink,$q);
$dbarray = mysqli_fetch_array($result);
+
+ /**
+ * Daca username-ul nu exista (sau contul e banat), fetch intoarce NULL
+ * si toate citirile de mai jos dadeau "Trying to access array offset on
+ * null". Iesim din start - oricum nu are cine sa fie sitter.
+ */
+ if (!is_array($dbarray)) {
+ return false;
+ }
+
+ $dbarray2 = null;
+ $dbarray3 = null;
+
if($dbarray['sit1'] != 0) {
$q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . (int) $dbarray['sit1'] . " and access != " . BANNED . " LIMIT 1";
$result2 = mysqli_query($this->dblink,$q2);
@@ -399,7 +412,10 @@ trait DatabaseUserQueries {
$dbarray3 = mysqli_fetch_array($result3);
}
if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) {
- if(password_verify($password, $dbarray2['password']) || password_verify($password, $dbarray3['password'])) {
+ // sit1/sit2 pot fi setati independent, deci unul dintre randuri
+ // poate lipsi; fara ?? '' iesea acelasi warning pe null.
+ if(password_verify($password, (string) ($dbarray2['password'] ?? ''))
+ || password_verify($password, (string) ($dbarray3['password'] ?? ''))) {
return true;
} else {
return false;
diff --git a/GameEngine/Ranking.php b/GameEngine/Ranking.php
index 8a005926..ba50ded2 100755
--- a/GameEngine/Ranking.php
+++ b/GameEngine/Ranking.php
@@ -513,11 +513,14 @@
}
$value['players'] = count($memberlist);
$value['totalap'] = $totalap;
- if($value['avg'] > 0) {
- $value['avg'] = ($totalap > 0 && count($memberlist) > 0) ? round($totalap / count($memberlist)) : 0;
- } else {
- $value['avg'] = 0;
- }
+ /**
+ * BUG: aici era "if($value['avg'] > 0)", dar getARanking()
+ * selecteaza doar id,name,tag,oldrank,Aap,Adp - cheia 'avg' nu
+ * exista niciodata. Conditia pica mereu pe ramura else, deci
+ * media pe membru era intotdeauna 0 in clasament (pe langa
+ * warning-ul "Undefined array key"). Calculam direct.
+ */
+ $value['avg'] = (count($memberlist) > 0) ? (int) round($totalap / count($memberlist)) : 0;
$holder[] = $value;
}
$holder = $multisort->sorte($holder, "Aap", false, 2);
@@ -540,11 +543,14 @@
}
$value['players'] = count($memberlist);
$value['totaldp'] = $totaldp;
- if($value['avg'] > 0) {
- $value['avg'] = ($totaldp > 0 && count($memberlist) > 0) ? round($totaldp / count($memberlist)) : 0;
- } else {
- $value['avg'] = 0;
- }
+ /**
+ * BUG: aici era "if($value['avg'] > 0)", dar getARanking()
+ * selecteaza doar id,name,tag,oldrank,Aap,Adp - cheia 'avg' nu
+ * exista niciodata. Conditia pica mereu pe ramura else, deci
+ * media pe membru era intotdeauna 0 in clasament (pe langa
+ * warning-ul "Undefined array key"). Calculam direct.
+ */
+ $value['avg'] = (count($memberlist) > 0) ? (int) round($totaldp / count($memberlist)) : 0;
$holder[] = $value;
}
$holder = $multisort->sorte($holder, "Adp", false, 2);
diff --git a/GameEngine/Units.php b/GameEngine/Units.php
index 3ab1a44f..de039af5 100755
--- a/GameEngine/Units.php
+++ b/GameEngine/Units.php
@@ -616,6 +616,20 @@ class Units {
exit;
} else {
+ /**
+ * Formularul de retragere trimite doar casutele completate,
+ * deci $post['t1'..'t10'] pot lipsi cu totul. Bucla de mai jos
+ * avea deja isset(), dar addAttack() si getWalkingTroopsTime()
+ * le citeau direct si scoteau "Undefined array key t10".
+ * Le normalizam o singura data, aici, ca toti consumatorii de
+ * mai jos sa primeasca numere.
+ */
+ for ($t = 1; $t <= 10; $t++) {
+ if (!isset($post['t'.$t]) || !is_numeric($post['t'.$t])) {
+ $post['t'.$t] = 0;
+ }
+ }
+
//change units
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
$start = ($tribe - 1 ) * 10 + 1;
diff --git a/Templates/Ranking/overview.tpl b/Templates/Ranking/overview.tpl
index 7f540df9..77e0855c 100644
--- a/Templates/Ranking/overview.tpl
+++ b/Templates/Ranking/overview.tpl
@@ -162,7 +162,7 @@ if (count($rankArray) > 1) {
echo "
";
$uid = (int)($row['userid'] ?? 0);
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
if (!empty($row['access']) && $row['access'] > 2) {
echo "{$username}";
@@ -177,7 +177,7 @@ if (count($rankArray) > 1) {
if (!empty($row['aname']) && !empty($row['alliance'])) {
$aid = (int)$row['alliance'];
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
echo "{$aname}";
} else {
echo "-";
diff --git a/Templates/Ranking/player_1.tpl b/Templates/Ranking/player_1.tpl
index 2ee4de67..549c0727 100644
--- a/Templates/Ranking/player_1.tpl
+++ b/Templates/Ranking/player_1.tpl
@@ -96,8 +96,8 @@ if ($totalRanks > 0) {
$uid = (int)$row['userid'];
$rank = (int)$i;
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
$highlight = ($i == $search) ? " class=\"hl\"" : "";
diff --git a/Templates/Ranking/player_3.tpl b/Templates/Ranking/player_3.tpl
index c2d41bcd..6291ccd0 100644
--- a/Templates/Ranking/player_3.tpl
+++ b/Templates/Ranking/player_3.tpl
@@ -95,8 +95,8 @@ if ($totalRanks > 0) {
$uid = (int)$row['userid'];
$rank = (int)$i;
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
$highlight = ($i == $search) ? " class=\"hl\"" : "";
diff --git a/Templates/Ranking/player_6.tpl b/Templates/Ranking/player_6.tpl
index 67e71dcb..799c0628 100644
--- a/Templates/Ranking/player_6.tpl
+++ b/Templates/Ranking/player_6.tpl
@@ -96,8 +96,8 @@ if ($totalRanks > 0) {
$uid = (int)$row['userid'];
$rank = (int)$i;
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
$highlight = ($i == $search) ? " class=\"hl\"" : "";
diff --git a/Templates/Ranking/player_7.tpl b/Templates/Ranking/player_7.tpl
index bdaf71f8..5cf6f7c7 100644
--- a/Templates/Ranking/player_7.tpl
+++ b/Templates/Ranking/player_7.tpl
@@ -96,8 +96,8 @@ if ($totalRanks > 0) {
$uid = (int)$row['userid'];
$rank = (int)$i;
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
$highlight = ($i == $search) ? " class=\"hl\"" : "";
diff --git a/Templates/Ranking/player_8.tpl b/Templates/Ranking/player_8.tpl
index 2cd20ef3..82476271 100644
--- a/Templates/Ranking/player_8.tpl
+++ b/Templates/Ranking/player_8.tpl
@@ -96,8 +96,8 @@ if ($totalRanks > 0) {
$uid = (int)$row['userid'];
$rank = (int)$i;
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
$highlight = ($i == $search) ? " class=\"hl\"" : "";
diff --git a/Templates/Ranking/player_9.tpl b/Templates/Ranking/player_9.tpl
index 4857f1f0..9a978396 100644
--- a/Templates/Ranking/player_9.tpl
+++ b/Templates/Ranking/player_9.tpl
@@ -96,8 +96,8 @@ if ($totalRanks > 0) {
$uid = (int)$row['userid'];
$rank = (int)$i;
- $username = htmlspecialchars($row['username'], ENT_QUOTES, 'UTF-8');
- $aname = htmlspecialchars($row['aname'], ENT_QUOTES, 'UTF-8');
+ $username = htmlspecialchars((string) $row['username'], ENT_QUOTES, 'UTF-8');
+ $aname = htmlspecialchars((string) $row['aname'], ENT_QUOTES, 'UTF-8');
$highlight = ($i == $search) ? " class=\"hl\"" : "";
diff --git a/ajax.php b/ajax.php
index c1543abf..09108bad 100644
--- a/ajax.php
+++ b/ajax.php
@@ -43,7 +43,12 @@ include_once($autoprefix.'GameEngine/config.php');
use App\Utils\AccessLogger;
AccessLogger::logRequest();
-switch($_GET['f']) {
+/**
+ * ajax.php poate fi cerut si fara parametrul "f" (boti, prefetch de browser,
+ * un link vechi). Fara isset() iesea "Undefined array key f" la fiecare
+ * astfel de cerere; acum pica linistit pe default.
+ */
+switch(isset($_GET['f']) ? $_GET['f'] : '') {
case 'k7':
header('Content-Type: application/json');
$x = preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['x']);
diff --git a/build.php b/build.php
index 4e86c247..edd990da 100644
--- a/build.php
+++ b/build.php
@@ -27,6 +27,14 @@ include_once( "GameEngine/Village.php" );
include_once( "GameEngine/Units.php" );
AccessLogger::logRequest();
+/**
+ * $route e setat doar in unele ramuri de mai jos, dar linia
+ * "if(... || $route == 1 || ...)" din zona de afisare il citeste mereu.
+ * Il initializam aici, o singura data, ca sa nu mai iasa
+ * "Undefined variable $route" pe fiecare deschidere de cladire.
+ */
+$route = 0;
+
if(isset($_GET['newdid'])){
$_SESSION['wid'] = $_GET['newdid'];
diff --git a/celebration.php b/celebration.php
index 29db9737..9b166680 100644
--- a/celebration.php
+++ b/celebration.php
@@ -38,7 +38,7 @@ if($village->resarray['f'.$_GET['id'].'t'] == 24 and $village->currentcel == 0){
$clay = 6650;
$iron = 5940;
$crop = 1340;
- $database->modifyResource($village->resarray['vref'],$wood,$clay,$iron,$crop,$mode);
+ $database->modifyResource($village->resarray['vref'],$wood,$clay,$iron,$crop,0);
$database->addCel($village->resarray['vref'],$endtime,$_GET['type']);
}
}
@@ -49,7 +49,7 @@ if($village->resarray['f'.$_GET['id'].'t'] == 24 and $village->currentcel == 0){
$clay= 33250;
$iron= 32000;
$crop= 6700;
- $database->modifyResource($village->resarray['vref'],$wood,$clay,$iron,$crop,$mode);
+ $database->modifyResource($village->resarray['vref'],$wood,$clay,$iron,$crop,0);
$database->addCel($village->resarray['vref'],$endtime,$_GET['type']);
}
}
|