Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin panel #1432

Merged
merged 14 commits into from
Sep 2, 2024
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ stds.factorio_defines = {
'on_gui_elem_changed',
'on_gui_opened',
'on_gui_selection_state_changed',
'on_gui_switch_state_changed',
'on_gui_text_changed',
'on_gui_value_changed',
'on_land_mine_armed',
Expand Down
3 changes: 3 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ global.config = {
clear_corpses = true,
battery_charge = true,
}
},
admin_panel = {
enabled = true,
}
}

Expand Down
5 changes: 5 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ if config.map_info.enabled then
require 'features.gui.info'
require 'features.gui.description_generator'
end
if config.admin_panel.enabled then
require 'features.gui.admin_panel.player_manager'
require 'features.gui.admin_panel.map_manager'
require 'features.gui.admin_panel.lua_console'
end
if config.player_list.enabled then
require 'features.gui.player_list'
end
Expand Down
84 changes: 52 additions & 32 deletions features/admin_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Global.register(
)

--- Informs the actor that there is no target. Acts as a central place where this message can be changed.
local function print_no_target(target_name)
Game.player_print({'common.fail_no_target', target_name}, Color.fail)
local function print_no_target(target_name, player)
Game.player_print({'common.fail_no_target', target_name}, Color.fail, player)
end

local function know_player_or_rerun(player_name, actor, command_name)
Expand All @@ -38,7 +38,7 @@ local function know_player_or_rerun(player_name, actor, command_name)
return true;
end

Game.player_print({'common.rerun_no_target', player_name}, Color.fail)
Game.player_print({'common.rerun_no_target', player_name}, Color.fail, actor)
return false
end

Expand All @@ -57,21 +57,21 @@ end
--- Toggles cheat mode for a player
local function toggle_cheat_mode(_, player)
player.cheat_mode = not player.cheat_mode
Game.player_print({'admin_commands.toggle_cheat_mode', tostring(player.cheat_mode)})
Game.player_print({'admin_commands.toggle_cheat_mode', tostring(player.cheat_mode)}, nil, player)
end

--- Promote someone to regular
local function add_regular(args)
local function add_regular(args, player)
local target_name = args.player
local maybe_target_player = game.get_player(target_name)
local actor = Utils.get_actor()
local actor = args.actor or Utils.get_actor()

if not maybe_target_player and not know_player_or_rerun(target_name, actor, 'regular') then
return
end

if Rank.less_than(target_name, Ranks.guest) then
Game.player_print({'admin_commands.regular_add_fail_probation'}, Color.fail)
Game.player_print({'admin_commands.regular_add_fail_probation'}, Color.fail, player)
return
end

Expand All @@ -82,15 +82,15 @@ local function add_regular(args)
maybe_target_player.print({'admin_commands.regular_add_notify_target'}, Color.warning)
end
else
Game.player_print({'admin_commands.regular_add_fail', target_name, Rank.get_player_rank_name(target_name)}, Color.fail)
Game.player_print({'admin_commands.regular_add_fail', target_name, Rank.get_player_rank_name(target_name)}, Color.fail, player)
end
end

--- Demote someone from regular
local function remove_regular(args)
local function remove_regular(args, player)
local target_name = args.player
local maybe_target_player = game.get_player(target_name)
local actor = Utils.get_actor()
local actor = args.actor or Utils.get_actor()

if not maybe_target_player and not know_player_or_rerun(target_name, actor, 'regular-remove') then
return
Expand All @@ -104,22 +104,22 @@ local function remove_regular(args)
end
else
local rank_name = Rank.get_player_rank_name(target_name)
Game.player_print({'admin_commands.regular_remove_fail', target_name, rank_name}, Color.fail)
Game.player_print({'admin_commands.regular_remove_fail', target_name, rank_name}, Color.fail, player)
end
end

--- Put someone on probation
local function probation_add(args)
local function probation_add(args, player)
local target_name = args.player
local maybe_target_player = game.get_player(target_name)
local actor = Utils.get_actor()
local actor = args.actor or Utils.get_actor()

if not maybe_target_player and not know_player_or_rerun(target_name, actor, 'probation') then
return
end

if Rank.equal(target_name, Ranks.admin) then
Game.player_print({'admin_commands.probation_add_fail_admin'}, Color.fail)
Game.player_print({'admin_commands.probation_add_fail_admin'}, Color.fail, player)
if maybe_target_player then
maybe_target_player.print({'admin_commands.probation_warn_admin', actor}, Color.warning)
end
Expand All @@ -133,15 +133,15 @@ local function probation_add(args)
maybe_target_player.print({'admin_commands.probation_add_notify_target'}, Color.warning)
end
else
Game.player_print({'admin_commands.probation_add_fail', target_name}, Color.fail)
Game.player_print({'admin_commands.probation_add_fail', target_name}, Color.fail, player)
end
end

--- Remove someone from probation
local function probation_remove(args)
local function probation_remove(args, player)
local target_name = args.player
local maybe_target_player = game.get_player(target_name)
local actor = Utils.get_actor()
local actor = args.actor or Utils.get_actor()

if not maybe_target_player and not know_player_or_rerun(target_name, actor, 'probation-remove') then
return
Expand All @@ -154,7 +154,7 @@ local function probation_remove(args)
maybe_target_player.print({'admin_commands.probation_remove_notify_target'}, Color.warning)
end
else
Game.player_print({'admin_commands.probation_remove_fail', target_name}, Color.fail)
Game.player_print({'admin_commands.probation_remove_fail', target_name}, Color.fail, player)
end
end

Expand All @@ -169,7 +169,7 @@ local function jail_player(args, player)
local target = Utils.validate_player(target_ident)

if not target then
print_no_target(target_ident)
print_no_target(target_ident, player)
return
end

Expand All @@ -182,7 +182,7 @@ local function unjail_player(args, player)
local target = Utils.validate_player(target_ident)

if not target then
print_no_target(target_ident)
print_no_target(target_ident, player)
return
end
Report.unjail(target, player)
Expand All @@ -199,6 +199,7 @@ local function pool(_, player)
end
player.surface.set_tiles(t)
player.surface.create_entity {name = 'fish', position = {p.x + 0.5, p.y + 5}}
Game.player_print({'admin_commands.create_pool'}, Color.success, player)
end

--- Takes a target and teleports them to player
Expand All @@ -207,13 +208,13 @@ local function invoke(args, player)
local target = Utils.validate_player(target_ident)

if not target then
print_no_target(target_ident)
print_no_target(target_ident, player)
return
end

local pos = player.surface.find_non_colliding_position('character', player.position, 50, 1)
if not pos then
Game.player_print({'admin_commands.invoke_fail_no_location'})
Game.player_print({'admin_commands.invoke_fail_no_location'}, player)
return
end
target.teleport({pos.x, pos.y}, player.surface)
Expand All @@ -226,35 +227,35 @@ local function teleport_player(args, player)
local target = Utils.validate_player(target_ident)

if not target then
print_no_target(target_ident)
print_no_target(target_ident, player)
return
end

local target_name = target.name
local surface = target.surface
local pos = surface.find_non_colliding_position('character', target.position, 50, 1)
if not pos then
Game.player_print({'admin_commands.tp_fail_no_location'})
Game.player_print({'admin_commands.tp_fail_no_location'}, Color.fail, player)
return
end
player.teleport(pos, surface)
game.print({'admin_commands.tp_player_announce', target_name})
Game.player_print({'admin_commands.tp_player_success', target_name})
Game.player_print({'admin_commands.tp_player_success', target_name}, Color.success, player)
end

--- Takes a selected entity and teleports player to it
local function teleport_location(_, player)
if not player.selected then
Game.player_print({'admin_commands.tp_ent_fail_no_ent'})
Game.player_print({'admin_commands.tp_ent_fail_no_ent'}, Color.fail, player)
return
end
local pos = player.surface.find_non_colliding_position('character', player.selected.position, 50, 1)
if not pos then
Game.player_print({'admin_commands.tp_fail_no_location'})
Game.player_print({'admin_commands.tp_fail_no_location'}, Color.fail, player)
return
end
player.teleport(pos)
Game.player_print({'admin_commands.tp_end_success'})
Game.player_print({'admin_commands.tp_end_success'}, Color.success, player)
end

--- If a player is in the tp_players list, remove ghosts they place and teleport them to that position
Expand All @@ -280,10 +281,10 @@ local function toggle_tp_mode(_, player)

if toggled then
tp_players[index] = nil
Game.player_print({'admin_commands.tp_mode_off'})
Game.player_print({'admin_commands.tp_mode_off'}, nil, player)
else
tp_players[index] = true
Game.player_print({'admin_commands.tp_mode_on'})
Game.player_print({'admin_commands.tp_mode_on'}, nil, player)
end
end

Expand All @@ -303,19 +304,22 @@ end
local function revive_ghosts(args, player)
local radius = args.radius
local pos = player.position
local count = 0
for _, e in pairs(player.surface.find_entities_filtered {area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}, type = 'entity-ghost'}) do
e.revive()
count = count + 1
end
Game.player_print({'admin_commands.revive_ghosts', count}, Color.success, player)
end

--- Destroys the player's selected entity
local function destroy_selected(_, player)
local ent = player.selected
if ent then
Game.player_print({'admin_commands.destroy_success', ent.localised_name})
Game.player_print({'admin_commands.destroy_success', ent.localised_name}, player)
ent.destroy()
else
Game.player_print({'admin_commands.destroy_fail'})
Game.player_print({'admin_commands.destroy_fail'}, player)
end
end

Expand Down Expand Up @@ -472,3 +476,19 @@ Command.add(
},
destroy_selected
)

return {
create_pool = pool,
destroy_selected = destroy_selected,
invoke_player = invoke,
jail_player = jail_player,
probation_add = probation_add,
probation_remove = probation_remove,
regular_add = add_regular,
regular_remove = remove_regular,
revive_ghosts = revive_ghosts,
show_reports = show_reports,
teleport_command = teleport_command,
toggle_cheat_mode = toggle_cheat_mode,
unjail_player = unjail_player,
}
Loading
Loading