diff --git a/Admin/Mods/addTroops.php b/Admin/Mods/addTroops.php
index 31c01a45..e6968e6a 100644
--- a/Admin/Mods/addTroops.php
+++ b/Admin/Mods/addTroops.php
@@ -13,11 +13,8 @@
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
-
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
$id = (int) $_POST['id'];
$village = $database->getVillage($id);
diff --git a/Admin/Mods/cp.php b/Admin/Mods/cp.php
index 778ea80e..163ee6a3 100644
--- a/Admin/Mods/cp.php
+++ b/Admin/Mods/cp.php
@@ -10,10 +10,8 @@
## ##
#################################################################################
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
$id = (int) $_POST['id'];
$admid = (int) $_POST['admid'];
diff --git a/Admin/Mods/deletemedalbyuser.php b/Admin/Mods/deletemedalbyuser.php
index 879681dc..51af05fa 100644
--- a/Admin/Mods/deletemedalbyuser.php
+++ b/Admin/Mods/deletemedalbyuser.php
@@ -10,10 +10,8 @@
#################################################################################
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
diff --git a/Admin/Mods/deletemedalbyweek.php b/Admin/Mods/deletemedalbyweek.php
index 5e334dcf..21ca8eeb 100644
--- a/Admin/Mods/deletemedalbyweek.php
+++ b/Admin/Mods/deletemedalbyweek.php
@@ -10,10 +10,8 @@
#################################################################################
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
diff --git a/Admin/Mods/editUser.php b/Admin/Mods/editUser.php
index a4a7e2c7..d2a0b5ad 100644
--- a/Admin/Mods/editUser.php
+++ b/Admin/Mods/editUser.php
@@ -10,10 +10,8 @@
## ##
#################################################################################
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
diff --git a/Admin/Mods/gold.php b/Admin/Mods/gold.php
index 97f4074f..7127904c 100644
--- a/Admin/Mods/gold.php
+++ b/Admin/Mods/gold.php
@@ -10,10 +10,8 @@
## ##
#################################################################################
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
$id = (int) $_POST['id'];
$gold = (int) $_POST['gold'];
diff --git a/Admin/Mods/gold_1.php b/Admin/Mods/gold_1.php
index 0371e782..8225bd10 100644
--- a/Admin/Mods/gold_1.php
+++ b/Admin/Mods/gold_1.php
@@ -10,10 +10,8 @@
## ##
#################################################################################
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
$id = $_POST['id'];
$admid = (int) $_POST['admid'];
diff --git a/Admin/Mods/medals.php b/Admin/Mods/medals.php
index 7583c253..9e56b05e 100644
--- a/Admin/Mods/medals.php
+++ b/Admin/Mods/medals.php
@@ -11,11 +11,8 @@
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
-
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
$medalid = (int) $_POST['medalid'];
$uid = (int) $_POST['uid'];
diff --git a/Admin/Mods/renameVillage.php b/Admin/Mods/renameVillage.php
index 5688778c..d078ef2c 100644
--- a/Admin/Mods/renameVillage.php
+++ b/Admin/Mods/renameVillage.php
@@ -10,11 +10,8 @@
include_once("../../Account.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
-
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
$origname = $_POST['villagename'];
diff --git a/Admin/Templates/resetServer.php b/Admin/Templates/resetServer.php
index 855c0090..e76a5105 100644
--- a/Admin/Templates/resetServer.php
+++ b/Admin/Templates/resetServer.php
@@ -12,9 +12,6 @@
include_once("../../GameEngine/config.php");
include_once("../../GameEngine/Database.php");
-mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db(SQL_DB);
-
if (!isset($_SESSION)) {
session_start();
}
@@ -100,4 +97,4 @@ mysqli_query($GLOBALS["link"], "DELETE FROM ".TB_PREFIX."vdata WHERE owner<>5");
mysqli_query($GLOBALS["link"], "TRUNCATE TABLE ".TB_PREFIX."ww_attacks");
header("Location: ../admin.php?p=resetdone");
-?>
+?>
diff --git a/GameEngine/Admin/Mods/addUsers.php b/GameEngine/Admin/Mods/addUsers.php
index e6872900..b5124ad7 100755
--- a/GameEngine/Admin/Mods/addUsers.php
+++ b/GameEngine/Admin/Mods/addUsers.php
@@ -24,8 +24,6 @@ include_once($autoprefix."GameEngine/config.php");
include_once($autoprefix."GameEngine/Session.php");
include_once($autoprefix."GameEngine/Automation.php");
include_once($autoprefix."GameEngine/Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
$wgarray=array(1=>1200,1700,2300,3100,4000,5000,6300,7800,9600,11800,14400,17600,21400,25900,31300,37900,45700,55100,66400,80000);
@@ -71,12 +69,12 @@ else
$userName = $baseName . $i;
// Random passwords disallow admin logging in to use the accounts
$password = $generator->generateRandStr(20);
-
+
// Leaving the line below but commented out - could be used to
// allow admin to log in to the generated accounts and play them
// Easily guessed by players so should only be used for testing
//$password = $baseName . $i . 'PASS';
-
+
$email = $baseName . $i . '@example.com';
if ($postTribe == 0)
{
@@ -92,7 +90,7 @@ else
$kid = rand(1,4);
// Dont need to activate, not 100% sure we need to initialise $act
$act = "";
-
+
// Check username not already registered
if(User::exists($database, $userName))
{
@@ -116,14 +114,14 @@ else
* Don't directly access the DB, create a $database function
* where required
*/
-
+
// Show the dove in User Profile - will show this even if
// beginners protection is not checked
// Need a $database function for this
// (assuming we don't already have one as creating Natars also updates this way)
$q = "UPDATE " . TB_PREFIX . "users SET desc2 = '[#0]' WHERE id = ".(int) $uid;
mysqli_query($GLOBALS["link"], $q) or die(mysqli_error($database->dblink));
-
+
if (!$beginnersProtection)
{
// No beginners protection so set it to current time
@@ -135,17 +133,17 @@ else
protect = '".$protection."'
WHERE id = ".(int) $uid) or die(mysqli_error($database->dblink));
}
-
+
$database->updateUserField($uid,"act","",1);
$wid = $database->generateBase($kid,0,false);
$database->setFieldTaken($wid);
-
+
//calculate random generate value and level building
$rand_resource=rand(30000, 80000);
$level_storage=rand(10, 20);
$cap_storage=$wgarray[$level_storage]*(STORAGE_BASE/800);
$rand_resource=($rand_resource>$cap_storage)? $cap_storage:$rand_resource;
-
+
//insert village with all resource and building with random level
$time = time();
$q = "INSERT INTO ".TB_PREFIX."vdata (`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`) values (".(int) $wid.",".(int) $uid.",'".$userName."\'s village',1,200,1,0,0,$rand_resource,$rand_resource,$rand_resource,$cap_storage,$rand_resource,$cap_storage,$time,100,0,0,0,$time)";
@@ -158,13 +156,13 @@ WHERE id = ".(int) $uid) or die(mysqli_error($database->dblink));
$addTechWrefs[] = $wid;
$addABTechWrefs[] = $wid;
$database->updateUserField($uid,"access",USER,1);
-
+
//insert units randomly generate the number of troops
$q = "UPDATE " . TB_PREFIX . "units SET u".(($tribe-1)*10+1)." = ".rand(100, 2000).", u".(($tribe-1)*10+2)." = ".rand(100, 2400).", u".(($tribe-1)*10+3)." = ".rand(100, 1600).", u".(($tribe-1)*10+4)." = ".rand(100, 1500).", u".(($tribe-1)*10+5)." = " .rand(48, 1700).", u".(($tribe-1)*10+6)." = ".rand(60, 1800)." WHERE vref = '".$wid."'";
mysqli_query($GLOBALS["link"], $q);
$created ++;
-
+
}
else
{
diff --git a/GameEngine/Admin/Mods/additional.php b/GameEngine/Admin/Mods/additional.php
index 983369a1..5a930d48 100755
--- a/GameEngine/Admin/Mods/additional.php
+++ b/GameEngine/Admin/Mods/additional.php
@@ -12,8 +12,6 @@ include_once("../../config.php");
include_once("../../Database.php");
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
$id = (int) $_POST['id'];
$admid = $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/cp.php b/GameEngine/Admin/Mods/cp.php
index 84b0c657..0096dea7 100755
--- a/GameEngine/Admin/Mods/cp.php
+++ b/GameEngine/Admin/Mods/cp.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$id = (int) $_POST['id'];
$admid = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/delallymedal.php b/GameEngine/Admin/Mods/delallymedal.php
index c26b5aef..7b12efa7 100755
--- a/GameEngine/Admin/Mods/delallymedal.php
+++ b/GameEngine/Admin/Mods/delallymedal.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$delete = (int) $_POST['medalid'];
$aid =(int) $_POST['aid'];
diff --git a/GameEngine/Admin/Mods/delallymedalbyaid.php b/GameEngine/Admin/Mods/delallymedalbyaid.php
index 9b2c9773..e1a22d7e 100755
--- a/GameEngine/Admin/Mods/delallymedalbyaid.php
+++ b/GameEngine/Admin/Mods/delallymedalbyaid.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$allyid =(int) $_POST['allyid'];
$aid = (int) $_POST['aid'];
diff --git a/GameEngine/Admin/Mods/delallymedalbyweek.php b/GameEngine/Admin/Mods/delallymedalbyweek.php
index 97c4ba95..5dc914fb 100755
--- a/GameEngine/Admin/Mods/delallymedalbyweek.php
+++ b/GameEngine/Admin/Mods/delallymedalbyweek.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$deleteweek = (int) $_POST['deleteweek'];
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/deletemedalbyuser.php b/GameEngine/Admin/Mods/deletemedalbyuser.php
index b4def9ec..69d95fdb 100755
--- a/GameEngine/Admin/Mods/deletemedalbyuser.php
+++ b/GameEngine/Admin/Mods/deletemedalbyuser.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$userid = (int) $_POST['userid'];
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/deletemedalbyweek.php b/GameEngine/Admin/Mods/deletemedalbyweek.php
index f925b2a1..51ec868b 100755
--- a/GameEngine/Admin/Mods/deletemedalbyweek.php
+++ b/GameEngine/Admin/Mods/deletemedalbyweek.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$deleteweek = (int) $_POST['medalweek'];
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/editAccess.php b/GameEngine/Admin/Mods/editAccess.php
index 4a08c28e..db108b2d 100755
--- a/GameEngine/Admin/Mods/editAccess.php
+++ b/GameEngine/Admin/Mods/editAccess.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['uid'];
diff --git a/GameEngine/Admin/Mods/editBuildings.php b/GameEngine/Admin/Mods/editBuildings.php
index 50f38afe..c8a25a1c 100755
--- a/GameEngine/Admin/Mods/editBuildings.php
+++ b/GameEngine/Admin/Mods/editBuildings.php
@@ -14,10 +14,18 @@ if(!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("
Access Denied: You are not Admin!
");
include_once("../../config.php");
-include_once("../../Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
diff --git a/GameEngine/Admin/Mods/editOverall.php b/GameEngine/Admin/Mods/editOverall.php
index 567b0e4e..b1139528 100755
--- a/GameEngine/Admin/Mods/editOverall.php
+++ b/GameEngine/Admin/Mods/editOverall.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/editPassword.php b/GameEngine/Admin/Mods/editPassword.php
index 529eb52f..f8828e7e 100755
--- a/GameEngine/Admin/Mods/editPassword.php
+++ b/GameEngine/Admin/Mods/editPassword.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['uid'];
diff --git a/GameEngine/Admin/Mods/editPlus.php b/GameEngine/Admin/Mods/editPlus.php
index 0358f0b5..ac9df4b1 100755
--- a/GameEngine/Admin/Mods/editPlus.php
+++ b/GameEngine/Admin/Mods/editPlus.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/editProtection.php b/GameEngine/Admin/Mods/editProtection.php
index 232fc83c..d0d2378d 100755
--- a/GameEngine/Admin/Mods/editProtection.php
+++ b/GameEngine/Admin/Mods/editProtection.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/editResources.php b/GameEngine/Admin/Mods/editResources.php
index ffe8dfac..db61dee4 100755
--- a/GameEngine/Admin/Mods/editResources.php
+++ b/GameEngine/Admin/Mods/editResources.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['did'];
diff --git a/GameEngine/Admin/Mods/editSitter.php b/GameEngine/Admin/Mods/editSitter.php
index 6eb7d62d..e3d302fc 100755
--- a/GameEngine/Admin/Mods/editSitter.php
+++ b/GameEngine/Admin/Mods/editSitter.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/editUser.php b/GameEngine/Admin/Mods/editUser.php
index d60bc685..a427fabd 100755
--- a/GameEngine/Admin/Mods/editUser.php
+++ b/GameEngine/Admin/Mods/editUser.php
@@ -11,10 +11,18 @@
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-include_once("../../Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
diff --git a/GameEngine/Admin/Mods/editUsername.php b/GameEngine/Admin/Mods/editUsername.php
index 209a4e1f..7ad046b3 100755
--- a/GameEngine/Admin/Mods/editUsername.php
+++ b/GameEngine/Admin/Mods/editUsername.php
@@ -11,10 +11,18 @@
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-include_once("../../Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
diff --git a/GameEngine/Admin/Mods/editVillageOwner.php b/GameEngine/Admin/Mods/editVillageOwner.php
index e9d94906..d7917be0 100755
--- a/GameEngine/Admin/Mods/editVillageOwner.php
+++ b/GameEngine/Admin/Mods/editVillageOwner.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['did'];
diff --git a/GameEngine/Admin/Mods/editWeek.php b/GameEngine/Admin/Mods/editWeek.php
index 0d29f552..ed4269ac 100755
--- a/GameEngine/Admin/Mods/editWeek.php
+++ b/GameEngine/Admin/Mods/editWeek.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/givePlus.php b/GameEngine/Admin/Mods/givePlus.php
index b2cf0ce2..d2ad8f41 100755
--- a/GameEngine/Admin/Mods/givePlus.php
+++ b/GameEngine/Admin/Mods/givePlus.php
@@ -18,8 +18,17 @@ function mysqli_result($res, $row, $field=0) {
return $datarow[$field];
}
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/givePlusRes.php b/GameEngine/Admin/Mods/givePlusRes.php
index 7dedd4a9..f2c95b38 100755
--- a/GameEngine/Admin/Mods/givePlusRes.php
+++ b/GameEngine/Admin/Mods/givePlusRes.php
@@ -18,8 +18,17 @@ function mysqli_result($res, $row, $field=0) {
return $datarow[$field];
}
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/giveResBonus.php b/GameEngine/Admin/Mods/giveResBonus.php
index 5a2585d1..04a03415 100755
--- a/GameEngine/Admin/Mods/giveResBonus.php
+++ b/GameEngine/Admin/Mods/giveResBonus.php
@@ -14,8 +14,17 @@ include_once("../../config.php");
error_reporting(E_ALL);
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/gold.php b/GameEngine/Admin/Mods/gold.php
index 5245e973..db2d76c0 100755
--- a/GameEngine/Admin/Mods/gold.php
+++ b/GameEngine/Admin/Mods/gold.php
@@ -14,8 +14,17 @@ include_once("../../config.php");
error_reporting(E_ALL);
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/gold_1.php b/GameEngine/Admin/Mods/gold_1.php
index d760afdb..ed8e2ecd 100755
--- a/GameEngine/Admin/Mods/gold_1.php
+++ b/GameEngine/Admin/Mods/gold_1.php
@@ -9,11 +9,20 @@
## ##
#################################################################################
if (!isset($_SESSION)) session_start();
-if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
+if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/mainteneceBan.php b/GameEngine/Admin/Mods/mainteneceBan.php
index 59b087d8..a3ae5ba1 100755
--- a/GameEngine/Admin/Mods/mainteneceBan.php
+++ b/GameEngine/Admin/Mods/mainteneceBan.php
@@ -11,10 +11,18 @@
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-include_once("../../Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
diff --git a/GameEngine/Admin/Mods/mainteneceCleanBanData.php b/GameEngine/Admin/Mods/mainteneceCleanBanData.php
index afd86a46..8dc08b30 100755
--- a/GameEngine/Admin/Mods/mainteneceCleanBanData.php
+++ b/GameEngine/Admin/Mods/mainteneceCleanBanData.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/mainteneceResetGold.php b/GameEngine/Admin/Mods/mainteneceResetGold.php
index d8e84da2..639fd124 100755
--- a/GameEngine/Admin/Mods/mainteneceResetGold.php
+++ b/GameEngine/Admin/Mods/mainteneceResetGold.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/mainteneceResetPlus.php b/GameEngine/Admin/Mods/mainteneceResetPlus.php
index e7a3c267..02f40dd8 100755
--- a/GameEngine/Admin/Mods/mainteneceResetPlus.php
+++ b/GameEngine/Admin/Mods/mainteneceResetPlus.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/mainteneceResetPlusBonus.php b/GameEngine/Admin/Mods/mainteneceResetPlusBonus.php
index 4834e046..b49d152b 100755
--- a/GameEngine/Admin/Mods/mainteneceResetPlusBonus.php
+++ b/GameEngine/Admin/Mods/mainteneceResetPlusBonus.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/Mods/mainteneceUnban.php b/GameEngine/Admin/Mods/mainteneceUnban.php
index 385ae1b3..add42f9e 100755
--- a/GameEngine/Admin/Mods/mainteneceUnban.php
+++ b/GameEngine/Admin/Mods/mainteneceUnban.php
@@ -11,10 +11,18 @@
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-include_once("../../Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
diff --git a/GameEngine/Admin/Mods/medals.php b/GameEngine/Admin/Mods/medals.php
index dd8a7433..2328084c 100755
--- a/GameEngine/Admin/Mods/medals.php
+++ b/GameEngine/Admin/Mods/medals.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../Account.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
diff --git a/GameEngine/Admin/Mods/natarbuildingplan.php b/GameEngine/Admin/Mods/natarbuildingplan.php
index c78042e9..1928f904 100755
--- a/GameEngine/Admin/Mods/natarbuildingplan.php
+++ b/GameEngine/Admin/Mods/natarbuildingplan.php
@@ -12,8 +12,18 @@
include_once("../../config.php");
include_once("../../Session.php");
include_once("../../Automation.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$id = (int) $_POST['id'];
$amt = (int) $_POST['vill_amount'];
diff --git a/GameEngine/Admin/Mods/natarend.php b/GameEngine/Admin/Mods/natarend.php
index ebd392de..68497aa4 100755
--- a/GameEngine/Admin/Mods/natarend.php
+++ b/GameEngine/Admin/Mods/natarend.php
@@ -12,8 +12,18 @@
include_once("../../config.php");
include_once("../../Session.php");
include_once("../../Automation.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$id = (int) $_POST['id'];
$amt = (int) $_POST['vill_amount'];
@@ -38,7 +48,7 @@ for($i=1;$i<=$amt;$i++) {
$addTechWrefs[] = $wid;
$addABTechWrefs[] = $wid;
$speed = NATARS_UNITS;
-
+
//new with random amount of troops
$q = "UPDATE " . TB_PREFIX . "units SET u41 = " . (rand(50, 1200) * $speed) . ", u42 = " . (rand(100, 1400) * $speed) . ", u43 = " . (rand(200, 1600) * $speed) . ", u44 = " . (rand(10, 50) * $speed) . ", u45 = " . (rand(48, 1700) * $speed) . ", u46 = " . (rand(60, 1800) * $speed) . ", u47 = " . (rand(200, 1600) * $speed) . ", u48 = " . (rand(40, 200) * $speed) . " , u49 = " . (rand(4, 20) * $speed) . ", u50 = " . (rand(5, 25) * $speed) . " WHERE vref = '".$wid."'";
mysqli_query($GLOBALS["link"], $q);
diff --git a/GameEngine/Admin/Mods/recalcWH.php b/GameEngine/Admin/Mods/recalcWH.php
index 47221232..c909e761 100755
--- a/GameEngine/Admin/Mods/recalcWH.php
+++ b/GameEngine/Admin/Mods/recalcWH.php
@@ -11,14 +11,22 @@
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-include_once("../../Database.php");
foreach ($_POST as $key => $value) {
$_POST[$key] = $database->escape($value);
}
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
diff --git a/GameEngine/Admin/Mods/renameVillage.php b/GameEngine/Admin/Mods/renameVillage.php
index 3b22eb95..e144acb1 100755
--- a/GameEngine/Admin/Mods/renameVillage.php
+++ b/GameEngine/Admin/Mods/renameVillage.php
@@ -11,10 +11,18 @@
if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-include_once("../../Database.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$nameorig = $_POST['villagename'];
diff --git a/GameEngine/Admin/Mods/sendMessage.php b/GameEngine/Admin/Mods/sendMessage.php
index e5a6afde..5e7120ec 100755
--- a/GameEngine/Admin/Mods/sendMessage.php
+++ b/GameEngine/Admin/Mods/sendMessage.php
@@ -12,8 +12,17 @@ if (!isset($_SESSION)) session_start();
if($_SESSION['access'] < 9) die("Access Denied: You are not Admin!");
include_once("../../config.php");
-$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
-mysqli_select_db($GLOBALS["link"], SQL_DB);
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
+
+include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
diff --git a/GameEngine/Admin/database.php b/GameEngine/Admin/database.php
index aac61d10..51f27867 100755
--- a/GameEngine/Admin/database.php
+++ b/GameEngine/Admin/database.php
@@ -44,21 +44,21 @@ if(isset($gameinstall) && $gameinstall == 1){
}
include_once($autoprefix."GameEngine/Database.php");
class adm_DB {
-
- var $connection;
+
+ var $connection;
function __construct(){
global $database;
- $database = new MYSQLi_DB(SQL_SERVER.':'.(defined('SQL_PORT') ? SQL_PORT : 3306), SQL_USER, SQL_PASS, SQL_DB);
+ $database = new MYSQLi_DB(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB, (defined('SQL_PORT') ? SQL_PORT : 3306));
$this->connection = $database->return_link();
}
function Login($username,$password){
global $database;
list($username,$password) = $database->escape_input($username,$password);
-
+
$q = "SELECT id, password, is_bcrypt FROM ".TB_PREFIX."users where username = '$username' and access >= ".MULTIHUNTER;
$result = mysqli_query($this->connection, $q);
-
+
// if we didn't update the database for bcrypt hashes yet...
if (mysqli_error($database->dblink) != '') {
$q = "SELECT id, password, 0 as is_bcrypt FROM ".TB_PREFIX."users where username = '$username' and access >= ".MULTIHUNTER;
@@ -67,27 +67,27 @@ class adm_DB {
} else {
$bcrypt_update_done = true;
}
-
+
$dbarray = mysqli_fetch_array($result);
-
+
// even if we didn't do a DB conversion for bcrypt passwords,
// we still need to check if this password wasn't encrypted via password_hash,
// since all methods were updated to use that instead of md5 and therefore
// new passwords in DB will be bcrypt already even without the is_bcrypt field present
$bcrypted = true;
$pwOk = password_verify($password, $dbarray['password']);
-
+
if (!$pwOk && !$dbarray['is_bcrypt']) {
$pwOk = ($dbarray['password'] == md5($password));
$bcrypted = false;
}
-
+
if($pwOk) {
// update password to bcrypt, if correct
if (!$dbarray['is_bcrypt'] && !$bcrypted) {
mysqli_query($this->connection, "UPDATE " . TB_PREFIX . "users SET password = '".password_hash($password, PASSWORD_BCRYPT,['cost' => 12])."'".($bcrypt_update_done ? ', is_bcrypt = 1' : '')." where id = ".(int) $dbarray['id']);
}
-
+
mysqli_query($this->connection,"Insert into ".TB_PREFIX."admin_log values (0,'X','$username logged in (IP: ".$_SERVER['REMOTE_ADDR'].")',".time().")");
return true;
}
@@ -122,7 +122,7 @@ class adm_DB {
$q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = ".(int) $vid;
mysqli_query($this->connection, $q);
}
-
+
function recountCP($vid){
global $database;
$fdata = $database->getResourceLevel($vid);
@@ -149,18 +149,18 @@ class adm_DB {
}
return $popT;
}
-
+
function buildingCP($f,$lvl){
$name = "bid".$f;
global $$name;
$popT = 0;
$dataarray = $$name;
-
+
for ($i = 1; $i <= $lvl; $i++) {
$popT += $dataarray[$i]['cp'];
}
return $popT;
- }
+ }
function getWref($x,$y) {
$q = "SELECT id FROM ".TB_PREFIX."wdata where x = ".(int) $x." and y = ".(int) $y;
@@ -261,7 +261,7 @@ class adm_DB {
}
$q = "DELETE FROM ".TB_PREFIX."hero where uid = ".(int) $uid;
mysqli_query($this->connection,$q);
-
+
$name = $database->getUserField($uid,"username",0);
mysqli_query($this->connection,"Insert into ".TB_PREFIX."admin_log values (0,$ID,'Deleted user $name',".time().")");
@@ -270,7 +270,7 @@ class adm_DB {
} else {
return false;
}
-
+
return true;
}
@@ -284,7 +284,7 @@ class adm_DB {
function CheckPass($password,$uid){
$q = "SELECT id,password, is_bcrypt FROM ".TB_PREFIX."users where id = ".(int) $uid." and access = ".ADMIN;
$result = mysqli_query($this->connection, $q);
-
+
// if we didn't update the database for bcrypt hashes yet...
if (mysqli_error($this->connection) != '') {
// no need to select ID here, since the DB is not updated, so there will be no password conversion later
@@ -296,19 +296,19 @@ class adm_DB {
}
$dbarray = mysqli_fetch_array($result);
-
+
// even if we didn't do a DB conversion for bcrypt passwords,
// we still need to check if this password wasn't encrypted via password_hash,
// since all methods were updated to use that instead of md5 and therefore
// new passwords in DB will be bcrypt already even without the is_bcrypt field present
$bcrypted = true;
$pwOk = password_verify($password, $dbarray['password']);
-
+
if (!$pwOk && !$dbarray['is_bcrypt']) {
$pwOk = ($dbarray['password'] == md5($password));
$bcrypted = false;
}
-
+
if($pwOk) {
// update password to bcrypt, if correct
if ($bcrypt_update_done && !$dbarray['is_bcrypt']) {
@@ -334,7 +334,7 @@ class adm_DB {
mysqli_query($this->connection,"Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Deleted village $wref',".time().")");
$database->clearExpansionSlot($wref);
-
+
$q = "DELETE FROM ".TB_PREFIX."abdata where vref = $wref";
mysqli_query($this->connection, $q);
$q = "DELETE FROM ".TB_PREFIX."bdata where wid = $wref";
@@ -357,13 +357,13 @@ class adm_DB {
mysqli_query($this->connection, $q);
$q = "DELETE FROM ".TB_PREFIX."raidlist where towref = $wref";
mysqli_query($this->connection, $q);
-
+
$q = "DELETE FROM ".TB_PREFIX."movement where `from` = $wref and proc=0";
mysqli_query($this->connection, $q);
-
+
$q = "UPDATE ".TB_PREFIX."wdata SET occupied = 0 where id = $wref";
mysqli_query($this->connection, $q);
-
+
$getmovement = $database->getMovement(3,$wref,1);
foreach($getmovement as $movedata) {
$time = microtime(true);
@@ -375,14 +375,14 @@ class adm_DB {
//check return enforcement from del village
$this->returnTroops($wref);
-
+
$q = "DELETE FROM ".TB_PREFIX."vdata WHERE `wref` = $wref";
mysqli_query($this->connection, $q);
-
+
if (mysqli_affected_rows($this->connection)>0) {
$q = "UPDATE ".TB_PREFIX."wdata set occupied = 0 where id = $wref";
mysqli_query($this->connection, $q);
-
+
$getprisoners = $database->getPrisoners($wref);
foreach($getprisoners as $pris) {
$troops = 0;
@@ -403,8 +403,8 @@ class adm_DB {
}
}
}
- }
-
+ }
+
function DelBan($uid,$id){
global $database;
$name = addslashes($database->getUserField($uid,"username",0));
@@ -511,7 +511,7 @@ class adm_DB {
public function getTypeLevel($tid,$vid) {
global $village,$database;
$keyholder = array();
-
+
if($vid == 0) {
$resourcearray = $village->resarray;
} else {
@@ -560,7 +560,7 @@ class adm_DB {
public function procDistanceTime($coor,$thiscoor,$ref,$vid) {
global $bid28,$bid14;
-
+
$xdistance = ABS($thiscoor['x'] - $coor['x']);
if($xdistance > WORLD_MAX) {
$xdistance = (2 * WORLD_MAX + 1) - $xdistance;
@@ -585,17 +585,17 @@ class adm_DB {
global $database;
$getenforce=$database->getEnforceVillage($wref,0);
-
+
//if(($enforce['from']==$village->wid) || ($enforce['vref']==$village->wid)){
foreach($getenforce as $enforce) {
-
+
$to = $database->getVillage($enforce['from']);
$Gtribe = "";
if ($database->getUserField($to['owner'],'tribe',0) == '2'){ $Gtribe = "1"; }
else if ($database->getUserField($to['owner'],'tribe',0) == '3'){ $Gtribe = "2"; }
else if ($database->getUserField($to['owner'],'tribe',0) == '4'){ $Gtribe = "3"; }
else if ($database->getUserField($to['owner'],'tribe',0) == '5'){ $Gtribe = "4"; }
-
+
$start = ($database->getUserField($to['owner'],'tribe',0)-1)*10+1;
$end = ($database->getUserField($to['owner'],'tribe',0)*10);
@@ -609,20 +609,20 @@ class adm_DB {
//find slowest unit.
for($i=$start;$i<=$end;$i++){
-
+
if(intval($enforce['u'.$i]) > 0){
if($unitarray) { reset($unitarray); }
$unitarray = $GLOBALS["u".$i];
$speeds[] = $unitarray['speed'];
//echo print_r(array_keys($speeds))."unitspd\n".$i."trib\n";
-
+
} else {
$enforce['u'.$i]='0';
}
-
+
}
-
+
if( intval($enforce['hero']) > 0){
$q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid = ".(int) $from['owner']." AND dead = 0";
$result = mysqli_query($q);
@@ -632,7 +632,7 @@ class adm_DB {
} else {
$enforce['hero']='0';
}
-
+
$artefact = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,3,0));
$artefact1 = count($database->getOwnUniqueArtefactInfo2($enforce['from'],2,1,1));
$artefact2 = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,2,0));
@@ -646,7 +646,7 @@ class adm_DB {
$fastertroops = 1;
}
$time = round($this->procDistanceTime($fromCor,$toCor,min($speeds),$enforce['from'])/$fastertroops);
-
+
$foolartefact2 = $database->getFoolArtefactInfo(2,$enforce['from'],$from['owner']);
if(count($foolartefact2) > 0){
foreach($foolartefact2 as $arte){
@@ -662,7 +662,7 @@ class adm_DB {
$database->addMovement(4,$wref,$enforce['from'],$reference,time(),($time+time()));
$database->deleteReinf($enforce['id']);
}
- }
+ }
public function calculateProduction($wid,$uid,$b1,$b2,$b3,$b4,$fdata,$ocounter,$pop) {
@@ -671,8 +671,8 @@ class adm_DB {
$largeA = $database->getOwnUniqueArtefactInfo($uid,4,2);
$uniqueA = $database->getOwnUniqueArtefactInfo($uid,4,3);
$upkeep = $this->getUpkeep($this->getAllUnits($wid),0,$wid,$uid);
-
-
+
+
$production=array();
$production['wood'] = $this->getWoodProd($fdata, $ocounter,$b1);
$production['clay'] = $this->getClayProd($fdata, $ocounter,$b2);
@@ -822,9 +822,9 @@ class adm_DB {
}
$ownunit['hero'] += $enforce['hero'];
}
- }
+ }
+
-
$prisoners = $database->getPrisoners($base,1);
if(!empty($prisoners)) {
foreach($prisoners as $prisoner){
@@ -840,7 +840,7 @@ class adm_DB {
}
}
}
-
+
if(!$InVillageOnly) {
$movement = $database->getVillageMovement($base);
if(!empty($movement)) {
@@ -854,7 +854,7 @@ class adm_DB {
}
return $ownunit;
}
-
+
public function getUpkeep($array,$type,$vid,$uid,$prisoners=0) {
global $database;
$buildarray = array();
@@ -956,7 +956,7 @@ class adm_DB {
}
return $upkeep;
}
-
+
};
$admin = new adm_DB;
diff --git a/GameEngine/Database.php b/GameEngine/Database.php
index af084c7b..f4debf06 100755
--- a/GameEngine/Database.php
+++ b/GameEngine/Database.php
@@ -442,15 +442,19 @@ class MYSQLi_DB implements IDbConnection {
*/
public function connect() {
// try to connect
- $this->dblink = mysqli_connect($this->hostname.':'.$this->port, $this->username, $this->password);
+ try {
+ $this->dblink = mysqli_connect( $this->hostname, $this->username, $this->password, $this->dbname, $this->port );
+ } catch (\Exception $exception) {
+ $this->dblink = mysqli_connect( $this->hostname . ':' . $this->port, $this->username, $this->password );
- // return on error
- if (mysqli_error($this->dblink)) {
- return false;
- }
+ // return on error
+ if (mysqli_error($this->dblink)) {
+ return false;
+ }
- // select the DB to use
- mysqli_select_db($this->dblink, $this->dbname);
+ // select the DB to use
+ mysqli_select_db($this->dblink, $this->dbname);
+ }
// return on error
if (mysqli_error($this->dblink)) {
diff --git a/Templates/Manual/52.tpl b/Templates/Manual/52.tpl
index 26888776..d2226a44 100644
--- a/Templates/Manual/52.tpl
+++ b/Templates/Manual/52.tpl
@@ -2,12 +2,21 @@
$count="0";
include_once("GameEngine/Config.php");
- $connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysqli_error($database->dblink));
- mysqli_select_db(SQL_DB, $connection) or die(mysqli_error($database->dblink));
+// go max 5 levels up - we don't have folders that go deeper than that
+$autoprefix = '';
+for ($i = 0; $i < 5; $i++) {
+ $autoprefix = str_repeat('../', $i);
+ if (file_exists($autoprefix.'autoloader.php')) {
+ // we have our path, let's leave
+ break;
+ }
+}
- $q = "SELECT Count(*) as Total FROM ".TB_PREFIX."movement where endtime < ".time()." and proc = 0";
- $result = mysqli_fetch_array(mysqli_query($GLOBALS["link"], $q, $connection), MYSQLI_ASSOC);
- $count=$result['Total'];
+include_once($autoprefix."GameEngine/Database.php");
+
+$q = "SELECT Count(*) as Total FROM ".TB_PREFIX."movement where endtime < ".time()." and proc = 0";
+$result = mysqli_fetch_array(mysqli_query($GLOBALS["link"], $q), MYSQLI_ASSOC);
+$count=$result['Total'];
?>