Feat: add ajustTime for reconnect after map change

This commit is contained in:
Linventif 2024-11-21 17:08:15 +00:00
parent 0a7ae28a75
commit 4ab93e1afe
2 changed files with 55 additions and 1 deletions

View File

@ -10,7 +10,8 @@ function gmInte.getPlayerFormat(ply)
["kills"] = ply:Frags(),
["deaths"] = ply:Deaths(),
["customValues"] = ply:gmIntGetCustomValues(),
["connectTime"] = math.Round(RealTime() - ply:gmIntGetConnectTime()),
["connectTime"] = math.Round(math.Round(RealTime() - ply:gmIntGetConnectTime())),
["ajustTime"] = math.Round(ply:getAjustTime()),
["ping"] = ply:Ping(),
["fps"] = ply:gmIntGetFPS(),
["position"] = gmInte.getVectorFormat(ply:GetPos()),

View File

@ -69,7 +69,60 @@ end
function ply:gmIntGetCustomValues()
return getCustomValues(self)
end
function ply:gmIntGetFPS()
return self.gmIntFPS || 0
end
// Backup players before map change
hook.Add("ShutDown", "gmInte:Server:ShutDown:SavePlayer", function()
// save in data/gm_integration/player_before_map_change.json
local dataToSave = {
["version"] = "1.0",
["serverID"] = gmInte.config.id,
["playersList"] = {},
["sysTime"] = os.time()
}
if SERVER then
for _, ply in ipairs(player.GetAll()) do
dataToSave.playersList[ply:SteamID()] = gmInte.getPlayerFormat(ply)
end
if !file.Exists("gm_integration", "DATA") then file.CreateDir("gm_integration") end
file.Write("gm_integration/player_before_map_change.json", util.TableToJSON(dataToSave, true))
else
dataToSave.playersList[LocalPlayer():SteamID()] = gmInte.getPlayerFormat(LocalPlayer())
local oldData = {}
if file.Exists("gmod_integration/player_before_map_change.json", "DATA") then oldData = util.JSONToTable(file.Read("gmod_integration/player_before_map_change.json", "DATA")) end
oldData[gmInte.config.id] = dataToSave
file.Write("gmod_integration/player_before_map_change.json", util.TableToJSON(oldData, true))
end
end)
gmInte.restoreFileCache = gmInte.restoreFileCache || {}
function ply:getAjustTime()
if SERVER then
if table.IsEmpty(gmInte.restoreFileCache) then
if file.Exists("gm_integration/player_before_map_change.json", "DATA") then
gmInte.restoreFileCache = util.JSONToTable(file.Read("gm_integration/player_before_map_change.json", "DATA"))
else
return 0
end
end
else
if table.IsEmpty(gmInte.restoreFileCache) then
if file.Exists("gmod_integration/player_before_map_change.json", "DATA") then
gmInte.restoreFileCache = util.JSONToTable(file.Read("gmod_integration/player_before_map_change.json", "DATA"))
else
return 0
end
gmInte.restoreFileCache = gmInte.restoreFileCache[gmInte.config.id]
end
end
if (gmInte.restoreFileCache.sysTime + 60 * 5) < (os.time() - self:gmIntGetConnectTime()) then return 0 end
if !gmInte.restoreFileCache.playersList || !gmInte.restoreFileCache.playersList[self:SteamID()] then return 0 end
return gmInte.restoreFileCache.playersList[self:SteamID()].connectTime || 0
end