feat: add a hook GMI:SaveBeforeCrash for trisomic server owner how crash server to auto reconnect client

This commit is contained in:
Linventif 2025-03-20 05:47:46 +00:00
parent da9b9d2392
commit 499c382066
3 changed files with 11 additions and 5 deletions

View File

@ -97,14 +97,16 @@ function gmInte.postLogPlayerGive(ply, class, swep)
})
end
hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) gmInte.playerReady(ply) end)
hook.Add("ShutDown", "gmInte:Server:Shutdown:SavePlayers", function()
local function savePlyDisconnect()
for _, ply in ipairs(player.GetAll()) do
gmInte.playerDisconnected(ply)
end
end)
end
gameevent.Listen("player_connect")
hook.Add("ShutDown", "gmInte:Server:Shutdown:SavePlayers", savePlyDisconnect)
hook.Add("GMI:SaveBeforeCrash", "gmInte:Server:BeforeCrash:SavePlayers", savePlyDisconnect)
hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) gmInte.playerReady(ply) end)
hook.Add("player_connect", "gmInte:Player:Connect", function(data) gmInte.playerConnect(data) end)
hook.Add("PlayerDisconnected", "gmInte:Player:Disconnect", function(ply) gmInte.playerDisconnected(ply) end)
hook.Add("PlayerSpawn", "gmInte:Player:Spawn", function(ply) gmInte.playerSpawn(ply) end)

View File

@ -108,6 +108,7 @@ local function flushLogs()
end
hook.Add("ShutDown", "gmInte:Server:ShutDown:FlushLogs", flushLogs)
hook.Add("GMI:SaveBeforeCrash", "gmInte:Server:BeforeCrash:SavePlayers", flushLogs)
timer.Create("gmInte:http:flushLogs", 3, 0, flushLogs)
function gmInte.http.postLog(endpoint, data)
table.insert(nextLogPacket, {

View File

@ -129,7 +129,7 @@ if SERVER then
end)
end
hook.Add("ShutDown", "gmInte:Server:ShutDown:SavePlayer", function()
local function saveTimeToLocal()
local dataToSave = {
["version"] = "1.0",
["serverID"] = gmInte.config.id,
@ -151,4 +151,7 @@ hook.Add("ShutDown", "gmInte:Server:ShutDown:SavePlayer", function()
oldData[gmInte.config.id] = dataToSave
file.Write("gmod_integration/player_before_map_change.json", util.TableToJSON(oldData, true))
end
end)
end
hook.Add("ShutDown", "gmInte:Server:ShutDown:SavePlayer", saveTimeToLocal)
hook.Add("GMI:SaveBeforeCrash", "gmInte:Server:BeforeCrash:SavePlayers", saveTimeToLocal)