add comments explaining utime compat desired behavior, fix GetUTime function (#44)

This commit is contained in:
plally 2023-06-29 19:51:45 -04:00 committed by GitHub
parent def1cd8b4a
commit 067e54b464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,20 +8,24 @@ CreateConVar( "utime_enable", "1", FCVAR_ARCHIVE )
local logger = CFCTime.Logger
local plyMeta = FindMetaTable( "Player" )
-- GetUTime returns the total time the player has played on the server excluding the current session
function plyMeta:GetUTime()
return self:GetNWFloat( "CFC_Time_TotalTime", 0 )
return self:GetNWFloat( "CFC_Time_TotalTime", 0 ) - self:GetUTimeSessionTime()
end
-- GetUTimeStart returns the time the player started their current session
function plyMeta:GetUTimeStart()
local now = os.time()
local sessionSeconds = now - self:GetNWFloat( "CFC_Time_SessionStart", now )
return CurTime() - sessionSeconds
end
-- GetUTimeSessionTime returns the time the player has played in their current session
function plyMeta:GetUTimeSessionTime()
return self:GetNWFloat( "CFC_Time_SessionDuration", 0 )
end
-- GetUTimeTotalTime returns the total time the player including the current session
function plyMeta:GetUTimeTotalTime()
local total = self:GetNWFloat( "CFC_Time_TotalTime", 0 )
@ -61,10 +65,10 @@ if SERVER then
logger:info(
string.format(
"Player %s [%s] migrated from UTime with existing time of %d",
ply:GetName(),
steamID,
totalTime
"Player %s [%s] migrated from UTime with existing time of %d",
ply:GetName(),
steamID,
totalTime
)
)