refact: extract module code into their own file

This commit is contained in:
Linventif 2025-05-26 00:33:20 +00:00
parent 6eebe5f165
commit f7dbb0250d
4 changed files with 144 additions and 144 deletions

View File

@ -0,0 +1,82 @@
local ply = FindMetaTable("Player")
function ply:gmIntGetTimeLastTeamChange()
return self.gmIntTimeLastTeamChange || RealTime()
end
function ply:gmInteResetTimeLastTeamChange()
self.gmIntTimeLastTeamChange = RealTime()
end
gmInte.restoreFileCache = gmInte.restoreFileCache || {}
function ply:getAdjustedTime()
if gmInte.restoreFileCache == nil || gmInte.restoreFileCache.sysTime == nil || gmInte.restoreFileCache.playersList == nil then return 0 end
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 || !gmInte.restoreFileCache.playersList then return 0 end
if (gmInte.restoreFileCache.sysTime + 60 * 5) < (os.time() - self:gmIntGetConnectTime()) then return 0 end
if !gmInte.restoreFileCache.playersList[self:SteamID()] then return 0 end
return gmInte.restoreFileCache.playersList[self:SteamID()].connectTime || 0
end
if SERVER then
gameevent.Listen("player_connect")
hook.Add("player_connect", "gmInte:Player:Connect:RemoveRestore", function(data)
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
end
end
if gmInte.restoreFileCache.playersList && gmInte.restoreFileCache.playersList[data.networkid] then
gmInte.restoreFileCache.playersList[data.networkid] = nil
file.Write("gm_integration/player_before_map_change.json", util.TableToJSON(gmInte.restoreFileCache, true))
end
end)
end
local function saveTimeToLocal()
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
hook.Add("ShutDown", "gmInte:Server:ShutDown:SavePlayer", saveTimeToLocal)
hook.Add("GMI:SaveBeforeCrash", "gmInte:Server:BeforeCrash:SavePlayers", saveTimeToLocal)

View File

@ -0,0 +1,57 @@
local ply = FindMetaTable("Player")
function ply:gmIntSetCustomValue(key, value)
self.gmIntCustomValues = self.gmIntCustomValues || {}
self.gmIntCustomValues[key] = value
end
function ply:gmIntGetCustomValue(key)
return self.gmIntCustomValues && self.gmIntCustomValues[key]
end
function ply:gmIntRemoveCustomValue(key)
if self.gmIntCustomValues then self.gmIntCustomValues[key] = nil end
end
local function getCustomCompatability(ply)
local values = {}
// DarkRP
if DarkRP then
values.money = ply:getDarkRPVar("money")
values.job = ply:getDarkRPVar("job")
end
// GUI Level System
if GUILevelSystem then
values.level = ply:GetLevel()
values.xp = ply:GetXP()
end
// Pointshop 2
if Pointshop2 && ply.PS2_Wallet then
values.ps2Points = ply.PS2_Wallet.points
values.ps2PremiumPoints = ply.PS2_Wallet.premiumPoints
end
if CH_ATM && SERVER then values.bank = CH_ATM.GetMoneyBankAccount(ply) end
return values
end
local function getCustomValues(ply)
local values = {}
// Get compatability values
for key, value in pairs(getCustomCompatability(ply)) do
values[key] = value
end
// Get custom values or overwrite compatability values
if ply.gmIntCustomValues then
for key, value in pairs(ply.gmIntCustomValues) do
values[key] = value
end
end
return values
end
function ply:gmIntGetCustomValues()
return getCustomValues(self)
end

View File

@ -3,83 +3,14 @@ function ply:gmIntGetConnectTime()
return self.gmIntTimeConnect || 0
end
function ply:gmIntIsVerified()
return self.gmIntVerified || false
end
function ply:gmIntGetTimeLastTeamChange()
return self.gmIntTimeLastTeamChange || RealTime()
end
function ply:gmInteResetTimeLastTeamChange()
self.gmIntTimeLastTeamChange = RealTime()
end
function ply:gmInteGetBranch()
return CLIENT && BRANCH || self.branch || "unknown"
end
function ply:gmIntSetCustomValue(key, value)
self.gmIntCustomValues = self.gmIntCustomValues || {}
self.gmIntCustomValues[key] = value
end
function ply:gmIntIsAdmin()
return gmInte.config.adminRank[self:GetUserGroup()] || false
end
function ply:gmIntGetCustomValue(key)
return self.gmIntCustomValues && self.gmIntCustomValues[key]
end
function ply:gmIntRemoveCustomValue(key)
if self.gmIntCustomValues then self.gmIntCustomValues[key] = nil end
end
local function getCustomCompatability(ply)
local values = {}
// DarkRP
if DarkRP then
values.money = ply:getDarkRPVar("money")
values.job = ply:getDarkRPVar("job")
end
// GUI Level System
if GUILevelSystem then
values.level = ply:GetLevel()
values.xp = ply:GetXP()
end
// Pointshop 2
if Pointshop2 && ply.PS2_Wallet then
values.ps2Points = ply.PS2_Wallet.points
values.ps2PremiumPoints = ply.PS2_Wallet.premiumPoints
end
if CH_ATM && SERVER then values.bank = CH_ATM.GetMoneyBankAccount(ply) end
return values
end
local function getCustomValues(ply)
local values = {}
// Get compatability values
for key, value in pairs(getCustomCompatability(ply)) do
values[key] = value
end
// Get custom values or overwrite compatability values
if ply.gmIntCustomValues then
for key, value in pairs(ply.gmIntCustomValues) do
values[key] = value
end
end
return values
end
function ply:gmIntGetCustomValues()
return getCustomValues(self)
end
function ply:gmIntGetFPS()
return self.gmIntFPS || 0
end
@ -89,77 +20,3 @@ function ply:gmInteSetFPS(fps)
fps = math.Clamp(fps, 0, 1000)
self.gmIntFPS = fps
end
gmInte.restoreFileCache = gmInte.restoreFileCache || {}
function ply:getAdjustedTime()
if gmInte.restoreFileCache == nil || gmInte.restoreFileCache.sysTime == nil || gmInte.restoreFileCache.playersList == nil then return 0 end
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 || !gmInte.restoreFileCache.playersList then return 0 end
if (gmInte.restoreFileCache.sysTime + 60 * 5) < (os.time() - self:gmIntGetConnectTime()) then return 0 end
if !gmInte.restoreFileCache.playersList[self:SteamID()] then return 0 end
return gmInte.restoreFileCache.playersList[self:SteamID()].connectTime || 0
end
if SERVER then
gameevent.Listen("player_connect")
hook.Add("player_connect", "gmInte:Player:Connect:RemoveRestore", function(data)
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
end
end
if gmInte.restoreFileCache.playersList && gmInte.restoreFileCache.playersList[data.networkid] then
gmInte.restoreFileCache.playersList[data.networkid] = nil
file.Write("gm_integration/player_before_map_change.json", util.TableToJSON(gmInte.restoreFileCache, true))
end
end)
end
local function saveTimeToLocal()
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
hook.Add("ShutDown", "gmInte:Server:ShutDown:SavePlayer", saveTimeToLocal)
hook.Add("GMI:SaveBeforeCrash", "gmInte:Server:BeforeCrash:SavePlayers", saveTimeToLocal)

View File

@ -0,0 +1,4 @@
local ply = FindMetaTable("Player")
function ply:gmIntIsVerified()
return self.gmIntVerified || false
end