2019-01-17 01:55:19 +02:00
|
|
|
local Command = require 'utils.command'
|
|
|
|
local Task = require 'utils.task'
|
|
|
|
local Token = require 'utils.token'
|
|
|
|
local Server = require 'features.server'
|
|
|
|
local Popup = require 'features.gui.popup'
|
|
|
|
local Global = require 'utils.global'
|
2019-01-30 05:52:43 +02:00
|
|
|
local Ranks = require 'resources.ranks'
|
2019-01-17 01:55:19 +02:00
|
|
|
|
|
|
|
local server_player = {name = '<server>', print = print}
|
|
|
|
|
|
|
|
local global_data = {restarting = nil}
|
|
|
|
|
|
|
|
Global.register(
|
|
|
|
global_data,
|
|
|
|
function(tbl)
|
|
|
|
global_data = tbl
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
local function double_print(str)
|
|
|
|
game.print(str)
|
|
|
|
print(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
local callback
|
|
|
|
callback =
|
|
|
|
Token.register(
|
|
|
|
function(data)
|
|
|
|
if not global_data.restarting then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local state = data.state
|
|
|
|
if state == 0 then
|
|
|
|
Server.start_scenario(data.scenario_name)
|
|
|
|
double_print('restarting')
|
|
|
|
return
|
|
|
|
elseif state == 1 then
|
|
|
|
Popup.all('\nServer restarting!\nInitiated by ' .. data.name .. '\n')
|
|
|
|
end
|
|
|
|
|
|
|
|
double_print(state)
|
|
|
|
|
|
|
|
data.state = state - 1
|
|
|
|
Task.set_timeout_in_ticks(60, callback, data)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
2019-03-04 00:13:56 +02:00
|
|
|
'crash-site-restart',
|
2019-01-17 01:55:19 +02:00
|
|
|
{
|
2019-03-05 17:34:32 +02:00
|
|
|
description = {'command_description.crash_site_restart'},
|
|
|
|
arguments = {'scenario_name'},
|
2019-01-17 01:55:19 +02:00
|
|
|
default_values = {scenario_name = 'crashsite'},
|
2019-01-30 05:52:43 +02:00
|
|
|
required_rank = Ranks.admin,
|
2019-01-17 01:55:19 +02:00
|
|
|
allowed_by_server = true
|
|
|
|
},
|
|
|
|
function(args, player)
|
2019-01-19 18:34:29 +02:00
|
|
|
player = player or server_player
|
2019-01-17 01:55:19 +02:00
|
|
|
|
|
|
|
if global_data.restarting then
|
|
|
|
player.print('Restart already in progress')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
global_data.restarting = true
|
|
|
|
|
|
|
|
double_print('#################-Attention-#################')
|
|
|
|
double_print('Server restart initiated by ' .. player.name)
|
|
|
|
double_print('###########################################')
|
|
|
|
|
|
|
|
for k, v in pairs(game.players) do
|
|
|
|
if v.admin then
|
|
|
|
game.print('Abort restart with /abort')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print('Abort restart with /abort')
|
|
|
|
|
|
|
|
Task.set_timeout_in_ticks(60, callback, {name = player.name, scenario_name = args.scenario_name, state = 10})
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
2019-03-04 00:13:56 +02:00
|
|
|
'crash-site-restart-abort',
|
2019-01-17 01:55:19 +02:00
|
|
|
{
|
2019-03-04 00:13:56 +02:00
|
|
|
description = {'command_description.crash_site_restart_abort'},
|
2019-01-30 05:52:43 +02:00
|
|
|
required_rank = Ranks.admin,
|
2019-01-17 01:55:19 +02:00
|
|
|
allowed_by_server = true
|
|
|
|
},
|
|
|
|
function(_, player)
|
2019-01-19 18:34:29 +02:00
|
|
|
player = player or server_player
|
2019-01-17 01:55:19 +02:00
|
|
|
|
|
|
|
if global_data.restarting then
|
|
|
|
global_data.restarting = nil
|
|
|
|
double_print('Restart aborted by ' .. player.name)
|
|
|
|
else
|
|
|
|
player.print('Cannot abort a restart that is not in progress.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|