0) ? (int)$_GET['id'] : false;
$house_SQL = "";
$house_SQL_params = [];
if ($house !== false) {
$house_SQL = "
SELECT
`h`.`id`, `h`.`owner`, `h`.`paid`, `h`.`name`, `h`.`rent`, `h`.`town_id`,
`h`.`size`, `h`.`beds`, " . houseSelect(array('bid','bid_end','last_bid','highest_bidder'), 'h') . ",
`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_SQL_params = [$house];
$house = db()->fetchOne($house_SQL, $house_SQL_params);
if (!is_array($house)) {
?>
= t('house.not_found') ?>
= t('house.go_back') ?> house list and select a house for further details.
$cost_points) {
if ($cost_sqm < $house['size']) $house['points'] = $cost_points;
}
}
//data_dump($house, false, "House data");
//////////////////////
// Bid on house logic
$bid_char = &$_POST['char'];
$bid_amount = &$_POST['amount'];
if ($bid_amount && $bid_char) {
$bid_char = (int)$bid_char;
$bid_amount = (int)$bid_amount;
$player = db()->fetchOne("
SELECT `id`, `account_id`, `name`, `level`, `balance`
FROM `players`
WHERE `id` = ? LIMIT 1;
", [$bid_char]);
if (user_logged_in() === true && is_array($player) && $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 = db()->fetchOne("
SELECT COUNT('id') AS `value`
FROM `houses`
WHERE (
(`" . houseCol('highest_bidder') . "` = ? AND `owner` = ?)
OR (`" . houseCol('highest_bidder') . "` = ?)
OR (`owner` = ?)
)
AND `id` != ? LIMIT 1;
", [$bid_char, $bid_char, $bid_char, $bid_char, $house['id']]);
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?
if ($bid_amount > $minbid) {
// Should only apply to external players, allowing a player to up his pledge without
// being forced to pay his full previous bid.
if ($house['highest_bidder'] != $player['id']) $lastbid = $house['bid'] + 1;
else {
$lastbid = $house['last_bid'];
echo "You have raised the house pledge to ".$bid_amount."gp!
";
}
// Has bid already started?
if ($house['bid_end'] > 0) {
if ($house['bid_end'] > time()) {
db()->execute("
UPDATE `houses`
SET
`" . houseCol('highest_bidder') . "` = ?,
`" . houseCol('bid') . "` = ?,
`" . houseCol('last_bid') . "` = ?
WHERE `id` = ? LIMIT 1;
", [$player['id'], $bid_amount, $lastbid, $house['id']]);
$house = db()->fetchOne("
SELECT
`id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`,
`beds`, " . houseSelect(array('bid','bid_end','last_bid','highest_bidder')) . "
FROM `houses`
WHERE `id` = ?;
", [$house['id']]);
}
} else {
$lastbid = $minbid + 1;
$bidend = time() + $config['houseConfig']['auctionPeriod'];
db()->execute("
UPDATE `houses`
SET
`" . houseCol('highest_bidder') . "` = ?,
`" . houseCol('bid') . "` = ?,
`" . houseCol('last_bid') . "` = ?,
`" . houseCol('bid_end') . "` = ?
WHERE `id` = ? LIMIT 1;
", [$player['id'], $bid_amount, $lastbid, $bidend, $house['id']]);
$house = db()->fetchOne("
SELECT
`id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`,
`beds`, " . houseSelect(array('bid','bid_end','last_bid','highest_bidder')) . "
FROM `houses`
WHERE `id` = ?;
", [$house['id']]);
}
echo "". t('house.highest_bid') ."";
} 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']) {
// Should only apply to external players, allowing a player to up his pledge without
// being forced to pay his full previous bid.
if ($house['highest_bidder'] != $player['id']) {
$lastbid = $bid_amount + 1;
db()->execute("
UPDATE `houses`
SET `" . houseCol('last_bid') . "` = ?
WHERE `id` = ? LIMIT 1;
", [$lastbid, $house['id']]);
$house = db()->fetchOne("
SELECT
`id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`,
`beds`, " . houseSelect(array('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 "". t('house.already_higher') ."";
}
} else {
echo "" . t('house.bid_too_low') . "";
}
}
} else echo "" . t('house.not_enough2') . "";
} else echo "" . t('house.level_too_low', ['level' => $config['houseConfig']['levelToBuyHouse'] - 1]) . "";
} else echo "". t('house.too_many') ."";
} else echo "" . t('house.need_premium2') . "";
} else echo "" . t('house.own_char_only') . "";
}
////////////////////////////////////////
// Instantly buy house with shop points
if ($config['houseConfig']['shopPoints']['enabled']
&& isset($_POST['instantbuy'])
&& $bid_char
&& $house['owner'] == 0
&& isset($house['points'])) {
$account_points = (int)$user_znote_data['points'];
if ($account_points >= $house['points']) {
$bid_char = (int)$bid_char;
$player = db()->fetchOne("
SELECT `id`, `account_id`, `name`, `level`
FROM `players`
WHERE `id` = ? LIMIT 1;
", [$bid_char]);
$pHouseCount = db()->fetchOne("
SELECT COUNT('id') AS `value`
FROM `houses`
WHERE (
(`" . houseCol('highest_bidder') . "` = ? AND `owner` = ?)
OR (`" . houseCol('highest_bidder') . "` = ?)
OR (`owner` = ?)
)
AND `id` != ? LIMIT 1;
", [$bid_char, $bid_char, $bid_char, $bid_char, $house['id']]);
if (user_logged_in() === true
&& $player['account_id'] == $session_user_id
&& $player['level'] >= $config['houseConfig']['levelToBuyHouse']
&& $pHouseCount['value'] < $config['houseConfig']['housesPerPlayer']) {
$house_points = (int)$house['points'];
$house_id = $house['id'];
$time = time();
// Lock the account balance and the house row together, so two
// concurrent purchases (or a purchase racing a bid) cannot both
// succeed or spend points that were already spent.
$purchased = db()->transaction(function ($db) use ($session_user_id, $bid_char, $house_id, $house_points, $time) {
$account = $db->fetchOne("SELECT `points` FROM `znote_accounts` WHERE `account_id` = ? LIMIT 1 FOR UPDATE;", [$session_user_id]);
if (!is_array($account) || (int)$account['points'] < $house_points) {
return false;
}
$houseRow = $db->fetchOne("SELECT `owner` FROM `houses` WHERE `id` = ? LIMIT 1 FOR UPDATE;", [$house_id]);
if (!is_array($houseRow) || (int)$houseRow['owner'] !== 0) {
return false;
}
$db->execute("UPDATE `znote_accounts` SET `points` = `points` - ? WHERE `account_id` = ? LIMIT 1;", [$house_points, $session_user_id]);
$db->execute("UPDATE `houses` SET `owner` = ? WHERE `id` = ? LIMIT 1;", [$bid_char, $house_id]);
$db->execute("
INSERT INTO `znote_shop_logs`
(`account_id`, `player_id`, `type`, `itemid`, `count`, `points`, `time`) VALUES
(?, ?, 7, ?, 1, ?, ?)
", [$session_user_id, $bid_char, $house_id, $house_points, $time]);
$db->execute("
INSERT INTO `znote_shop_orders`
(`account_id`, `type`, `itemid`, `count`, `time`) VALUES
(?, 7, ?, ?, ?)
", [$session_user_id, $house_id, $bid_char, $time]);
return true;
});
if ($purchased) {
// Reload house data
$house = db()->fetchOne($house_SQL, $house_SQL_params);
$minbid = $config['houseConfig']['minimumBidSQM'] * $house['size'];
if ($house['owner'] > 0) $house['ownername'] = user_name($house['owner']);
// Congratulate user and tell them they still has to pay rent (if rent > 0)
?>
= t('house.congrats') ?>
You now own this house!
= t('house.remember_say') ?> !shop in-game to process your ownership!
0): ?>
Keep in mind you still need to pay rent on this house, make sure you have enough bank balance to cover it!
Error:
This house was already bought or your points balance changed. Please refresh and try again.
Error:
Either your level is too low, or your player already have or is bidding on another house.
= t('house.your_level') ?> . Minimum level to buy house:
= t('house.your_bids') ?> . Maximum house per player: .
= t('house.label') ?>
- Town:
". ($town_name ? $town_name : 'Specify town id ' . $house['town_id'] . ' name in config.php first.') ."";
?>
- Size:
- Beds:
- Owner: 0) echo "{$house['ownername']}";
else echo "Available for auction.";
?>
- Rent:
- = t('house.shop_points2') ?>:
= t('house.on_auction2') ?>
" . t('house.no_bidders2') . "";
else {
$bidder = db()->fetchOne("SELECT `name` FROM `players` WHERE `id` = ? LIMIT 1;", [$house['highest_bidder']]);
echo "" . t('house.has_bidders') . "";
echo "
" . t('house.active_bid') . " {$house['last_bid']}gp";
echo "
" . t('house.active_bid_by') . " " . htmlspecialchars((string)$bidder['name'], ENT_QUOTES, 'UTF-8') . "";
echo "
" . t('house.bid_ends') . " ". 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 = db()->fetchAll("SELECT `id`, `name`, `balance` FROM `players` WHERE `account_id` = ?;", [$user_data['id']]);
if ($yourChars !== false) {
$charData = array();
foreach ($yourChars as $char) {
$charData[$char['id']] = $char;
}
?>
= $house['points']): ?>
= t('house.your_account') ?> available shop points.
You don't have enough shop points to instantly buy this house.
You need a character to bid on this house.";
} else echo "
You need to login before you can bid on houses.";
} else echo "
Bid has ended! House transaction will proceed next server restart assuming active bidder have sufficient balance.";
}
} else {
?>
= t('house.none_selected') ?>
= t('house.go_back') ?> house list and select a house for further details.