Skip to content

Commit

Permalink
General fixes
Browse files Browse the repository at this point in the history
+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
  • Loading branch information
iopietro committed May 21, 2018
1 parent e1b0dcf commit f0b9f32
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 267 deletions.
22 changes: 7 additions & 15 deletions GameEngine/Automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ public function __construct() {
$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);
Expand Down Expand Up @@ -167,9 +156,10 @@ function recountCP($vid){
return $popTot;
}

function buildingPOP($f,$lvl){
function buildingPOP($f, $lvl){
$name = "bid".$f;
global $$name;

$popT = 0;
$dataarray = $$name;

Expand All @@ -179,9 +169,10 @@ function buildingPOP($f,$lvl){
return $popT;
}

function buildingCP($f,$lvl){
function buildingCP($f, $lvl){
$name = "bid".$f;
global $$name;

$popT = 0;
$dataarray = $$name;

Expand Down Expand Up @@ -293,7 +284,7 @@ public function getTypeLevel($tid, $vid) {
}

private function clearDeleting() {
global $autoprefix, $units, $database;
global $autoprefix, $database;

if(file_exists($autoprefix."GameEngine/Prevention/cleardeleting.txt")) {
unlink($autoprefix."GameEngine/Prevention/cleardeleting.txt");
Expand Down Expand Up @@ -950,7 +941,7 @@ private function resolveCatapultsDestruction(&$bdo, &$battlepart, &$info_cat, &$
}

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");
Expand Down Expand Up @@ -2689,6 +2680,7 @@ private function sendunitsComplete() {

function DelVillage($wref){
global $database, $units;

$database->clearExpansionSlot($wref);
$wref = (int) $wref;
$q = "DELETE FROM ".TB_PREFIX."abdata where vref = $wref";
Expand Down
6 changes: 6 additions & 0 deletions GameEngine/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4997,6 +4997,12 @@ function checkEmbassiesAfterBattle($vid, $current_level, $use_cache = true) {
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
*
Expand Down
50 changes: 26 additions & 24 deletions GameEngine/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ public function encodeStr($str,$length) {
}

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;
Expand All @@ -55,35 +59,33 @@ public function procDistanceTime($coor, $thiscoor, $ref, $mode, $vid = 0) {
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) {
/*
Expand Down
8 changes: 4 additions & 4 deletions GameEngine/Lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -1335,13 +1335,13 @@
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");
Expand Down
97 changes: 49 additions & 48 deletions GameEngine/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,18 @@ function __construct() {

$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;
Expand All @@ -113,19 +111,13 @@ public function Login($user) {

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();
Expand Down Expand Up @@ -159,15 +151,15 @@ public function Logout() {

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);

Expand All @@ -181,11 +173,13 @@ private function checkLogin(){
}

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;
}
}
Expand All @@ -195,16 +189,32 @@ private function checkLogin(){
//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;
Expand Down Expand Up @@ -261,21 +271,13 @@ private function PopulateVar() {
$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();
}

/**
Expand All @@ -286,8 +288,7 @@ private function PopulateVar() {
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)
{
Expand Down
Loading

0 comments on commit f0b9f32

Please sign in to comment.