diff --git a/house.php b/house.php
index 01ebec7..4935d8a 100644
--- a/house.php
+++ b/house.php
@@ -5,11 +5,20 @@ if ($config['log_ip']) {
$house = (isset($_GET['id']) && (int)$_GET['id'] > 0) ? (int)$_GET['id'] : false;
-if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
- $house_SQL = "SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='$house';";
- $house = mysql_select_single($house_SQL);
+if ($house !== false) {
+ $house = mysql_select_single("
+ SELECT
+ `h`.`id`, `h`.`owner`, `h`.`paid`, `h`.`name`, `h`.`rent`, `h`.`town_id`,
+ `h`.`size`, `h`.`beds`, `h`.`bid`, `h`.`bid_end`, `h`.`last_bid`, `h`.`highest_bidder`,
+ `p`.`name` AS `ownername`
+ FROM `houses` AS `h`
+ LEFT JOIN `players` AS `p`
+ ON `h`.`owner` > 0
+ AND `p`.`id` = `h`.`owner`
+ WHERE `h`.`id`='{$house}';
+ ");
$minbid = $config['houseConfig']['minimumBidSQM'] * $house['size'];
- if ($house['owner'] > 0) $house['ownername'] = user_name($house['owner']);
+ if ($house['owner'] == 0) unset($house['ownername']);
if ($config['houseConfig']['shopPoints']['enabled']) {
$house['points'] = $house['size'];
@@ -28,19 +37,36 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
if ($bid_amount && $bid_char) {
$bid_char = (int)$bid_char;
$bid_amount = (int)$bid_amount;
- $player = mysql_select_single("SELECT `id`, `account_id`, `name`, `level`, `balance` FROM `players` WHERE `id`='$bid_char' LIMIT 1;");
+
+ $player = mysql_select_single("
+ SELECT `id`, `account_id`, `name`, `level`, `balance`
+ FROM `players`
+ WHERE `id`='$bid_char' LIMIT 1;
+ ");
if (user_logged_in() === true && $player['account_id'] == $session_user_id) {
// Does player have or need premium?
$premstatus = ($config['houseConfig']['requirePremium'] && $user_data['premdays'] == 0) ? false : true;
if ($premstatus) {
+
// Can player have or bid on more houses?
- $pHouseCount = mysql_select_single("SELECT COUNT('id') AS `value` FROM `houses` WHERE ((`highest_bidder`='$bid_char' AND `owner`='$bid_char') OR (`highest_bidder`='$bid_char') OR (`owner`='$bid_char')) AND `id`!='".$house['id']."' LIMIT 1;");
+ $pHouseCount = mysql_select_single("
+ SELECT COUNT('id') AS `value`
+ FROM `houses`
+ WHERE (
+ (`highest_bidder`='{$bid_char}' AND `owner`='{$bid_char}')
+ OR (`highest_bidder`='{$bid_char}')
+ OR (`owner`='{$bid_char}')
+ )
+ AND `id`!='{$house['id']}' LIMIT 1;
+ ");
+
if ($pHouseCount['value'] < $config['houseConfig']['housesPerPlayer']) {
// Is character level high enough?
if ($player['level'] >= $config['houseConfig']['levelToBuyHouse']) {
// Can player afford this bid?
if ($player['balance'] > $bid_amount) {
+
// Is bid higher than previous bid?
if ($bid_amount > $house['bid']) {
// Is bid higher than lowest bid?
@@ -55,17 +81,51 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
// Has bid already started?
if ($house['bid_end'] > 0) {
if ($house['bid_end'] > time()) {
- mysql_update("UPDATE `houses` SET `highest_bidder`='". $player['id'] ."', `bid`='$bid_amount', `last_bid`='$lastbid' WHERE `id`='". $house['id'] ."' LIMIT 1;");
- $house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='". $house['id'] ."';");
+
+ mysql_update("
+ UPDATE `houses`
+ SET
+ `highest_bidder`='{$player['id']}',
+ `bid`='{$bid_amount}',
+ `last_bid`='{$lastbid}'
+ WHERE `id`='{$house['id']}' LIMIT 1;
+ ");
+
+ $house = mysql_select_single("
+ SELECT
+ `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`,
+ `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder`
+ FROM `houses`
+ WHERE `id`='{$house['id']}';
+ ");
}
+
} else {
$lastbid = $minbid + 1;
$bidend = time() + $config['houseConfig']['auctionPeriod'];
- mysql_update("UPDATE `houses` SET `highest_bidder`='". $player['id'] ."', `bid`='$bid_amount', `last_bid`='$lastbid', `bid_end`='$bidend' WHERE `id`='". $house['id'] ."' LIMIT 1;");
- $house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='". $house['id'] ."';");
+
+ mysql_update("
+ UPDATE `houses`
+ SET
+ `highest_bidder`='{$player['id']}',
+ `bid`='{$bid_amount}',
+ `last_bid`='{$lastbid}',
+ `bid_end`='{$bidend}'
+ WHERE `id`='{$house['id']}' LIMIT 1;
+ ");
+
+ $house = mysql_select_single("
+ SELECT
+ `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`,
+ `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder`
+ FROM `houses`
+ WHERE `id`='{$house['id']}';
+ ");
+
}
echo "You have the highest bid on this house!";
} else echo "You need to place a bid that is higher or equal to {$minbid}gp.";
+
} else {
// Check if current bid is higher than last_bid
if ($bid_amount > $house['last_bid']) {
@@ -73,8 +133,21 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
// being forced to pay his full previous bid.
if ($house['highest_bidder'] != $player['id']) {
$lastbid = $bid_amount + 1;
- mysql_update("UPDATE `houses` SET `last_bid`='$lastbid' WHERE `id`='". $house['id'] ."' LIMIT 1;");
- $house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='". $house['id'] ."';");
+
+ mysql_update("
+ UPDATE `houses`
+ SET `last_bid`='$lastbid'
+ WHERE `id`='{$house['id']}' LIMIT 1;
+ ");
+
+ $house = mysql_select_single("
+ SELECT
+ `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`,
+ `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder`
+ FROM `houses`
+ WHERE `id`='{$house['id']}';
+ ");
+
echo "Unfortunately your bid was not higher than previous bidder.";
} else {
echo "You already have a higher pledge on this house.";
@@ -103,8 +176,22 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
if ($account_points >= $house['points']) {
$bid_char = (int)$bid_char;
- $player = mysql_select_single("SELECT `id`, `account_id`, `name`, `level` FROM `players` WHERE `id`='$bid_char' LIMIT 1;");
- $pHouseCount = mysql_select_single("SELECT COUNT('id') AS `value` FROM `houses` WHERE ((`highest_bidder`='$bid_char' AND `owner`='$bid_char') OR (`highest_bidder`='$bid_char') OR (`owner`='$bid_char')) AND `id`!='".$house['id']."' LIMIT 1;");
+ $player = mysql_select_single("
+ SELECT `id`, `account_id`, `name`, `level`
+ FROM `players`
+ WHERE `id`='$bid_char' LIMIT 1;
+ ");
+
+ $pHouseCount = mysql_select_single("
+ SELECT COUNT('id') AS `value`
+ FROM `houses`
+ WHERE (
+ (`highest_bidder`='$bid_char' AND `owner`='$bid_char')
+ OR (`highest_bidder`='$bid_char')
+ OR (`owner`='$bid_char')
+ )
+ AND `id`!='{$house['id']}' LIMIT 1;
+ ");
if (user_logged_in() === true
&& $player['account_id'] == $session_user_id
@@ -177,12 +264,12 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
Town:
". ($town_name ? $town_name : 'Specify town id ' . $house['town_id'] . ' name in config.php first.') ."";
+ echo "". ($town_name ? $town_name : 'Specify town id ' . $house['town_id'] . ' name in config.php first.') ."";
?>
Size:
Beds:
Owner: 0) echo "". $house['ownername'] ."";
+ if ($house['owner'] > 0) echo "{$house['ownername']}";
else echo "Available for auction.";
?>
Rent:
@@ -198,17 +285,17 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
This house don't have any bidders yet.";
else {
- $bidder = mysql_select_single("SELECT `name` FROM `players` WHERE `id`='". $house['highest_bidder'] ."' LIMIT 1;");
+ $bidder = mysql_select_single("SELECT `name` FROM `players` WHERE `id`='{$house['highest_bidder']}' LIMIT 1;");
echo "This house have bidders! If you want this house, now is your chance!";
- echo "
Active bid: ". $house['last_bid'] ."gp";
- echo "
Active bid by: ". $bidder['name'] ."";
+ echo "
Active bid: {$house['last_bid']}gp";
+ echo "
Active bid by: {$bidder['name']}";
echo "
Bid will end on: ". getClock($house['bid_end'], true);
}
if ($house['bid_end'] == 0 || $house['bid_end'] > time()) {
if (user_logged_in()) {
// Your characters, indexed by char_id
- $yourChars = mysql_select_multi("SELECT `id`, `name`, `balance` FROM `players` WHERE `account_id`='". $user_data['id'] ."';");
+ $yourChars = mysql_select_multi("SELECT `id`, `name`, `balance` FROM `players` WHERE `account_id`='{$user_data['id']}';");
if ($yourChars !== false) {
$charData = array();
foreach ($yourChars as $char) {
@@ -219,7 +306,7 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') {
diff --git a/houses.php b/houses.php
index 378945b..611f217 100644
--- a/houses.php
+++ b/houses.php
@@ -5,317 +5,150 @@ include 'layout/overall/header.php';
if ($config['log_ip'])
znote_visitor_insert_detailed_data(3);
-if (empty($_POST) === false && $config['ServerEngine'] === 'TFS_03') {
+// Fetch values
+$querystring_id = &$_GET['id'];
+$townid = ($querystring_id) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
+$towns = $config['towns'];
- /* Token used for cross site scripting security */
- if (isset($_POST['token']) && Token::isValid($_POST['token'])) {
+$order = &$_GET['order'];
+$type = &$_GET['type'];
- $townid = (int)$_POST['selected'];
- $cache = new Cache('engine/cache/houses');
- $array = array();
- if ($cache->hasExpired()) {
- $tmp = fetchAllHouses_03();
- $cache->setContent($tmp);
- $cache->save();
+// Create Search house box
+?>
+
+load();
- foreach ($tmp as $t) {
- if ($t['town'] == $townid) $array[] = $t;
- }
- $array = isset($array) ? $array : false;
+if(!in_array($type, $type_allowed))
+ $type = 'desc';
+
+// Create or fetch data from cache
+$cache = new Cache('engine/cache/houses/houses-' . $order . '-' . $type);
+$houses = array();
+
+if ($cache->hasExpired()) {
+
+ $houses = mysql_select_multi("
+ SELECT
+ `id`, `owner`, `paid`, `warnings`, `name`, `rent`, `town_id`,
+ `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder`
+ FROM `houses`
+ ORDER BY {$order} {$type};
+ ");
+
+ if ($houses !== false) {
+ // Fetch player names
+ $playerlist = array();
+
+ foreach ($houses as $h)
+ if ($h['owner'] > 0)
+ $playerlist[] = $h['owner'];
+
+ if (!empty($playerlist)) {
+ $ids = join(',', $playerlist);
+ $tmpPlayers = mysql_select_multi("SELECT `id`, `name` FROM players WHERE `id` IN ($ids);");
+
+ // Sort $tmpPlayers by player id
+ $tmpById = array();
+ foreach ($tmpPlayers as $p)
+ $tmpById[$p['id']] = $p['name'];
+
+ for ($i = 0; $i < count($houses); $i++)
+ if ($houses[$i]['owner'] > 0)
+ $houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
}
- // Design and present the list
- if ($array) {
- $guild_support = (isset($array[0]['guild'])) ? true : false;
- ?>
-
- house list.
-
-
-
-
- Name: |
- Size: |
- Doors: |
- Beds: |
- Price: |
- Owner: |
-
-
- ';
- echo "". $value['name'] ." | ";
- echo "". $value['size'] ." | ";
- echo "". $value['doors'] ." | ";
- echo "". $value['beds'] ." | ";
- echo "". $value['price'] ." | ";
- if ($value['owner'] == 0)
- echo "None | ";
- else {
- if ($guild_support && $value['guild'] == 1) {
- $guild_name = get_guild_name($value['owner']);
- echo ''. $guild_name .' | ';
- } else {
- $data = user_character_data($value['owner'], 'name');
- echo ''. $data['name'] .' | ';
- }
- }
- echo '';
- }
- ?>
-
-
';
- //Token::debug($_POST['token']);
- echo 'Please clear your web cache/cookies OR use another web browser
';
+ $cache->setContent($houses);
+ $cache->save();
}
-} else {
- if (empty($_POST) === true && $config['ServerEngine'] === 'TFS_03') {
- ?>
-
+} else
+ $houses = $cache->load();
+
+if ($houses !== false || !empty($houses)) {
+ // Intialize stuff
+ //data_dump($houses, false, "House data");
+ ?>
+
+
+ Name |
+ Size |
+ Beds |
+ Rent |
+ Owner |
+ Town |
+
House file not foundFAILED TO LOCATE/READ FILE AT:
". $house['house_file'] ."
LINUX users: Make sure www-data have read access to file.
WINDOWS users: Learn to write correct file path.
");
- exit();
- }
-
- // Load and cache SQL house data:
- $cache = new Cache('engine/cache/houses/sqldata');
- if ($cache->hasExpired()) {
- $house_query = mysql_select_multi('SELECT `players`.`name`, `houses`.`id` FROM `players`, `houses` WHERE `houses`.`owner` = `players`.`id`;');
-
- $cache->setContent($house_query);
- $cache->save();
- } else
- $house_query = $cache->load();
-
- $sqmPrice = $house['price_sqm'];
- $house_load = simplexml_load_file($house['house_file']);
- if ($house_query !== false && $house_load !== false) {
- ?>
- House list
-
-
- House |
- Location |
- Owner |
- Size |
- Rent |
-
-
- '. $row['name'] .'';
-
- foreach ($house_load as $house_fetch){
- $house_price = (int)$house_fetch['size'] * $sqmPrice;
- ?>
-
- |
-
-
- |
-
-
- |
- |
- |
-
+ foreach ($houses as $house) {
+ if ($house['town_id'] == $townid) {
+ ?>
+
+ ". $house['name'] .""; ?> |
+ |
+ |
+ |
-
- Something is wrong with the cache.';
- } else if ($config['ServerEngine'] === 'TFS_10') {
- // Fetch values
- $querystring_id = &$_GET['id'];
- $townid = ($querystring_id) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
- $towns = $config['towns'];
-
- $order = &$_GET['order'];
- $type = &$_GET['type'];
-
- // Create Search house box
- ?>
-
- hasExpired()) {
- $houses = mysql_select_multi("SELECT `id`, `owner`, `paid`, `warnings`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` ORDER BY {$order} {$type};");
- if ($houses !== false) {
- // Fetch player names
- $playerlist = array();
-
- foreach ($houses as $h)
- if ($h['owner'] > 0)
- $playerlist[] = $h['owner'];
-
- if (!empty($playerlist)) {
- $ids = join(',', $playerlist);
- $tmpPlayers = mysql_select_multi("SELECT `id`, `name` FROM players WHERE `id` IN ($ids);");
-
- // Sort $tmpPlayers by player id
- $tmpById = array();
- foreach ($tmpPlayers as $p)
- $tmpById[$p['id']] = $p['name'];
-
- for ($i = 0; $i < count($houses); $i++)
- if ($houses[$i]['owner'] > 0)
- $houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
- }
-
- $cache->setContent($houses);
- $cache->save();
- }
- } else
- $houses = $cache->load();
-
- if ($houses !== false || !empty($houses)) {
- // Intialize stuff
- //data_dump($houses, false, "House data");
- ?>
-
-
- Name |
- Size |
- Beds |
- Rent |
- Owner |
- Town |
+ // Status:
+ if ($house['owner'] != 0)
+ echo "". $house['ownername'] ." | ";
+ else
+ echo ($house['highest_bidder'] == 0 ? 'None | ' : 'Selling | ');
+ ?>
+ |
-
- ". $house['name'] .""; ?> |
- |
- |
- |
- ". $house['ownername'] ."";
- else
- echo ($house['highest_bidder'] == 0 ? 'None | ' : 'Selling | ');
- ?>
- |
-
-
-
+ }
+ }
+ ?>
+
- Failed to fetch data from sql->houses table.Is the table empty?
";
- } // End TFS 1.0 logic
+ Failed to fetch data from sql->houses table.Is the table empty?
";
}
+
include 'layout/overall/footer.php'; ?>