From 73f5c5a66ca0436295ffc6fb4a148bd08df8a3df Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 13 Nov 2024 02:25:22 -0300 Subject: [PATCH] cleanup: simplify some account functions and fix console error (#3110) Removes a duplicate function. Fixed console error related to missing string.format. --- data/libs/compat/compat.lua | 13 +------------ data/libs/functions/functions.lua | 15 --------------- data/libs/functions/game.lua | 15 +++++++++++++++ data/scripts/creaturescripts/player/login.lua | 2 +- .../globalevents/update_guild_war_status.lua | 2 +- data/scripts/talkactions/gm/ban.lua | 2 +- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/data/libs/compat/compat.lua b/data/libs/compat/compat.lua index 33aa0290841..ed1a229a826 100644 --- a/data/libs/compat/compat.lua +++ b/data/libs/compat/compat.lua @@ -618,18 +618,7 @@ function getPlayerGUIDByName(name) end function getAccountNumberByPlayerName(name) - local player = Player(name) - if player then - return player:getAccountId() - end - - local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) - if resultId ~= false then - local accountId = Result.getNumber(resultId, "account_id") - Result.free(resultId) - return accountId - end - return 0 + return Game.getPlayerAccountId(name) end getPlayerAccountBalance = getPlayerBalance diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index 2327a1cf937..4b9a94968ca 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -110,21 +110,6 @@ function getRateFromTable(t, level, default) return default end -function getAccountNumberByPlayerName(name) - local player = Player(name) - if player ~= nil then - return player:getAccountId() - end - - local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) - if resultId ~= false then - local accountId = Result.getNumber(resultId, "account_id") - Result.free(resultId) - return accountId - end - return 0 -end - function getMoneyCount(string) local b, e = string:find("%d+") local money = b and e and tonumber(string:sub(b, e)) or -1 diff --git a/data/libs/functions/game.lua b/data/libs/functions/game.lua index a7c7f7617ce..ae13f50038a 100644 --- a/data/libs/functions/game.lua +++ b/data/libs/functions/game.lua @@ -167,3 +167,18 @@ function Game.getTimeInWords(seconds) end return timeStr end + +function Game.getPlayerAccountId(name) + local player = Player(name) + if player then + return player:getAccountId() + end + + local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) + if resultId then + local accountId = result.getNumber(resultId, "account_id") + result.free(resultId) + return accountId + end + return 0 +end diff --git a/data/scripts/creaturescripts/player/login.lua b/data/scripts/creaturescripts/player/login.lua index 20049d87621..fe52be71b06 100644 --- a/data/scripts/creaturescripts/player/login.lua +++ b/data/scripts/creaturescripts/player/login.lua @@ -80,7 +80,7 @@ function playerLoginGlobal.onLogin(player) end -- Send Recruiter Outfit - local resultId = db.storeQuery("SELECT `recruiter` FROM `accounts` WHERE `id`= " .. getAccountNumberByPlayerName(getPlayerName(player))) + local resultId = db.storeQuery("SELECT `recruiter` FROM `accounts` WHERE `id`= " .. Game.getPlayerAccountId(getPlayerName(player))) if resultId then local recruiterStatus = Result.getNumber(resultId, "recruiter") local sex = player:getSex() diff --git a/data/scripts/globalevents/update_guild_war_status.lua b/data/scripts/globalevents/update_guild_war_status.lua index 2ede80428ef..e499d5aa22e 100644 --- a/data/scripts/globalevents/update_guild_war_status.lua +++ b/data/scripts/globalevents/update_guild_war_status.lua @@ -2,7 +2,7 @@ local updateGuildWarStatus = GlobalEvent("UpdateGuildWarStatus") function updateGuildWarStatus.onThink(interval) local currentTime = os.time() - db.query("UPDATE `guild_wars` SET `status` = 4, `ended` = %d WHERE `status` = 1 AND `ended` != 0 AND `ended` < %d", currentTime, currentTime) + db.query(string.format("UPDATE `guild_wars` SET `status` = 4, `ended` = %d WHERE `status` = 1 AND `ended` != 0 AND `ended` < %d", currentTime, currentTime)) return true end diff --git a/data/scripts/talkactions/gm/ban.lua b/data/scripts/talkactions/gm/ban.lua index 2796444a70b..4d7569c78f5 100644 --- a/data/scripts/talkactions/gm/ban.lua +++ b/data/scripts/talkactions/gm/ban.lua @@ -19,7 +19,7 @@ function ban.onSay(player, words, param) return true end - local accountId = getAccountNumberByPlayerName(playerName) + local accountId = Game.getPlayerAccountId(playerName) if accountId == 0 then return true end