From 08b54e44afc59848f60266daf14d65d36aa70320 Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 20:34:18 +0100 Subject: [PATCH 1/7] Added jail to playerlist report for admins and toggle jail in showreports --- features/gui/player_list.lua | 7 +++++-- features/report.lua | 36 +++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/features/gui/player_list.lua b/features/gui/player_list.lua index a422ff96..611f2020 100644 --- a/features/gui/player_list.lua +++ b/features/gui/player_list.lua @@ -752,7 +752,10 @@ Gui.on_click( function(event) local reporting_player = event.player local reported_player = Gui.get_data(event.element) - - Report.spawn_reporting_popup(reporting_player, reported_player) + if reporting_player.admin then + Report.jail(reported_player, reporting_player) + else + Report.spawn_reporting_popup(reporting_player, reported_player) + end end ) diff --git a/features/report.lua b/features/report.lua index 2467dae3..4669537c 100644 --- a/features/report.lua +++ b/features/report.lua @@ -9,13 +9,13 @@ local report_close_button_name = Gui.uid_name() local report_tab_button_name = Gui.uid_name() local jail_offender_button_name = Gui.uid_name() local report_body_name = Gui.uid_name() +local jail_name = 'Jail' local prefix = '------------------NOTICE-------------------' local prefix_e = '--------------------------------------------' global.reports = {} global.player_report_data = {} - local function draw_report(parent, report_id) local report = global.reports[report_id] if report_id == 0 or not report then @@ -34,11 +34,14 @@ local function draw_report(parent, report_id) local message = report.message Gui.clear(parent) + local permission_group = game.permissions.get_group(jail_name) + local jail_offender_button_caption = (Game.get_player_by_index(report.reported_player_index).permission_group == permission_group) and 'Unjail ' .. reported_player_name or 'Jail ' .. reported_player_name + parent.add {type="label", caption="Offender: " .. reported_player_name} local msg_label_pane = parent.add {type="scroll-pane", vertical_scroll_policy = "auto-and-reserve-space", horizontal_scroll_policy="never"} msg_label_pane.style.maximal_height = 400 local msg_label = msg_label_pane.add {type="label", caption="Message: " .. message} - local jail_offender_button = parent.add {type = 'button', name = jail_offender_button_name, caption = 'Jail ' .. reported_player_name} + local jail_offender_button = parent.add {type = 'button', name = jail_offender_button_name, caption = jail_offender_button_caption} jail_offender_button.style.height = 24 jail_offender_button.style.font = 'default-small' jail_offender_button.style.top_padding = 0 @@ -137,7 +140,6 @@ end -- Places a target in jail as long as player is admin or server function Module.jail(target_player, player) -- Set the name of the jail permission group - local jail_name = 'Jail' local print local jailed_by @@ -160,6 +162,11 @@ function Module.jail(target_player, player) local permission_group = permissions.get_group(jail_name) if not permission_group then permission_group = permissions.create_group(jail_name) + + -- Set all permissions to disabled + for action_name, _ in pairs(defines.input_action) do + permission_group.set_allows_action(defines.input_action[action_name], false) + end end if target_player.permission_group == permission_group then @@ -167,10 +174,6 @@ function Module.jail(target_player, player) return end - -- Set all permissions to disabled - for action_name, _ in pairs(defines.input_action) do - permission_group.set_allows_action(defines.input_action[action_name], false) - end -- Enable writing to console to allow a person to speak permission_group.set_allows_action(defines.input_action.write_to_console, true) permission_group.set_allows_action(defines.input_action.edit_permission_group, true) @@ -187,11 +190,11 @@ function Module.jail(target_player, player) -- Check that it worked if target_player.permission_group == permission_group then -- Let admin know it worked, let target know what's going on. - print(target_player.name .. ' has been jailed. They have been advised of this.') target_player.print(prefix) target_player.print('You have been placed in jail by ' .. jailed_by .. '. The only action avaliable to you is chatting.') target_player.print('Please respond to inquiries from the admins.', {r = 1, g = 1, b = 0, a = 1}) - Utils.print_admins(target_player.name .. 'has been jailed by' .. player.name) + target_player.print(prefix_e) + Utils.print_admins(target_player.name .. ' has been jailed by ' .. player.name) Utils.log_command(player, 'jail', target_player.name) else -- Let admin know it didn't work. @@ -201,11 +204,13 @@ end function Module.unjail_player(cmd) local default_group = 'Default' - local player = game.player + local player = game.player ~= nil and game.player or cmd['player'] -- Check if the player can run the command if player and not player.admin then Utils.cant_run(cmd.name) return + elseif not player then + player = 'Server' end -- Check if the target is valid (copied from the invoke command) local target = cmd['parameter'] @@ -246,6 +251,8 @@ function Module.unjail_player(cmd) target_player.print(prefix) target_player.print('Your ability to perform actions has been restored', {r = 0, g = 1, b = 0, a = 1}) target_player.print(prefix_e) + Utils.print_admins(target_player.name .. ' has been set free by ' .. player.name) + Utils.log_command(player, 'unjail', target_player.name) else -- Let admin know it didn't work. Game.player_print( @@ -274,7 +281,14 @@ Gui.on_click( function(event) local target_name = string.sub(event.element.caption, 6) local target = game.players[target_name] - Module.jail(target, event.player) + if target then + Module.jail(target, event.player) + else + target_name = string.sub(event.element.caption, 8) + Module.unjail_player({['parameter'] = target_name, ['player'] = event.player}) + end + Module.show_reports(event.player) + Module.show_reports(event.player) -- Double toggle, first destroy then draw. end ) From 11038fcda28ccae4ba44fd6caea243db10b08ebb Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 21:13:45 +0100 Subject: [PATCH 2/7] Attempt to fix server crash on server jail/unjail --- features/report.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/report.lua b/features/report.lua index 4669537c..a6063452 100644 --- a/features/report.lua +++ b/features/report.lua @@ -148,6 +148,7 @@ function Module.jail(target_player, player) print = player.print else jailed_by = "script for causing too many collapses" + player.name = 'server' print = log end @@ -210,7 +211,7 @@ function Module.unjail_player(cmd) Utils.cant_run(cmd.name) return elseif not player then - player = 'Server' + player.name = 'Server' end -- Check if the target is valid (copied from the invoke command) local target = cmd['parameter'] From 3876402e876c26ae8a49d9995e5d16498f94561e Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 21:23:19 +0100 Subject: [PATCH 3/7] Second attempt to fix server crash --- features/report.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/report.lua b/features/report.lua index a6063452..c74c3410 100644 --- a/features/report.lua +++ b/features/report.lua @@ -148,7 +148,7 @@ function Module.jail(target_player, player) print = player.print else jailed_by = "script for causing too many collapses" - player.name = 'server' + player = {name = 'server'} print = log end @@ -211,7 +211,7 @@ function Module.unjail_player(cmd) Utils.cant_run(cmd.name) return elseif not player then - player.name = 'Server' + player = {name = 'Server'} end -- Check if the target is valid (copied from the invoke command) local target = cmd['parameter'] From 0e6ba3e2cb0a9eabc10329dfbcf62ee2fef921a1 Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 21:24:35 +0100 Subject: [PATCH 4/7] Prevents walking when jailed --- features/report.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/report.lua b/features/report.lua index c74c3410..f0af6838 100644 --- a/features/report.lua +++ b/features/report.lua @@ -188,6 +188,10 @@ function Module.jail(target_player, player) target_player.shooting_state.state = {state = defines.shooting.not_shooting, position = {0,0}} end + if jail_target.walking_state.walking == true -- Stop them walking while jailed + jail_target.walking_state = {walking = false, direction = defines.direction.north} + end + -- Check that it worked if target_player.permission_group == permission_group then -- Let admin know it worked, let target know what's going on. From 662398069d7a16661d52fea4e16cbf9c7a33b851 Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 21:29:05 +0100 Subject: [PATCH 5/7] changed output --- features/report.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/report.lua b/features/report.lua index f0af6838..b9da249d 100644 --- a/features/report.lua +++ b/features/report.lua @@ -147,8 +147,8 @@ function Module.jail(target_player, player) jailed_by = "a server admin" print = player.print else - jailed_by = "script for causing too many collapses" player = {name = 'server'} + jailed_by = "the server" print = log end @@ -215,7 +215,7 @@ function Module.unjail_player(cmd) Utils.cant_run(cmd.name) return elseif not player then - player = {name = 'Server'} + player = {name = 'server'} end -- Check if the target is valid (copied from the invoke command) local target = cmd['parameter'] From 8e770f60527778669195ea1121d3226eb601b509 Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 21:45:02 +0100 Subject: [PATCH 6/7] Setting shooting state seems not to work. Locks the player into shooting. Moved the logic above the permission setting --- features/report.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/features/report.lua b/features/report.lua index b9da249d..0d1d24b7 100644 --- a/features/report.lua +++ b/features/report.lua @@ -181,17 +181,19 @@ function Module.jail(target_player, player) -- Kick player out of vehicle target_player.driving=false - -- Add player to jail group - permission_group.add_player(target_player) + -- If a player is shooting when they're jailed they can't stop shooting, so we change their shooting state if target_player.shooting_state.state ~= 0 then target_player.shooting_state.state = {state = defines.shooting.not_shooting, position = {0,0}} end - if jail_target.walking_state.walking == true -- Stop them walking while jailed - jail_target.walking_state = {walking = false, direction = defines.direction.north} + if jail_target.walking_state.walking == true then -- Stop them walking while jailed + jail_target.walking_state = {walking = false, direction = defines.direction.north} end + -- Add player to jail group + permission_group.add_player(target_player) + -- Check that it worked if target_player.permission_group == permission_group then -- Let admin know it worked, let target know what's going on. From 4ef7de7898e9678d1bbe164b4e0728f3dd1c2dae Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Sun, 18 Nov 2018 21:49:43 +0100 Subject: [PATCH 7/7] "Go to bed simon" --- features/report.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/report.lua b/features/report.lua index 0d1d24b7..f6f97848 100644 --- a/features/report.lua +++ b/features/report.lua @@ -187,8 +187,8 @@ function Module.jail(target_player, player) target_player.shooting_state.state = {state = defines.shooting.not_shooting, position = {0,0}} end - if jail_target.walking_state.walking == true then -- Stop them walking while jailed - jail_target.walking_state = {walking = false, direction = defines.direction.north} + if target_player.walking_state.walking == true then -- Stop them walking while jailed + target_player.walking_state = {walking = false, direction = defines.direction.north} end -- Add player to jail group