• 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] Query: UPDATE `server_config` SET `value`

jefersonzc

New Member
Joined
Apr 13, 2011
Messages
17
Reaction score
4
Hello everyone. First of all, sorry for the english, I'm using ChatGPT ^^
I'm using TFS 1.4 (from the official forgottenserver repository) and Ubuntu 24.04. And I'm getting the following error:
Code:
[Error - mysql_real_query] Query: UPDATE `server_config` SET `value` = '3' WHERE `config` = 'motd_num'

But as we can see, my database seems to be getting updated regardless of the error.
Screenshot_3.webp

Anyway, I'm trying to get rid of this error. So, I found the following line in the GAME.CPP file.
Code:
db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:d}' WHERE `config` = 'motd_num'", motdNum));

And if I remove it and recompile the code, everything seems to work well, but my database will no longer be updated at that line, and I don't know if that will be a problem at some point.

I also found something in the 11.lua file. I’m not sure if it’s related to the issue, but maybe it is. I suspect it could be line 4, which in my opinion should be receiving 0, not "empty".
Or, maybe, the problem is the lastMotd.txt file, which doesn’t exist. I already tried creating it (blank) in the root folder, but it didn’t work (maybe I did it wrong).

LUA:
function onUpdateDatabase()
    print("> Updating database to version 12 (storing players record and message of the day in database)")

    local motdNum = ""
    local motd = ""

    local lastMotdFile = io.open("lastMotd.txt", "r")
    if lastMotdFile then
        motdNum = lastMotdFile:read()
        motd = lastMotdFile:read()
        lastMotdFile:close()
    end

    local record = 0

    local playersRecordFile = io.open("playersRecord.txt", "r")
    if playersRecordFile then
        record = playersRecordFile:read("*n")
        playersRecordFile:close()
    end

    db.query("INSERT INTO `server_config` (`config`, `value`) VALUES ('players_record', '" .. record .. "'), ('motd_hash', SHA1(" .. db.escapeString(motd) .. ")), ('motd_num', " .. db.escapeString(motdNum) .. ")")
    return true
end

Any help? Thank you guys.
 
Last edited:
Sorry, no. Just that line :/
it was fixed here, you can try solutions from there
 
it was fixed here, you can try solutions from there
Sorry, my friend. But I had already seen that thread before posting, and it didn’t help me too much. Here's the code from my game.cpp file. The error seems to be on the second-to-last line, when it tries to update the database with the motdNum variable. I believe that at some point this variable is getting a value that isn't an integer. Or I might just be hallucinating XD
C++:
void Game::loadMotdNum()
{
    Database& db = Database::getInstance();

    DBResult_ptr result = db.storeQuery("SELECT `value` FROM `server_config` WHERE `config` = 'motd_num'");
    if (result) {
        motdNum = result->getNumber<uint32_t>("value");
    } else {
        db.executeQuery("INSERT INTO `server_config` (`config`, `value`) VALUES ('motd_num', '0')");
    }

    result = db.storeQuery("SELECT `value` FROM `server_config` WHERE `config` = 'motd_hash'");
    if (result) {
        motdHash = result->getString("value");
        if (motdHash != transformToSHA1(g_config.getString(ConfigManager::MOTD))) {
            ++motdNum;
        }
    } else {
        db.executeQuery("INSERT INTO `server_config` (`config`, `value`) VALUES ('motd_hash', '')");
    }
}

void Game::saveMotdNum() const
{
    Database& db = Database::getInstance();
    db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:d}' WHERE `config` = 'motd_num'", motdNum));
    db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:s}' WHERE `config` = 'motd_hash'", transformToSHA1(g_config.getString(ConfigManager::MOTD))));
}
 

Similar threads

Back
Top