Guest User

Untitled

a guest
Dec 12th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. -------------------- Configuration --------------------
  2. -- Defines delay before issuing a warning [seconds].
  3. -- Default: 180 (3 minutes)
  4. WarnTime = 180
  5. -- Defines interval between warning and kick [seconds].
  6. -- Default: 60 (1 minute)
  7. KickTime = 60
  8. -- Warning message text.
  9. WarningMessage = "^7Server is full, please join a team or you might get kicked."
  10. -- Shrubbot file.
  11. ShrubFile = "shrubbot.cfg"
  12. -- Starting level which from players are excluded from kicking.
  13. AdminLevel = 2
  14. -------------------------------------------------------
  15.  
  16. players = {}
  17. admins = {}
  18. runFrameLast = 0
  19. maxClients = 64
  20. privateClients = 0
  21. serverFull = false
  22.  
  23. function et_InitGame(levelTime, randomSeed, restart)
  24.  
  25. et.RegisterModname("fsk.lua " .. et.FindSelf());
  26.  
  27. runFrameLast = 0
  28. maxClients = tonumber(et.trap_Cvar_Get("sv_maxclients"))
  29. privateClients = tonumber(et.trap_Cvar_Get("sv_privateclients"))
  30.  
  31. for clientNum = 0, maxClients - 1 do
  32. players[clientNum] = nil
  33. end
  34.  
  35. local fd, len = et.trap_FS_FOpenFile(ShrubFile, et.FS_READ)
  36. local adminsCount = 0
  37.  
  38. if len == -1 then
  39. et.G_Print("FSK: Failed to read shrubbot file.\n")
  40. else
  41.  
  42. local content = et.trap_FS_Read(fd, len)
  43.  
  44. for guid, level in string.gfind(content, "[Gg]uid%s*=%s*(%x+)%s*\n[Ll]evel%s*=%s*(%d+)") do
  45. guid = string.lower(guid)
  46. level = tonumber(level)
  47. if level >= AdminLevel then
  48. admins[guid] = true
  49. adminsCount = adminsCount + 1
  50. end
  51. end
  52.  
  53. et.G_Print("FSK: Loaded " .. adminsCount .. " admins from shrubbot.\n")
  54.  
  55. end
  56.  
  57. et.trap_FS_FCloseFile( fd )
  58.  
  59. end
  60.  
  61. function et_ClientUserinfoChanged(clientNum)
  62.  
  63. local team = tonumber(et.gentity_get(clientNum, "sess.sessionTeam"))
  64.  
  65. if players[clientNum] == nil or players[clientNum].team ~= team then
  66.  
  67. local userinfo = et.trap_GetUserinfo(clientNum)
  68. local password = et.Info_ValueForKey(userinfo, "password")
  69. local guid = et.Info_ValueForKey(userinfo, "cl_guid")
  70.  
  71. local private = false
  72. local protected = false
  73.  
  74. if password ~= "" and password == et.trap_Cvar_Get("sv_privatepassword") then
  75. private = true
  76. protected = true
  77. elseif guid ~= "" and admins[string.lower(guid)] ~= nil then
  78. protected = true
  79. end
  80.  
  81. players[clientNum] = {team = team, joined = et.trap_Milliseconds(), warned = nil, protected = protected, private = private}
  82.  
  83. end
  84.  
  85. updateServerFull()
  86.  
  87. end
  88.  
  89. function et_ClientDisconnect(clientNum)
  90. players[clientNum] = nil
  91. updateServerFull()
  92. end
  93.  
  94. function et_RunFrame(levelTime)
  95.  
  96. if serverFull and runFrameLast + 5000 < levelTime then
  97.  
  98. runFrameLast = levelTime
  99.  
  100. local milliseconds = et.trap_Milliseconds()
  101. local kickClientNum = nil
  102. local kickMin = milliseconds
  103.  
  104. for clientNum = 0, maxClients - 1 do
  105. if players[clientNum] ~= nil and players[clientNum].team == 3 and not players[clientNum].protected then
  106. if players[clientNum].warned == nil and players[clientNum].joined + WarnTime * 1000 < milliseconds then
  107.  
  108. name = et.gentity_get(clientNum, "pers.netname")
  109. et.trap_SendConsoleCommand(et.EXEC_APPEND, "m \"" .. name .. "\" " .. WarningMessage .. "\n")
  110. players[clientNum].warned = milliseconds
  111.  
  112. elseif players[clientNum].warned ~= nil and players[clientNum].warned + KickTime * 1000 < milliseconds then
  113.  
  114. if kickMin > players[clientNum].joined then
  115. kickMin = players[clientNum].joined
  116. kickClientNum = clientNum
  117. end
  118.  
  119. end
  120. end
  121. end
  122.  
  123. if kickClientNum ~= nil then
  124. et.trap_SendConsoleCommand(et.EXEC_APPEND, "ref kick " .. kickClientNum .. "\n")
  125. end
  126.  
  127. end
  128.  
  129. end
  130.  
  131. function updateServerFull()
  132.  
  133. local count = 0
  134.  
  135. for clientNum = 0, maxClients - 1 do
  136. if players[clientNum] ~= nil and not players[clientNum].private then
  137. count = count + 1
  138. end
  139. end
  140.  
  141. if count >= maxClients - privateClients then
  142. serverFull = true
  143. else
  144. serverFull = false
  145. end
  146.  
  147. end
Add Comment
Please, Sign In to add comment