Add debug commands, cleanup code

This commit is contained in:
Samuel Williams 2020-12-21 20:58:20 +00:00 committed by Brandon Sturgeon
parent 21cefc125c
commit 0012cdffb7
3 changed files with 33 additions and 14 deletions

View File

@ -22,7 +22,7 @@ function api._checkCFCEndpoint()
if not success then return false end
local data = util.JSONToTable( body )
return tobool( data and data["server-is-up"] )
return tobool( data and data.status == "server-is-up" )
end
api.checkCFCEndpoint = async( api._checkCFCEndpoint )
@ -33,6 +33,8 @@ end
api.checkGlobalEndpoint = async( api._checkGlobalEndpoint )
function api._ping()
if api.stateOverride then return api.stateOverride end
api.state = api.PINGING_API
local _, data = await( promises.all( api.checkCFCEndpoint(), api.checkGlobalEndpoint() ) )
@ -49,3 +51,23 @@ function api._ping()
return api.state
end
api.ping = async( api._ping )
function api.getState()
return api.stateOverride or api.state
end
concommand.Add( "cfc_di_testcrash", function()
api.stateOverride = api.SERVER_DOWN
end )
concommand.Add( "cfc_di_testnointernet", function()
api.stateOverride = api.NO_INTERNET
end )
concommand.Add( "cfc_di_testrestart", function()
api.stateOverride = api.SERVER_UP
end )
concommand.Add( "cfc_di_testrecover", function()
api.stateOverride = nil
end )

View File

@ -97,17 +97,12 @@ local function leave()
end )
end
local init
init = function()
http.Fetch( GAME_URL, function( body )
GAME_CODE = body
end, function()
dTimer.Simple( 5, init )
end )
end
hook.Add( "Initialize", "cfc_di_init", init )
hook.Add( "InitPostEntity", "cfc_di_getGame", async( function()
repeat
success, GAME_CODE = await( NP.http.fetch( GAME_URL ) )
GAME_CODE = success and GAME_CODE
until GAME_CODE
end ) )
-- Creates and populates a title bar for the frame
local function addTitleBar( frame )
@ -294,9 +289,9 @@ local function addButtonsBar( frame )
leave()
end
end )
-- Color( 74, 251, 191 ), nil, Color( 74, 251, 191 ), Color( 64, 141, 131 ) )
-- Reconnect button will usually start as disabled
barPanel.reconBtn:SetDisabled( true )
barPanel.disconBtn = makeButton( barPanel, "DISCONNECT", 0.75, function( self )
if not barPanel.disconMode then
showMessage( getDisconnectMessage() )

View File

@ -11,6 +11,8 @@ local pongerStatus = false
local pingLoopRunning = false
net.Receive( "cfc_di_ping", function()
if CFCCrashAPI.stateOverride then return end
if PING_MISS > 0 then -- Allow some pings before actually starting crash systems. ( Avoid bugs on join stutter. )
PING_MISS = PING_MISS - 1
else
@ -53,7 +55,7 @@ local function checkCrashTick()
pingLoop()
end
hook.Run( "cfc_di_crashTick", pongerStatus, timedown, CFCCrashAPI.state )
hook.Run( "cfc_di_crashTick", pongerStatus, timedown, CFCCrashAPI.getState() )
end
-- Ping the server when the client is ready.