• 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!

Solved lastday / premiumdays not counting

Solution
Did you tried mine with MyAAC?

Also, here's version you posted modified by me (for Gesior) - untested, try if it works:
PHP:
<?php
/**
* Created by Notepad++.
* User: Malucooo - Erick Nunes
* Remaked of login.php by JLCVP and parts of login.php by Monteiro. Thanks for both!
* Date: 18/09/17
* Time: 03:01
*/

require 'config/config.php';

// comment to show E_NOTICE [undefinied variable etc.], comment if you want make script and see all errors
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);

// true = show sent queries and SQL queries status/status code/error message
define('DEBUG_DATABASE', false);
define('INITIALIZED', true);

if (!defined('ONLY_PAGE'))
    define('ONLY_PAGE', true);

// check if site is disabled/requires installation...
If I use yours my client says illegal value, do you know what I have to change in mine to make it work? Im using gesior by the way (this one GitHub - malucooo/Gesior-AAC)

Code:
<?php
/**
* Created by Notepad++.
* User: Malucooo - Erick Nunes
* Remaked of login.php by JLCVP and parts of login.php by Monteiro. Thanks for both!
* Date: 18/09/17
* Time: 03:01
*/

require 'config/config.php';

// comment to show E_NOTICE [undefinied variable etc.], comment if you want make script and see all errors
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);

// true = show sent queries and SQL queries status/status code/error message
define('DEBUG_DATABASE', false);
define('INITIALIZED', true);

if (!defined('ONLY_PAGE'))
    define('ONLY_PAGE', true);

// check if site is disabled/requires installation
include_once('./system/load.loadCheck.php');

// fix user data, load config, enable class auto loader
include_once('./system/load.init.php');

// DATABASE
include_once('./system/load.database.php');
if (DEBUG_DATABASE)
    Website::getDBHandle()->setPrintQueries(true);

// DATABASE END
/*error example:
{
    "errorCode":3,
    "errorMessage":"Account name or password is not correct."
}*/

# Declare variables with array structure
$characters = array();
$playerData = array();
$data = array();
$isCasting = false;

# error function
function sendError($msg){
    $ret = array();
    $ret["errorCode"] = 3;
    $ret["errorMessage"] = $msg;
  
    die(json_encode($ret));
}

# getting infos
    $request = file_get_contents('php://input');
    $result = json_decode($request, true);

# account infos
    $accountName = $result["accountname"];
    $password = $result["password"];
# game port
    $port = 7172;

# check if player wanna see cast list
if (strtolower($accountName) == "cast")
    $isCasting = true;
if ($isCasting) {
    $casts = $SQL->query("SELECT `player_id` FROM `live_casts`")->fetchAll();
    if (count($casts[0]) == 0)
        sendError("There is no live casts right now!");
    foreach($casts as $cast) {
        $character = new Player();
        $character->load($cast['player_id']);
      
        if ($character->isLoaded()) {
            $char = array("worldid" => 0, "name" => $character->getName(), "ismale" => (($character->getSex() == 1) ? true : false), "tutorial" => false);
            $characters[] = $char;
        }          
    }
    $port = 7173;
    $lastLogin = 0;
    $premiumAccount = true;
    $timePremium = 0;
} else {
    $account = new Account();
    $account->find($accountName);
  
    if (!$account->isLoaded())
        sendError("Failed to get account. Try again!");
    if ($account->getPassword() != Website::encryptPassword($password))
        sendError("The password for this account is wrong. Try again!");
  
    foreach($account->getPlayersList() as $character) {
        $char = array("worldid" => 0, "name" => $character->getName(), "ismale" => (($character->getSex() == 1) ? true : false), "tutorial" => false);
        $characters[] = $char;
    }
  
    $lastLogin = $account->getLastLogin();
    $premiumAccount = ($account->isPremium()) ? true : false;
    $timePremium = time() + ($account->getPremDays() * 86400);
}
$session = array(
    "fpstracking" => false,
    "isreturner" => true,
    "returnernotification" => false,
    "showrewardnews" => false,
    "sessionkey" => $accountName . "\n" . $password,
    "lastlogintime" => $lastLogin,
    "ispremium" => $premiumAccount,
    "premiumuntil" => $timePremium,
    "status" => "active"  
);
$world = array(
    "id" => 0,
    "name" => $config['server']['serverName'],
    "externaladdress" => $config['server']['ip'],
    "externalport" => $port,
    "previewstate" => 0,
    "location" => "BRA",
    "anticheatprotection" => false
);

//Survey by: Cjaker
$survey = array(
    "id" => rand(0, 999999),
    "invitationtext" => "Querido tibiano, obrigado por usar OTX, a base mais atualizada do Tibia Global.\n'Mensagem dita por Cjaker'.",
    "invitationtoken" => "1751f1beddf001e1d36dee78ace974",
    "endtimestamp" => 1510614000
);

// https://limesurvey.cipsoft.com/index.php/survey/index/sid/527875/lang-en?token=1751f1beddf001e1d36dee78ace974
// token=invitationtoken
// o endtimestamp acima é o tempo convertido em unix timestamp, onde o mesmo é o prazo que irá acabar o survey!

$worlds = array($world);
$data["session"] = $session;
$playerData["worlds"] = $worlds;
$playerData["characters"] = $characters;
$data["playdata"] = $playerData;
$data["survey"] = $survey;

echo json_encode($data);
 
Last edited:
Did you tried mine with MyAAC?

Also, here's version you posted modified by me (for Gesior) - untested, try if it works:
PHP:
<?php
/**
* Created by Notepad++.
* User: Malucooo - Erick Nunes
* Remaked of login.php by JLCVP and parts of login.php by Monteiro. Thanks for both!
* Date: 18/09/17
* Time: 03:01
*/

require 'config/config.php';

// comment to show E_NOTICE [undefinied variable etc.], comment if you want make script and see all errors
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);

// true = show sent queries and SQL queries status/status code/error message
define('DEBUG_DATABASE', false);
define('INITIALIZED', true);

if (!defined('ONLY_PAGE'))
    define('ONLY_PAGE', true);

// check if site is disabled/requires installation
include_once('./system/load.loadCheck.php');

// fix user data, load config, enable class auto loader
include_once('./system/load.init.php');

// DATABASE
include_once('./system/load.database.php');
if (DEBUG_DATABASE)
    Website::getDBHandle()->setPrintQueries(true);

// DATABASE END
/*error example:
{
    "errorCode":3,
    "errorMessage":"Account name or password is not correct."
}*/

# Declare variables with array structure
$characters = array();
$playerData = array();
$data = array();
$isCasting = false;

# error function
function sendError($msg){
    $ret = array();
    $ret["errorCode"] = 3;
    $ret["errorMessage"] = $msg;
  
    die(json_encode($ret));
}

# getting infos
    $request = file_get_contents('php://input');
    $result = json_decode($request, true);

# account infos
    $accountName = $result["accountname"];
    $password = $result["password"];
# game port
    $port = 7172;

# check if player wanna see cast list
if (strtolower($accountName) == "cast")
    $isCasting = true;
if ($isCasting) {
    $casts = $SQL->query("SELECT `player_id` FROM `live_casts`")->fetchAll();
    if (count($casts[0]) == 0)
        sendError("There is no live casts right now!");
    foreach($casts as $cast) {
        $character = new Player();
        $character->load($cast['player_id']);
      
        if ($character->isLoaded()) {
            $char = array("worldid" => 0, "name" => $character->getName(), "ismale" => (($character->getSex() == 1) ? true : false), "tutorial" => false);
            $characters[] = $char;
        }        
    }
    $port = 7173;
    $lastLogin = 0;
    $premiumAccount = true;
    $timePremium = 0;
} else {
    $account = new Account();
    $account->find($accountName);
  
    if (!$account->isLoaded())
        sendError("Failed to get account. Try again!");
    if ($account->getPassword() != Website::encryptPassword($password))
        sendError("The password for this account is wrong. Try again!");
  
    foreach($account->getPlayersList() as $character) {
        $char = array("worldid" => 0, "name" => $character->getName(), "ismale" => (($character->getSex() == 1) ? true : false), "tutorial" => false);
        $characters[] = $char;
    }
  
    $save = false;
    $timeNow = time();
    $query = $SQL->query('SELECT `premdays`, `lastday` FROM `accounts` WHERE `id` = ' . $account->getId());
    if($query->rowCount() > 0) {
        $query = $query->fetch();
        $premDays = (int)$query['premdays'];
        $lastDay = (int)$query['lastday'];
        $lastLogin = $lastDay;
    }
    else {
        sendError("Error while fetching your account data. Please contact admin.");
    }
  
    if($premDays != 0 && $premDays != PHP_INT_MAX ) {
        if($lastDay == 0) {
            $lastDay = $timeNow;
            $save = true;
        } else {
            $days = (int)(($timeNow - $lastDay) / 86400);
            if($days > 0) {
                if($days >= $premDays) {
                    $premDays = 0;
                    $lastDay = 0;
                } else {
                    $premDays -= $days;
                    $remainder = (int)(($timeNow - $lastDay) % 86400);
                    $lastDay = $timeNow - $remainder;
                }
                $save = true;
            }
        }
    } else if ($lastDay != 0) {
        $lastDay = 0;
        $save = true;
    }
    if($save) {
        $SQL->query('UPDATE `accounts` SET `premdays` = ' . $premDays . ', `lastday` = ' . $lastDay . ' WHERE `id` = ' . $account->getId());
    }
    $premiumAccount = $premDays > 0;
    $timePremium = time() + ($premDays * 86400);
}
$session = array(
    "fpstracking" => false,
    "isreturner" => true,
    "returnernotification" => false,
    "showrewardnews" => false,
    "sessionkey" => $accountName . "\n" . $password,
    "lastlogintime" => $lastLogin,
    "ispremium" => $premiumAccount,
    "premiumuntil" => $timePremium,
    "status" => "active"
);
$world = array(
    "id" => 0,
    "name" => $config['server']['serverName'],
    "externaladdress" => $config['server']['ip'],
    "externalport" => $port,
    "previewstate" => 0,
    "location" => "BRA",
    "anticheatprotection" => false
);

//Survey by: Cjaker
$survey = array(
    "id" => rand(0, 999999),
    "invitationtext" => "Querido tibiano, obrigado por usar OTX, a base mais atualizada do Tibia Global.\n'Mensagem dita por Cjaker'.",
    "invitationtoken" => "1751f1beddf001e1d36dee78ace974",
    "endtimestamp" => 1510614000
);

// https://limesurvey.cipsoft.com/index.php/survey/index/sid/527875/lang-en?token=1751f1beddf001e1d36dee78ace974
// token=invitationtoken
// o endtimestamp acima é o tempo convertido em unix timestamp, onde o mesmo é o prazo que irá acabar o survey!

$worlds = array($world);
$data["session"] = $session;
$playerData["worlds"] = $worlds;
$playerData["characters"] = $characters;
$data["playdata"] = $playerData;
$data["survey"] = $survey;

echo json_encode($data);
 
Last edited:
Solution
Small fix:
change
Code:
$lastDay = $timeNow - remainder;

To:
Code:
$lastDay = $timeNow - $remainder;

or you might become illegal value error in client sometimes.

I've updated the other post.
 
Back
Top