refactor: Units class-related caching done

#313
This commit is contained in:
Martin Ambrus
2017-11-17 15:34:08 +01:00
parent 079c830b94
commit 1318f34cba
2 changed files with 470 additions and 365 deletions
+93 -26
View File
@@ -229,11 +229,31 @@ class MYSQLi_DB implements IDbConnection {
*/ */
$prisonersCacheByVillageAndFromIDs = [], $prisonersCacheByVillageAndFromIDs = [],
/**
* @var array Cache of info about whether a village is an oasis.
*/
$isVillageOasisCache = [],
/** /**
* @var array Cache of resource levels. * @var array Cache of resource levels.
*/ */
$resourceLevelsCache = [], $resourceLevelsCache = [],
/**
* @var array Cache of oasis data.
*/
$oasisFieldsCache = [],
/**
* @var array Cache of oasis data by conquered ID.
*/
$oasisFieldsCacheByConqueredID = [],
/**
* @var array Cache of research.
*/
$abTechCache = [],
/** /**
* @var array Cache of messages to be sent out to players, * @var array Cache of messages to be sent out to players,
* so we can collect them and send them out together * so we can collect them and send them out together
@@ -581,6 +601,7 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_query($this->dblink,$q); return mysqli_query($this->dblink,$q);
} }
// no need to cache this method
public function hasBeginnerProtection($vid) { public function hasBeginnerProtection($vid) {
list($vid) = $this->escape_input($vid); list($vid) = $this->escape_input($vid);
@@ -636,6 +657,7 @@ class MYSQLi_DB implements IDbConnection {
return $this->mysqli_fetch_all($result); return $this->mysqli_fetch_all($result);
} }
// no need to cache this method
function getVilWref($x, $y) { function getVilWref($x, $y) {
list($x, $y) = $this->escape_input((int) $x, (int) $y); list($x, $y) = $this->escape_input((int) $x, (int) $y);
@@ -798,11 +820,7 @@ class MYSQLi_DB implements IDbConnection {
} }
function getVrefField($ref, $field) { function getVrefField($ref, $field) {
list($ref, $field) = $this->escape_input((int) $ref, $field); return $this->getVillage($ref)[$field];
$q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref";
$result = mysqli_query($this->dblink,$q) or die(mysqli_error($this->dblink));
$dbarray = mysqli_fetch_array($result);
return $dbarray[$field];
} }
function getVrefCapital($ref) { function getVrefCapital($ref) {
@@ -1198,15 +1216,24 @@ class MYSQLi_DB implements IDbConnection {
} }
return mysqli_query($this->dblink,$q); return mysqli_query($this->dblink,$q);
} }
function isVillageOases($wref) { function isVillageOases($wref, $use_cache = true) {
list($wref) = $this->escape_input((int) $wref); list($wref) = $this->escape_input((int) $wref);
// first of all, check if we should be using cache and whether the field
// required is already cached
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$isVillageOasisCache, $wref)) && !is_null($cachedValue)) {
return $cachedValue;
}
$q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = ". $wref; $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = ". $wref;
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
if($result){ if($result){
$dbarray = mysqli_fetch_array($result); $dbarray = mysqli_fetch_array($result);
return $dbarray['oasistype']; $result = $dbarray['oasistype'];
}else return 0; }else $result = 0;
self::$isVillageOasisCache[$wref] = $result;
return self::$isVillageOasisCache[$wref];
} }
public function VillageOasisCount($vref) { public function VillageOasisCount($vref) {
@@ -1499,12 +1526,20 @@ class MYSQLi_DB implements IDbConnection {
return $dbarray['pop']; return $dbarray['pop'];
} }
function getOasisV($vid) { function getOasisV($vid, $use_cache = true) {
list($vid) = $this->escape_input((int) $vid); list($vid) = $this->escape_input((int) $vid);
// first of all, check if we should be using cache and whether the field
// required is already cached
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$oasisFieldsCache, $vid)) && !is_null($cachedValue)) {
return $cachedValue;
}
$q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid"; $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid";
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
return mysqli_fetch_array($result);
self::$oasisFieldsCache[$vid] = mysqli_fetch_array($result, MYSQLI_ASSOC);
return self::$oasisFieldsCache[$vid];
} }
function getMInfo($id) { function getMInfo($id) {
@@ -1523,20 +1558,24 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_fetch_array($result); return mysqli_fetch_array($result);
} }
function getOasis($vid) { function getOasis($vid, $use_cache = true) {
list($vid) = $this->escape_input((int) $vid); list($vid) = $this->escape_input((int) $vid);
// first of all, check if we should be using cache and whether the field
// required is already cached
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$oasisFieldsCacheByConqueredID, $vid)) && !is_null($cachedValue)) {
return $cachedValue;
}
$q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid"; $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid";
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
return $this->mysqli_fetch_all($result);
self::$oasisFieldsCacheByConqueredID[$vid] = $this->mysqli_fetch_all($result);
return self::$oasisFieldsCacheByConqueredID[$vid];
} }
function getOasisInfo($wid) { function getOasisInfo($wid, $use_cache = true) {
list($wid) = $this->escape_input((int) $wid); return $this->getOasisV($wid, $use_cache);
$q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid";
$result = mysqli_query($this->dblink,$q);
return mysqli_fetch_assoc($result);
} }
function getVillageField($ref, $field, $use_cache = true) { function getVillageField($ref, $field, $use_cache = true) {
@@ -1577,20 +1616,27 @@ class MYSQLi_DB implements IDbConnection {
} else return 0;*/ } else return 0;*/
} }
function getOasisField($ref, $field) { function getOasisField($ref, $field, $use_cache = true) {
list($ref, $field) = $this->escape_input((int) $ref, $field); // return all data, don't waste time by selecting fields one by one
$oasisArray = $this->getOasisV($ref, $use_cache);
$result = (isset($oasisArray[$field]) ? $oasisArray[$field] : null);
/*list($ref, $field) = $this->escape_input((int) $ref, $field);
$q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref"; $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref";
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
$dbarray = mysqli_fetch_array($result); $dbarray = mysqli_fetch_array($result);
return $dbarray[$field]; return $dbarray[$field];*/
} }
function getOasisFields($ref, $fields) { function getOasisFields($ref, $fields, $use_cache = true) {
list($ref, $fields) = $this->escape_input((int) $ref, $fields); // return all data, don't waste time by selecting fields one by one
return $this->getOasisV($ref, $use_cache);
/*list($ref, $fields) = $this->escape_input((int) $ref, $fields);
$q = "SELECT $fields FROM " . TB_PREFIX . "odata where wref = $ref"; $q = "SELECT $fields FROM " . TB_PREFIX . "odata where wref = $ref";
return mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC); return mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);*/
} }
function setVillageField($ref, $field, $value) { function setVillageField($ref, $field, $value) {
@@ -1907,6 +1953,7 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_fetch_array($result); return mysqli_fetch_array($result);
} }
// no need to cache this method
function checkVilExist($wref) { function checkVilExist($wref) {
list($wref) = $this->escape_input((int) $wref); list($wref) = $this->escape_input((int) $wref);
@@ -1919,6 +1966,7 @@ class MYSQLi_DB implements IDbConnection {
} }
} }
// no need to cache this method
function checkOasisExist($wref) { function checkOasisExist($wref) {
list($wref) = $this->escape_input((int) $wref); list($wref) = $this->escape_input((int) $wref);
@@ -4266,6 +4314,7 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_query($this->dblink,$q); return mysqli_query($this->dblink,$q);
} }
// no need to cache this method
function getVillageByName($name) { function getVillageByName($name) {
list($name) = $this->escape_input($name); list($name) = $this->escape_input($name);
@@ -4573,6 +4622,7 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_insert_id($this->dblink); return mysqli_insert_id($this->dblink);
} }
// no need to cache this method
function getA2b($ckey, $check) { function getA2b($ckey, $check) {
list($ckey, $check) = $this->escape_input($ckey, $check); list($ckey, $check) = $this->escape_input($ckey, $check);
@@ -4842,12 +4892,20 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_query($this->dblink,$q); return mysqli_query($this->dblink,$q);
} }
function getABTech($vid) { function getABTech($vid, $use_cache = true) {
list($vid) = $this->escape_input((int) $vid); list($vid) = $this->escape_input((int) $vid);
// first of all, check if we should be using cache and whether the field
// required is already cached
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$abTechCache, $vid)) && !is_null($cachedValue)) {
return $cachedValue;
}
$q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid"; $q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid";
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
return mysqli_fetch_assoc($result);
self::$abTechCache[$vid] = mysqli_fetch_assoc($result);
return self::$abTechCache[$vid];
} }
function addResearch($vid, $tech, $time) { function addResearch($vid, $tech, $time) {
@@ -6304,6 +6362,9 @@ References:
*****************************************/ *****************************************/
function setvacmode($uid,$days) { function setvacmode($uid,$days) {
// TODO: refactor vacation mode
return;
list($uid,$days) = $this->escape_input((int) $uid,(int) $days); list($uid,$days) = $this->escape_input((int) $uid,(int) $days);
$days1 =60*60*24*$days; $days1 =60*60*24*$days;
$time =time()+$days1; $time =time()+$days1;
@@ -6312,12 +6373,18 @@ References:
} }
function removevacationmode($uid) { function removevacationmode($uid) {
// TODO: refactor vacation mode
return;
list($uid) = $this->escape_input((int) $uid); list($uid) = $this->escape_input((int) $uid);
$q ="UPDATE ".TB_PREFIX."users SET vac_mode = '0' , vac_time='0' WHERE id=".$uid.""; $q ="UPDATE ".TB_PREFIX."users SET vac_mode = '0' , vac_time='0' WHERE id=".$uid."";
$result =mysqli_query($this->dblink,$q); $result =mysqli_query($this->dblink,$q);
} }
function getvacmodexy($wref) { function getvacmodexy($wref) {
// TODO: refactor vacation mode
return;
list($wref) = $this->escape_input((int) $wref); list($wref) = $this->escape_input((int) $wref);
$q = "SELECT id,oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref"; $q = "SELECT id,oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
+91 -53
View File
@@ -21,6 +21,10 @@ class Units {
public function procUnits($post) { public function procUnits($post) {
if(isset($post['c'])) { if(isset($post['c'])) {
if (!isset($post['disabled'])) {
$post['disabled'] = '';
}
switch($post['c']) { switch($post['c']) {
case "1": case "1":
@@ -33,7 +37,7 @@ class Units {
break; break;
case "2": case "2":
if (isset($post['a'])&& $post['a']==533374 && $post['disabledr'] == ""){ if (isset($post['a'])&& $post['a']==533374 && $post['disabled'] == ""){
$this->sendTroops($post); $this->sendTroops($post);
}else{ }else{
$post = $this->loadUnits($post); $post = $this->loadUnits($post);
@@ -283,10 +287,7 @@ class Units {
} }
} }
if( intval($enforce['hero']) > 0){ if( intval($enforce['hero']) > 0){
$q = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $from['owner']." AND dead = 0"; $hero_unit = $database->getHeroField($from['owner'], 'unit')['unit'];
$result = mysqli_query($GLOBALS['link'],$q);
$hero_f=mysqli_fetch_array($result);
$hero_unit=$hero_f['unit'];
$speeds[] = $GLOBALS['u'.$hero_unit]['speed']; $speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
}else{ }else{
$enforce['hero']='0'; $enforce['hero']='0';
@@ -326,65 +327,93 @@ class Units {
global $form, $database, $village, $generator, $session; global $form, $database, $village, $generator, $session;
$data = $database->getA2b( $post['timestamp_checksum'], $post['timestamp'] ); $data = $database->getA2b( $post['timestamp_checksum'], $post['timestamp'] );
$Gtribe = ""; $Gtribe = "";
if ($session->tribe == '2'){ $Gtribe = "1"; } else if ($session->tribe == '3'){ $Gtribe = "2"; }else if ($session->tribe == '4'){ $Gtribe = "3"; }else if ($session->tribe == '5'){ $Gtribe = "4"; }
if ( $session->tribe == '2' ) {
$Gtribe = "1";
} else if ( $session->tribe == '3' ) {
$Gtribe = "2";
} else if ( $session->tribe == '4' ) {
$Gtribe = "3";
} else if ( $session->tribe == '5' ) {
$Gtribe = "4";
}
for ( $i = 1; $i < 10; $i ++ ) { for ( $i = 1; $i < 10; $i ++ ) {
if ( isset( $data[ 'u' . $i ] ) ) { if ( isset( $data[ 'u' . $i ] ) ) {
if ($data['u'.$i] > $village->unitarray['u'.$Gtribe.$i]) if ( $data[ 'u' . $i ] > $village->unitarray[ 'u' . $Gtribe . $i ] ) {
{
$form->addError( "error", "You can't send more units than you have" ); $form->addError( "error", "You can't send more units than you have" );
break; break;
} }
if($data['u'.$i]<0) if ( $data[ 'u' . $i ] < 0 ) {
{
$form->addError( "error", "You can't send negative units." ); $form->addError( "error", "You can't send negative units." );
break; break;
} }
} }
} }
if ($data['u11'] > $village->unitarray['hero'])
{ if ( $data['u11'] > $village->unitarray['hero'] ) {
$form->addError( "error", "You can't send more units than you have" ); $form->addError( "error", "You can't send more units than you have" );
} }
if($data['u11']<0) if ( $data['u11'] < 0 ) {
{
$form->addError( "error", "You can't send negative units." ); $form->addError( "error", "You can't send negative units." );
} }
if ( $form->returnErrors() > 0 ) { if ( $form->returnErrors() > 0 ) {
$_SESSION['errorarray'] = $form->getErrors(); $_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $_POST; $_SESSION['valuearray'] = $_POST;
header( "Location: a2b.php" ); header( "Location: a2b.php" );
exit; exit;
} else { } else {
if ( $session->access != BANNED ) { if ( $session->access != BANNED ) {
if ( $session->tribe == 1 ) {
if($session->tribe == 1){ $u = ""; } elseif($session->tribe == 2){ $u = "1"; } elseif($session->tribe == 3){ $u = "2"; }elseif($session->tribe == 4){ $u = "3"; }else {$u = "4"; } $u = "";
} elseif ( $session->tribe == 2 ) {
$u = "1";
} elseif ( $session->tribe == 3 ) {
$u = "2";
} elseif ( $session->tribe == 4 ) {
$u = "3";
} else {
$u = "4";
}
$database->modifyUnit( $database->modifyUnit(
$village->wid, $village->wid,
array($u."1",$u."2",$u."3",$u."4",$u."5",$u."6",$u."7",$u."8",$u."9",$u.$session->tribe."0","hero"), array(
array($data['u1'],$data['u2'],$data['u3'],$data['u4'],$data['u5'],$data['u6'],$data['u7'],$data['u8'],$data['u9'],$data['u10'],$data['u11']), $u . "1",
$u . "2",
$u . "3",
$u . "4",
$u . "5",
$u . "6",
$u . "7",
$u . "8",
$u . "9",
$u . $session->tribe . "0",
"hero"
),
array(
$data['u1'],
$data['u2'],
$data['u3'],
$data['u4'],
$data['u5'],
$data['u6'],
$data['u7'],
$data['u8'],
$data['u9'],
$data['u10'],
$data['u11']
),
array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
); );
$query1 = mysqli_query($GLOBALS['link'],'SELECT owner FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = ' . mysqli_escape_string($GLOBALS['link'],(int) $data['to_vid'])); $data21 = $database->getUserField( $database->getVrefField( $village->wid, 'owner' )['owner'], 'tribe', 0 );
$data1 = mysqli_fetch_assoc($query1);
$query11 = mysqli_query($GLOBALS['link'],'SELECT owner FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = ' . mysqli_escape_string($GLOBALS['link'],(int) $village->wid));
$data11 = mysqli_fetch_assoc($query11);
$query21 = mysqli_query($GLOBALS['link'],'SELECT tribe FROM `' . TB_PREFIX . 'users` WHERE `id` = ' . (int) $data11['owner']);
$data21 = mysqli_fetch_assoc($query21);
$eigen = $database->getCoor( $village->wid ); $eigen = $database->getCoor( $village->wid );
$from = array( 'x' => $eigen['x'], 'y' => $eigen['y'] ); $from = array( 'x' => $eigen['x'], 'y' => $eigen['y'] );
$ander = $database->getCoor( $data['to_vid'] ); $ander = $database->getCoor( $data['to_vid'] );
@@ -399,7 +428,9 @@ if($session->access != BANNED){
for ( $i = 1; $i <= 10; $i ++ ) { for ( $i = 1; $i <= 10; $i ++ ) {
if ( isset( $data[ 'u' . $i ] ) ) { if ( isset( $data[ 'u' . $i ] ) ) {
if ( $data[ 'u' . $i ] != '' && $data[ 'u' . $i ] > 0 ) { if ( $data[ 'u' . $i ] != '' && $data[ 'u' . $i ] > 0 ) {
if($unitarray) { reset($unitarray); } if ( $unitarray ) {
reset( $unitarray );
}
$unitarray = $GLOBALS[ "u" . ( ( $session->tribe - 1 ) * 10 + $i ) ]; $unitarray = $GLOBALS[ "u" . ( ( $session->tribe - 1 ) * 10 + $i ) ];
$speeds[] = $unitarray['speed']; $speeds[] = $unitarray['speed'];
} }
@@ -443,8 +474,7 @@ if($session->access != BANNED){
// Fixed by Advocaite and Shadow // Fixed by Advocaite and Shadow
$q = mysqli_fetch_array( mysqli_query( $GLOBALS['link'], "SELECT Count(*) as Total FROM " . TB_PREFIX . "fdata WHERE f99t = '40' AND vref = " . (int) $data['to_vid'] ), MYSQLI_ASSOC ); $q = mysqli_fetch_array( mysqli_query( $GLOBALS['link'], "SELECT Count(*) as Total FROM " . TB_PREFIX . "fdata WHERE f99t = '40' AND vref = " . (int) $data['to_vid'] ), MYSQLI_ASSOC );
$isThere = $q['Total']; $isThere = $q['Total'];
if($isThere > 0) if ( $isThere > 0 ) {
{
$iswwvilla = 1; $iswwvilla = 1;
$artefact_2 = count( $database->getOwnUniqueArtefactInfo2( $to_owner, 7, 3, 0 ) ); $artefact_2 = count( $database->getOwnUniqueArtefactInfo2( $to_owner, 7, 3, 0 ) );
$artefact1_2 = count( $database->getOwnUniqueArtefactInfo2( $data['to_vid'], 7, 1, 1 ) ); $artefact1_2 = count( $database->getOwnUniqueArtefactInfo2( $data['to_vid'], 7, 1, 1 ) );
@@ -498,7 +528,8 @@ if($session->access != BANNED){
$post['ctar2'] = $post['ctar2']; $post['ctar2'] = $post['ctar2'];
} }
} else { } else {
$post['ctar2'] = 0;} $post['ctar2'] = 0;
}
if ( isset( $post['spy'] ) ) { if ( isset( $post['spy'] ) ) {
$post['spy'] = $post['spy']; $post['spy'] = $post['spy'];
} else { } else {
@@ -528,7 +559,8 @@ if($session->access != BANNED){
header( "Location: banned.php" ); header( "Location: banned.php" );
exit; exit;
} }
}} }
}
private function sendTroopsBack($post) { private function sendTroopsBack($post) {
global $form, $database, $village, $generator, $session, $technology; global $form, $database, $village, $generator, $session, $technology;
@@ -538,19 +570,25 @@ if($session->access != BANNED){
if ( ( $enforce['from'] == $village->wid ) || ( $enforce['vref'] == $village->wid ) || ( $enforceoasis['conqured'] == $village->wid ) ) { if ( ( $enforce['from'] == $village->wid ) || ( $enforce['vref'] == $village->wid ) || ( $enforceoasis['conqured'] == $village->wid ) ) {
$to = $database->getVillage( $enforce['from'] ); $to = $database->getVillage( $enforce['from'] );
$Gtribe = ""; $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"; } 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";
}
for ( $i = 1; $i < 10; $i ++ ) { for ( $i = 1; $i < 10; $i ++ ) {
if ( isset( $post[ 't' . $i ] ) ) { if ( isset( $post[ 't' . $i ] ) ) {
if ( $i != 10 ) { if ( $i != 10 ) {
if ($post['t'.$i] > $enforce['u'.$Gtribe.$i]) if ( $post[ 't' . $i ] > $enforce[ 'u' . $Gtribe . $i ] ) {
{
$form->addError( "error", "You can't send more units than you have" ); $form->addError( "error", "You can't send more units than you have" );
break; break;
} }
if($post['t'.$i]<0) if ( $post[ 't' . $i ] < 0 ) {
{
$form->addError( "error", "You can't send negative units." ); $form->addError( "error", "You can't send negative units." );
break; break;
} }
@@ -560,13 +598,11 @@ if($session->access != BANNED){
} }
} }
if ( isset( $post['t11'] ) ) { if ( isset( $post['t11'] ) ) {
if ($post['t11'] > $enforce['hero']) if ( $post['t11'] > $enforce['hero'] ) {
{
$form->addError( "error", "You can't send more units than you have" ); $form->addError( "error", "You can't send more units than you have" );
} }
if($post['t11']<0) if ( $post['t11'] < 0 ) {
{
$form->addError( "error", "You can't send negative units." ); $form->addError( "error", "You can't send negative units." );
} }
} else { } else {
@@ -586,9 +622,11 @@ if($session->access != BANNED){
$j = '1'; $j = '1';
for ( $i = $start; $i <= $end; $i ++ ) { for ( $i = $start; $i <= $end; $i ++ ) {
$database->modifyEnforce($post['ckey'],$i,$post['t'.$j.''],0); $j++; $database->modifyEnforce( $post['ckey'], $i, $post[ 't' . $j . '' ], 0 );
$j ++;
} }
$database->modifyEnforce($post['ckey'],'hero',$post['t11'],0); $j++; $database->modifyEnforce( $post['ckey'], 'hero', $post['t11'], 0 );
$j ++;
//get cord //get cord
$from = $database->getVillage( $enforce['from'] ); $from = $database->getVillage( $enforce['from'] );
$fromcoor = $database->getCoor( $enforce['from'] ); $fromcoor = $database->getCoor( $enforce['from'] );
@@ -602,7 +640,9 @@ if($session->access != BANNED){
for ( $i = 1; $i <= 10; $i ++ ) { for ( $i = 1; $i <= 10; $i ++ ) {
if ( isset( $post[ 't' . $i ] ) ) { if ( isset( $post[ 't' . $i ] ) ) {
if ( $post[ 't' . $i ] != '' && $post[ 't' . $i ] > 0 ) { if ( $post[ 't' . $i ] != '' && $post[ 't' . $i ] > 0 ) {
if($unitarray) { reset($unitarray); } if ( $unitarray ) {
reset( $unitarray );
}
$unitarray = $GLOBALS[ "u" . ( ( $session->tribe - 1 ) * 10 + $i ) ]; $unitarray = $GLOBALS[ "u" . ( ( $session->tribe - 1 ) * 10 + $i ) ];
$speeds[] = $unitarray['speed']; $speeds[] = $unitarray['speed'];
} else { } else {
@@ -614,10 +654,7 @@ if($session->access != BANNED){
} }
if ( isset( $post['t11'] ) ) { if ( isset( $post['t11'] ) ) {
if ( $post['t11'] != '' && $post['t11'] > 0 ) { if ( $post['t11'] != '' && $post['t11'] > 0 ) {
$qh = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $from['owner']." AND dead = 0"; $hero_unit = $database->getHeroField($from['owner'], 'unit')['unit'];
$resulth = mysqli_query($GLOBALS['link'],$qh);
$hero_f=mysqli_fetch_array($resulth);
$hero_unit=$hero_f['unit'];
$speeds[] = $GLOBALS[ 'u' . $hero_unit ]['speed']; $speeds[] = $GLOBALS[ 'u' . $hero_unit ]['speed'];
} else { } else {
$post['t11'] = '0'; $post['t11'] = '0';
@@ -674,6 +711,7 @@ exit;
public function Settlers($post) { public function Settlers($post) {
global $form, $database, $village, $session; global $form, $database, $village, $session;
if ( $session->access != BANNED ) { if ( $session->access != BANNED ) {
$mode = CP; $mode = CP;
$total = count( $database->getProfileVillages( $session->uid ) ); $total = count( $database->getProfileVillages( $session->uid ) );