Distance calculation optimization and bug fixing

-Removed a lot of redundant code and put into a function
+Fixed a bug that permitted to found a new village in already founded
village
+Fixed a bug that permitted to found in an oasis
+Fixed a bug that permitted to hack the time you need to found a new
village
+Fixed a bug that permitted to found a new village to an inexistent one
This commit is contained in:
iopietro
2018-04-29 00:49:24 +02:00
parent 48410e960b
commit a40accc101
11 changed files with 201 additions and 454 deletions
+2 -29
View File
@@ -283,35 +283,8 @@ $end = $tribe * 10;
<?php
$speeds = [];
$scout = 1;
//find slowest unit.
for($i = 1; $i <= 11; $i++)
{
if (isset($process['t'.$i]))
{
if(!empty($process['t'.$i]) && $process['t'.$i] > 0)
{
if ($i < 11) $speeds[] = ${'u'.(($session->tribe-1) * 10 + $i)}['speed'];
else
{
$hero_unit = $database->getHeroField($uid, 'unit');
$speeds[] = ${'u'.$hero_unit}['speed'];
}
if($i != 4) $scout = 0;
}
}
}
if($scout) $process['c'] = 1;
$ownVillage = $database->getCoor($village->wid);
$from = ['x' => $ownVillage['x'], 'y' => $ownVillage['y']];
$to = ['x' => $coor['x'], 'y' => $coor['y']];
$troopsTime = $generator->procDistanceTime($from, $to, min($speeds), 1);
<?php
$troopsTime = $units->getWalkingTroopsTime($village->wid, $process[0], $session->uid, $session->tribe, $process, 1, 't');
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
+12 -19
View File
@@ -1,25 +1,19 @@
<?php
//-- Prevent user from founding a new village if there are not enough settlers or the player put an invalid village ID or an already occupied one
//-- fix by AL-Kateb - Semplified and additions by iopietro
if(($settlers = $village->unitarray['u'.$session->tribe.'0']) < 3 || !isset($_GET['id']) || ($newvillage = $database->getMInfo($_GET['id']))['id'] == 0 || $newvillage['occupied'] > 0 || $newvillage['oasistype'] > 0){
header("location: dorf1.php");
exit;
}
//--
$wood = round($village->awood);
$clay = round($village->aclay);
$iron = round($village->airon);
$crop = round($village->acrop);
$founder = $database->getVillage($village->wid);
$newvillage = $database->getMInfo($_GET['id']);
$eigen = $database->getCoor($village->wid);
$from = array('x'=>$eigen['x'], 'y'=>$eigen['y']);
$to = array('x'=>$newvillage['x'], 'y'=>$newvillage['y']);
$troopsTime = $generator->procDistanceTime($from, $to, 300, 0);
$troopsTime = $units->getWalkingTroopsTime($village->wid, $newvillage['id'], 0, 0, [300], 0);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
//-- Prevent user from founding a new village if there are not enough settlers
//-- fix by AL-Kateb - Semplified by iopietro
if($village->unitarray['u'.$session->tribe.'0'] < 3){
header("location: dorf1.php");
exit;
}
//--
echo '<pre>';
echo '</pre>';
?>
@@ -29,23 +23,22 @@ echo '</pre>';
<input type="hidden" name="c" value="5" />
<input type="hidden" name="s" value="<?php echo $_GET['id']; ?>" />
<input type="hidden" name="id" value="39" />
<input type="hidden" name="timestamp" value="<?php echo $time; ?>" />
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<td class="role"><a href="karte.php?d=<?php echo (isset($founder['0']) ? $founder['0'] : ''); ?>&c=<?php echo $generator->getMapCheck((isset($founder['0']) ? $founder['0'] : '')); ?>"><?php echo $session->username; ?></a></td><td colspan="10"><a href="karte.php?d=<?php echo $newvillage['id']; ?>&c=<?php echo $generator->getMapCheck($newvillage['0']) ?>">Found new village (<?php echo $newvillage['x']; ?>|<?php echo $newvillage['y']; ?>)</a></td>
<td class="role"><a href="spieler.php?uid=<?php echo $session->uid; ?>"><?php echo $session->username; ?></a></td><td colspan="10"><a href="karte.php?d=<?php echo $newvillage['id']; ?>&c=<?php echo $generator->getMapCheck($newvillage[0]) ?>">Found new village (<?php echo $newvillage['x']; ?>|<?php echo $newvillage['y']; ?>)</a></td>
</tr>
</thead>
<tbody class="units">
<tr>
<th>&nbsp;</th>
<?php for($i=($session->tribe-1)*10+1;$i<=$session->tribe*10;$i++) {
<?php for($i = ($session->tribe-1) * 10 + 1; $i <= $session->tribe * 10; $i++) {
echo "<td><img src=\"img/x.gif\" class=\"unit u".$i."\" title=\"".$technology->getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" /></td>";
} ?>
</tr>
<tr>
<th>Troops</th>
<?php for($i=1;$i<=9;$i++) {
<?php for($i = 1;$i <= 9; $i++) {
echo "<td class=\"none\">0</td>";
}
@@ -76,7 +69,7 @@ echo '</pre>';
</table>
<p class="btn">
<?php
if ($wood>749 && $clay>749 && $iron>749 && $crop>749) {
if ($wood >= 750 && $clay >= 750 && $iron >= 750 && $crop >= 750) {
?>
<input type="image" value="ok" name="s1" id="btn_ok" class="dynamic_img" alt="OK" src="img/x.gif" onclick="this.disabled=true;this.form.submit();"/>
<?php
+1 -25
View File
@@ -3,9 +3,6 @@ $to = $database->getVillage($enforce['from']);
$fromcoor = $database->getCoor($enforce['from']);
$tocoor = $database->getCoor($enforce['vref']);
$fromCor = ['x'=>$tocoor['x'], 'y'=>$tocoor['y']];
$toCor = ['x'=>$fromcoor['x'], 'y'=>$fromcoor['y']];
$att_tribe = $database->getUserField($to['owner'],'tribe',0);
$start = ($att_tribe - 1) * 10 + 1;
$end = $att_tribe * 10;
@@ -124,28 +121,7 @@ $end = $att_tribe * 10;
<th>Arrived:</th>
<?php
$speeds = [];
//find slowest unit.
for($i = $start; $i <= $end; $i++)
{
if (isset($enforce['u'.$i]))
{
if(!empty($enforce['u'.$i]) && $enforce['u'.$i] > 0)
{
$speeds[] = ${'u'.$i}['speed'];
}
}
}
if ($enforce['hero']>0){
$qh = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $to['owner']." AND dead = 0";
$resulth = mysqli_query($database->dblink,$qh);
$hero_f=mysqli_fetch_array($resulth);
$hero_unit=$hero_f['unit'];
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
}
$troopsTime = $generator->procDistanceTime($fromCor, $toCor, min($speeds), 1);
$troopsTime = $units->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $att_tribe, $enforce, 1);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
+3 -28
View File
@@ -60,33 +60,8 @@
$id = $database->addA2b( $ckey, $time_now, $wref, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, 4 );
$data = $database->getA2b( $ckey, $time_now );
$eigen = $database->getCoor( $getFLData['wref'] );
$from = array( 'x' => $eigen['x'], 'y' => $eigen['y'] );
$ander = $database->getCoor( $data['to_vid'] );
$to = array( 'x' => $ander['x'], 'y' => $ander['y'] );
$start = ( $tribe - 1 ) * 10 + 1;
$end = ( $tribe * 10 );
$speeds = array();
$scout = 1;
//find slowest unit.
for ( $i = 1; $i <= 10; $i ++ ) {
if ( $data[ 'u' . $i ] ) {
if ( $data[ 'u' . $i ] != '' && $data[ 'u' . $i ] > 0 ) {
if ( $unitarray ) {
reset( $unitarray );
}
$unitarray = $GLOBALS[ "u" . ( ( $tribe - 1 ) * 10 + $i ) ];
$speeds[] = $unitarray['speed'];
}
}
}
$troopsTime = $generator->procDistanceTime($from, $to, min($speeds), 1);
$troopsTime = $units->getWalkingTroopsTime($getFLData['wref'], $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
$time = $database->getArtifactsValueInfluence($getFLData['owner'], $getFLData['wref'], 2, $troopsTime);
$ctar1 = $ctar2 = 0;
@@ -114,8 +89,8 @@
$amounts[] = $data['u11'];
$modes[] = 0;
$database->modifyUnit( $getFLData['wref'], $units, $amounts, $modes );
$database->addMovement( 3, $getFLData['wref'], $data['to_vid'], $reference, time(), ( $time + time() ) );
$database->modifyUnit($getFLData['wref'], $units, $amounts, $modes);
$database->addMovement(3, $getFLData['wref'], $data['to_vid'], $reference, time(), ($time + time()));
// prevent re-use of the same attack via re-POSTing the same data
$database->remA2b( $id );