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

fix: global result table to Result #731

Merged
merged 1 commit into from
Dec 31, 2022
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
8 changes: 4 additions & 4 deletions data-canary/scripts/creaturescripts/player_death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
local deathRecords = 0
local tmpResultId = resultId
while tmpResultId ~= false do
tmpResultId = result.next(resultId)
tmpResultId = Result.next(resultId)
deathRecords = deathRecords + 1
end

if resultId ~= false then
result.free(resultId)
Result.free(resultId)
end

local limit = deathRecords - maxDeathRecords
Expand All @@ -72,8 +72,8 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
local warId = false
resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild .. " AND `guild2` = " .. targetGuild .. ") OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. killerGuild .. "))")
if resultId ~= false then
warId = result.getNumber(resultId, "id")
result.free(resultId)
warId = Result.getNumber(resultId, "id")
Result.free(resultId)
end

if warId ~= false then
Expand Down
20 changes: 10 additions & 10 deletions data-canary/scripts/globalevents/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ function startup.onStartup()
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") .. ")")
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)
until not Result.next(resultId)
Result.free(resultId)
end

-- Check house auctions
local resultId = db.storeQuery("SELECT `id`, `highest_bidder`, `last_bid`, (SELECT `balance` FROM `players` WHERE `players`.`id` = `highest_bidder`) AS `balance` FROM `houses` WHERE `owner` = 0 AND `bid_end` != 0 AND `bid_end` < " .. os.time())
if resultId ~= false then
repeat
local house = House(result.getNumber(resultId, "id"))
local house = House(Result.getNumber(resultId, "id"))
if house then
local highestBidder = result.getNumber(resultId, "highest_bidder")
local balance = result.getNumber(resultId, "balance")
local lastBid = result.getNumber(resultId, "last_bid")
local highestBidder = Result.getNumber(resultId, "highest_bidder")
local balance = Result.getNumber(resultId, "balance")
local lastBid = Result.getNumber(resultId, "last_bid")
if balance >= lastBid then
db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
house:setOwnerGuid(highestBidder)
end
db.asyncQuery("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())
end
until not result.next(resultId)
result.free(resultId)
until not Result.next(resultId)
Result.free(resultId)
end

-- store towns in database
Expand Down
2 changes: 1 addition & 1 deletion data-canary/scripts/talkactions/god/ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ban.onSay(player, words, param)

local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
if resultId ~= false then
result.free(resultId)
Result.free(resultId)
return false
end

Expand Down
6 changes: 3 additions & 3 deletions data-canary/scripts/talkactions/god/gold_highscore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function gold_rank.onSay(player, words, param)
local x = 0
repeat
x = x + 1
str = str.."\n"..x.."- "..result.getString(resultId, "name").." ("..result.getNumber(resultId, "balance")..")."
until not result.next(resultId)
result.free(resultId)
str = str.."\n"..x.."- "..Result.getString(resultId, "name").." ("..Result.getNumber(resultId, "balance")..")."
until not Result.next(resultId)
Result.free(resultId)
if str == "" then
str = "No highscore to show."
end
Expand Down
8 changes: 4 additions & 4 deletions data-canary/scripts/talkactions/god/ip_ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function ipBan.onSay(player, words, param)
return false
end

local targetName = result.getString(resultId, "name")
local targetIp = result.getNumber(resultId, "lastip")
result.free(resultId)
local targetName = Result.getString(resultId, "name")
local targetIp = Result.getNumber(resultId, "lastip")
Result.free(resultId)

local targetPlayer = Player(param)
if targetPlayer then
Expand All @@ -34,7 +34,7 @@ function ipBan.onSay(player, words, param)
resultId = db.storeQuery("SELECT 1 FROM `ip_bans` WHERE `ip` = " .. targetIp)
if resultId ~= false then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, targetName .. " is already IP banned.")
result.free(resultId)
Result.free(resultId)
return false
end

Expand Down
6 changes: 3 additions & 3 deletions data-canary/scripts/talkactions/god/unban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function unban.onSay(player, words, param)
return false
end

db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. result.getNumber(resultId, "account_id"))
db.asyncQuery("DELETE FROM `ip_bans` WHERE `ip` = " .. result.getNumber(resultId, "lastip"))
result.free(resultId)
db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. Result.getNumber(resultId, "account_id"))
db.asyncQuery("DELETE FROM `ip_bans` WHERE `ip` = " .. Result.getNumber(resultId, "lastip"))
Result.free(resultId)
player:sendTextMessage(MESSAGE_LOOK, param .. " has been unbanned.")
return false
end
Expand Down
3 changes: 3 additions & 0 deletions data-otservbr-global/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ MESSAGE_EVENT_DEFAULT = MESSAGE_STATUS
MESSAGE_EVENT_ORANGE = TALKTYPE_MONSTER_SAY
MESSAGE_STATUS_CONSOLE_ORANGE = TALKTYPE_MONSTER_YELL

if type(result) then
result = Result
end
result.getDataInt = result.getNumber
result.getDataLong = result.getNumber
result.getDataString = result.getString
Expand Down
8 changes: 4 additions & 4 deletions data-otservbr-global/npc/hireling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ function createHirelingType(HirelingName)
"SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(name),
function(resultId)
if resultId then
func(result.getNumber(resultId, "id"))
result.free(resultId)
func(Result.getNumber(resultId, "id"))
Result.free(resultId)
else
func(nil)
end
Expand All @@ -471,8 +471,8 @@ function createHirelingType(HirelingName)
local balance
local resultId = db.storeQuery("SELECT `balance` FROM `guilds` WHERE `id` = " .. id)
if resultId then
balance = result.getNumber(resultId, "balance")
result.free(resultId)
balance = Result.getNumber(resultId, "balance")
Result.free(resultId)
end

return balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ local function updateGoldenOutfitCache()

local resultId = db.storeQuery("SELECT `name`, `value` FROM `player_storage` INNER JOIN `players` as `p` ON `p`.`id` = `player_id` WHERE `key` = " .. Storage.OutfitQuest.GoldenOutfit .. " AND `value` >= 1;")
if not resultId then
result.free(resultId)
Result.free(resultId)
lastUpdated = os.time()
return
end

repeat
table.insert(goldenOutfitCache[result.getNumber(resultId, "value")], result.getString(resultId, "name"))
until not result.next(resultId)
result.free(resultId)
table.insert(goldenOutfitCache[Result.getNumber(resultId, "value")], Result.getString(resultId, "name"))
until not Result.next(resultId)
Result.free(resultId)

lastUpdated = os.time()
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function playerLogin.onLogin(player)

-- Recruiter system
local resultId = db.storeQuery('SELECT `recruiter` from `accounts` where `id`='..getAccountNumberByPlayerName(getPlayerName(player)))
local recruiterStatus = result.getNumber(resultId, 'recruiter')
local recruiterStatus = Result.getNumber(resultId, 'recruiter')
local sex = player:getSex()
if recruiterStatus >= 1 then
if sex == 1 then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
local deathRecords = 0
local tmpResultId = resultId
while tmpResultId ~= false do
tmpResultId = result.next(resultId)
tmpResultId = Result.next(resultId)
deathRecords = deathRecords + 1
end

if resultId ~= false then
result.free(resultId)
Result.free(resultId)
end

if byPlayer == 1 then
Expand All @@ -83,8 +83,8 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
((`guild1` = ' .. killerGuild .. ' AND `guild2` = ' .. targetGuild .. ') OR \z
(`guild1` = ' .. targetGuild .. ' AND `guild2` = ' .. killerGuild .. '))')
if resultId ~= false then
warId = result.getNumber(resultId, 'id')
result.free(resultId)
warId = Result.getNumber(resultId, 'id')
Result.free(resultId)
end

if warId ~= false then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ function checkInbox.onThink(interval, lastExecution)
if records ~= false then
local count = 0
repeat
local player_id = result.getNumber(records, 'player_id')
local player_id = Result.getNumber(records, 'player_id')
db.asyncQuery('DELETE FROM `player_inboxitems` WHERE `player_id` = ' .. player_id)
db.asyncQuery('DELETE FROM `player` WHERE `id` = ' .. player_id)
until not result.next(records)
result.free(records)
until not Result.next(records)
Result.free(records)
end
return true
end
Expand Down
24 changes: 12 additions & 12 deletions data-otservbr-global/scripts/globalevents/others/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ function serverstartup.onStartup()
local banResultId = db.storeQuery('SELECT * FROM `account_bans` WHERE `expires_at` != 0 AND `expires_at` <= ' .. time)
if banResultId ~= false then
repeat
local accountId = result.getNumber(banResultId, 'account_id')
local accountId = Result.getNumber(banResultId, 'account_id')
db.asyncQuery('INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, \z
`expired_at`, `banned_by`) VALUES (' .. accountId .. ', \z
' .. db.escapeString(result.getString(banResultId, 'reason')) .. ', \z
' .. result.getNumber(banResultId, 'banned_at') .. ', ' .. result.getNumber(banResultId, 'expires_at') .. ', \z
' .. result.getNumber(banResultId, 'banned_by') .. ')')
' .. db.escapeString(Result.getString(banResultId, 'reason')) .. ', \z
' .. Result.getNumber(banResultId, 'banned_at') .. ', ' .. Result.getNumber(banResultId, 'expires_at') .. ', \z
' .. Result.getNumber(banResultId, 'banned_by') .. ')')
db.asyncQuery('DELETE FROM `account_bans` WHERE `account_id` = ' .. accountId)
until not result.next(banResultId)
result.free(banResultId)
until not Result.next(banResultId)
Result.free(banResultId)
end

-- Ferumbras Ascendant quest
Expand All @@ -108,20 +108,20 @@ function serverstartup.onStartup()
`bid_end` != 0 AND `bid_end` < ' .. time)
if resultId ~= false then
repeat
local house = House(result.getNumber(resultId, 'id'))
local house = House(Result.getNumber(resultId, 'id'))
if house then
local highestBidder = result.getNumber(resultId, 'highest_bidder')
local balance = result.getNumber(resultId, 'balance')
local lastBid = result.getNumber(resultId, 'last_bid')
local highestBidder = Result.getNumber(resultId, 'highest_bidder')
local balance = Result.getNumber(resultId, 'balance')
local lastBid = Result.getNumber(resultId, 'last_bid')
if balance >= lastBid then
db.query('UPDATE `players` SET `balance` = ' .. (balance - lastBid) .. ' WHERE `id` = ' .. highestBidder)
house:setOwnerGuid(highestBidder)
end
db.asyncQuery('UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, \z
`bid` = 0 WHERE `id` = ' .. house:getId())
end
until not result.next(resultId)
result.free(resultId)
until not Result.next(resultId)
Result.free(resultId)
end

do -- Event Schedule rates
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/talkactions/god/ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ban.onSay(player, words, param)

local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
if resultId ~= false then
result.free(resultId)
Result.free(resultId)
return false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function gold_rank.onSay(player, words, param)
local x = 0
repeat
x = x + 1
str = str.."\n"..x.."- "..result.getDataString(resultId, "name").." ("..result.getDataInt(resultId, "balance")..")."
until not result.next(resultId)
result.free(resultId)
str = str.."\n"..x.."- "..Result.getDataString(resultId, "name").." ("..Result.getDataInt(resultId, "balance")..")."
until not Result.next(resultId)
Result.free(resultId)
if str == "" then
str = "No highscore to show."
end
Expand Down
8 changes: 4 additions & 4 deletions data-otservbr-global/scripts/talkactions/god/ip_ban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function ipBan.onSay(player, words, param)
return false
end

local targetName = result.getString(resultId, "name")
local targetIp = result.getNumber(resultId, "lastip")
result.free(resultId)
local targetName = Result.getString(resultId, "name")
local targetIp = Result.getNumber(resultId, "lastip")
Result.free(resultId)

local targetPlayer = Player(param)
if targetPlayer then
Expand All @@ -34,7 +34,7 @@ function ipBan.onSay(player, words, param)
resultId = db.storeQuery("SELECT 1 FROM `ip_bans` WHERE `ip` = " .. targetIp)
if resultId ~= false then
player:sendTextMessage(MESSAGE_ADMINISTRADOR, targetName .. " is already IP banned.")
result.free(resultId)
Result.free(resultId)
return false
end

Expand Down
6 changes: 3 additions & 3 deletions data-otservbr-global/scripts/talkactions/god/unban.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function unban.onSay(player, words, param)
return false
end

db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. result.getNumber(resultId, "account_id"))
db.asyncQuery("DELETE FROM `ip_bans` WHERE `ip` = " .. result.getNumber(resultId, "lastip"))
result.free(resultId)
db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. Result.getNumber(resultId, "account_id"))
db.asyncQuery("DELETE FROM `ip_bans` WHERE `ip` = " .. Result.getNumber(resultId, "lastip"))
Result.free(resultId)
player:sendTextMessage(MESSAGE_ADMINISTRADOR, param .. " has been unbanned.")
return false
end
Expand Down
4 changes: 2 additions & 2 deletions data/libs/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ end
function RetrieveGlobalStorage(key)
local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key)
if resultId ~= false then
local val = result.getNumber(resultId, "value")
result.free(resultId)
local val = Result.getNumber(resultId, "value")
Result.free(resultId)
return val
end
return 1
Expand Down
Loading