mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-18 01:01:01 +00:00
refactor: Session.php only included once, login procedure optimization
#313
This commit is contained in:
@@ -5,15 +5,15 @@ use App\Entity\User;
|
|||||||
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
||||||
## --------------------------------------------------------------------------- ##
|
## --------------------------------------------------------------------------- ##
|
||||||
## Project: TravianZ ##
|
## Project: TravianZ ##
|
||||||
## Version: 22.06.2015 ##
|
## Version: 22.06.2015 ##
|
||||||
## Filename Account.php ##
|
## Filename Account.php ##
|
||||||
## 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 ##
|
||||||
## License: TravianZ Project ##
|
## License: TravianZ Project ##
|
||||||
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
|
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
|
||||||
## URLs: http://travian.shadowss.ro ##
|
## URLs: http://travian.shadowss.ro ##
|
||||||
## Source code: https://github.com/Shadowss/TravianZ ##
|
## Source code: https://github.com/Shadowss/TravianZ ##
|
||||||
## ##
|
## ##
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ for ($i = 0; $i < 5; $i++) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include($autoprefix."GameEngine/Session.php");
|
include_once($autoprefix."GameEngine/Session.php");
|
||||||
|
|
||||||
class Account {
|
class Account {
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class Account {
|
|||||||
$form->addError("invt",$_POST['invited']);
|
$form->addError("invt",$_POST['invited']);
|
||||||
$_SESSION['errorarray'] = $form->getErrors();
|
$_SESSION['errorarray'] = $form->getErrors();
|
||||||
$_SESSION['valuearray'] = $_POST;
|
$_SESSION['valuearray'] = $_POST;
|
||||||
|
|
||||||
|
|
||||||
header("Location: anmelden.php");
|
header("Location: anmelden.php");
|
||||||
exit;
|
exit;
|
||||||
@@ -277,7 +277,7 @@ class Account {
|
|||||||
$database->addTech($wid);
|
$database->addTech($wid);
|
||||||
$database->addABTech($wid);
|
$database->addABTech($wid);
|
||||||
$database->updateUserField($uid,"access",USER,1);
|
$database->updateUserField($uid,"access",USER,1);
|
||||||
|
|
||||||
$message = new Message();
|
$message = new Message();
|
||||||
$message->sendWelcome($uid,$username);
|
$message->sendWelcome($uid,$username);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -1191,13 +1191,19 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateActiveUser($username, $time) {
|
function updateActiveUser($username, $time) {
|
||||||
|
static $updated = false;
|
||||||
|
|
||||||
|
if ($updated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
list($username, $time) = $this->escape_input($username, $time);
|
list($username, $time) = $this->escape_input($username, $time);
|
||||||
|
|
||||||
$q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
|
$res1 = $this->addActiveUser($username, $time);
|
||||||
$q2 = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
|
$q = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
|
||||||
$exec1 = mysqli_query($this->dblink,$q);
|
$res2 = mysqli_query($this->dblink,$q);
|
||||||
$exec2 = mysqli_query($this->dblink,$q2);
|
if($res1 && $res2) {
|
||||||
if($exec1 && $exec2) {
|
$updated = true;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ mb_internal_encoding("UTF-8"); // Add for utf8 varriables.
|
|||||||
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
||||||
## --------------------------------------------------------------------------- ##
|
## --------------------------------------------------------------------------- ##
|
||||||
## Project: TravianZ ##
|
## Project: TravianZ ##
|
||||||
## Version: 22.06.2015 ##
|
## Version: 22.06.2015 ##
|
||||||
## Filename Session.php ##
|
## Filename Session.php ##
|
||||||
## 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 ##
|
||||||
## License: TravianZ Project ##
|
## License: TravianZ Project ##
|
||||||
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
|
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
|
||||||
## URLs: http://travian.shadowss.ro ##
|
## URLs: http://travian.shadowss.ro ##
|
||||||
## Source code: https://github.com/Shadowss/TravianZ ##
|
## Source code: https://github.com/Shadowss/TravianZ ##
|
||||||
## ##
|
## ##
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
@@ -127,8 +127,8 @@ class Session {
|
|||||||
$_SESSION['wid'] = $data['wref'];
|
$_SESSION['wid'] = $data['wref'];
|
||||||
}
|
}
|
||||||
$this->PopulateVar();
|
$this->PopulateVar();
|
||||||
|
|
||||||
$database->addActiveUser($user_sanitized, $this->time);
|
$database->updateActiveUser($user_sanitized, $this->time);
|
||||||
$database->updateUserField($user_sanitized, "sessid", $_SESSION['sessid'], 0);
|
$database->updateUserField($user_sanitized, "sessid", $_SESSION['sessid'], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ class Session {
|
|||||||
$id = (int) $_SESSION['id'];
|
$id = (int) $_SESSION['id'];
|
||||||
$admin = true;
|
$admin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($user && ($admin || isset($_SESSION['sessid']))) {
|
if($user && ($admin || isset($_SESSION['sessid']))) {
|
||||||
// check if this is not a support user, for who only messages and statistics are available
|
// check if this is not a support user, for who only messages and statistics are available
|
||||||
if ($user == 1) {
|
if ($user == 1) {
|
||||||
@@ -191,14 +191,14 @@ class Session {
|
|||||||
//Get and Populate Data
|
//Get and Populate Data
|
||||||
$this->PopulateVar();
|
$this->PopulateVar();
|
||||||
//update database
|
//update database
|
||||||
$database->addActiveUser($user, $this->time);
|
$database->updateActiveUser($user, $this->time);
|
||||||
$database->updateUserField($user, "timestamp", $this->time, 0);
|
$database->updateUserField($user, "timestamp", $this->time, 0);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************************
|
/***************************
|
||||||
Function to check Real Hero
|
Function to check Real Hero
|
||||||
@@ -300,7 +300,7 @@ $form = new Form;
|
|||||||
// if there is no user, we'd try to load messages for user with ID 0, which is wrong
|
// if there is no user, we'd try to load messages for user with ID 0, which is wrong
|
||||||
if (!empty($_SESSION['id_user'])) {
|
if (!empty($_SESSION['id_user'])) {
|
||||||
$message = new Message;
|
$message = new Message;
|
||||||
|
|
||||||
// create a global user variable which will later be removed from here
|
// create a global user variable which will later be removed from here
|
||||||
// and created + retrieved either via Service Locator or other DI concept
|
// and created + retrieved either via Service Locator or other DI concept
|
||||||
$user = new User((int) $_SESSION['id_user'], $database);
|
$user = new User((int) $_SESSION['id_user'], $database);
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
## ##
|
## ##
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
include("Session.php");
|
include_once("Session.php");
|
||||||
include("Building.php");
|
include_once("Building.php");
|
||||||
include("Market.php");
|
include_once("Market.php");
|
||||||
include_once("GameEngine/Units.php");
|
include_once("GameEngine/Units.php");
|
||||||
include("Technology.php");
|
include_once("Technology.php");
|
||||||
|
|
||||||
class Village {
|
class Village {
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ class Village {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
global $session, $database;
|
global $session, $database;
|
||||||
if(isset($_SESSION['wid'])) {
|
if(isset($_SESSION['wid'])) {
|
||||||
$this->wid = $_SESSION['wid'];
|
$this->wid = $_SESSION['wid'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->wid = $session->villages[0];
|
$this->wid = $session->villages[0];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include("GameEngine/Session.php");
|
include_once("GameEngine/Session.php");
|
||||||
header("Content-Type: application/json;");
|
header("Content-Type: application/json;");
|
||||||
$currentcoor = $database->getCoor($z);
|
$currentcoor = $database->getCoor($z);
|
||||||
$y = $currentcoor['y'];
|
$y = $currentcoor['y'];
|
||||||
@@ -68,7 +68,7 @@ for($i=0;$i<=12;$i++) {
|
|||||||
}
|
}
|
||||||
if($row1 != 13 && $i != 12) {
|
if($row1 != 13 && $i != 12) {
|
||||||
echo "\\n";
|
echo "\\n";
|
||||||
}
|
}
|
||||||
$index+=1;
|
$index+=1;
|
||||||
}
|
}
|
||||||
echo "<\\/div><div id=\\\"map_rulers\\\">";
|
echo "<\\/div><div id=\\\"map_rulers\\\">";
|
||||||
@@ -119,7 +119,7 @@ echo"<area id=\\\"ma_n4p7\\\" href=\\\"karte2.php?z=";
|
|||||||
echo $generator->getBaseID($xp13,$y);
|
echo $generator->getBaseID($xp13,$y);
|
||||||
echo "\\\" coords=\\\"4,15,26,3,48,15,26,27\\\" shape=\\\"poly\\\" title=\\\"West\\\"\\/>\\n";
|
echo "\\\" coords=\\\"4,15,26,3,48,15,26,27\\\" shape=\\\"poly\\\" title=\\\"West\\\"\\/>\\n";
|
||||||
echo "<\\/map><div id=\\\"map_coords\\\"><form name=\\\"map_coords\\\" method=\\\"post\\\" action=\\\"karte2.php\\\">\\n\\t\\t\\t<span>x <\\/span><input id=\\\"mcx\\\" class=\\\"text\\\" name=\\\"xp\\\" value=\\\"";
|
echo "<\\/map><div id=\\\"map_coords\\\"><form name=\\\"map_coords\\\" method=\\\"post\\\" action=\\\"karte2.php\\\">\\n\\t\\t\\t<span>x <\\/span><input id=\\\"mcx\\\" class=\\\"text\\\" name=\\\"xp\\\" value=\\\"";
|
||||||
echo $x;
|
echo $x;
|
||||||
echo "\\\" maxlength=\\\"4\\\"\\/>\\n\\t\\t\\t<span>y <\\/span><input id=\\\"mcy\\\" class=\\\"text\\\" name=\\\"yp\\\" value=\\\"";
|
echo "\\\" maxlength=\\\"4\\\"\\/>\\n\\t\\t\\t<span>y <\\/span><input id=\\\"mcy\\\" class=\\\"text\\\" name=\\\"yp\\\" value=\\\"";
|
||||||
echo $y;
|
echo $y;
|
||||||
echo "\\\" maxlength=\\\"4\\\"\\/>\\n\\t\\t\\t<input type=\\\"image\\\" id=\\\"btn_ok\\\" class=\\\"dynamic_img\\\" value=\\\"ok\\\" name=\\\"s1\\\" src=\\\"img\\/x.gif\\\" alt=\\\"\\\" \\/>\\n\\t\\t\\t<\\/form><\\/div><table cellpadding=\\\"1\\\" cellspacing=\\\"1\\\" id=\\\"map_infobox\\\" class=\\\"default\\\"><thead><tr><th colspan=\\\"2\\\">Details<\\/th><\\/tr><\\/thead><tbody><tr><th>Player<\\/th><td>-<\\/td><\\/tr><tr><th>Population<\\/th><td>-<\\/td><\\/tr><tr><th>Alliance<\\/th><td>-<\\/td><\\/tr><\\/tbody><\\/table><\\/div><\\/div><\\/div><\\/div>\",\"dat\":{\"m_c\":{\"az\":{\"n1\":";
|
echo "\\\" maxlength=\\\"4\\\"\\/>\\n\\t\\t\\t<input type=\\\"image\\\" id=\\\"btn_ok\\\" class=\\\"dynamic_img\\\" value=\\\"ok\\\" name=\\\"s1\\\" src=\\\"img\\/x.gif\\\" alt=\\\"\\\" \\/>\\n\\t\\t\\t<\\/form><\\/div><table cellpadding=\\\"1\\\" cellspacing=\\\"1\\\" id=\\\"map_infobox\\\" class=\\\"default\\\"><thead><tr><th colspan=\\\"2\\\">Details<\\/th><\\/tr><\\/thead><tbody><tr><th>Player<\\/th><td>-<\\/td><\\/tr><tr><th>Population<\\/th><td>-<\\/td><\\/tr><tr><th>Alliance<\\/th><td>-<\\/td><\\/tr><\\/tbody><\\/table><\\/div><\\/div><\\/div><\\/div>\",\"dat\":{\"m_c\":{\"az\":{\"n1\":";
|
||||||
@@ -183,5 +183,5 @@ echo "],\"z\":{\"x\":";
|
|||||||
echo $x;
|
echo $x;
|
||||||
echo ",\"y\":";
|
echo ",\"y\":";
|
||||||
echo $y;
|
echo $y;
|
||||||
echo "},\"size\":13},\"mdim\":{\"x\":13,\"y\":13,\"rad\":6},\"mmode\":0}}";
|
echo "},\"size\":13},\"mdim\":{\"x\":13,\"y\":13,\"rad\":6},\"mmode\":0}}";
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user