mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-08 21:56:09 +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 =- ##
|
||||
## --------------------------------------------------------------------------- ##
|
||||
## Project: TravianZ ##
|
||||
## Version: 22.06.2015 ##
|
||||
## Version: 22.06.2015 ##
|
||||
## 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: InCube - double troops ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
|
||||
## 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 {
|
||||
|
||||
@@ -113,7 +113,7 @@ class Account {
|
||||
$form->addError("invt",$_POST['invited']);
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
|
||||
|
||||
|
||||
header("Location: anmelden.php");
|
||||
exit;
|
||||
@@ -277,7 +277,7 @@ class Account {
|
||||
$database->addTech($wid);
|
||||
$database->addABTech($wid);
|
||||
$database->updateUserField($uid,"access",USER,1);
|
||||
|
||||
|
||||
$message = new Message();
|
||||
$message->sendWelcome($uid,$username);
|
||||
}
|
||||
|
||||
+11
-5
@@ -1191,13 +1191,19 @@ class MYSQLi_DB implements IDbConnection {
|
||||
}
|
||||
|
||||
function updateActiveUser($username, $time) {
|
||||
static $updated = false;
|
||||
|
||||
if ($updated) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($username, $time) = $this->escape_input($username, $time);
|
||||
|
||||
$q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
|
||||
$q2 = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
|
||||
$exec1 = mysqli_query($this->dblink,$q);
|
||||
$exec2 = mysqli_query($this->dblink,$q2);
|
||||
if($exec1 && $exec2) {
|
||||
$res1 = $this->addActiveUser($username, $time);
|
||||
$q = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
|
||||
$res2 = mysqli_query($this->dblink,$q);
|
||||
if($res1 && $res2) {
|
||||
$updated = true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -8,15 +8,15 @@ mb_internal_encoding("UTF-8"); // Add for utf8 varriables.
|
||||
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
||||
## --------------------------------------------------------------------------- ##
|
||||
## Project: TravianZ ##
|
||||
## Version: 22.06.2015 ##
|
||||
## Version: 22.06.2015 ##
|
||||
## 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: InCube - double troops ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
|
||||
## 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'];
|
||||
}
|
||||
$this->PopulateVar();
|
||||
|
||||
$database->addActiveUser($user_sanitized, $this->time);
|
||||
|
||||
$database->updateActiveUser($user_sanitized, $this->time);
|
||||
$database->updateUserField($user_sanitized, "sessid", $_SESSION['sessid'], 0);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class Session {
|
||||
$id = (int) $_SESSION['id'];
|
||||
$admin = true;
|
||||
}
|
||||
|
||||
|
||||
if($user && ($admin || isset($_SESSION['sessid']))) {
|
||||
// check if this is not a support user, for who only messages and statistics are available
|
||||
if ($user == 1) {
|
||||
@@ -191,14 +191,14 @@ class Session {
|
||||
//Get and Populate Data
|
||||
$this->PopulateVar();
|
||||
//update database
|
||||
$database->addActiveUser($user, $this->time);
|
||||
$database->updateActiveUser($user, $this->time);
|
||||
$database->updateUserField($user, "timestamp", $this->time, 0);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************
|
||||
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 (!empty($_SESSION['id_user'])) {
|
||||
$message = new Message;
|
||||
|
||||
|
||||
// create a global user variable which will later be removed from here
|
||||
// and created + retrieved either via Service Locator or other DI concept
|
||||
$user = new User((int) $_SESSION['id_user'], $database);
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
## ##
|
||||
#################################################################################
|
||||
|
||||
include("Session.php");
|
||||
include("Building.php");
|
||||
include("Market.php");
|
||||
include_once("Session.php");
|
||||
include_once("Building.php");
|
||||
include_once("Market.php");
|
||||
include_once("GameEngine/Units.php");
|
||||
include("Technology.php");
|
||||
include_once("Technology.php");
|
||||
|
||||
class Village {
|
||||
|
||||
@@ -30,7 +30,7 @@ class Village {
|
||||
function __construct() {
|
||||
global $session, $database;
|
||||
if(isset($_SESSION['wid'])) {
|
||||
$this->wid = $_SESSION['wid'];
|
||||
$this->wid = $_SESSION['wid'];
|
||||
}
|
||||
else {
|
||||
$this->wid = $session->villages[0];
|
||||
|
||||
Reference in New Issue
Block a user