startup.lua

main 46 lines · 2.5 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1function onStartup()
2
3 db.query("TRUNCATE TABLE `players_online`")
4 db.asyncQuery("DELETE FROM `guild_wars` WHERE `status` = 0")
5 db.asyncQuery("DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < " .. os.time())
6 db.asyncQuery("DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
7 db.asyncQuery("DELETE FROM `market_history` WHERE `inserted` <= " .. (os.time() - configManager.getNumber(configKeys.MARKET_OFFER_DURATION)))
8
9 -- Move expired bans to ban history
10 local resultId = db.storeQuery("SELECT * FROM `account_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
11 if resultId ~= false then
12 repeat
13 local accountId = result.getNumber(resultId, "account_id")
14 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") .. ")")
15 db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. accountId)
16 until not result.next(resultId)
17 result.free(resultId)
18 end
19
20 -- Check house auctions
21 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())
22 if resultId ~= false then
23 repeat
24 local house = House(result.getNumber(resultId, "id"))
25 if house then
26 local highestBidder = result.getNumber(resultId, "highest_bidder")
27 local balance = result.getNumber(resultId, "balance")
28 local lastBid = result.getNumber(resultId, "last_bid")
29 if balance >= lastBid then
30 db.query("UPDATE `players` SET `balance` = " .. (balance - lastBid) .. " WHERE `id` = " .. highestBidder)
31 house:setOwnerGuid(highestBidder)
32 end
33 db.asyncQuery("UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " .. house:getId())
34 end
35 until not result.next(resultId)
36 result.free(resultId)
37 end
38
39 -- store towns in database
40 db.query("TRUNCATE TABLE `towns`")
41 for i, town in ipairs(Game.getTowns()) do
42 local position = town:getTemplePosition()
43 db.query("INSERT INTO `towns` (`id`, `name`, `posx`, `posy`, `posz`) VALUES (" .. town:getId() .. ", " .. db.escapeString(town:getName()) .. ", " .. position.x .. ", " .. position.y .. ", " .. position.z .. ")")
44 end
45end
46
Top