From f0b9f328260137f0eef34ddb860dc33c9fdd7037 Mon Sep 17 00:00:00 2001 From: iopietro Date: Tue, 22 May 2018 00:33:09 +0200 Subject: [PATCH] General fixes +Moved "isWinner()" method from Automation.php to Session.php, it's now triggered when activating plus function or entering in plus1.php/build.php +General clean-up and better indentation +The tournament square bonus is now displayed correctly --- GameEngine/Automation.php | 22 +++---- GameEngine/Database.php | 6 ++ GameEngine/Generator.php | 50 ++++++++-------- GameEngine/Lang/en.php | 8 +-- GameEngine/Session.php | 97 +++++++++++++++--------------- GameEngine/Units.php | 46 ++++++++------- Templates/Map/mapview.tpl | 14 ++--- Templates/Map/mapviewlarge.tpl | 14 ++--- a2b.php | 1 - a2b2.php | 5 +- allianz.php | 1 - build.php | 14 ++--- dorf2.php | 1 - nachrichten.php | 104 ++++++++++++++++----------------- plus.php | 89 ++++++++++++++-------------- spieler.php | 23 +++----- support.php | 5 +- version.php | 6 +- 18 files changed, 239 insertions(+), 267 deletions(-) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index a114f014..0cf09d39 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -108,17 +108,6 @@ class Automation { $this->artefactOfTheFool(); } - public function isWinner() { - global $database; - // check whether someone already built a level 100 Wonder of the World - $q = mysqli_fetch_array(mysqli_query($database->dblink,"SELECT Count(*) as Total FROM ".TB_PREFIX."fdata WHERE f99 = 100 and f99t = 40"), MYSQLI_ASSOC); - if($q['Total'] > 0) - { - header('Location: winner.php'); - exit; - } - } - public function procResType($ref, $mode = 0) { //Capital or only 1 village left = cannot be destroyed return addslashes(empty($build = Building::procResType($ref)) && !$mode ? "Village can't be" : $build); @@ -167,9 +156,10 @@ class Automation { return $popTot; } - function buildingPOP($f,$lvl){ + function buildingPOP($f, $lvl){ $name = "bid".$f; global $$name; + $popT = 0; $dataarray = $$name; @@ -179,9 +169,10 @@ class Automation { return $popT; } - function buildingCP($f,$lvl){ + function buildingCP($f, $lvl){ $name = "bid".$f; global $$name; + $popT = 0; $dataarray = $$name; @@ -293,7 +284,7 @@ class Automation { } private function clearDeleting() { - global $autoprefix, $units, $database; + global $autoprefix, $database; if(file_exists($autoprefix."GameEngine/Prevention/cleardeleting.txt")) { unlink($autoprefix."GameEngine/Prevention/cleardeleting.txt"); @@ -950,7 +941,7 @@ class Automation { } private function sendunitsComplete() { - global $bid19, $bid23, $bid34, $u99, $database, $battle, $technology, $logging, $generator, $units, $autoprefix; + global $bid19, $bid23, $bid34, $u99, $database, $battle, $technology, $logging, $units, $autoprefix; if(file_exists($autoprefix."GameEngine/Prevention/sendunits.txt")) { unlink($autoprefix."GameEngine/Prevention/sendunits.txt"); @@ -2689,6 +2680,7 @@ class Automation { function DelVillage($wref){ global $database, $units; + $database->clearExpansionSlot($wref); $wref = (int) $wref; $q = "DELETE FROM ".TB_PREFIX."abdata where vref = $wref"; diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 11277809..e02376c5 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -4997,6 +4997,12 @@ References: User ID/Message ID, Mode else return ''; // all is good, no need to append additional alliance-related text } + function isThereAWinner(){ + $q = "SELECT Count(*) as Total FROM ".TB_PREFIX."fdata WHERE f99 = 100 and f99t = 40"; + $result = mysqli_fetch_array(mysqli_query($this->dblink, $q), MYSQLI_ASSOC); + return $result['Total'] > 0; + } + /** * Modify or delete a building being constructed/in queue * diff --git a/GameEngine/Generator.php b/GameEngine/Generator.php index 15072870..8278a762 100755 --- a/GameEngine/Generator.php +++ b/GameEngine/Generator.php @@ -36,17 +36,21 @@ class MyGenerator { } public function procDistanceTime($coor, $thiscoor, $ref, $mode, $vid = 0) { - global $bid28, $bid14, $building; + global $database, $bid28, $bid14, $village; + + if($vid == 0) $vid = $village->wid; $xdistance = ABS($thiscoor['x'] - $coor['x']); if($xdistance > WORLD_MAX) { $xdistance = (2 * WORLD_MAX + 1) - $xdistance; } + $ydistance = ABS($thiscoor['y'] - $coor['y']); if($ydistance > WORLD_MAX) { $ydistance = (2 * WORLD_MAX + 1) - $ydistance; } - $distance = SQRT(POW($xdistance,2)+POW($ydistance,2)); + + $distance = SQRT(POW($xdistance,2) + POW($ydistance,2)); if(!$mode){ if($ref == 1) $speed = 16; else if($ref == 2) $speed = 12; @@ -55,35 +59,33 @@ class MyGenerator { else $speed = 1; }else{ $speed = $ref; - if(($tSquareLevel = $building->getTypeLevel(14, $vid)) > 0 && $distance >= TS_THRESHOLD) { + if(($tSquareLevel = $database->getFieldLevelInVillage($vid, 14)) > 0 && $distance >= TS_THRESHOLD) { $speed *= ($bid14[$tSquareLevel]['attri'] / 100) ; } } - if($speed != 0) return round(($distance / $speed) * 3600 / INCREASE_SPEED); + if($speed > 0) return round(($distance / $speed) * 3600 / INCREASE_SPEED); else return round($distance * 3600 / INCREASE_SPEED); } - public function getTimeFormat($time) { - $min = 0; - $hr = 0; - $days = 0; - while($time >= 60) : - $time -= 60; - $min += 1; - endwhile; - while ($min >= 60) : - $min -= 60; - $hr += 1; - endwhile; - if ($min < 10) { - $min = "0".$min; - } - if($time < 10) { - $time = "0".$time; - } - return $hr.":".$min.":".$time; - } + public function getTimeFormat($time) { + $min = $hr = $days = 0; + + while($time >= 60){ + $time -= 60; + $min += 1; + } + + while($min >= 60){ + $min -= 60; + $hr += 1; + } + + if($min < 10) $min = "0" . $min; + if($time < 10) $time = "0" . $time; + + return $hr . ":" . $min . ":" . $time; + } public function procMtime($time, $pref = 3) { /* diff --git a/GameEngine/Lang/en.php b/GameEngine/Lang/en.php index ceb1c8d7..a4b9c5a1 100755 --- a/GameEngine/Lang/en.php +++ b/GameEngine/Lang/en.php @@ -1335,13 +1335,13 @@ define("CONF_SERV_WWSTATS_TOOLTIP","Enable (True) or disable (False) the display define("CONF_SERV_NTRTIME","Nature Troops Regeneration Time"); define("CONF_SERV_NTRTIME_TOOLTIP","Time through which the nature troops will be restored in oases."); define("CONF_SERV_OASIS_WOOD_PROD_MULT","Oasis Wood Production Multiplier"); -define("CONF_SERV_OASIS_WOOD_PROD_MULT_TOOLTIP","Multiply the base oasis production (40) of wood"); +define("CONF_SERV_OASIS_WOOD_PROD_MULT_TOOLTIP","The base wood oasis production"); define("CONF_SERV_OASIS_CLAY_PROD_MULT","Oasis Clay Production Multiplier"); -define("CONF_SERV_OASIS_CLAY_PROD_MULT_TOOLTIP","Multiply the base oasis production (40) of clay"); +define("CONF_SERV_OASIS_CLAY_PROD_MULT_TOOLTIP","The base clay oasis production"); define("CONF_SERV_OASIS_IRON_PROD_MULT","Oasis Iron Production Multiplier"); -define("CONF_SERV_OASIS_IRON_PROD_MULT_TOOLTIP","Multiply the base oasis production (40) of iron"); +define("CONF_SERV_OASIS_IRON_PROD_MULT_TOOLTIP","The base iron oasis production"); define("CONF_SERV_OASIS_CROP_PROD_MULT","Oasis Crop Production Multiplier"); -define("CONF_SERV_OASIS_CROP_PROD_MULT_TOOLTIP","Multiply the base oasis production (40) of crop"); +define("CONF_SERV_OASIS_CROP_PROD_MULT_TOOLTIP","The base crop oasis production"); define("CONF_SERV_MEDALINTERVAL","Medal Interval"); define("CONF_SERV_MEDALINTERVAL_TOOLTIP","The time interval for issuing medals for the top players and alliances. If this parameter is changed on the installed server, the time interval changes after the subsequent issuance of the medals."); define("CONF_SERV_TOURNTHRES","Tourn Threshold"); diff --git a/GameEngine/Session.php b/GameEngine/Session.php index 03047d72..e8d30111 100755 --- a/GameEngine/Session.php +++ b/GameEngine/Session.php @@ -84,20 +84,18 @@ class Session { $this->logged_in = $this->checkLogin(); - if($this->logged_in && TRACK_USR) { - $database->updateActiveUser($this->username, $this->time); - } - if(isset($_SESSION['url'])) { - $this->referrer = $_SESSION['url']; - } else { - $this->referrer = "/"; - } + if($this->logged_in && TRACK_USR) $database->updateActiveUser($this->username, $this->time); + + if(isset($_SESSION['url'])) $this->referrer = $_SESSION['url']; + else $this->referrer = "/"; + $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; $this->SurfControl(); } public function Login($user) { global $database, $generator, $logging; + $this->logged_in = true; $_SESSION['sessid'] = $generator->generateRandID(); $_SESSION['username'] = $user; @@ -113,19 +111,13 @@ class Session { if ($dbarray['id'] > 1) { if(!isset($_SESSION['wid'])) { - if($selected_village!='') { - $data = $database->getVillage($selected_village); - }else{ - $data = $database->getVillage($userFields["id"]); - } + if(!empty($selected_village)) $data = $database->getVillage($selected_village); + else $data = $database->getVillage($userFields["id"]); $_SESSION['wid'] = $data['wref']; } else - if($_SESSION['wid'] == '') { - if($selected_village!='') { - $data = $database->getVillage($selected_village); - }else{ - $data = $database->getVillage($userFields["id"]); - } + if(empty($_SESSION['wid'])) { + if(!empty($selected_village)) $data = $database->getVillage($selected_village); + else $data = $database->getVillage($userFields["id"]); $_SESSION['wid'] = $data['wref']; } $this->PopulateVar(); @@ -159,15 +151,15 @@ class Session { public function changeChecker() { global $generator; + $this->checker = $_SESSION['checker'] = $generator->generateRandStr(3); $this->mchecker = $_SESSION['mchecker'] = $generator->generateRandStr(5); } private function checkLogin(){ global $database; - - $user = ''; - $id = ''; + + $user = $id = ''; $admin = false; $inAdmin = (strpos($_SERVER['REQUEST_URI'], '/Admin') !== false); @@ -181,11 +173,13 @@ class Session { } if($user && ($admin || isset($_SESSION['sessid']))) { + $this->isWinner(); + // check if this is not a support user, for who only messages and statistics are available if ($user == 'Support') { $req_file = basename($_SERVER['PHP_SELF']); if (!in_array($req_file, ['nachrichten.php', 'logout.php', 'statistiken.php', 'rules.php', 'karte.php', 'karte2.php', 'spieler.php'])) { - header('Location:nachrichten.php'); + header('Location: nachrichten.php'); exit; } } @@ -195,16 +189,32 @@ class Session { //update database $database->updateActiveUser($user, $this->time); return true; - } else { - return false; - } + } + else return false; } - - /*************************** - Function to check Real Hero - Made by: Shadow and brainiacX - ***************************/ + /** + * Called when there's a player who built a WW to level 100 + * + */ + + function isWinner(){ + global $database; + + $requiredPage = basename($_SERVER['PHP_SELF']); + if($database->isThereAWinner() && (in_array($requiredPage, ['build.php', 'plus1.php']) || + (in_array($requiredPage, ['plus.php']) && isset($_GET['id']) && !empty($_GET['id'] && $_GET['id'] >= 7)))) + { + header('Location: winner.php'); + exit; + } + } + + /** + * Function to check Real Hero + * Made by: Shadow and brainiacX + * + */ function CheckHeroReal () { global $database,$link; @@ -261,21 +271,13 @@ class Session { $this->oldrank = $this->userarray['oldrank']; $this->sharedForums = $database->getSharedForums($this->uid, $this->alliance); $_SESSION['ok'] = $this->userarray['ok']; - if($this->userarray['b1'] > $this->time) { - $this->bonus1 = 1; - } - if($this->userarray['b2'] > $this->time) { - $this->bonus2 = 1; - } - if($this->userarray['b3'] > $this->time) { - $this->bonus3 = 1; - } - if($this->userarray['b4'] > $this->time) { - $this->bonus4 = 1; - } - if (!in_array($this->username, ['Support', 'Multihunter'])) { - $this->CheckHeroReal(); - } + + if($this->userarray['b1'] > $this->time) $this->bonus1 = 1; + if($this->userarray['b2'] > $this->time) $this->bonus2 = 1; + if($this->userarray['b3'] > $this->time) $this->bonus3 = 1; + if($this->userarray['b4'] > $this->time) $this->bonus4 = 1; + + if (!in_array($this->username, ['Support', 'Multihunter'])) $this->CheckHeroReal(); } /** @@ -286,8 +288,7 @@ class Session { public function populateAttacks(){ global $database, $village; - $troopsMovement = $database->getMovement(3, $village->wid, 0); - + $troopsMovement = $database->getMovement(3, $village->wid, 0); if(count($troopsMovement) > 0){ foreach($troopsMovement as $movement) { diff --git a/GameEngine/Units.php b/GameEngine/Units.php index 3b300b25..e085947a 100755 --- a/GameEngine/Units.php +++ b/GameEngine/Units.php @@ -23,48 +23,52 @@ class Units { if (!isset($post['disabled'])) $post['disabled'] = ''; switch($post['c']) { - case "1": - if (isset($post['a'])&& $post['a']==533374){ - $this->sendTroops($post); - }else{ + case 1: + if (isset($post['a']) && $post['a'] == 533374) $this->sendTroops($post); + else + { $post = $this->loadUnits($post); return $post; } break; - case "2": - if (isset($post['a'])&& $post['a']==533374 && $post['disabled'] == ""){ - $this->sendTroops($post); - }else{ + case 2: + if (isset($post['a']) && $post['a'] == 533374 && empty($post['disabled'])) $this->sendTroops($post); + else + { $post = $this->loadUnits($post); return $post; } break; - case "3": + case 3: if (isset($post['a']) && $post['a'] == 533374 && empty($post['disabled'])) $this->sendTroops($post); - else{ + else + { $post = $this->loadUnits($post); return $post; } break; - case "4": + case 4: if (isset($post['a']) && $post['a'] == 533374) $this->sendTroops($post); - else{ + else + { $post = $this->loadUnits($post); return $post; } + break; - case "5": + case 5: if (isset($post['a']) && $post['a'] == "new") $this->Settlers($post); else { $post = $this->loadUnits($post); return $post; } + break; - case "8": + case 8: $this->sendTroopsBack($post); break; } @@ -72,7 +76,7 @@ class Units { } private function loadUnits($post) { - global $database,$village,$session,$generator,$logging,$form; + global $database, $village, $session, $generator, $logging, $form; // Search by town name // Coordinates and look confirm name people if(isset($post['x']) && isset($post['y']) && !empty($post['x']) && !empty($post['y'])) { @@ -175,7 +179,7 @@ class Units { $villageOwner = $database->getVillageField($id,'owner'); $userAccess = $database->getUserField($villageOwner,'access',0); $userID = $database->getUserField($villageOwner,'id',0); - if($userAccess == 0 or ($userAccess == MULTIHUNTER && $userID == 5) or (!ADMIN_ALLOW_INCOMING_RAIDS && $userAccess == ADMIN)){ + if($userAccess == 0 || ($userAccess == MULTIHUNTER && $userID == 5) || (!ADMIN_ALLOW_INCOMING_RAIDS && $userAccess == ADMIN)){ $form->addError("error","Player is Banned. You can't attack him"); //break; } @@ -200,7 +204,7 @@ class Units { // We must return an array with $ post, which contains all the data more // another variable that will define the flag is raised and is being sent and the type of shipping $villageName = $database->getVillageField($id,'name'); - $speed= 300; + $speed = 300; $timetaken = $generator->procDistanceTime($coor, $village->coor, INCREASE_SPEED, 1); array_push($post, "$id", "$villageName", "$villageOwner","$timetaken"); return $post; @@ -213,7 +217,7 @@ class Units { exit; } else if (isset($id)) { $villageName = $database->getOasisField($id,"name"); - $speed= 300; + $speed = 300; $timetaken = $generator->procDistanceTime($coor, $village->coor, INCREASE_SPEED, 1); array_push($post, "$id", "$villageName", "2","$timetaken"); return $post; @@ -239,7 +243,7 @@ class Units { } private function processReturnTroops($enforce) { - global $database, $generator; + global $database; $to = $database->getVillage($enforce['from']); $tribe = $database->getUserField($to['owner'], 'tribe', 0); @@ -253,7 +257,7 @@ class Units { } private function sendTroops($post) { - global $form, $database, $village, $generator, $session; + global $form, $database, $village, $session; $data = $database->getA2b( $post['timestamp_checksum'], $post['timestamp'] ); $Gtribe = ($session->tribe == 1) ? "" : $session->tribe - 1; @@ -430,7 +434,7 @@ class Units { } private function sendTroopsBack($post) { - global $form, $database, $village, $generator, $session, $technology; + global $form, $database, $village, $session, $technology; if ( $session->access != BANNED ) { $enforce = $database->getEnforceArray( $post['ckey'], 0 ); $enforceoasis = $database->getOasisEnforceArray( $post['ckey'], 0 ); diff --git a/Templates/Map/mapview.tpl b/Templates/Map/mapview.tpl index 22c3df18..98806675 100644 --- a/Templates/Map/mapview.tpl +++ b/Templates/Map/mapview.tpl @@ -23,25 +23,19 @@ if(isset($_GET['z'])) { $y = $currentcoor['y']; $x = $currentcoor['x']; $bigmid = $_GET['z']; -} -else if(isset($_POST['xp']) && isset($_POST['yp'])){ +}else if(isset($_POST['xp']) && isset($_POST['yp'])){ $x = $_POST['xp']; $y = $_POST['yp']; $bigmid = $generator->getBaseID($x,$y); -} -else { +}else{ $y = $village->coor['y']; $x = $village->coor['x']; $bigmid = $village->wid; } -if(isset($_SESSION['troops_movement'])){ - unset($_SESSION['troops_movement']); -} +if(isset($_SESSION['troops_movement'])) unset($_SESSION['troops_movement']); -if($session->plus){ - $session->populateAttacks(); -} +if($session->plus) $session->populateAttacks(); $xm7 = ($x-7) < -WORLD_MAX? $x+WORLD_MAX+WORLD_MAX-6 : $x-7; $xm3 = ($x-3) < -WORLD_MAX? $x+WORLD_MAX+WORLD_MAX-2 : $x-3; diff --git a/Templates/Map/mapviewlarge.tpl b/Templates/Map/mapviewlarge.tpl index 980644da..92493d1d 100644 --- a/Templates/Map/mapviewlarge.tpl +++ b/Templates/Map/mapviewlarge.tpl @@ -20,25 +20,19 @@ if(isset($_GET['z'])){ $y = $currentcoor['y']; $x = $currentcoor['x']; $bigmid = $_GET['z']; -} -else if(isset($_POST['xp']) && isset($_POST['yp'])){ +}else if(isset($_POST['xp']) && isset($_POST['yp'])){ $x = $_POST['xp']; $y = $_POST['yp']; $bigmid = $generator->getBaseID($x,$y); -} -else{ +}else{ $y = $village->coor['y']; $x = $village->coor['x']; $bigmid = $village->wid; } -if(isset($_SESSION['troops_movement'])){ - unset($_SESSION['troops_movement']); -} +if(isset($_SESSION['troops_movement'])) unset($_SESSION['troops_movement']); -if($session->plus){ - $session->populateAttacks(); -} +if($session->plus) $session->populateAttacks(); $xm7 = ($x-7) < -WORLD_MAX? $x+WORLD_MAX+WORLD_MAX-6 : $x-7; $xm6 = ($x-6) < -WORLD_MAX? $x+WORLD_MAX+WORLD_MAX-5 : $x-6; diff --git a/a2b.php b/a2b.php index a72f9729..a240f590 100644 --- a/a2b.php +++ b/a2b.php @@ -68,7 +68,6 @@ if(isset($_GET['o'])){ else $disabled = "disabled=disabled"; } $process = $units->procUnits($_POST); -$automation->isWinner(); ?> diff --git a/a2b2.php b/a2b2.php index caa6ab6c..e2547f3f 100644 --- a/a2b2.php +++ b/a2b2.php @@ -23,10 +23,7 @@ if(isset($_GET['newdid'])) { header("Location: ".$_SERVER['PHP_SELF']); exit; } -else { - $building->procBuild($_GET); -} -$automation->isWinner(); +else $building->procBuild($_GET); ?> diff --git a/allianz.php b/allianz.php index e573caf7..79e05ce7 100644 --- a/allianz.php +++ b/allianz.php @@ -29,7 +29,6 @@ if(isset($_GET['newdid'])) { exit; } } -if(isset($_GET['s'])) $automation->isWinner(); if(isset($_GET['fid']) || isset($_GET['fid2'])){ $fid = preg_replace("/[^0-9]/","",!empty($_GET['fid']) ? $_GET['fid'] : $_GET['fid2']); diff --git a/build.php b/build.php index 1161328c..5d607a95 100644 --- a/build.php +++ b/build.php @@ -275,7 +275,7 @@ if(isset($_GET['mode']) && $_GET['mode'] == 'troops' && isset($_GET['cancel']) & exit(); } } -if(isset($_GET['id'])) $automation->isWinner(); + ?> @@ -295,13 +295,13 @@ if(isset($_GET['id'])) $automation->isWinner(); gpack == null || GP_ENABLE == false) { - echo " - - "; + echo " + + "; } else { - echo " - - "; + echo " + + "; } ?>