From fa5fac75a78437605a71c34851c7b8fbc1a4a2ae Mon Sep 17 00:00:00 2001 From: Znote Date: Sat, 31 Oct 2020 14:29:29 +0100 Subject: [PATCH] Fix #446 TFS 1.3 premium time which was implemented here: https://github.com/otland/forgottenserver/pull/2813 and merged 28th october 2020. --- engine/function/users.php | 16 ++++++++++++---- engine/init.php | 17 ++++++++++++++--- guilds.php | 3 +-- house.php | 6 +----- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/engine/function/users.php b/engine/function/users.php index 7885b15..836acb6 100644 --- a/engine/function/users.php +++ b/engine/function/users.php @@ -1113,14 +1113,22 @@ function user_account_id_from_name($id) { // Add additional premium days to account id function user_account_add_premdays($accid, $days) { + global $tfs_10_hasPremDays; // Initialized in engine/init.php $accid = (int)$accid; $days = (int)$days; if (config('ServerEngine') !== 'OTHIRE') { - $data = mysql_select_single("SELECT `premdays` FROM `accounts` WHERE `id`='$accid';"); - $tmp = $data['premdays']; - $tmp += $days; - mysql_update("UPDATE `accounts` SET `premdays`='$tmp' WHERE `id`='$accid'"); + if ($tfs_10_hasPremDays) { + $data = mysql_select_single("SELECT `premdays` FROM `accounts` WHERE `id`='$accid';"); + $tmp = $data['premdays']; + $tmp += $days; + mysql_update("UPDATE `accounts` SET `premdays`='$tmp' WHERE `id`='$accid'"); + } else { + mysql_update(" UPDATE `accounts` + SET `premium_ends_at` = GREATEST(CAST(`premium_ends_at` as signed) - UNIX_TIMESTAMP(CURDATE()), 0) + ({$days} * 86400) + UNIX_TIMESTAMP(CURDATE()) + WHERE `id`='{$accid}'; + "); + } } else { $data = mysql_select_single("SELECT `premend` FROM `accounts` WHERE `id`='$accid';"); $tmp = $data['premend']; diff --git a/engine/init.php b/engine/init.php index 857fa6d..eb6daba 100644 --- a/engine/init.php +++ b/engine/init.php @@ -50,11 +50,22 @@ if (isset($_SESSION['token'])) { } Token::generate(); +$tfs_10_hasPremDays = true; // https://github.com/otland/forgottenserver/pull/2813 + if (user_logged_in() === true) { $session_user_id = getSession('user_id'); - if ($config['ServerEngine'] !== 'OTHIRE') - $user_data = user_data($session_user_id, 'id', 'name', 'password', 'email', 'premdays'); - else + if ($config['ServerEngine'] !== 'OTHIRE') { + if ($config['ServerEngine'] == 'TFS_10') { + $hasPremDays = mysql_select_single("SHOW COLUMNS from `accounts` WHERE `Field` = 'premdays'"); + if ($hasPremDays === false) { + $tfs_10_hasPremDays = false; + $user_data = user_data($session_user_id, 'id', 'name', 'password', 'email', 'premium_ends_at'); + $user_data['premdays'] = ($user_data['premium_ends_at'] - time() > 0) ? floor(($user_data['premium_ends_at'] - time()) / 86400) : 0; + } else { + $user_data = user_data($session_user_id, 'id', 'name', 'password', 'email', 'premdays'); + } + } + } else $user_data = user_data($session_user_id, 'id', 'password', 'email', 'premend'); $user_znote_data = user_znote_account_data($session_user_id, 'ip', 'created', 'points', 'cooldown', 'flag' ,'active_email'); } diff --git a/guilds.php b/guilds.php index 9c04b40..db89818 100644 --- a/guilds.php +++ b/guilds.php @@ -111,10 +111,9 @@ if (user_logged_in() === true) { // If character is offline if ($char_data['online'] == 0) { - $acc_data = user_data($user_data['id'], 'premdays'); // If character is premium - if ($config['guild_require_premium'] == false || $acc_data['premdays'] > 0) { + if ($config['guild_require_premium'] == false || $user_data['premdays'] > 0) { if (get_character_guild_rank($user_id) < 1) { diff --git a/house.php b/house.php index cc35025..01ebec7 100644 --- a/house.php +++ b/house.php @@ -32,11 +32,7 @@ if ($house !== false && $config['ServerEngine'] === 'TFS_10') { if (user_logged_in() === true && $player['account_id'] == $session_user_id) { // Does player have or need premium? - $premstatus = $config['houseConfig']['requirePremium']; - if ($premstatus) { - $premstatus = mysql_select_single("SELECT `premdays` FROM `accounts` WHERE `id`='".$player['account_id']."' LIMIT 1;"); - $premstatus = ($premstatus['premdays'] > 0) ? true : false; - } else $premstatus = true; + $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;");