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

TFS 1.X+ [Error - mysql_real_query] Query: INSERT INTO `players_online` VALUES (1)

ForgottenNot

Member
Joined
Feb 10, 2023
Messages
192
Reaction score
19
I use nekiro's tfs 1.5 with multiworld system i get this error while logging in, how do i remove or fix this error console?
Lua:
>> Forgotten Server Online!
GM Ratx has logged in.
[Error - mysql_real_query] Query: INSERT INTO `players_online` VALUES (1)
Message: Column count doesn't match value count at row 1
GM Ratx has logged out.
Blex has logged in.
[Error - mysql_real_query] Query: INSERT INTO `players_online` VALUES (8)
Message: Column count doesn't match value count at row 1
Blex has logged out.
Blex has logged in.
[Error - mysql_real_query] Query: INSERT INTO `players_online` VALUES (8)
Message: Column count doesn't match value count at row 1
Blex has logged out.
 
It's not about column named count.
The error “Column count doesn't match value count at row 1” means
that the number of columns does not match the number of rows in your INSERT statement.

Check your table columns, it should have only one column player_id, easiest to do is to remove it and re-add:
SQL:
CREATE TABLE IF NOT EXISTS `players_online` (
  `player_id` int NOT NULL,
  PRIMARY KEY (`player_id`)
) ENGINE=MEMORY DEFAULT CHARACTER SET=utf8;
 
His players_online probably contains 2 columns, because he uses multiworld.

So its probably player_id, and world_id.

To fix the error, you need to find the query in your sources (lua or c++), and add world_id to it.
 
Adjust these queries


C++:
uint16_t worldId = g_gameworld.getWorldId();
if (login) {
    Database::getInstance().executeQuery(fmt::format("INSERT INTO `players_online` VALUES ({:d}, {:d})", guid, worldId));
} else {
    Database::getInstance().executeQuery(fmt::format("DELETE FROM `players_online` WHERE `player_id` = {:d} AND `world_id` = {:d}", guid, worldId));
}


Lua:
local worldId = configManager.getNumber(configKeys.WORLD_ID)
db.query('DELETE FROM `players_online` WHERE `world_id` = '.. worldId)
 
Last edited:
His players_online probably contains 2 columns, because he uses multiworld.

So its probably player_id, and world_id.

To fix the error, you need to find the query in your sources (lua or c++), and add world_id to it.
Message: Column count doesn't match value count at row 1
 
Adjust these queries


C++:
uint16_t worldId = g_gameworld.getWorldId();
if (login) {
    Database::getInstance().executeQuery(fmt::format("INSERT INTO `players_online` VALUES ({:d}, {:d})", guid, worldId));
} else {
    Database::getInstance().executeQuery(fmt::format("DELETE FROM `players_online` WHERE `player_id` = {:d} AND `world_id` = {:d}", guid, worldId));
}


Lua:
local worldId = configManager.getNumber(configKeys.WORLD_ID)
db.query('DELETE FROM `players_online` WHERE `world_id` = '.. worldId)
Hi, thank you for your quick reply @lursky i'm getting a new error on login now.
Lua:
>> Forgotten Server Online!

multiworld is definedGM Ratx has logged in.
[Error - mysql_real_query] Query:
Message: Query was empty
Code:
some weird thing is tha twith your changes i cannot use this piece of code
Code:
output->addString(g_gameworld.getWorldIp(worldId));
located in:
Code:
void ProtocolLogin::getCharacterList(const std::string& accountName, const std::string& password, const std::string&, uint16_t version)
and had to replace it with a bypass? that don't know if it's working with the multiworld system but im able to log in
Code:
    output->add<uint32_t>(inet_addr(g_config.getString(ConfigManager::IP).c_str()));
because with this code i get this error
Code:
Connecting to: 127.0.0.1:7171
ERROR: protected lua call failed: C++ call failed: InputMessage eof reached
stack traceback:
    [builtin#146]: at 0x00853df0
    [C]: in function 'getString'
    /modules/gamelib/protocollogin.lua:254: in function 'parseCharacterList'
    /modules/gamelib/protocollogin.lua:181: in function </modules/gamelib/protocollogin.lua:163>

this is my full code
Code:
void ProtocolLogin::getCharacterList(const std::string& accountName, const std::string& password, const std::string&, uint16_t version)
{
    Account account;
    if (!IOLoginData::loginserverAuthentication(accountName, password, account)) {
        disconnectClient("Account name or password is not correct.", version);
        return;
    }


    auto output = OutputMessagePool::getOutputMessage();

    //Update premium days
    //Game::updatePremium(account);

    const std::string& motd = g_config.getString(ConfigManager::MOTD);
    if (!motd.empty()) {
        //Add MOTD
        output->addByte(0x14);

        std::ostringstream ss;
        ss << g_game.getMotdNum() << "\n" << motd;
        output->addString(ss.str());
    }

    output->addByte(0x64);

    uint8_t size = std::min<size_t>(std::numeric_limits<uint8_t>::max(), account.characters.size());
    output->addByte(size);

#ifdef MULTIWORLD_SYSTEM
    //Add char list
    printf("multiworld is defined");

    for (uint8_t i = 0; i < size; i++) {
        output->addString(account.characters[i].name);

        const uint16_t worldId = account.characters[i].worldid;

        output->addString(g_gameworld.getWorldName(worldId));
        //world envia ip 255.255.255
        //output->add<uint32_t>(inet_addr(g_gameworld.getWorldIp(worldId)));
        //output->addString(g_gameworld.getWorldIp(worldId));//supuesto fix
        //output->add<uint16_t>(g_gameworld.getWorldPort(worldId));

        //sin multiworld bypass pedorro
        output->add<uint32_t>(inet_addr(g_config.getString(ConfigManager::IP).c_str()));
        output->add<uint16_t>(g_gameworld.getWorldPort(worldId));
    }
#else
    printf("multiworld is NOT defined");

    //Add char list
    for (uint8_t i = 0; i < size; i++) {
        output->addString(account.characters[i]);
        output->addString(g_config.getString(ConfigManager::SERVER_NAME));
        output->add<uint32_t>(inet_addr(g_config.getString(ConfigManager::IP).c_str()));
        output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT));
    }
#endif

    // Add premium days
    output->addByte(0);
    if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) {
        output->addByte(1);
        output->add<uint32_t>(0);
    }
    else {
        output->addByte(account.premiumEndsAt > time(nullptr) ? 1 : 0);
        //output->add<uint32_t>(account.premiumEndsAt);
        output->add<uint16_t>(std::max<time_t>(0, account.premiumEndsAt - time(nullptr)) / 86400);
    }

    send(output);

    disconnect();
}

this is how updateonidlestatus looks now
Code:
void IOLoginData::updateOnlineStatus(uint32_t guid, bool login)
{
    if (g_config.getBoolean(ConfigManager::ALLOW_CLONES)) {
        return;
    }

    std::ostringstream query;
    uint16_t worldId = g_gameworld.getWorldId();
    if (login) {
        Database::getInstance().executeQuery(fmt::format("INSERT INTO `players_online` VALUES ({:d}, {:d})", guid, worldId));
    }
    else {
        Database::getInstance().executeQuery(fmt::format("DELETE FROM `players_online` WHERE `player_id` = {:d} AND `world_id` = {:d}", guid, worldId));
    }
    Database::getInstance().executeQuery(query.str());
}

startup.lua
Code:
-- Move expired bans to ban history
    local resultId = db.storeQuery("SELECT * FROM `account_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
    if resultId ~= false then
        repeat
            local accountId = result.getNumber(resultId, "account_id")
            db.asyncQuery("INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES (" .. accountId .. ", " .. db.escapeString(result.getString(resultId, "reason")) .. ", " .. result.getNumber(resultId, "banned_at") .. ", " .. result.getNumber(resultId, "expires_at") .. ", " .. result.getNumber(resultId, "banned_by") .. ")")
            db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. accountId)
        until not result.next(resultId)
        result.free(resultId)
    end
function onStartup()

    local worldId = configManager.getNumber(configKeys.WORLD_ID)
db.query('DELETE FROM `players_online` WHERE `world_id` = '.. worldId)
    db.asyncQuery("DELETE FROM `guild_wars` WHERE `status` = 0")
    db.asyncQuery("DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < " .. os.time())
    db.asyncQuery("DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
    db.asyncQuery("DELETE FROM `market_history` WHERE `inserted` <= " .. (os.time() - configManager.getNumber(configKeys.MARKET_OFFER_DURATION)))
 
Back
Top