• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Premium Account - Znote AAC

Nottinghster

Tibia World RPG Developer
Joined
Oct 24, 2007
Messages
1,635
Solutions
6
Reaction score
590
Location
Brazil - Rio de Janeiro
GitHub
Nottinghster
Hello OTlanders!

I've started a project to converting Znote AAC to make it work with OTServ_SVN 0.6.3, it's almost (99,5%) finished.
But I'm having some problems with Premium Account System, since I'm kinda "noob" with PHP!

Here's the original function:

Code:
function user_account_add_premdays($accid, $days) {
	$accid = (int)$accid;
	$days = (int)$days;
	$tmp = mysql_result(mysql_query("SELECT `premdays` FROM `accounts` WHERE `id`='$accid';"), 0, 'premdays');
	$tmp += $days;
	mysql_query("UPDATE `accounts` SET `premdays`='$tmp' WHERE `id`='$accid'");
}

Changed:

Code:
function user_account_add_premdays($accid, $days) {
	$accid = (int)$accid;
	$days = (int)$days;
	$tmp = mysql_result(mysql_query("SELECT `premend` FROM `accounts` WHERE `id`='$accid';"), 0, 'premend');
	$tmp += $days;
	mysql_query("UPDATE `accounts` SET `premend` = IF(`premend` > UNIX_TIMESTAMP(), `premend`+(60*60*24*$tmp), UNIX_TIMESTAMP()+(60*60*24*$tmp)) WHERE `id` = '$accid'");
}


Explaining the Query:
Add X days to any account with active premium or set the premium to expire in X days from now to any non-premium account.

But the problem is, when I buy 7 days, works fine, but if I buy more 7 days, give me Gratis Premium Account. (expires in 2106).
What I need to do to make it work ?

Thank you!
 
Maybe this will work:
PHP:
function user_account_add_premdays($accid, $days) {
	$accid = (int)$accid;
	$days = (int)$days;
	$tmp = mysql_result(mysql_query("SELECT `premend` FROM `accounts` WHERE `id`='$accid';"), 0, 'premend');
	if($tmp == 0)
	{
		$tmp = time() + ($days * 24 * 60 * 60);
	}
	else
	{
		$tmp = $tmp + ($days * 24 * 60 * 60);
	}
	mysql_query("UPDATE `accounts` SET `premend` = '$tmp' WHERE `id` = '$accid'");
}
 
Last edited:
Back
Top