mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-11 23:26:08 +00:00
Fixed a lot of bugs/security issues in the market
+Fixed a bug that permitted to send resourcers to himself +Fixed a bug that permitted to send resources to invalid villages +Fixed a bug that permitted to create offerings with 0 resources or invalid resources type +Fixed a bug that permitted to accept offerings of other allies +Fixed a bug that permitted to accept offerings with a too high maxtime +Fixed a bug that permitted to accept offering from the same village +Fixed a bug that permitted to accept offering with too few merchants +Fixed a bug that permitted to accept offerings without the requested resources +Fixed a bug that hid offerings with a valid maxtime +Fixed some bugs relative to errors diplaying +Added some error +Some clean-up
This commit is contained in:
+65
-40
@@ -36,27 +36,26 @@ class Market
|
||||
|
||||
public function procRemove($get)
|
||||
{
|
||||
global $database,$village,$session;
|
||||
global $database, $village, $session;
|
||||
|
||||
if(isset($get['t']) && $get['t'] == 1)
|
||||
{
|
||||
$this->filterNeed($get);
|
||||
}
|
||||
else if(isset($get['t']) && $get['t'] ==2 && isset($get['a']) && $get['a'] == 5 && isset($get['del']))
|
||||
else if(isset($get['t']) && $get['t'] == 2 && isset($get['a']) && $get['a'] == 5 && isset($get['del']))
|
||||
{
|
||||
//GET ALL FIELDS FROM MARKET
|
||||
$type = $database->getMarketField($village->wid,"gtype");
|
||||
$amt = $database->getMarketField($village->wid,"gamt");
|
||||
$vref = $village->wid;
|
||||
$database->getResourcesBack($vref,$type,$amt);
|
||||
$database->addMarket($village->wid,$get['del'],0,0,0,0,0,0,1);
|
||||
$type = $database->getMarketField($village->wid, "gtype");
|
||||
$amt = $database->getMarketField($village->wid, "gamt");
|
||||
$database->getResourcesBack($village->wid, $type, $amt);
|
||||
$database->addMarket($village->wid, $get['del'], 0, 0, 0, 0, 0, 0, 1);
|
||||
header("Location: build.php?id=".$get['id']."&t=2");
|
||||
exit;
|
||||
}
|
||||
if(isset($get['t']) && $get['t'] == 1 && isset($get['a']) && $get['a'] == $session->mchecker && !isset($get['del']))
|
||||
{
|
||||
$session->changeChecker();
|
||||
$this->acceptOffer($get);
|
||||
$this->acceptOffer($get);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +84,12 @@ class Market
|
||||
|
||||
private function sendResource($post)
|
||||
{
|
||||
global $database,$village,$session,$generator,$logging,$form;
|
||||
global $database, $village, $session, $generator, $logging, $form;
|
||||
|
||||
$wtrans = (isset($post['r1']) && $post['r1'] != "")? $post['r1'] : 0;
|
||||
$ctrans = (isset($post['r2']) && $post['r2'] != "")? $post['r2'] : 0;
|
||||
$itrans = (isset($post['r3']) && $post['r3'] != "")? $post['r3'] : 0;
|
||||
$crtrans = (isset($post['r4']) && $post['r4'] != "")? $post['r4'] : 0;
|
||||
$wtrans = (isset($post['r1']) && !empty($post['r1']))? $post['r1'] : 0;
|
||||
$ctrans = (isset($post['r2']) && !empty($post['r2']))? $post['r2'] : 0;
|
||||
$itrans = (isset($post['r3']) && !empty($post['r3']))? $post['r3'] : 0;
|
||||
$crtrans = (isset($post['r4']) && !empty($post['r4']))? $post['r4'] : 0;
|
||||
$wtrans = str_replace("-", "", $wtrans);
|
||||
$ctrans = str_replace("-", "", $ctrans);
|
||||
$itrans = str_replace("-", "", $itrans);
|
||||
@@ -103,20 +102,22 @@ class Market
|
||||
$availableIron = $database->getIronAvailable($village->wid);
|
||||
$availableCrop = $database->getCropAvailable($village->wid);
|
||||
//check if vacation mode:
|
||||
if($database->getvacmodexy($id)){
|
||||
$form->addError("error","User is on vacation mode");
|
||||
}
|
||||
if($database->getvacmodexy($id)) $form->addError("error", USER_ON_VACATION);
|
||||
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
else if($availableWood >= $post['r1'] AND $availableClay >= $post['r2'] AND $availableIron >= $post['r3'] AND $availableCrop >= $post['r4'])
|
||||
elseif(!$database->checkVilExist($getwref)) $form->addError("error", NO_COORDINATES_SELECTED);
|
||||
elseif($post['getwref'] == $village->wid) $form->addError("error", CANNOT_SEND_RESOURCES);
|
||||
elseif($post['send3'] < 1 || $post['send3'] > 3 || ($post['send3'] > 1 && !$session->goldclub)) $form->addError("error", INVALID_MERCHANTS_REPETITION);
|
||||
elseif($availableWood >= $post['r1'] && $availableClay >= $post['r2'] && $availableIron >= $post['r3'] && $availableCrop >= $post['r4'])
|
||||
{
|
||||
$resource = array($wtrans,$ctrans,$itrans,$crtrans);
|
||||
$reqMerc = ceil((array_sum($resource)-0.1)/$this->maxcarry);
|
||||
|
||||
if($this->merchantAvail() != 0 && $reqMerc <= $this->merchantAvail())
|
||||
if($this->merchantAvail() > 0 && $reqMerc <= $this->merchantAvail())
|
||||
{
|
||||
$id = $post['getwref'];
|
||||
$coor = $database->getCoor($id);
|
||||
@@ -132,15 +133,12 @@ class Market
|
||||
$logging->addMarketLog($village->wid,1,array($resource[0],$resource[1],$resource[2],$resource[3],$id));
|
||||
}
|
||||
}
|
||||
header("Location: build.php?id=".$post['id']);
|
||||
exit;
|
||||
}
|
||||
header("Location: build.php?id=".$post['id']);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: WTF??? :D
|
||||
// something
|
||||
else $form->addError("error", TOO_FEW_MERCHANTS);
|
||||
}
|
||||
else $form->addError("error","You cannot send more resources than you have");
|
||||
}
|
||||
|
||||
private function addOffer($post)
|
||||
@@ -154,6 +152,12 @@ class Market
|
||||
header("Location: build.php?id=".$post['id']."&t=2&e2");
|
||||
exit;
|
||||
}
|
||||
elseif(!isset($post['m1']) || !isset($post['m2']) || $post['m1'] <= 0 || $post['m2'] <= 0)
|
||||
{
|
||||
// No resources selected (invalid)
|
||||
header("Location: build.php?id=".$post['id']."&t=2&e2");
|
||||
exit;
|
||||
}
|
||||
elseif($post['m1'] > (2 * $post['m2']))
|
||||
{
|
||||
// Trade is for more than 2x (invalid)
|
||||
@@ -166,6 +170,12 @@ class Market
|
||||
header("Location: build.php?id=".$post['id']."&t=2&e2");
|
||||
exit;
|
||||
}
|
||||
elseif($post['rid1'] < 1 || $post['rid1'] > 4 || $post['rid2'] < 1 || $post['rid2'] > 4)
|
||||
{
|
||||
// Inexistent resources type (invalid)
|
||||
header("Location: build.php?id=".$post['id']."&t=2&e2");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$wood = ($post['rid1'] == 1)? $post['m1'] : 0;
|
||||
@@ -187,7 +197,7 @@ class Market
|
||||
exit;
|
||||
}
|
||||
|
||||
elseif($availableWood >= $wood AND $availableClay >= $clay AND $availableIron >= $iron AND $availableCrop >= $crop)
|
||||
elseif($availableWood >= $wood && $availableClay >= $clay && $availableIron >= $iron && $availableCrop >= $crop)
|
||||
{
|
||||
$reqMerc = 1;
|
||||
|
||||
@@ -195,20 +205,14 @@ class Market
|
||||
{
|
||||
$reqMerc = round(($wood+$clay+$iron+$crop)/$this->maxcarry);
|
||||
|
||||
if(($wood+$clay+$iron+$crop) > $this->maxcarry*$reqMerc)
|
||||
{
|
||||
$reqMerc += 1;
|
||||
}
|
||||
if(($wood+$clay+$iron+$crop) > $this->maxcarry*$reqMerc) $reqMerc += 1;
|
||||
}
|
||||
if($this->merchantAvail() != 0 && $reqMerc <= $this->merchantAvail())
|
||||
if($this->merchantAvail() > 0 && $reqMerc <= $this->merchantAvail())
|
||||
{
|
||||
if($database->modifyResource($village->wid,$wood,$clay,$iron,$crop,0))
|
||||
{
|
||||
$time = 0;
|
||||
if(isset($_POST['d1']))
|
||||
{
|
||||
$time = $_POST['d2'] * 3600;
|
||||
}
|
||||
if(isset($_POST['d1'])) $time = $_POST['d2'] * 3600;
|
||||
$alliance = (isset($post['ally']) && $post['ally'] == 1)? $session->userinfo['alliance'] : 0;
|
||||
$database->addMarket($village->wid,$post['rid1'],$post['m1'],$post['rid2'],$post['m2'],$time,$alliance,$reqMerc,0);
|
||||
}
|
||||
@@ -246,6 +250,27 @@ class Market
|
||||
$reqMerc += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We don't have enough resources
|
||||
if($infoarray['wamt'] > ([$village->awood, $village->aclay, $village->airon, $village->acrop])[$infoarray['wtype']])
|
||||
{
|
||||
header("Location: build.php?id=".$get['id']."&t=1&e1");
|
||||
exit;
|
||||
} // We're accepting the offering from the same village/of another alliance/with a too high maxtime
|
||||
elseif
|
||||
(($infoarray['vref'] == $village->wid) ||
|
||||
($infoarray['alliance'] > 0 && $infoarray['alliance'] != $session->alliance) ||
|
||||
($infoarray['maxtime'] > 0 && ($infoarray['maxtime'] * 3600) < $generator->procDistanceTime($database->getCoor($infoarray['vref']), $village->coor, $session->tribe, 0)))
|
||||
{
|
||||
header("Location: build.php?id=".$get['id']."&t=1&e2");
|
||||
exit;
|
||||
} // We don't have enough merchants
|
||||
elseif($reqMerc > $this->merchantAvail()){
|
||||
header("Location: build.php?id=".$get['id']."&t=1&e3");
|
||||
exit;
|
||||
}
|
||||
|
||||
$myresource = $hisresource = array(1=>0,0,0,0);
|
||||
$myresource[$infoarray['wtype']] = $infoarray['wamt'];
|
||||
$mysendid = $database->sendResource($myresource[1],$myresource[2],$myresource[3],$myresource[4],$reqMerc,0);
|
||||
@@ -266,7 +291,7 @@ class Market
|
||||
);
|
||||
$resource = array(1=>0,0,0,0);
|
||||
$resource[$infoarray['wtype']] = $infoarray['wamt'];
|
||||
$database->modifyResource($village->wid,$resource[1],$resource[2],$resource[3],$resource[4],0);
|
||||
$database->modifyResource($village->wid, $resource[1], $resource[2], $resource[3], $resource[4] , 0);
|
||||
$database->setMarketAcc($get['g']);
|
||||
$database->removeAcceptedOffer($get['g']);
|
||||
$logging->addMarketLog($village->wid,2,array($infoarray['vref'],$get['g']));
|
||||
@@ -284,7 +309,7 @@ class Market
|
||||
{
|
||||
$targetcoor = $database->getCoor($value['vref']);
|
||||
$duration = $generator->procDistanceTime($targetcoor,$village->coor,$session->tribe,0);
|
||||
if($duration <= $value['maxtime'] || $value['maxtime'] == 0)
|
||||
if($duration <= ($value['maxtime'] * 3600) || $value['maxtime'] == 0)
|
||||
{
|
||||
$value['duration'] = $duration;
|
||||
array_push($holderarray,$value);
|
||||
@@ -353,11 +378,11 @@ class Market
|
||||
global $session,$database,$village;
|
||||
|
||||
$wwvillage = $database->getResourceLevel($village->wid);
|
||||
if($wwvillage['f99t']!=40)
|
||||
if($wwvillage['f99t'] != 40)
|
||||
{
|
||||
if($session->userinfo['gold'] >= 3)
|
||||
{
|
||||
//kijken of ze niet meer gs invoeren dan ze hebben
|
||||
//check if there are too many resources
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
@@ -370,7 +395,7 @@ class Market
|
||||
["wood", "clay", "iron", "crop"],
|
||||
[$post['m2'][0], $post['m2'][1], $post['m2'][2], $post['m2'][3]]
|
||||
);
|
||||
$database->modifyGold($session->uid,3,0);
|
||||
$database->modifyGold($session->uid, 3, 0);
|
||||
header("Location: build.php?id=".$post['id']."&t=3&c");;
|
||||
exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user