A Don't Starve Together mod to kick high-latency people

This script will kick a player after five seconds of joining if their netscore is 2, which means their ping is 300 or above.

local function checkNetscore(userid)
	local netscore = 0
	local name = "Player"

	if userid then
		for k, v in ipairs(GLOBAL.TheNet:GetClientTable()) do
			if v.admin == false and v.userid == userid and v.netscore ~= nil then
				netscore = v.netscore
				name = v.name
			end
		end
	end

	if netscore >= 2 then
		GLOBAL.TheNet:Announce(name .. " was kicked because of a bad connection.")
		GLOBAL.TheNet:Kick(userid)
	end
end

local function playerSpawner(PlayerSpawner, inst)
	inst:ListenForEvent("ms_playerjoined", function(inst, player)
		inst:DoTaskInTime(5, function()
			checkNetscore(player.userid)
		end)
	end)
end

AddComponentPostInit("playerspawner", playerSpawner)

Comments