Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: simplify some account functions and fix console error #3110

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions data/libs/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions data/libs/functions/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion data/scripts/creaturescripts/player/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/globalevents/update_guild_war_status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/talkactions/gm/ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading