Fix crash on player joining
parent
83d48fe2cb
commit
4a815cd04e
44
init.lua
44
init.lua
|
@ -7,7 +7,7 @@ to this software to the public domain worldwide. This software is
|
|||
distributed without any warranty.
|
||||
]]
|
||||
|
||||
local MAX_INACTIVE_TIME = 300
|
||||
local MAX_INACTIVE_TIME = 20
|
||||
local CHECK_INTERVAL = 1
|
||||
local WARN_TIME = 20
|
||||
|
||||
|
@ -36,30 +36,32 @@ minetest.register_globalstep(function(dtime)
|
|||
--Loop through each player in players
|
||||
for playerName,_ in pairs(players) do
|
||||
local player = minetest.get_player_by_name(playerName)
|
||||
if player then
|
||||
|
||||
--Check for inactivity once every CHECK_INTERVAL seconds
|
||||
checkTimer = checkTimer + dtime
|
||||
if checkTimer > CHECK_INTERVAL then
|
||||
checkTimer = 0
|
||||
--Check for inactivity once every CHECK_INTERVAL seconds
|
||||
checkTimer = checkTimer + dtime
|
||||
if checkTimer > CHECK_INTERVAL then
|
||||
checkTimer = 0
|
||||
|
||||
--Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
||||
print(dump(players[playerName]["lastAction"]))
|
||||
print(dump(currGameTime))
|
||||
print(dump(MAX_INACTIVE_TIME))
|
||||
minetest.kick_player(playerName, "Kicked for inactivity")
|
||||
--Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
||||
print(dump(players[playerName]["lastAction"]))
|
||||
print(dump(currGameTime))
|
||||
print(dump(MAX_INACTIVE_TIME))
|
||||
minetest.kick_player(playerName, "Kicked for inactivity")
|
||||
end
|
||||
|
||||
--Warn player if he/she has less than WARN_TIME seconds to move or be kicked
|
||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
|
||||
minetest.chat_send_player(playerName, "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked")
|
||||
end
|
||||
end
|
||||
|
||||
--Warn player if he/she has less than WARN_TIME seconds to move or be kicked
|
||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
|
||||
minetest.chat_send_player(playerName, "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked")
|
||||
end
|
||||
end
|
||||
|
||||
--Check if this player is doing an action
|
||||
for _,keyPressed in pairs(player:get_player_control()) do
|
||||
if keyPressed then
|
||||
players[playerName]["lastAction"] = currGameTime
|
||||
--Check if this player is doing an action
|
||||
for _,keyPressed in pairs(player:get_player_control()) do
|
||||
if keyPressed then
|
||||
players[playerName]["lastAction"] = currGameTime
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue