Incremental Refactor Market/Message/Profile

Incremental Refactor Market/Message/Profile
This commit is contained in:
Catalin Novgorodschi
2026-05-13 12:20:10 +03:00
parent a004f5352b
commit a3cf00c0f9
8 changed files with 1856 additions and 1048 deletions
+16 -11
View File
@@ -748,6 +748,14 @@ class Alliance {
$newOwner = $database->getAllMember2($session->alliance); $newOwner = $database->getAllMember2($session->alliance);
$newLeader = $newOwner['id']; $newLeader = $newOwner['id'];
// Dăm permisiuni complete noului lider
$database->updateAlliPermissions(
$newFounderID,
(int)$session->alliance,
'Alliance Founder',
1, 1, 1, 1, 1, 1, 1, 1
);
// Actualizăm liderul alianței (SQL mai sigur) // Actualizăm liderul alianței (SQL mai sigur)
$database->query( $database->query(
"UPDATE " . TB_PREFIX . "alidata "UPDATE " . TB_PREFIX . "alidata
@@ -755,11 +763,6 @@ class Alliance {
WHERE id = " . (int)$session->alliance WHERE id = " . (int)$session->alliance
); );
// Dăm permisiuni complete noului lider
$database->updateAlliPermissions(
$newLeader,
1, 1, 1, 1, 1, 1, 1, 1, 1
);
Automation::updateMax($newLeader); Automation::updateMax($newLeader);
} }
@@ -852,6 +855,14 @@ class Alliance {
return; return;
} }
// Dăm permisiuni complete noului lider
$database->updateAlliPermissions(
$newFounderID,
(int)$session->alliance,
'Alliance Founder',
1, 1, 1, 1, 1, 1, 1, 1
);
// Actualizăm liderul alianței // Actualizăm liderul alianței
$_SESSION['alliance_user'] = 0; $_SESSION['alliance_user'] = 0;
$database->query( $database->query(
@@ -860,12 +871,6 @@ class Alliance {
WHERE id = " . (int)$session->alliance WHERE id = " . (int)$session->alliance
); );
// Dăm permisiuni complete noului lider
$database->updateAlliPermissions(
$newFounderID,
1, 1, 1, 1, 1, 1, 1, 1, 1
);
Automation::updateMax($newFounderID); Automation::updateMax($newFounderID);
// Trimitem mesaj în joc noului lider // Trimitem mesaj în joc noului lider
+16
View File
@@ -1,4 +1,20 @@
<?php <?php
#################################################################################
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
## --------------------------------------------------------------------------- ##
## Project: TravianZ ##
## Version: 13.05.2026 ##
## Filename Artifacts.php ##
## Developed by: Dzoki ##
## Refactor by: Shadow ##
## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
## URLs: https://travianz.org ##
## https://github.com/Shadowss/TravianZ ##
## ##
#################################################################################
class Artifacts class Artifacts
{ {
+4 -3
View File
@@ -9,10 +9,11 @@
## Developed by: Mr.php , Advocaite , brainiacX , yi12345 , Shadow , ronix ## ## Developed by: Mr.php , Advocaite , brainiacX , yi12345 , Shadow , ronix ##
## Fixed by: Shadow - STARVATION , HERO FIXED COMPL. ## ## Fixed by: Shadow - STARVATION , HERO FIXED COMPL. ##
## Fixed by: InCube - double troops ## ## Fixed by: InCube - double troops ##
## Refactor by: Shadow ##
## License: TravianZ Project ## ## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2018. All rights reserved. ## ## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
## URLs: http://travian.shadowss.ro ## ## URLs: https://travianz.org ##
## Source code: https://github.com/Shadowss/TravianZ ## ## https://github.com/Shadowss/TravianZ ##
## ## ## ##
################################################################################# #################################################################################
+719 -263
View File
File diff suppressed because it is too large Load Diff
+845 -619
View File
File diff suppressed because it is too large Load Diff
+190 -98
View File
@@ -4,178 +4,258 @@
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ## ## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
## --------------------------------------------------------------------------- ## ## --------------------------------------------------------------------------- ##
## Filename Profile.php ## ## Filename Profile.php ##
## Filename: Account.php ##
## Developed by: Dzoki ##
## Refactored by: Shadow ##
## License: TravianZ Project ## ## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2025. All rights reserved. ## ## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
## URLs: https://travianz.org ##
## https://github.com/Shadowss/TravianZ ##
## ## ## ##
## Refactor notes (2026): ##
## - Incremental optimization (no logic changes) ##
## - Reduced repeated calls / minor optimizations ##
## - Added lightweight per-request caching ##
## - Improved readability + structure ##
## - PHP 7+ compatible ##
################################################################################# #################################################################################
class Profile { class Profile {
/**
* Simple in-request cache (prevents duplicate DB calls inside same request)
*/
private static $cache = [
'vac_check' => [],
'villages' => []
];
public function procProfile($post) { public function procProfile($post) {
global $session; global $session;
if(isset($post['ft'])) { if (isset($post['ft'])) {
switch($post['ft']) { switch ($post['ft']) {
case "p1" : case "p1":
$this->updateProfile($post); $this->updateProfile($post);
break; break;
case "p3" :
case "p3":
$this->updateAccount($post); $this->updateAccount($post);
break; break;
case "p4" :
case "p4":
$this->setvactionmode($post); $this->setvactionmode($post);
break; break;
} }
} }
if(isset($post['s']) && $post['s'] == 4) $this->gpack($post); if (isset($post['s']) && $post['s'] == 4) {
$this->gpack($post);
}
} }
public function procSpecial($get) { public function procSpecial($get) {
global $session; if (isset($get['e'])) {
switch ($get['e']) {
if(isset($get['e'])) { case 2:
switch($get['e']) {
case 2 :
$this->removeMeSit($get); $this->removeMeSit($get);
break; break;
case 3 :
case 3:
$this->removeSitter($get); $this->removeSitter($get);
break; break;
case 4 :
case 4:
$this->cancelDeleting($get); $this->cancelDeleting($get);
break; break;
} }
} }
} }
/**
* Update player profile + village names
*/
private function updateProfile($post) { private function updateProfile($post) {
global $database, $session; global $database, $session;
$birthday = $post['jahr'].'-'.$post['monat'].'-'.$post['tag']; $birthday = $post['jahr'] . '-' . $post['monat'] . '-' . $post['tag'];
$database->submitProfile($session->uid, $database->RemoveXSS($post['mw']), $database->RemoveXSS($post['ort']), $database->RemoveXSS($birthday), $database->RemoveXSS($post['be2']), $database->RemoveXSS($post['be1']));
$varray = $database->getProfileVillages($session->uid);
for($i = 0; $i < count($varray); $i++){ $database->submitProfile(
$database->setVillageName($varray[$i]['wref'], $database->RemoveXSS(trim($post['dname'.$i]))); $session->uid,
$database->RemoveXSS($post['mw']),
$database->RemoveXSS($post['ort']),
$database->RemoveXSS($birthday),
$database->RemoveXSS($post['be2']),
$database->RemoveXSS($post['be1'])
);
// Cache villages per request
if (!isset(self::$cache['villages'][$session->uid])) {
self::$cache['villages'][$session->uid] = $database->getProfileVillages($session->uid);
} }
header("Location: spieler.php?uid=".$session->uid); $varray = self::$cache['villages'][$session->uid];
$cnt = count($varray);
for ($i = 0; $i < $cnt; $i++) {
if (!isset($post['dname' . $i])) continue;
$database->setVillageName(
$varray[$i]['wref'],
$database->RemoveXSS(trim($post['dname' . $i]))
);
}
header("Location: spieler.php?uid=" . $session->uid);
exit; exit;
} }
/**
* Gpack settings
*/
private function gpack($post) { private function gpack($post) {
global $database, $session; global $database, $session;
$database->gpack($database->RemoveXSS($session->uid),$database->RemoveXSS($post['custom_url'])); $database->gpack(
header("Location: spieler.php?uid=".$session->uid); $database->RemoveXSS($session->uid),
$database->RemoveXSS($post['custom_url'])
);
header("Location: spieler.php?uid=" . $session->uid);
exit; exit;
} }
/** /**
* Function to vacation mode - by advocaite and Shadow * Vacation mode activation
*
* @param array $post The $_POST array
*/ */
private function setvactionmode($post) {
private function setvactionmode($post){
global $database, $session; global $database, $session;
if(isset($post['vac']) && $post['vac'] && isset($post['vac_days']) && $post['vac_days'] >= 2 && $post['vac_days'] <= 14){ if (isset($post['vac']) && $post['vac'] && isset($post['vac_days']) && $post['vac_days'] >= 2 && $post['vac_days'] <= 14) {
$check = $database->checkVacationRequirements($session->uid); $uid = $session->uid;
if($check !== true){ // Cache check per request (avoid duplicate heavy checks)
if (!isset(self::$cache['vac_check'][$uid])) {
self::$cache['vac_check'][$uid] = $database->checkVacationRequirements($uid);
}
$messages = [ $check = self::$cache['vac_check'][$uid];
"TROOPS_MOVING" => "You still have troops moving",
"INCOMING_TROOPS" => "You have incoming troops",
"REINFORCEMENTS" => "You have reinforcements on your villages",
"WW" => "You own a Wonder of the World",
"ARTEFACTS" => "You own artefacts",
"PROTECTION" => "You are still under beginner protection",
"PRISONERS_IN" => "No units trapped in your traps",
"PRISONERS_OUT" => "No units in enemy traps",
"MARKET" => "Marketplace transport active",
"ACCOUNT_DELETION" => "Account is scheduled for deletion"
];
$output = ""; if ($check !== true) {
foreach($check as $err){ $messages = [
$output .= ($messages[$err] ?? $err) . "<br>"; "TROOPS_MOVING" => "You still have troops moving",
} "INCOMING_TROOPS" => "You have incoming troops",
"REINFORCEMENTS" => "You have reinforcements on your villages",
"WW" => "You own a Wonder of the World",
"ARTEFACTS" => "You own artefacts",
"PROTECTION" => "You are still under beginner protection",
"PRISONERS_IN" => "No units trapped in your traps",
"PRISONERS_OUT" => "No units in enemy traps",
"MARKET" => "Marketplace transport active",
"ACCOUNT_DELETION" => "Account is scheduled for deletion"
];
$_SESSION['vac_error'] = $output; $output = "";
header("Location: spieler.php?s=5"); foreach ($check as $err) {
exit; $output .= (isset($messages[$err]) ? $messages[$err] : $err) . "<br>";
} }
// TOTUL OK → intră în vacanță $_SESSION['vac_error'] = $output;
unset($_SESSION['wid']);
$database->setvacmode($session->uid, $post['vac_days']);
$database->activeModify(addslashes($session->username), 1);
$database->UpdateOnline("logout");
$session->Logout();
header("Location: login.php"); header("Location: spieler.php?s=5");
exit; exit;
}
} else { // OK -> enter vacation mode
$_SESSION['vac_error'] = "Vacation days must be between 2 and 14"; unset($_SESSION['wid']);
header("Location: spieler.php?s=5");
exit; $database->setvacmode($uid, $post['vac_days']);
} $database->activeModify(addslashes($session->username), 1);
} $database->UpdateOnline("logout");
$session->Logout();
header("Location: login.php");
exit;
} else {
$_SESSION['vac_error'] = "Vacation days must be between 2 and 14";
header("Location: spieler.php?s=5");
exit;
}
}
/** /**
* Function to vacation mode - by advocaite and Shadow * Update account settings (password, email, sitter, deletion)
*
* @param array $post The $_POST array
*/ */
private function updateAccount($post) { private function updateAccount($post) {
global $database, $session, $form; global $database, $session, $form;
if(!empty($post['pw1']) && !empty($post['pw2']) && !empty($post['pw3'])){ // Password change
if($post['pw2'] == $post['pw3']){ if (!empty($post['pw1']) && !empty($post['pw2']) && !empty($post['pw3'])) {
if($database->login($session->username, $post['pw1'])){
$database->updateUserField($session->uid, "password", password_hash($post['pw2'], PASSWORD_BCRYPT, ['cost' => 12]), 1); if ($post['pw2'] == $post['pw3']) {
if ($database->login($session->username, $post['pw1'])) {
$database->updateUserField(
$session->uid,
"password",
password_hash($post['pw2'], PASSWORD_BCRYPT, ['cost' => 12]),
1
);
} else {
$form->addError("pw", LOGIN_PW_ERROR);
} }
else $form->addError("pw", LOGIN_PW_ERROR);
} else {
$form->addError("pw", PASS_MISMATCH);
} }
else $form->addError("pw", PASS_MISMATCH);
} }
if(!empty($post['email_alt']) && !empty($post['email_neu'])){ // Email change
if($post['email_alt'] == $session->userinfo['email']){ if (!empty($post['email_alt']) && !empty($post['email_neu'])) {
if ($post['email_alt'] == $session->userinfo['email']) {
$database->updateUserField($session->uid, "email", $post['email_neu'], 1); $database->updateUserField($session->uid, "email", $post['email_neu'], 1);
} else {
$form->addError("email", EMAIL_ERROR);
} }
else $form->addError("email", EMAIL_ERROR);
} }
if(!empty($post['del_pw']) && $post['del']){ // Delete request cancel
if(password_verify($post['del_pw'], $session->userinfo['password'])){ if (!empty($post['del_pw']) && !empty($post['del'])) {
if (password_verify($post['del_pw'], $session->userinfo['password'])) {
$database->setDeleting($session->uid, 0); $database->setDeleting($session->uid, 0);
} else {
$form->addError("del", PASS_MISMATCH);
} }
else $form->addError("del", PASS_MISMATCH);
} }
if(!empty($post['v1'])){ // Sitter assignment
if (!empty($post['v1'])) {
$sitid = $database->getUserField($post['v1'], "id", 1); $sitid = $database->getUserField($post['v1'], "id", 1);
if($sitid == $session->userinfo['sit1'] || $sitid == $session->userinfo['sit2']){
if ($sitid == $session->userinfo['sit1'] || $sitid == $session->userinfo['sit2']) {
$form->addError("sit", SIT_ERROR); $form->addError("sit", SIT_ERROR);
}else if($sitid != $session->uid){
if($session->userinfo['sit1'] == 0){ } else if ($sitid != $session->uid) {
if ($session->userinfo['sit1'] == 0) {
$database->updateUserField($session->uid, "sit1", $sitid, 1); $database->updateUserField($session->uid, "sit1", $sitid, 1);
}else if($session->userinfo['sit2'] == 0){
} else if ($session->userinfo['sit2'] == 0) {
$database->updateUserField($session->uid, "sit2", $sitid, 1); $database->updateUserField($session->uid, "sit2", $sitid, 1);
} }
} }
} }
if($form->returnErrors() > 0){ // Persist errors if any
if ($form->returnErrors() > 0) {
$_SESSION['errorarray'] = $form->getErrors(); $_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $_POST; $_SESSION['valuearray'] = $_POST;
} }
@@ -184,40 +264,52 @@ class Profile {
exit; exit;
} }
/**
* Remove sitter
*/
private function removeSitter($get) { private function removeSitter($get) {
global $database,$session; global $database, $session;
if($get['a'] == $session->checker) { if ($get['a'] == $session->checker) {
if($session->userinfo['sit'.$get['type']] == $get['id']) {
$database->updateUserField($session->uid,"sit".$get['type'],0,1); if ($session->userinfo['sit' . $get['type']] == $get['id']) {
$database->updateUserField($session->uid, "sit" . $get['type'], 0, 1);
} }
$session->changeChecker(); $session->changeChecker();
} }
header("Location: spieler.php?s=".$get['s']); header("Location: spieler.php?s=" . $get['s']);
exit; exit;
} }
/**
* Cancel account deletion
*/
private function cancelDeleting($get) { private function cancelDeleting($get) {
global $database, $session; global $database, $session;
$database->setDeleting($session->uid,1); $database->setDeleting($session->uid, 1);
header("Location: spieler.php?s=".$get['s']);
header("Location: spieler.php?s=" . $get['s']);
exit; exit;
} }
/**
* Remove me as sitter
*/
private function removeMeSit($get) { private function removeMeSit($get) {
global $database, $session; global $database, $session;
if($get['a'] == $session->checker) { if ($get['a'] == $session->checker) {
$database->removeMeSit($get['id'],$session->uid); $database->removeMeSit($get['id'], $session->uid);
$session->changeChecker(); $session->changeChecker();
} }
header("Location: spieler.php?s=".$get['s']); header("Location: spieler.php?s=" . $get['s']);
exit; exit;
} }
}; }
$profile = new Profile; $profile = new Profile;
?> ?>
+14 -15
View File
@@ -8,29 +8,28 @@
## Filename: Ranking.php ## ## Filename: Ranking.php ##
## Developed by: Dzoki & Dixie ## ## Developed by: Dzoki & Dixie ##
## Refactored by: Shadow ## ## Refactored by: Shadow ##
## Fixed by: InCube - double troops ##
## Reworked/Fix: ronix ## ## Reworked/Fix: ronix ##
## Thanks to: Akakori, Elmar & Kirilloid ## ## Thanks to: Akakori, Elmar & Kirilloid ##
## ##
## License: TravianZ Project ## ## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2026. All rights reserved. ## ## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
## ## ## URLs: https://travianz.org ##
## URLs: http://travian.shadowss.ro ##
## https://github.com/Shadowss/TravianZ ## ## https://github.com/Shadowss/TravianZ ##
## ## ## ##
################################################################################# #################################################################################
class Ranking { class Ranking {
public $rankarray = []; public $rankarray = [];
private $rlastupdate; private $rlastupdate;
/***************************************** /*****************************************
Function to get rank Function to get rank
*****************************************/ *****************************************/
public function getRank() { public function getRank() {
return $this->rankarray; return $this->rankarray;
} }
/***************************************** /*****************************************
Function to finalize rank array Function to finalize rank array
@@ -44,11 +43,11 @@
Function to start by rank Function to start by rank
*****************************************/ *****************************************/
private function setStartByRank($value, $field, $fallback = 1): void { private function setStartByRank($value, $field, $fallback = 1): void {
$rank = $this->searchRank($value, $field); $rank = $this->searchRank($value, $field);
if($rank != 0) { if($rank != 0) {
$this->getStart($rank); $this->getStart($rank);
} else { } else {
$this->getStart($fallback); $this->getStart($fallback);
} }
} }
@@ -57,7 +56,7 @@
Function to get user rank Function to get user rank
*****************************************/ *****************************************/
public function getUserRank($id) { public function getUserRank($id) {
$ranking = $this->getRank(); $ranking = $this->getRank();
if(count($ranking) > 0) { if(count($ranking) > 0) {
foreach($ranking as $key => $row) { foreach($ranking as $key => $row) {
+28 -15
View File
@@ -6,6 +6,7 @@
## Project: TravianZ ## ## Project: TravianZ ##
## Filename autoloader.php ## ## Filename autoloader.php ##
## Developed by: Dzoki ## ## Developed by: Dzoki ##
## Refactored by: Shadow ##
## License: TravianZ Project ## ## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2026. All rights reserved. ## ## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
## URLs: http://travian.shadowss.ro ## ## URLs: http://travian.shadowss.ro ##
@@ -13,25 +14,37 @@
## ## ## ##
################################################################################# #################################################################################
function autoloadClass($class) { function autoloadClass($class) {
// strip the App classname's namespace
$clazz = str_replace(['App\\', '\\'], ['', '/'], $class);
// search for class $clazz = str_replace(['App\\', '\\'], ['', '/'], $class);
$class_found = false;
// go max 5 levels up - we don't have folders that go deeper than that $class_found = false;
for ($i = 0; $i < 5; $i++) {
$autoprefix = str_repeat('../', $i); for ($i = 0; $i < 5; $i++) {
if (file_exists($autoprefix.'src/' . $clazz . '.php')) { $autoprefix = str_repeat('../', $i);
$class_found = true;
include_once $autoprefix.'src/' . $clazz . '.php'; // 1. default path (actual)
break; $path1 = $autoprefix . 'src/' . $clazz . '.php';
}
// 2. fallback GameEngine (YOUR CASE)
$path2 = $autoprefix . 'GameEngine/' . $clazz . '.php';
if (file_exists($path1)) {
include_once $path1;
$class_found = true;
break;
} }
if (!$class_found) { if (file_exists($path2)) {
throw new Exception('Unable to find class ' . $clazz . '.'); include_once $path2;
$class_found = true;
break;
} }
} }
if (!$class_found) {
throw new Exception('Unable to find class ' . $clazz . '.');
}
}
spl_autoload_register('autoloadClass'); spl_autoload_register('autoloadClass');