IsServerTimingOut()

Is there any function or a way to find out if the server is not responding anymore?

I tried to use “Move” hook as it is not called anymore if server stops responding. Drawback is that Move hook is not called when you are for example in a vehicle so I couldn’t reliably detect it.

Move hook allowed me to get something like 1/50 second accuracy with the timeout. Can any other hook do better or the same? I need at least four seconds accuracy.
And please, no pingpong usermessages. We have enough traffic going through the server<->client link to be able to detect when nothing is being received. Problem is how to detect this like I said already.

Server:
[lua]
TIMEOUT_LASTTICK = 0
TIMEOUT_SECONDS_PER_TICK = 0.5
function TimeoutFunction()
if LAST_TIMEOUT_TICK < SysTime() then
LAST_TIMEOUT_TICK = SysTime() + TIMEOUT_SECONDS_PER_TICK
local rf = RecipientFilter()
rf:AddAllPlayers()
umsg.Start(“TO”, rf)
umsg.End()
end
end
hook.Add(“Tick”,“TimeoutFunction”,TimeoutFunction)
[/lua]
Client:

[lua]
TIMEOUT_LAST_MESSAGE = SysTime()
TIMEOUT_SECONDS_PER_TICK = 0.5

function ReceiveTimeoutMessage()
TIMEOUT_LAST_MESSAGE = SysTime()
end
usermessage.Hook(“TO”, ReceiveTimeoutMessage)

function IsServerTimedOut()
if SysTime()-TIMEOUT_LAST_MESSSAGE < TIMEOUT_SECONDS_PER_TICK+1 then
return true;
else
return false;
end
end
[/lua]

It sends 4 bytes of data in that usermessage. I think you’ll be OK.
This will detect if the server is timedout to a 1.5 second accuracy.

[editline]05:56PM[/editline]

Use http://www.facepunch.com/showthread.php?t=803617 by Spacetech to detect if a client has timed out or is timing out.

He wants to know if the server has timed out, not if a client has timed out. So that method wouldn’t work on other servers not running the script.

Does GAMEMODE:Shutdown( ) get called when the server times out and drops the client?

The above code is to tell when the server has timed out, check it again <3

Misread, but the issue still stands - if the server isn’t running the serverside code, the solution falls through.

Thanks Gbps, I could have done that myself too. I was just asking if there was an actual function or something. Usermessages just to see if the server is alive is not the pefect solution. I’ve checked the protocol, at a time when nothing is sent, and there is still a pingpong going on within the connection. So the client is perfectly capable of knowing when the server is not sending anything.
I was thinking of implementing something like TimeOut() which tells the seconds since last received message from server. This CAN be done with usermessages but if there’s a better alternative I would rather use it. Like Kogitsune said it would also be nice if it was purely clientside.

If nothing is found I’ll make a feature request to Garry.

Does CurTime() stop updating if the server crashed?

[LUA]
print(CurTime())
print(FrameTime() )
print(SysTime( ))
print(RealFrameTime())
print(UnPredictedCurTime())
hook.Add(‘CreateMove’,‘a’,function(a)
print(‘test4’)
hook.Remove(‘CreateMove’,‘a’)
end)
hook.Add(‘Tick’,‘a’,function()
print(‘test5’)
hook.Remove(‘Tick’,‘a’)
end)
hook.Add(‘Think’,‘a’,function()
print(‘test6’)
hook.Remove(‘Think’,‘a’)
end)


] lua_openscript_cl test.lua
257.08532714844
0.011554520577192
2081.4868164063
0.006591796875
257.08532714844
test4
test6
test5
] lua_openscript_cl test.lua
264.75674438477
0.010078665800393
2089.1591796875
0.007080078125
264.75674438477
test4
test6
test5
[/LUA]

Extra pingpong, here I come…