gmsv_timeout - Check if a player is timing out

This small library is useful for handling players who are crashing / timing out.


Functions

[lua]
Player:IsTimingOut() - (Bool) Check if a player is marked as timing out
Player:GetTimeSinceLastReceived() - (Float) Get the time since the last recieved packet in seconds
INET_TIMEOUT_SECONDS - Global variable with the default timeout time in seconds (180)
[/lua]


Download

Source: http://spacetechmodules.googlecode.com/svn/trunk/gmsv_timeout/gmsv_timeout
Windows: http://spacetechmodules.googlecode.com/svn/trunk/gmsv_timeout/Release/gmsv_timeout.dll


Example

  • This example kicks players who are timing out after 10 seconds
    [lua]
    require(“timeout”)

timer.Create(“Timeout”, 1, 0, function()
for k,v in pairs(player.GetAll()) do
if(v:IsTimingOut() and v:GetTimeSinceLastReceived() > 10) then
v:Kick(“Timed Out”)
end
end
end)
[/lua]

Neat. Would have helped with an issue I had ages ago, why couldn’t you have posted this then? D:

Nice, this will certainly be helpful somewhere.

Isn’t there sv_timeout on the orangebox engine anymore?

Oh nice, another piece for my binary modules collection. :smiley:

sv_timeout 10 does the same thing?

Well you might not want to kick them, you might just want to set them as afk or kill them to end a round. Sure you could just do that but this library is for controlling timeout’s from lua.

This is a pure Lua way to do pretty much the same thing:

[lua]if ( SERVER ) then
timer.Create( “Ping”, 10, 0, function ( )
umsg.Start( “Ping” )
umsg.End( )

	for _, pl in pairs( player.GetAll( ) ) do
		if ( CurTime( ) - pl.LastResponse > 10 ) then
			pl:Kick( "Timed out." )
		end
	end
end )

hook.Add( "PlayerInitialSpawn", "PingInit", function( ply )
	pl.LastResponse = CurTime( )
end )

concommand.Add( "Pong", function( ply, com, args )
	ply.LastResponse = CurTime( )
end )

else
usermessage.Hook( “Ping”, function( um )
RunConsoleCommand( “Pong” )
end )
end[/lua]

(Not tested) Not trying to make this look bad, just saying it can also be done without a module without too much code.

User will get kicked if he doesn’t get the lua. Consumes unnecessary bandwidth. gmsv_timeout is(/seems to be) also accurate.
I think gmsv_timeout does it a lot better and uses source’s internal timeout check mechanism, what else could we wish for?
The module isn’t really even bothering me as this is server side.

Why would he not get the Lua? Also, the two * player amount packets each 10 seconds are nothing compared to what’s transferred every second. And what’s inaccurate about it?

Interesting. This might be useful for me.

There has been happening some random lua download droppings what I have heard. I can’t even get to some servers because it gives me “failed to update dua files” so I have to turn off lua download to be able to even join the server, which is most often naturally unusable. This would nail me too.
And why generate extra traffic if it’s not necessary?
Accuracy is not necessary a good thing, but that GetTimeSinceLastReceived gives extreme amount of decimals for example.

Why the hell would you need microsecond accuracy for a timeout kicker? Besides, the extra traffic is so low it’s like it doesn’t exist. I for one would rather use a Lua script than a much bigger .dll file.

Like I said accuracy is not necessary a good thing, but it doesnt hurt if you can get the timeout’s start in 1/4 second accuracy.
I for one prefer a “clean” way of extending Garry’s Mod. File size is not everything. We should do some testing which one consumes less CPU for example. But really, it’s in 1/1000 second difference I bet so there is really no reason to do that.
And I still dont understand the reason behind yet another pingpong between the client and server when you can just use the internal pingpong features.

In the end I just dont understand why we couldn’t use what was already done but not exposed to lua. I think your mind would change if garry added the bindings for this feature, which I think he should.

Overv’s method is better for any gamemode other than Sandbox, as then you know people are downloading your files (Anticheats, gamemode files, etc) Still a neat module though.

No, I would want them out of the server ASAP before Source’s shitty networking starts lagging the entire server and then I’d make an AFK checker with KeyPress and looking for gui.MousePos changing.

I used to have sv_timeout set to default, whatever it was, I think 3 minutes (20 seconds now). Every time there was a mass client crash due to a broken map or something, the server would lag and sometimes even trigger the auto-restart script to run because the server wouldn’t respond due to being so laggy. Try it. Broadcast some lua to crash a few clients (10 or so) and watch the remaining pings go to 800.

Unfortunately, you’re right, some modules are great in an aspect of development , but as far as practicality, I don’t see how this can be legitimately used, when I can just add some new meta hooks based on response times.

Which means, you could, in theory, attack a server into restarting by having many different clients crashing, like a botnet.

_R.Player.IsTimingOut(NULL) – crash

Please add error checking since I can make this crash the server even if IsValid() returns true on players.GetAll() at a certain stage.

Updated Module, check first post.
It will return nil if the player is invalid.