General fixes

+Fixed an exploit that permit to maintain the crop level constant if the
page was refreshed every second, with a negative production
This commit is contained in:
iopietro
2018-05-06 15:20:58 +02:00
parent bd033334c4
commit ec63b04587
3 changed files with 11 additions and 13 deletions
+1 -2
View File
@@ -3974,7 +3974,6 @@ class Automation {
$unitArrays = $this->getAllUnits($wref, false); $unitArrays = $this->getAllUnits($wref, false);
$villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref); $villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref);
$starv = $getVillage['starv']; $starv = $getVillage['starv'];
if ($crop < $villageUpkeep){ if ($crop < $villageUpkeep){
//Add starvation data //Add starvation data
$database->setVillageFields($wref, ['starv', 'starvupdate'], [$villageUpkeep, time()]); $database->setVillageFields($wref, ['starv', 'starvupdate'], [$villageUpkeep, time()]);
@@ -4156,7 +4155,7 @@ class Automation {
break; break;
} }
$database->modifyResource($starv['wref'], 0, 0, 0, max(intval($newCrop), 0), 1); $database->modifyResource($starv['wref'], 0, 0, 0, max($newCrop, 0), 1);
$database->setVillageField($starv['wref'], ['starv', 'starvupdate'], [$upkeep, $time]); $database->setVillageField($starv['wref'], ['starv', 'starvupdate'], [$upkeep, $time]);
} }
} }
+8 -9
View File
@@ -3274,7 +3274,7 @@ class MYSQLi_DB implements IDbConnection {
/////////////ADDED BY BRAINIAC - THANK YOU /////////////ADDED BY BRAINIAC - THANK YOU
function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) { function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) {
list($vid, $wood, $clay, $iron, $crop, $mode) = $this->escape_input((int) $vid, (int) $wood, (int) $clay, (int) $iron, (int) $crop, $mode); list($vid, $wood, $clay, $iron, $crop, $mode) = $this->escape_input((int) $vid, $wood, $clay, $iron, $crop, $mode);
$sign = (!$mode ? '-' : '+'); $sign = (!$mode ? '-' : '+');
$q = " $q = "
@@ -7407,17 +7407,16 @@ References: User ID/Message ID, Mode
return $cachedValue; return $cachedValue;
} }
$wood = $cropo = $clay = $iron = 0; $basecrop = $grainmill = $bakery = $cropo = 0;
$basecrop = $grainmill = $bakery = 0;
$owner = $this->getVrefField($wref, 'owner', $use_cache); $owner = $this->getVrefField($wref, 'owner', $use_cache);
$bonus = $this->getUserField($owner, 'b4', 0); $bonus = $this->getUserField($owner, 'b4', 0);
$buildarray = $this->getResourceLevel($wref); $buildarray = $this->getResourceLevel($wref);
$cropholder = []; $cropholder = [];
for($i = 1; $i <= 38; $i++){ for($i = 1; $i <= 38; $i++){
if($buildarray['f'.$i.'t'] == 4) array_push($cropholder, 'f' . $i); if($buildarray['f'.$i.'t'] == 4) array_push($cropholder, 'f'.$i);
if($buildarray['f'.$i.'t'] == 8) $grainmill = $buildarray['f' . $i]; if($buildarray['f'.$i.'t'] == 8) $grainmill = $buildarray['f'.$i];
if($buildarray['f'.$i.'t'] == 9) $bakery = $buildarray['f' . $i]; if($buildarray['f'.$i.'t'] == 9) $bakery = $buildarray['f'.$i];
} }
$q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = ".(int) $wref; $q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = ".(int) $wref;
@@ -7440,14 +7439,14 @@ References: User ID/Message ID, Mode
for($i = 0; $i <= count($cropholder) - 1; $i++){ for($i = 0; $i <= count($cropholder) - 1; $i++){
$basecrop += $bid4[$buildarray[$cropholder[$i]]]['prod']; $basecrop += $bid4[$buildarray[$cropholder[$i]]]['prod'];
} }
$crop = $basecrop + $basecrop * 0.25 * $cropo; $crop = $basecrop + $basecrop * 0.25 * $cropo;
if($grainmill >= 1 || $bakery >= 1){ if($grainmill >= 1 || $bakery >= 1){
$crop += $basecrop / 100 * ((isset($bid8[$grainmill]['attri']) ? $bid8[$grainmill]['attri'] : 0) + (isset($bid9[$bakery]['attri']) ? $bid9[$bakery]['attri'] : 0)); $crop += $basecrop / 100 * ((isset($bid8[$grainmill]['attri']) ? $bid8[$grainmill]['attri'] : 0) + (isset($bid9[$bakery]['attri']) ? $bid9[$bakery]['attri'] : 0));
} }
if($bonus > time()){ if($bonus > time()) $crop *= 1.25;
$crop *= 1.25;
}
$crop *= SPEED; $crop *= SPEED;
self::$cropProductionStarvationValueCache[$wref] = $crop; self::$cropProductionStarvationValueCache[$wref] = $crop;
+2 -2
View File
@@ -37,9 +37,9 @@ class Village {
//add new line code //add new line code
//check exist village if from village destroy to avoid error msg. //check exist village if from village destroy to avoid error msg.
if ( !$database->checkVilExist($this->wid) ) { if(!$database->checkVilExist($this->wid)){
$this->wid=$database->getVillageID($session->uid); $this->wid=$database->getVillageID($session->uid);
$_SESSION['wid']=$this->wid; $_SESSION['wid'] = $this->wid;
} }
$this->LoadTown(); $this->LoadTown();