Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------- Configuration --------------------
- -- Defines delay before issuing a warning [seconds].
- -- Default: 180 (3 minutes)
- WarnTime = 180
- -- Defines interval between warning and kick [seconds].
- -- Default: 60 (1 minute)
- KickTime = 60
- -- Warning message text.
- WarningMessage = "^7Server is full, please join a team or you might get kicked."
- -- Shrubbot file.
- ShrubFile = "shrubbot.cfg"
- -- Starting level which from players are excluded from kicking.
- AdminLevel = 2
- -------------------------------------------------------
- players = {}
- admins = {}
- runFrameLast = 0
- maxClients = 64
- privateClients = 0
- serverFull = false
- function et_InitGame(levelTime, randomSeed, restart)
- et.RegisterModname("fsk.lua " .. et.FindSelf());
- runFrameLast = 0
- maxClients = tonumber(et.trap_Cvar_Get("sv_maxclients"))
- privateClients = tonumber(et.trap_Cvar_Get("sv_privateclients"))
- for clientNum = 0, maxClients - 1 do
- players[clientNum] = nil
- end
- local fd, len = et.trap_FS_FOpenFile(ShrubFile, et.FS_READ)
- local adminsCount = 0
- if len == -1 then
- et.G_Print("FSK: Failed to read shrubbot file.\n")
- else
- local content = et.trap_FS_Read(fd, len)
- for guid, level in string.gfind(content, "[Gg]uid%s*=%s*(%x+)%s*\n[Ll]evel%s*=%s*(%d+)") do
- guid = string.lower(guid)
- level = tonumber(level)
- if level >= AdminLevel then
- admins[guid] = true
- adminsCount = adminsCount + 1
- end
- end
- et.G_Print("FSK: Loaded " .. adminsCount .. " admins from shrubbot.\n")
- end
- et.trap_FS_FCloseFile( fd )
- end
- function et_ClientUserinfoChanged(clientNum)
- local team = tonumber(et.gentity_get(clientNum, "sess.sessionTeam"))
- if players[clientNum] == nil or players[clientNum].team ~= team then
- local userinfo = et.trap_GetUserinfo(clientNum)
- local password = et.Info_ValueForKey(userinfo, "password")
- local guid = et.Info_ValueForKey(userinfo, "cl_guid")
- local private = false
- local protected = false
- if password ~= "" and password == et.trap_Cvar_Get("sv_privatepassword") then
- private = true
- protected = true
- elseif guid ~= "" and admins[string.lower(guid)] ~= nil then
- protected = true
- end
- players[clientNum] = {team = team, joined = et.trap_Milliseconds(), warned = nil, protected = protected, private = private}
- end
- updateServerFull()
- end
- function et_ClientDisconnect(clientNum)
- players[clientNum] = nil
- updateServerFull()
- end
- function et_RunFrame(levelTime)
- if serverFull and runFrameLast + 5000 < levelTime then
- runFrameLast = levelTime
- local milliseconds = et.trap_Milliseconds()
- local kickClientNum = nil
- local kickMin = milliseconds
- for clientNum = 0, maxClients - 1 do
- if players[clientNum] ~= nil and players[clientNum].team == 3 and not players[clientNum].protected then
- if players[clientNum].warned == nil and players[clientNum].joined + WarnTime * 1000 < milliseconds then
- name = et.gentity_get(clientNum, "pers.netname")
- et.trap_SendConsoleCommand(et.EXEC_APPEND, "m \"" .. name .. "\" " .. WarningMessage .. "\n")
- players[clientNum].warned = milliseconds
- elseif players[clientNum].warned ~= nil and players[clientNum].warned + KickTime * 1000 < milliseconds then
- if kickMin > players[clientNum].joined then
- kickMin = players[clientNum].joined
- kickClientNum = clientNum
- end
- end
- end
- end
- if kickClientNum ~= nil then
- et.trap_SendConsoleCommand(et.EXEC_APPEND, "ref kick " .. kickClientNum .. "\n")
- end
- end
- end
- function updateServerFull()
- local count = 0
- for clientNum = 0, maxClients - 1 do
- if players[clientNum] ~= nil and not players[clientNum].private then
- count = count + 1
- end
- end
- if count >= maxClients - privateClients then
- serverFull = true
- else
- serverFull = false
- end
- end
Add Comment
Please, Sign In to add comment