mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-10-13 22:34:53 +02:00
Full Distribution
This commit is contained in:
4
data/globalevents/scripts/record.lua
Normal file
4
data/globalevents/scripts/record.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
function onRecord(current, old)
|
||||
addEvent(broadcastMessage, 150, "New record: " .. current .. " players are logged in.", MESSAGE_STATUS_DEFAULT)
|
||||
return true
|
||||
end
|
33
data/globalevents/scripts/serversave.lua
Normal file
33
data/globalevents/scripts/serversave.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
local shutdownAtServerSave = true
|
||||
local cleanMapAtServerSave = false
|
||||
|
||||
local function serverSave()
|
||||
if shutdownAtServerSave then
|
||||
Game.setGameState(GAME_STATE_SHUTDOWN)
|
||||
else
|
||||
Game.setGameState(GAME_STATE_CLOSED)
|
||||
|
||||
if cleanMapAtServerSave then
|
||||
cleanMap()
|
||||
end
|
||||
|
||||
Game.setGameState(GAME_STATE_NORMAL)
|
||||
end
|
||||
end
|
||||
|
||||
local function secondServerSaveWarning()
|
||||
broadcastMessage("Server is saving game in one minute.\nPlease log out.", MESSAGE_STATUS_WARNING)
|
||||
addEvent(serverSave, 60000)
|
||||
end
|
||||
|
||||
local function firstServerSaveWarning()
|
||||
broadcastMessage("Server is saving game in 3 minutes.\nPlease come back in 10 minutes.", MESSAGE_STATUS_WARNING)
|
||||
addEvent(secondServerSaveWarning, 120000)
|
||||
end
|
||||
|
||||
function onTime(interval)
|
||||
broadcastMessage("Server is saving game in 5 minutes.\nPlease come back in 10 minutes.", MESSAGE_STATUS_WARNING)
|
||||
Game.setGameState(GAME_STATE_STARTUP)
|
||||
addEvent(firstServerSaveWarning, 120000)
|
||||
return not shutdownAtServerSave
|
||||
end
|
50
data/globalevents/scripts/startup.lua
Normal file
50
data/globalevents/scripts/startup.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
function onStartup()
|
||||
math.randomseed(os.mtime())
|
||||
|
||||
db.query("TRUNCATE TABLE `players_online`")
|
||||
db.asyncQuery("DELETE FROM `guild_wars` WHERE `status` = 0")
|
||||
db.asyncQuery("DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < " .. os.time())
|
||||
db.asyncQuery("DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= " .. os.time())
|
||||
|
||||
-- Move expired bans to ban history
|
||||
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.getDataInt(resultId, "account_id")
|
||||
db.asyncQuery("INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES (" .. accountId .. ", " .. db.escapeString(result.getDataString(resultId, "reason")) .. ", " .. result.getDataLong(resultId, "banned_at") .. ", " .. result.getDataLong(resultId, "expires_at") .. ", " .. result.getDataInt(resultId, "banned_by") .. ")")
|
||||
db.asyncQuery("DELETE FROM `account_bans` WHERE `account_id` = " .. accountId)
|
||||
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.getDataInt(resultId, "id"))
|
||||
if house ~= nil then
|
||||
local highestBidder = result.getDataInt(resultId, "highest_bidder")
|
||||
local balance = result.getDataLong(resultId, "balance")
|
||||
local lastBid = result.getDataInt(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)
|
||||
end
|
||||
|
||||
-- Remove murders that are more than 60 days old
|
||||
local resultId = db.storeQuery("SELECT * FROM `player_murders` WHERE `date` <= " .. os.time() - 60 * 24 * 60 * 60)
|
||||
if resultId ~= false then
|
||||
repeat
|
||||
local playerId = result.getDataInt(resultId, "player_id")
|
||||
local id = result.getDataLong(resultId, "id")
|
||||
|
||||
db.asyncQuery("DELETE FROM `player_murders` WHERE `player_id` = " .. playerId .. " AND `id` = " .. id)
|
||||
until not result.next(resultId)
|
||||
result.free(resultId)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user