• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

TravianZ - Multiple Marketplace Fixes

Status
Not open for further replies.
Junior Spellweaver
Joined
Jan 7, 2012
Messages
147
Reaction score
100
Hello all, Today I have a few marketplace fixes for you today (only for creating offers) but makes the marketplace more attractive place on your server.

  1. Trading resources of same type e.g trading 300 wood for 8000 wood - Not allowed (Fixed)
  2. Trading resources for more than 2x amount or less than 0.5x amount e.g trading 3000 wood for 1 clay, or 3000 wood for 999999 iron - Not allowed (Fixed)
  3. Some error reporting, e.g not enough merchants, not enough resources, invalid offer etc.



You need to replace 2 files:

GameEngine/Market.php

PHP:
<?php
#################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 ##
## --------------------------------------------------------------------------- ##
##  Filename       Market.php                                                  ##
##  Developed by:  Dzoki                                                       ##
##  Some fixes:    aggenkeech                                                  ##
##  License:       TravianX Project                                            ##
##  Copyright:     TravianX (c) 2010-2011. All rights reserved.                ##
##                                                                             ##
#################################################################################

class Market
{
	public $onsale,$onmarket,$sending,$recieving,$return = array();
	public $maxcarry,$merchant,$used;

	public function procMarket($post)
	{
		$this->loadMarket();
		if(isset($_SESSION['loadMarket']))
		{
			$this->loadOnsale();
			unset($_SESSION['loadMarket']);
		}
		if(isset($post['ft']))
		{
			switch($post['ft'])
			{
				case "mk1": $this->sendResource($post); break;
				case "mk2": $this->addOffer($post); break;
				case "mk3": $this->tradeResource($post); break;
			}
		}
	}

	public function procRemove($get)
	{
		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']))
		{
			//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);
			header("Location: build.php?id=".$get['id']."&t=2");
		}
		if(isset($get['t']) && $get['t'] == 1 && isset($get['a']) && $get['a'] == $session->mchecker && !isset($get['del']))
		{
			$session->changeChecker();
			$this->acceptOffer($get);
		}
	}

	public function merchantAvail()
	{
		return $this->merchant - $this->used;
	}

	private function loadMarket()
	{
		global $session,$building,$bid28,$bid17,$database,$village;
		
		$this->recieving = $database->getMovement(0,$village->wid,1);
		$this->sending = $database->getMovement(0,$village->wid,0);
		$this->return  = $database->getMovement(2,$village->wid,1);
		$this->merchant = ($building->getTypeLevel(17) > 0)? $bid17[$building->getTypeLevel(17)]['attri'] : 0;
		$this->used = $database->totalMerchantUsed($village->wid);
		$this->onmarket = $database->getMarket($village->wid,0);
		$this->maxcarry = ($session->tribe == 1)? 500 : (($session->tribe == 2)? 1000 : 750);
		$this->maxcarry *= TRADER_CAPACITY;
		if($building->getTypeLevel(28) != 0)
		{
			$this->maxcarry *= $bid28[$building->getTypeLevel(28)]['attri'] / 100;
		}
	}

	private function sendResource($post)
	{
		global $database,$village,$session,$generator,$logging;
		
		$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 = str_replace("-", "", $wtrans);
		$ctrans = str_replace("-", "", $ctrans);
		$itrans = str_replace("-", "", $itrans);
		$crtrans = str_replace("-", "", $crtrans);
		$availableWood = $database->getWoodAvailable($village->wid);
		$availableClay = $database->getClayAvailable($village->wid);
		$availableIron = $database->getIronAvailable($village->wid);
		$availableCrop = $database->getCropAvailable($village->wid);
		if($session->access == BANNED)
		{
			header("Location: banned.php");
		}
		else if($availableWood >= $post['r1'] AND $availableClay >= $post['r2'] AND $availableIron >= $post['r3'] AND $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())
			{
				$id = $post['getwref'];
				$coor = $database->getCoor($id);
				if($database->getVillageState($id))
				{
					$timetaken = $generator->procDistanceTime($coor,$village->coor,$session->tribe,0);
					$res = $resource[0]+$resource[1]+$resource[2]+$resource[3];
					if($res!=0)
					{
						$reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0);
						$database->modifyResource($village->wid,$resource[0],$resource[1],$resource[2],$resource[3],0);
						$database->addMovement(0,$village->wid,$id,$reference,time(),time()+$timetaken,$post['send3']);
						$logging->addMarketLog($village->wid,1,array($resource[0],$resource[1],$resource[2],$resource[3],$id));
					}
				}
			}
			header("Location: build.php?id=".$post['id']);
		}
		else
		{
			// something
		}
	}

	private function addOffer($post)
	{
		global $database,$village,$session;
		
		
		if($post['rid1'] == $post['rid2'])
		{
			// Trading res for res of same type (invalid)
			header("Location: build.php?id=".$post['id']."&t=2&e2");
		}
		elseif($post['m1'] > (2 * $post['m2']))
		{
			// Trade is for more than 2x (invalid)
			header("Location: build.php?id=".$post['id']."&t=2&e2");
		}
		elseif($post['m2'] > (2 * $post['m1']))
		{
			// Trade is for less than 0.5x (invalid)
			header("Location: build.php?id=".$post['id']."&t=2&e2");
		}
		else
		{
			$wood = ($post['rid1'] == 1)? $post['m1'] : 0;
			$clay = ($post['rid1'] == 2)? $post['m1'] : 0;
			$iron = ($post['rid1'] == 3)? $post['m1'] : 0;
			$crop = ($post['rid1'] == 4)? $post['m1'] : 0;
			$availableWood = $database->getWoodAvailable($village->wid);
			$availableClay = $database->getClayAvailable($village->wid);
			$availableIron = $database->getIronAvailable($village->wid);
			$availableCrop = $database->getCropAvailable($village->wid);
			
			if($session->access == BANNED)
			{
				header("Location: banned.php");
			}
			
			elseif($availableWood >= $wood AND $availableClay >= $clay AND $availableIron >= $iron AND $availableCrop >= $crop)
			{
				$reqMerc = 1;
				
				if(($wood+$clay+$iron+$crop) > $this->maxcarry)
				{
					$reqMerc = round(($wood+$clay+$iron+$crop)/$this->maxcarry);
					
					if(($wood+$clay+$iron+$crop) > $this->maxcarry*$reqMerc)
					{
						$reqMerc += 1;
					}
				}
				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;
						}
						$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);
					}
					// Enough merchants
					header("Location: build.php?id=".$post['id']."&t=2");
				}
				else
				{
					// Not enough merchants
					header("Location: build.php?id=".$post['id']."&t=2&e3");
				}
			}
			else
			{
				// not enough resources
				header("Location: build.php?id=".$post['id']."&t=2&e1");
			}
		}
	}

	private function acceptOffer($get)
	{
		global $database,$village,$session,$logging,$generator;
		
		$infoarray = $database->getMarketInfo($get['g']);
		$reqMerc = 1;
		if($infoarray['wamt'] > $this->maxcarry)
		{
			$reqMerc = round($infoarray['wamt']/$this->maxcarry);
			if($infoarray['wamt'] > $this->maxcarry*$reqMerc)
			{
				$reqMerc += 1;
			}
		}
		$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);
		$hisresource[$infoarray['gtype']] = $infoarray['gamt'];
		$hissendid = $database->sendResource($hisresource[1],$hisresource[2],$hisresource[3],$hisresource[4],$infoarray['merchant'],0);
		$hiscoor = $database->getCoor($infoarray['vref']);
		$mytime = $generator->procDistanceTime($hiscoor,$village->coor,$session->tribe,0);
		$targettribe = $database->getUserField($database->getVillageField($infoarray['vref'],"owner"),"tribe",0);
		$histime = $generator->procDistanceTime($village->coor,$hiscoor,$targettribe,0);
		$database->addMovement(0,$village->wid,$infoarray['vref'],$mysendid,time(),$mytime+time());
		$database->addMovement(0,$infoarray['vref'],$village->wid,$hissendid,time(),$histime+time());
		$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->setMarketAcc($get['g']);
		$database->removeAcceptedOffer($get['g']);
		$logging->addMarketLog($village->wid,2,array($infoarray['vref'],$get['g']));
		header("Location: build.php?id=".$get['id']);
	}

	private function loadOnsale()
	{
		global $database,$village,$session,$multisort,$generator;
		
		$displayarray = $database->getMarket($village->wid,1);
		$holderarray = array();
		foreach($displayarray as $value)
		{
			$targetcoor = $database->getCoor($value['vref']);
			$duration = $generator->procDistanceTime($targetcoor,$village->coor,$session->tribe,0);
			if($duration <= $value['maxtime'] || $value['maxtime'] == 0)
			{
				$value['duration'] = $duration;
				array_push($holderarray,$value);
			}
		}
		$this->onsale = $multisort->sorte($holderarray, "'duration'", true, 2);
	}

	private function filterNeed($get)
	{
		if(isset($get['v']) || isset($get['s']) || isset($get['b']))
		{
			$holder = $holder2 = array();
			if(isset($get['v']) && $get['v'] == "1:1")
			{
				foreach($this->onsale as $equal)
				{
					if($equal['wamt'] <= $equal['gamt'])
					{
						array_push($holder,$equal);
					}
				}
			}
			else
			{
				$holder = $this->onsale;
			}
			foreach($holder as $sale)
			{
				if(isset($get['s']) && isset($get['b']))
				{
					if($sale['gtype'] == $get['s'] && $sale['wtype'] == $get['b'])
					{
						array_push($holder2,$sale);
					}
				}
				else if(isset($get['s']) && !isset($get['b']))
				{
					if($sale['gtype'] == $get['s'])
					{
						array_push($holder2,$sale);
					}
				}
				else if(isset($get['b']) && !isset($get['s'])) 
				{
					if($sale['wtype'] == $get['b'])
					{
						array_push($holder2,$sale);
					}
				}
				else
				{
					$holder2 = $holder;
				}
			}
			$this->onsale = $holder2;
		}
		else
		{
			$this->loadOnsale();
		}
	}

	private function tradeResource($post)
	{
		global $session,$database,$village;
		
		$wwvillage = $database->getResourceLevel($village->wid);
		if($wwvillage['f99t']!=40)
		{
			if($session->userinfo['gold'] >= 3)
			{
				//kijken of ze niet meer gs invoeren dan ze hebben
				if($session->access == BANNED)
				{
					header("Location: banned.php");
				}
				else if (($post['m2'][0]+$post['m2'][1]+$post['m2'][2]+$post['m2'][3])<=(round($village->awood)+round($village->aclay)+round($village->airon)+round($village->acrop)))
				{
					$database->setVillageField($village->wid,"wood",$post['m2'][0]);
					$database->setVillageField($village->wid,"clay",$post['m2'][1]);
					$database->setVillageField($village->wid,"iron",$post['m2'][2]);
					$database->setVillageField($village->wid,"crop",$post['m2'][3]);
					$database->modifyGold($session->uid,3,0);
					header("Location: build.php?id=".$post['id']."&t=3&c");;
				}
				else
				{
					header("Location: build.php?id=".$post['id']."&t=3");
				}
			}
			else
			{
				header("Location: build.php?id=".$post['id']."&t=3");
			}
		}
	}
};

$market = new Market;
?>


Templates/Build/17_2.tpl

PHP:
<div id="build" class="gid17"><a href="#" onClick="return Popup(17,4);" class="build_logo"> 
	<img class="building g17" src="img/x.gif" alt="Marketplace" title="Marketplace" /> 
</a> 
<h1>Marketplace <span class="level">level <?php echo $village->resarray['f'.$id]; ?></span></h1> 
<p class="build_desc">At the Marketplace you can trade resources with other players. The higher its level, the more resources can be transported at the same time.</p> 
 
<?php include("17_menu.tpl"); ?>
<form method="POST" action="build.php"> 
	<input type="hidden" name="id" value="<?php echo $id; ?>" /> 
	<input type="hidden" name="ft" value="mk2" /> 
 
	<table id="sell" cellpadding="1" cellspacing="1"> 
		<tr> 
			<th>Offering</th> 
			<td class="val"><input class="text" tabindex="1" name="m1" value="" maxlength="6" /></td> 
			<td class="res"> 
				<select name="rid1" tabindex="2" class="dropdown"> 
					<option value="1" selected="selected">Lumber</option> 
					<option value="2">Clay</option> 
					<option value="3">Iron</option> 
					<option value="4">Crop</option> 
				</select> 
			</td> 
			<td class="tra"><input class="check" type="checkbox" tabindex="5" name="d1" value="1" /> max. time of transport: <input class="text" tabindex="6" name="d2" value="2" maxlength="2" /> hours</td>
		</tr> 
		<tr> 
			<th>Searching</th> 
			<td class="val"><input class="text" tabindex="3" name="m2" value="" maxlength="6" /></td> 
			<td class="res"> 
				<select name="rid2" tabindex="4" class="dropdown"> 
					<option value="1">Lumber</option> 
					<option value="2" selected="selected">Clay</option> 
					<option value="3">Iron</option> 
					<option value="4">Crop</option> 
				</select> 
			</td> 
			<td class="al">
				<?php 
					if($session->userinfo['alliance'] != 0)
					{
						echo "<input class=\"check\" type=\"checkbox\" tabindex=\"7\" name=\"ally\" value=\"1\" /> own alliance only";
					}
				?> 
			</td>
		</tr> 
	</table>

	<?php
		if(isset($_GET['e1']))
		{
			echo "<p class=\"error2\">Not enough resources</p>";
		}
		elseif(isset($_GET['e2']))
		{
			echo "<p class=\"error2\">Invalid offer</p>";
		}
		elseif(isset($_GET['e3']))
		{
			echo "<p class=\"error2\">Not enough merchants</p>";
		}
		else
		{
			echo "<p>Merchants: ".$market->merchantAvail()."/".$market->merchant."</p>";
		}
	?>
	<input type="image" tabindex="8" value="ok" name="s1" id="btn_ok" class="dynamic_img" src="img/x.gif" alt="OK" <?php //if(!$market->merchantAvail()) { echo "DISABLED"; }?>/></p>
</form>
<?php
if(count($market->onmarket) > 0)
{
	echo "<table id=\"sell_overview\" cellpadding=\"1\" cellspacing=\"1\"><thead><tr><th colspan=\"6\">Own offers</th></tr><tr><td> </td><td>Offer</td><td>Search</td><td>Merchants</td><td>Alliance</td><td>Duration</td></tr></thead><tbody>";
	foreach($market->onmarket as $offer)
	{
		if($session->access != BANNED)
		{
			echo "<tr><td class=\"abo\"><a href=\"build.php?id=$id&t=2&a=5&del=".$offer['id']."\"><img class=\"del\"src=\"img/x.gif\" alt=\"Delete\" title=\"Delete\" /></a></td>";
			echo "<td class=\"val\">";
		}
		else
		{
			echo "<tr><td class=\"abo\"><a href=\"banned.php\"><img class=\"del\"src=\"img/x.gif\" alt=\"Delete\" title=\"Delete\" /></a></td>";
			echo "<td class=\"val\">";
		}
		switch($offer['gtype'])
		{
			case 1: echo "<img src=\"img/x.gif\" class=\"r1\" alt=\"Wood\" title=\"Wood\" />"; break;
			case 2: echo "<img src=\"img/x.gif\" class=\"r2\" alt=\"Clay\" title=\"Clay\" />"; break;
			case 3: echo "<img src=\"img/x.gif\" class=\"r3\" alt=\"Iron\" title=\"Iron\" />"; break;
			case 4: echo "<img src=\"img/x.gif\" class=\"r4\" alt=\"Crop\" title=\"Crop\" />"; break;
		}
		echo $offer['gamt'];
		echo "</td><td class=\"val\">";
		switch($offer['wtype'])
		{
			case 1: echo "<img src=\"img/x.gif\" class=\"r1\" alt=\"Wood\" title=\"Wood\" />"; break;
			case 2: echo "<img src=\"img/x.gif\" class=\"r2\" alt=\"Clay\" title=\"Clay\" />"; break;
			case 3: echo "<img src=\"img/x.gif\" class=\"r3\" alt=\"Iron\" title=\"Iron\" />"; break;
			case 4: echo "<img src=\"img/x.gif\" class=\"r4\" alt=\"Crop\" title=\"Crop\" />"; break;
		}
		echo $offer['wamt'];
		echo "</td><td class=\"tra\">1</td><td class=\"al\">";
		echo ($offer['alliance'] == 0)? 'No' : 'Yes';
		echo "</td><td class=\"dur\">";
		if($offer['maxtime'] != 0)
		{
			echo $offer['maxtime']/3600;
			echo " hrs.";
		}
		else
		{
			echo "All";
		}
		echo "</td></tr>";
	}
	echo "</table>";
}
?>
</div>


Enjoy :sneaky2:
 

Attachments

You must be registered for see attachments list
Last edited:
Experienced Elementalist
Joined
Jan 15, 2009
Messages
237
Reaction score
8
nice thank you :w00t:..now market place is good as one..
 
Junior Spellweaver
Joined
Jul 22, 2012
Messages
138
Reaction score
7
I think it works, but I have this error when I click at extend/edit/delete:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
 
Junior Spellweaver
Joined
Jul 22, 2012
Messages
138
Reaction score
7
Bugs I've found:
- Everytime I click at extend | edit | delete, I get this error: (DB/SQL error)

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

- Most of the times, the 2nd and the 3rd time of sending resources it doesn't send the full amount (maybe not enough traders or a bug).

Please fix this, because it's a nice release!
 
Newbie Spellweaver
Joined
May 7, 2012
Messages
14
Reaction score
0
hello

my market not work in travian script

Templates/Build/17.tpl its not work and can not send recurece to another member
can you send me word fine files abount market i upload and fix it?
Regards
 
Status
Not open for further replies.
Back
Top