Some important fixes PHP 8.1

Some important fixes PHP 8.1
This commit is contained in:
novgorodschi catalin
2026-08-11 09:19:32 +03:00
parent ac262db66f
commit 8c5a5b94ea
13 changed files with 77 additions and 28 deletions
+17 -1
View File
@@ -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;
+16 -10
View File
@@ -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);
+14
View File
@@ -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;
+2 -2
View File
@@ -162,7 +162,7 @@ if (count($rankArray) > 1) {
echo "<td class=\"pla\">";
$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 "<u><a href=\"spieler.php?uid={$uid}\">{$username}</a></u>";
@@ -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 "<a href=\"allianz.php?aid={$aid}\">{$aname}</a>";
} else {
echo "-";
+2 -2
View File
@@ -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\"" : "";
+2 -2
View File
@@ -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\"" : "";
+2 -2
View File
@@ -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\"" : "";
+2 -2
View File
@@ -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\"" : "";
+2 -2
View File
@@ -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\"" : "";
+2 -2
View File
@@ -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\"" : "";
+6 -1
View File
@@ -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']);
+8
View File
@@ -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'];
+2 -2
View File
@@ -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']);
}
}