2022-06-26 22:37:31 +02:00
|
|
|
local Event = require 'utils.event'
|
|
|
|
local Server = require 'utils.server'
|
|
|
|
local Token = require 'utils.token'
|
|
|
|
|
2022-11-24 15:21:41 +01:00
|
|
|
local Public = {}
|
|
|
|
|
2022-06-26 23:40:56 +02:00
|
|
|
local ban_by_join_enabled = false
|
2022-06-26 22:37:31 +02:00
|
|
|
|
|
|
|
local try_get_ban = Server.try_get_ban
|
|
|
|
|
2022-11-29 15:35:42 +01:00
|
|
|
local valid_commands = {
|
|
|
|
['ban'] = true,
|
|
|
|
['unban'] = true
|
|
|
|
}
|
|
|
|
|
2022-06-26 22:37:31 +02:00
|
|
|
local try_get_is_banned_token =
|
|
|
|
Token.register(
|
|
|
|
function(data)
|
|
|
|
if not data then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local username = data.username
|
|
|
|
if not username then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local state = data.state
|
|
|
|
|
|
|
|
if state == true then
|
|
|
|
game.ban_player(data.username, data.reason)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Event.add(
|
|
|
|
defines.events.on_player_joined_game,
|
|
|
|
function(event)
|
2022-06-26 23:40:56 +02:00
|
|
|
if not ban_by_join_enabled then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-06-26 23:33:27 +02:00
|
|
|
local player = game.get_player(event.player_index)
|
2022-06-26 22:37:31 +02:00
|
|
|
if not player or not player.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local secs = Server.get_current_time()
|
|
|
|
if secs == nil then
|
|
|
|
return
|
|
|
|
else
|
|
|
|
try_get_ban(player.name, try_get_is_banned_token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Event.add(
|
|
|
|
defines.events.on_console_command,
|
|
|
|
function(event)
|
2022-11-29 15:35:42 +01:00
|
|
|
if valid_commands[event.command] then
|
|
|
|
Server.ban_handler(event)
|
|
|
|
end
|
2022-06-26 22:37:31 +02:00
|
|
|
end
|
|
|
|
)
|
2022-11-24 15:21:41 +01:00
|
|
|
|
|
|
|
return Public
|