• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

TFS 0.X Login queue - Change order

potinho

Premium User
Premium User
Joined
Oct 11, 2009
Messages
938
Solutions
17
Reaction score
66
Location
Brazil
Hello everyone, everything good? My server is growing and I'm getting close to the supportable engine/host limit. I would like that, in case of a day of queue to login, I prioritize the players that have VIP in my OT, how to do it? Follow my VIP system.

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if query:getID() == -1 then
    return func("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. getPlayerAccountId(cid) ..", ".. key ..", ".. value ..")")
  end
  return func("UPDATE `account_storage` SET `value` = ".. value .." WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
end

function isVIP(cid)
  return getAccountVIP(cid) > 0
end

function getAccountVIP(cid)
  return (getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() > 0) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() or 0
end

function setAccountVIP(cid, days)
  return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (60 * 60 * 24 * days) + (getAccountVIP(cid) > 0 and  getAccountVIP(cid) or 0))
end
 
Solution
C++:
    Database* db = Database::getInstance();
    DBQuery query;
    query << "SELECT `value` FROM `account_storage` WHERE `account_id` = " << player->getAccount() << " AND `key` = 30009 LIMIT 1";
    DBResult* result;
    if ((result = db->storeQuery(query.str()))) {
        time_t accountVIP = result->getDataLong("value");
        result->free();

        if (accountVIP > time(NULL))
            return true;
    }

Loney

🇲🇽
Senator
Premium User
Joined
Jul 23, 2012
Messages
2,047
Solutions
31
Reaction score
236
Location
MX
OP
OP
potinho

potinho

Premium User
Premium User
Joined
Oct 11, 2009
Messages
938
Solutions
17
Reaction score
66
Location
Brazil
Edit this line: forgottenserver036pl1/waitlist.cpp at caf524d396542b489d8c7e22cbb329be80f5b949 · peonso/forgottenserver036pl1 (https://github.com/peonso/forgottenserver036pl1/blob/caf524d396542b489d8c7e22cbb329be80f5b949/src/waitlist.cpp#L61)

Replace isPremium() check with your VIP storage check and recompile.
Then you can set premiumPlayerSkipWaitList to true in config.lua and desired max players.
Can u show me how to check an account storage value in a cpp file? I have VIP functions in library:

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if query:getID() == -1 then
    return func("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. getPlayerAccountId(cid) ..", ".. key ..", ".. value ..")")
  end
  return func("UPDATE `account_storage` SET `value` = ".. value .." WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
end

function isVIP(cid)
  return getAccountVIP(cid) > 0
end

function getAccountVIP(cid)
  return (getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() > 0) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() or 0
end

function setAccountVIP(cid, days)
  return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (60 * 60 * 24 * days) + (getAccountVIP(cid) > 0 and  getAccountVIP(cid) or 0))
end
 

Loney

🇲🇽
Senator
Premium User
Joined
Jul 23, 2012
Messages
2,047
Solutions
31
Reaction score
236
Location
MX
I honestly don't know as I never did something like that, showed you where and what you need to do but I can't give you a code right now.
However, I think there's a lot of information in OtLand regarding your request.


Hope you get an idea,
good luck.
 
OP
OP
potinho

potinho

Premium User
Premium User
Joined
Oct 11, 2009
Messages
938
Solutions
17
Reaction score
66
Location
Brazil
I honestly don't know as I never did something like that, showed you where and what you need to do but I can't give you a code right now.
However, I think there's a lot of information in OtLand regarding your request.


Hope you get an idea,
good luck.
Im trying some things, but gotting error. Believe i will have problems using accountStorage, like my vip =/, queue check player
 

Alberto Cabrera

Well-Known Member
Joined
Sep 17, 2020
Messages
74
Solutions
17
Reaction score
70
Location
México
Below
C++:
if(player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->isAccountManager() || (waitList.empty()
        && online < max) || (g_config.getBool(ConfigManager::PREMIUM_SKIP_WAIT) && player->isPremium()))

Try

C++:
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `value` FROM `account_storage` WHERE `account_id` = " << player->getAccount() << " LIMIT 1";

DBResult* result;
if((result = db->storeQuery(query.str())))
    time_t accountVIP = result->getDataLong("value");
    result->free();
    if (accountVIP > time(nullptr))
        return true;
 
OP
OP
potinho

potinho

Premium User
Premium User
Joined
Oct 11, 2009
Messages
938
Solutions
17
Reaction score
66
Location
Brazil
Below
C++:
if(player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->isAccountManager() || (waitList.empty()
        && online < max) || (g_config.getBool(ConfigManager::PREMIUM_SKIP_WAIT) && player->isPremium()))

Try

C++:
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `value` FROM `account_storage` WHERE `account_id` = " << player->getAccount() << " LIMIT 1";

DBResult* result;
if((result = db->storeQuery(query.str())))
    time_t accountVIP = result->getDataLong("value");
    result->free();
    if (accountVIP > time(nullptr))
        return true;
got error

C++:
waitlist.cpp: In member function ‘bool WaitingList::login(const Player*)’:
waitlist.cpp:61:14: warning: unused variable ‘db’ [-Wunused-variable]
    Database* db = Database::getInstance();
              ^~
waitlist.cpp:66:17: error: ‘db’ was not declared in this scope
    if((result = db->storeQuery(query.str())))
                 ^~
waitlist.cpp:67:11: warning: unused variable ‘accountVIP’ [-Wunused-variable]
    time_t accountVIP = result->getDataLong("value");
           ^~~~~~~~~~
waitlist.cpp:69:7: error: ‘accountVIP’ was not declared in this scope
   if (accountVIP > time(nullptr))
       ^~~~~~~~~~
 

Loney

🇲🇽
Senator
Premium User
Joined
Jul 23, 2012
Messages
2,047
Solutions
31
Reaction score
236
Location
MX
You'll need to use getStorage since your VIP function is only for lua methods.

Replace lines 60-61 with this and try:

C++:
if(player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->isAccountManager() || (waitList.empty()
        && online < max) || (g_config.getBool(ConfigManager::PREMIUM_SKIP_WAIT) && player->getStorage(30009, value)))
 
OP
OP
potinho

potinho

Premium User
Premium User
Joined
Oct 11, 2009
Messages
938
Solutions
17
Reaction score
66
Location
Brazil
You'll need to use getStorage since your VIP function is only for lua methods.

Replace lines 60-61 with this and try:

C++:
if(player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->isAccountManager() || (waitList.empty()
        && online < max) || (g_config.getBool(ConfigManager::PREMIUM_SKIP_WAIT) && player->getStorage(30009, value)))
But one problem, my VIP Storage is account, not player...has problem?
 

Roddet

life.rbegin()
Joined
May 1, 2013
Messages
643
Solutions
61
Reaction score
380
Location
MX
C++:
    Database* db = Database::getInstance();
    DBQuery query;
    query << "SELECT `value` FROM `account_storage` WHERE `account_id` = " << player->getAccount() << " AND `key` = 30009 LIMIT 1";
    DBResult* result;
    if ((result = db->storeQuery(query.str()))) {
        time_t accountVIP = result->getDataLong("value");
        result->free();

        if (accountVIP > time(NULL))
            return true;
    }
 
Solution
OP
OP
potinho

potinho

Premium User
Premium User
Joined
Oct 11, 2009
Messages
938
Solutions
17
Reaction score
66
Location
Brazil
C++:
    Database* db = Database::getInstance();
    DBQuery query;
    query << "SELECT `value` FROM `account_storage` WHERE `account_id` = " << player->getAccount() << " AND `key` = 30009 LIMIT 1";
    DBResult* result;
    if ((result = db->storeQuery(query.str()))) {
        time_t accountVIP = result->getDataLong("value");
        result->free();

        if (accountVIP > time(NULL))
            return true;
    }
where i put this code Rod?
 
Top