2019-10-20 11:48:14 +02:00
--antigrief things made by mewmew
2020-07-01 19:35:38 +02:00
local Event = require ' utils.event '
2020-08-14 22:07:54 +02:00
local Jailed = require ' utils.datastore.jail_data '
2022-04-05 19:28:08 +02:00
local Gui = require ' utils.gui '
2021-12-05 22:15:49 +01:00
local AntiGrief = require ' utils.antigrief '
2020-12-14 19:36:37 +01:00
local SpamProtection = require ' utils.spam_protection '
2023-11-12 22:39:24 +01:00
local Color = require ' utils.color_presets '
local Server = require ' utils.server '
2024-02-07 20:36:39 +01:00
local Task = require ' utils.task_token '
2021-03-25 23:49:57 +01:00
local Token = require ' utils.token '
2024-01-28 23:13:32 +01:00
local Global = require ' utils.global '
2024-03-28 23:19:18 +01:00
local Discord = require ' utils.discord_handler '
2023-11-24 19:38:17 +01:00
local Public = { }
2019-10-20 11:48:14 +02:00
2023-11-24 19:38:17 +01:00
local insert = table.insert
2020-07-01 19:35:38 +02:00
local lower = string.lower
2024-01-28 23:13:32 +01:00
local ceil = math.ceil
local max = math.max
local min = math.min
2022-04-05 19:28:08 +02:00
local module_name = Gui.uid_name ( )
2024-01-28 23:13:32 +01:00
local next_button_name = Gui.uid_name ( )
local prev_button_name = Gui.uid_name ( )
2024-01-29 08:06:24 +01:00
local listable_players_name = Gui.uid_name ( )
2024-01-31 22:19:48 +01:00
local count_label_name = Gui.uid_name ( )
local rows_per_page = 500
local create_admin_panel
2024-01-28 23:13:32 +01:00
local this = {
2024-01-31 22:19:48 +01:00
player_data = { }
2024-01-28 23:13:32 +01:00
}
Global.register (
this ,
2024-06-10 16:14:37 +02:00
function ( tbl )
2024-01-28 23:13:32 +01:00
this = tbl
end
)
2019-10-20 11:48:14 +02:00
2024-01-31 22:19:48 +01:00
local function get_player_data ( player , remove )
local data = this.player_data [ player.name ]
if remove and data then
if data and data.frame and data.frame . valid then
data.frame . destroy ( )
end
this.player_data [ player.name ] = nil
return
end
if not this.player_data [ player.name ] then
this.player_data [ player.name ] = {
selected_history_index = nil ,
filter_player = nil ,
show_all_players = nil ,
current_page = nil
}
end
return this.player_data [ player.name ]
end
2024-02-07 20:36:39 +01:00
local delayed_last_page_token =
Task.register (
2024-06-10 16:14:37 +02:00
function ( event )
local player_index = event.player_index
local player = game.get_player ( player_index )
if not player or not player.valid then
return
end
2024-02-07 20:36:39 +01:00
2024-06-10 16:14:37 +02:00
local element = event.element
if not element or not element.valid then
return
end
2024-02-07 20:36:39 +01:00
2024-06-10 16:14:37 +02:00
local player_data = get_player_data ( player )
if not player_data or not player_data.table_count then
return
end
local last_page = ceil ( player_data.table_count / rows_per_page )
2024-02-07 20:36:39 +01:00
2024-06-10 16:14:37 +02:00
player_data.current_page = last_page
local data = { player = player , frame = element }
create_admin_panel ( data )
end
)
2024-02-07 20:36:39 +01:00
2023-11-12 22:39:24 +01:00
local function clear_validation_action ( player_name , action )
local admin_button_validation = AntiGrief.get ( ' admin_button_validation ' )
if admin_button_validation and admin_button_validation [ action ] then
admin_button_validation [ action ] [ player_name ] = nil
end
end
local clear_validation_token =
Token.register (
2024-06-10 16:14:37 +02:00
function ( event )
local action = event.action
if not action then
return
end
local player_name = event.player_name
if not player_name then
return
end
2023-11-12 22:39:24 +01:00
2024-06-10 16:14:37 +02:00
local admin_button_validation = AntiGrief.get ( ' admin_button_validation ' )
if admin_button_validation and admin_button_validation [ action ] then
admin_button_validation [ action ] [ player_name ] = nil
end
2023-11-12 22:39:24 +01:00
end
2024-06-10 16:14:37 +02:00
)
2023-11-12 22:39:24 +01:00
local function validate_action ( player , action )
local admin_button_validation = AntiGrief.get ( ' admin_button_validation ' )
if not admin_button_validation [ action ] then
admin_button_validation [ action ] = { }
end
if not admin_button_validation [ action ] [ player.name ] then
admin_button_validation [ action ] [ player.name ] = true
2024-06-10 16:14:37 +02:00
Task.set_timeout_in_ticks ( 200 , clear_validation_token , { player_name = player.name , action = action } )
2023-11-12 22:39:24 +01:00
player.print ( ' Please run this again if you are certain that you want to run this action[ ' .. action .. ' ]. ' , Color.warning )
return true
end
return false
end
2020-07-10 13:52:55 +02:00
local function admin_only_message ( str )
for _ , player in pairs ( game.connected_players ) do
if player.admin == true then
2024-06-10 16:14:37 +02:00
player.print ( ' Admins-only-message: ' .. str , { r = 0.88 , g = 0.88 , b = 0.88 } )
2020-07-10 13:52:55 +02:00
end
end
end
2019-10-20 11:48:14 +02:00
local function jail ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' jail ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' jail ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2023-11-12 22:39:24 +01:00
Jailed.try_ul_data ( player.name , true , source_player.name , ' Jailed by ' .. source_player.name .. ' ! ' )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' jail ' )
2023-11-12 22:39:24 +01:00
end
2024-06-10 16:14:37 +02:00
local function clear_biters ( player )
if validate_action ( player , ' clear_biters ' ) then
return
end
local surface = player.surface
local count = 0
for c in surface.get_chunks ( ) do
for _ , entity in pairs ( surface.find_entities_filtered ( { area = { { c.x * 32 , c.y * 32 } , { c.x * 32 + 32 , c.y * 32 + 32 } } , type = " unit " } ) ) do
if entity and entity.valid then
entity.destroy ( )
count = count + 1
end
end
end
player.print ( ' Cleared: ' .. count .. ' biters. ' , Color.warning )
clear_validation_action ( player.name , ' clear_biters ' )
end
2023-11-12 22:39:24 +01:00
local function mute ( player , source_player )
if validate_action ( source_player , ' mute ' ) then
return
end
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' mute ' )
2023-11-12 22:39:24 +01:00
return
end
Jailed.try_ul_data ( player.name , true , source_player.name , ' Jailed and muted by ' .. source_player.name .. ' ! ' , true )
local muted = Jailed.mute_player ( player )
local muted_str = muted and ' muted ' or ' unmuted '
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' jail ' )
2024-06-10 16:14:37 +02:00
game.print ( player.name .. ' was ' .. muted_str .. ' by player ' .. source_player.name .. ' ! ' , { r = 1 , g = 0.5 , b = 0.1 } )
2019-10-20 11:48:14 +02:00
end
local function free ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' free ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' free ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-07-07 23:42:44 +02:00
Jailed.try_ul_data ( player.name , false , source_player.name )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' free ' )
2019-10-20 11:48:14 +02:00
end
local bring_player_messages = {
2020-06-28 14:40:39 +02:00
' Come here my friend! ' ,
' Papers, please. ' ,
' What are you up to? '
2019-10-20 11:48:14 +02:00
}
2020-06-28 14:40:39 +02:00
2019-10-20 11:48:14 +02:00
local function bring_player ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' bring_player ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' bring_player ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if player.driving == true then
2024-06-10 16:14:37 +02:00
source_player.print ( ' Target player is in a vehicle, teleport not available. ' , { r = 0.88 , g = 0.88 , b = 0.88 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' bring_player ' )
2020-06-28 14:40:39 +02:00
return
end
local pos = source_player.surface . find_non_colliding_position ( ' character ' , source_player.position , 50 , 1 )
if pos then
player.teleport ( pos , source_player.surface )
2024-06-10 16:14:37 +02:00
game.print ( player.name .. ' has been teleported to ' .. source_player.name .. ' . ' .. bring_player_messages [ math.random ( 1 , # bring_player_messages ) ] , { r = 0.98 , g = 0.66 , b = 0.22 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' bring_player ' )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local go_to_player_messages = {
2020-06-28 14:40:39 +02:00
' Papers, please. ' ,
' What are you up to? '
2019-10-20 11:48:14 +02:00
}
local function go_to_player ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' go_to_player ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' go_to_player ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
local pos = player.surface . find_non_colliding_position ( ' character ' , player.position , 50 , 1 )
if pos then
source_player.teleport ( pos , player.surface )
2024-06-10 16:14:37 +02:00
game.print ( source_player.name .. ' is visiting ' .. player.name .. ' . ' .. go_to_player_messages [ math.random ( 1 , # go_to_player_messages ) ] , { r = 0.98 , g = 0.66 , b = 0.22 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' go_to_player ' )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local function spank ( player , source_player )
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
return player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if player.character then
if player.character . health > 1 then
player.character . damage ( 1 , ' player ' )
end
player.character . health = player.character . health - 5
2024-06-10 16:14:37 +02:00
player.surface . create_entity ( { name = ' water-splash ' , position = player.position } )
game.print ( source_player.name .. ' spanked ' .. player.name , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local damage_messages = {
2020-06-28 14:40:39 +02:00
' recieved a love letter from ' ,
' recieved a strange package from '
2019-10-20 11:48:14 +02:00
}
local function damage ( player , source_player )
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
return player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if player.character then
if player.character . health > 1 then
player.character . damage ( 1 , ' player ' )
end
player.character . health = player.character . health - 125
2024-06-10 16:14:37 +02:00
player.surface . create_entity ( { name = ' big-explosion ' , position = player.position } )
game.print ( player.name .. damage_messages [ math.random ( 1 , # damage_messages ) ] .. source_player.name , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local kill_messages = {
2020-06-28 14:40:39 +02:00
' did not obey the law. ' ,
' should not have triggered the admins. ' ,
' did not respect authority. ' ,
' had a strange accident. ' ,
' was struck by lightning. '
2019-10-20 11:48:14 +02:00
}
local function kill ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' kill ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' kill ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if player.character then
player.character . die ( ' player ' )
2024-06-10 16:14:37 +02:00
game.print ( player.name .. kill_messages [ math.random ( 1 , # kill_messages ) ] , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
admin_only_message ( source_player.name .. ' killed ' .. player.name )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' kill ' )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local enemy_messages = {
2020-06-28 14:40:39 +02:00
' Shoot on sight! ' ,
' Wanted dead or alive! '
2019-10-20 11:48:14 +02:00
}
local function enemy ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' enemy ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' enemy ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if not game.forces . enemy_players then
game.create_force ( ' enemy_players ' )
end
player.force = game.forces . enemy_players
2024-06-10 16:14:37 +02:00
game.print ( player.name .. ' is now an enemy! ' .. enemy_messages [ math.random ( 1 , # enemy_messages ) ] , { r = 0.95 , g = 0.15 , b = 0.15 } )
2020-06-28 14:40:39 +02:00
admin_only_message ( source_player.name .. ' has turned ' .. player.name .. ' into an enemy ' )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' enemy ' )
2019-10-20 11:48:14 +02:00
end
local function ally ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' ally ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2024-06-10 16:14:37 +02:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' ally ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
player.force = game.forces . player
2024-06-10 16:14:37 +02:00
game.print ( player.name .. ' is our ally again! ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
admin_only_message ( source_player.name .. ' made ' .. player.name .. ' our ally ' )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' ally ' )
2019-10-20 11:48:14 +02:00
end
2019-10-20 12:52:19 +02:00
local function turn_off_global_speakers ( player )
2023-11-12 22:39:24 +01:00
if validate_action ( player , ' turn_off_global_speakers ' ) then
return
end
2020-06-28 14:40:39 +02:00
local counter = 0
for _ , surface in pairs ( game.surfaces ) do
2024-06-10 16:14:37 +02:00
local speakers = surface.find_entities_filtered ( { name = ' programmable-speaker ' } )
2023-11-12 22:39:24 +01:00
for _ , speaker in pairs ( speakers ) do
2020-06-28 14:40:39 +02:00
if speaker.parameters . playback_globally == true then
2024-06-10 16:14:37 +02:00
speaker.surface . create_entity ( { name = ' massive-explosion ' , position = speaker.position } )
2023-08-10 14:29:05 +02:00
speaker.destroy ( )
2020-06-28 14:40:39 +02:00
counter = counter + 1
end
end
end
if counter == 0 then
return
end
if counter == 1 then
2024-06-10 16:14:37 +02:00
game.print ( player.name .. ' has nuked ' .. counter .. ' global speaker. ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
else
2024-06-10 16:14:37 +02:00
game.print ( player.name .. ' has nuked ' .. counter .. ' global speakers. ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
end
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' turn_off_global_speakers ' )
2019-10-20 11:48:14 +02:00
end
2019-10-20 12:52:19 +02:00
local function delete_all_blueprints ( player )
2023-11-12 22:39:24 +01:00
if validate_action ( player , ' delete_all_blueprints ' ) then
return
end
2020-06-28 14:40:39 +02:00
local counter = 0
for _ , surface in pairs ( game.surfaces ) do
2024-06-10 16:14:37 +02:00
for _ , ghost in pairs ( surface.find_entities_filtered ( { type = { ' entity-ghost ' , ' tile-ghost ' } } ) ) do
2020-06-28 14:40:39 +02:00
ghost.destroy ( )
counter = counter + 1
end
end
if counter == 0 then
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' delete_all_blueprints ' )
2020-06-28 14:40:39 +02:00
return
end
if counter == 1 then
2024-06-10 16:14:37 +02:00
game.print ( counter .. ' blueprint has been cleared! ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
else
2024-06-10 16:14:37 +02:00
game.print ( counter .. ' blueprints have been cleared! ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
end
2024-03-28 23:19:18 +01:00
local server_name = Server.get_server_name ( ) or ' CommandHandler '
Discord.send_notification_raw ( server_name , player.name .. ' cleared all the blueprints on the map. ' )
2020-06-28 14:40:39 +02:00
admin_only_message ( player.name .. ' has cleared all blueprints. ' )
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' delete_all_blueprints ' )
end
local function pause_game_tick ( player )
if validate_action ( player , ' pause_game_tick ' ) then
return
end
local paused = game.tick_paused
local paused_str = paused and ' unpaused ' or ' paused '
game.tick_paused = not paused
2024-06-10 16:14:37 +02:00
game.print ( ' Game has been ' .. paused_str .. ' by ' .. player.name , { r = 0.98 , g = 0.66 , b = 0.22 } )
2024-03-28 23:19:18 +01:00
local server_name = Server.get_server_name ( ) or ' CommandHandler '
Discord.send_notification_raw ( server_name , player.name .. ' ' .. paused_str .. ' the game. ' )
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' pause_game_tick ' )
end
local function save_game ( player )
if validate_action ( player , ' save_game ' ) then
return
end
local date = Server.get_start_time ( ) or game.tick
game.server_save ( ' _currently_running ' .. tostring ( date ) .. ' _ ' .. player.name )
clear_validation_action ( player.name , ' save_game ' )
2019-10-20 11:48:14 +02:00
end
2023-11-24 19:38:17 +01:00
local function clear_items_on_ground ( player )
if validate_action ( player , ' clear_items_on_ground ' ) then
return
end
local i = 0
2024-06-10 16:14:37 +02:00
for _ , entity in pairs ( player.surface . find_entities_filtered { type = ' item-entity ' , name = ' item-on-ground ' } ) do
2023-11-24 19:38:17 +01:00
if entity and entity.valid then
entity.destroy ( )
i = i + 1
end
end
if i == 0 then
return player.print ( ' No items to clear! ' , Color.warning )
end
player.print ( ' Cleared: ' .. i .. ' items. ' , Color.success )
clear_validation_action ( player.name , ' clear_items_on_ground ' )
end
2020-06-29 15:50:01 +02:00
local function create_mini_camera_gui ( player , caption , position , surface )
2020-06-28 14:40:39 +02:00
if player.gui . center [ ' mini_camera ' ] then
player.gui . center [ ' mini_camera ' ] . destroy ( )
end
2024-06-10 16:14:37 +02:00
local frame = player.gui . center.add ( { type = ' frame ' , name = ' mini_camera ' , caption = caption } )
2020-06-29 15:50:01 +02:00
surface = tonumber ( surface )
2021-06-06 20:14:26 +02:00
surface = game.surfaces [ surface ]
if not surface or not surface.valid then
return
end
2020-06-28 14:40:39 +02:00
local camera =
frame.add (
2024-06-10 16:14:37 +02:00
{
type = ' camera ' ,
name = ' mini_cam_element ' ,
position = position ,
zoom = 0.6 ,
surface_index = surface.index
}
)
2020-06-28 14:40:39 +02:00
camera.style . minimal_width = 640
camera.style . minimal_height = 480
2019-10-20 11:48:14 +02:00
end
2020-07-01 19:35:38 +02:00
local function filter_brackets ( str )
return ( string.find ( str , ' %[ ' ) ~= nil )
end
local function match_test ( value , pattern )
return lower ( value : gsub ( ' - ' , ' ' ) ) : find ( pattern )
end
2020-07-07 23:42:44 +02:00
local function contains_text ( key , value , search_text )
2024-01-31 22:19:48 +01:00
if not key then
return false
end
2020-07-07 23:42:44 +02:00
if filter_brackets ( search_text ) then
return false
end
if value then
if not match_test ( key [ value ] , search_text ) then
return false
end
else
if not match_test ( key , search_text ) then
return false
end
end
return true
end
2024-01-31 22:19:48 +01:00
local function search_text_locally ( history , player_data , callback )
local antigrief = AntiGrief.get ( )
local history_index = {
[ ' Capsule History ' ] = antigrief.capsule_history ,
[ ' Message History ' ] = antigrief.message_history ,
[ ' Friendly Fire History ' ] = antigrief.friendly_fire_history ,
[ ' Mining History ' ] = antigrief.mining_history ,
[ ' Mining Override History ' ] = antigrief.whitelist_mining_history ,
[ ' Landfill History ' ] = antigrief.landfill_history ,
[ ' Corpse Looting History ' ] = antigrief.corpse_history ,
[ ' Cancel Crafting History ' ] = antigrief.cancel_crafting_history ,
[ ' Deconstruct History ' ] = antigrief.deconstruct_history ,
2024-03-28 23:19:18 +01:00
[ ' Scenario History ' ] = antigrief.scenario_history ,
[ ' Whisper History ' ] = antigrief.whisper_history
2024-01-31 22:19:48 +01:00
}
2024-01-28 23:13:32 +01:00
2024-01-31 22:19:48 +01:00
local tooltip = ' Click to open mini camera. '
if not player_data.current_page then
player_data.current_page = 1
2024-01-28 23:13:32 +01:00
end
2024-01-31 22:19:48 +01:00
local target = game.get_player ( player_data.target_player_name )
local search_text = player_data.search_text
2024-01-28 23:13:32 +01:00
2024-01-31 22:19:48 +01:00
local start_index = ( player_data.current_page - 1 ) * rows_per_page + 1
2024-01-28 23:13:32 +01:00
local end_index = start_index + rows_per_page - 1
2020-07-01 19:35:38 +02:00
2024-01-31 22:19:48 +01:00
if target ~= nil then
if not history_index or not history_index [ history ] or # history_index [ history ] <= 0 then
return
end
if search_text then
2024-02-07 20:36:39 +01:00
for i = end_index , start_index , - 1 do
2024-01-31 22:19:48 +01:00
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if success then
if history == ' Message History ' then
tooltip = ' '
end
callback ( history_index [ history ] [ i ] , tooltip )
end
end
else
2024-02-07 20:36:39 +01:00
for i = end_index , start_index , - 1 do
2024-01-31 22:19:48 +01:00
if history_index [ history ] [ i ] and history_index [ history ] [ i ] : find ( player_data.target_player_name ) then
callback ( history_index [ history ] [ i ] , tooltip )
end
end
end
else
if search_text then
2024-02-07 20:36:39 +01:00
for i = end_index , start_index , - 1 do
2024-01-31 22:19:48 +01:00
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if success then
callback ( history_index [ history ] [ i ] , tooltip )
end
end
else
2024-02-07 20:36:39 +01:00
for i = end_index , start_index , - 1 do
2024-01-31 22:19:48 +01:00
callback ( history_index [ history ] [ i ] , tooltip )
end
end
end
end
local function draw_events ( player_data )
local frame = player_data.frame
local history = frame.pagination_table . admin_history_select.items [ frame.pagination_table . admin_history_select.selected_index ]
local target_player_name = frame [ ' admin_player_select ' ] . items [ frame [ ' admin_player_select ' ] . selected_index ]
player_data.target_player_name = target_player_name
2020-07-01 19:35:38 +02:00
local scroll_pane
if frame.datalog then
frame.datalog . clear ( )
else
scroll_pane =
frame.add (
2024-06-10 16:14:37 +02:00
{
type = ' scroll-pane ' ,
name = ' datalog ' ,
direction = ' vertical ' ,
horizontal_scroll_policy = ' never ' ,
vertical_scroll_policy = ' auto '
}
)
2020-07-01 19:35:38 +02:00
scroll_pane.style . maximal_height = 200
2020-07-30 19:09:18 +02:00
scroll_pane.style . minimal_width = 790
2020-07-01 19:35:38 +02:00
end
2024-01-31 22:19:48 +01:00
search_text_locally (
2023-11-24 19:38:17 +01:00
history ,
2024-01-31 22:19:48 +01:00
player_data ,
2024-06-10 16:14:37 +02:00
function ( history_label , tooltip )
2024-01-28 23:13:32 +01:00
if not history_label then
return
end
2020-07-30 19:09:18 +02:00
frame.datalog . add (
{
type = ' label ' ,
2023-11-24 19:38:17 +01:00
caption = history_label ,
tooltip = tooltip
2020-07-30 19:09:18 +02:00
}
)
2024-01-31 22:19:48 +01:00
end
2023-11-24 19:38:17 +01:00
)
2020-07-01 19:35:38 +02:00
end
local function text_changed ( event )
local element = event.element
if not element then
return
end
if not element.valid then
return
end
2021-12-05 22:26:18 +01:00
local player = game.get_player ( event.player_index )
2020-07-01 19:35:38 +02:00
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2020-07-01 19:35:38 +02:00
if not frame then
return
end
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-07-01 19:35:38 +02:00
return
end
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Text Changed ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
player_data.frame = frame
player_data.search_text = element.text : lower ( )
2020-07-01 19:35:38 +02:00
2024-01-31 22:19:48 +01:00
local value = string.len ( element.text )
if value >= 1000 then
player_data.search_text = nil
element.text = ' '
return
2024-01-09 21:57:10 +01:00
end
2024-01-31 22:19:48 +01:00
if player_data.search_text == ' ' then
player_data.search_text = nil
2024-02-07 20:36:39 +01:00
local last_page = ceil ( player_data.table_count / rows_per_page )
player_data.current_page = last_page
2024-06-10 16:14:37 +02:00
local data = { player = player , frame = frame }
2024-01-31 22:19:48 +01:00
create_admin_panel ( data )
return
end
draw_events ( player_data )
2020-07-01 19:35:38 +02:00
end
2024-01-31 22:19:48 +01:00
local function create_pagination_buttons ( player_data , frame , table_count )
2024-01-28 23:13:32 +01:00
if table_count == 0 then
return
end
local last_page = ceil ( table_count / rows_per_page )
2024-01-31 22:19:48 +01:00
if not player_data.current_page then
2024-02-07 20:36:39 +01:00
player_data.current_page = last_page
2024-01-28 23:13:32 +01:00
end
2024-01-31 22:19:48 +01:00
local current_page = player_data.current_page
2024-01-28 23:13:32 +01:00
if current_page == 1 and current_page == last_page then
return
end
local button_flow =
frame.add {
2024-06-10 16:14:37 +02:00
type = ' flow ' ,
direction = ' horizontal '
}
2024-01-28 23:13:32 +01:00
local prev_button =
button_flow.add {
2024-06-10 16:14:37 +02:00
type = ' button ' ,
name = prev_button_name ,
caption = ' ◀️ ' ,
style = ' back_button '
}
2024-01-28 23:13:32 +01:00
prev_button.style . font = ' default-bold '
prev_button.style . minimal_width = 32
prev_button.tooltip = ' Previous page \n Holding [color=yellow]shift[/color] while pressing LMB/RMB will jump to the first page. '
local count_label =
button_flow.add {
2024-06-10 16:14:37 +02:00
type = ' label ' ,
name = count_label_name ,
caption = current_page .. ' / ' .. last_page
}
2024-01-28 23:13:32 +01:00
count_label.style . font = ' default-bold '
2024-01-31 22:19:48 +01:00
player_data.count_label = count_label
2024-01-28 23:13:32 +01:00
local next_button =
button_flow.add {
2024-06-10 16:14:37 +02:00
type = ' button ' ,
name = next_button_name ,
caption = ' ▶️ ' ,
style = ' forward_button '
}
2024-01-28 23:13:32 +01:00
next_button.style . font = ' default-bold '
next_button.style . minimal_width = 32
next_button.tooltip = ' Next page \n Holding [color=yellow]shift[/color] while pressing LMB/RMB will jump to the last page. '
2024-01-31 22:19:48 +01:00
player_data.table_count = table_count
2024-01-28 23:13:32 +01:00
end
2024-06-10 16:14:37 +02:00
create_admin_panel = function ( data )
2021-03-25 23:49:57 +01:00
local player = data.player
local frame = data.frame
2020-06-29 15:50:01 +02:00
local antigrief = AntiGrief.get ( )
2022-07-04 00:27:35 +02:00
if not antigrief then
return
end
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
local checkbox_state = player_data.show_all_players
2024-01-28 23:13:32 +01:00
2020-06-28 14:40:39 +02:00
frame.clear ( )
2024-01-28 23:13:32 +01:00
local players = game.connected_players
if checkbox_state then
players = game.players
end
2020-06-28 14:40:39 +02:00
local player_names = { }
2024-01-28 23:13:32 +01:00
for _ , p in pairs ( players ) do
2023-11-24 19:38:17 +01:00
insert ( player_names , tostring ( p.name ) )
2020-06-28 14:40:39 +02:00
end
2023-11-24 19:38:17 +01:00
insert ( player_names , ' Select Player ' )
2020-06-28 14:40:39 +02:00
local selected_index = # player_names
2024-01-31 22:19:48 +01:00
local selected = player_data.filter_player
2024-01-28 23:13:32 +01:00
if selected then
2024-01-31 22:19:48 +01:00
if player_names [ selected ] then
selected_index = selected
2020-06-28 14:40:39 +02:00
end
end
2024-01-28 23:13:32 +01:00
local checkbox_caption = ' Currently showing: connected players only. '
if checkbox_state then
checkbox_caption = ' Currently showing: all players that have played on this server. '
end
2024-06-10 16:14:37 +02:00
frame.add ( { type = ' checkbox ' , name = listable_players_name , caption = checkbox_caption , state = checkbox_state or false } )
2024-01-28 23:13:32 +01:00
2024-06-10 16:14:37 +02:00
local drop_down = frame.add ( { type = ' drop-down ' , name = ' admin_player_select ' , items = player_names , selected_index = selected_index } )
2020-06-28 14:40:39 +02:00
drop_down.style . minimal_width = 326
drop_down.style . right_padding = 12
drop_down.style . left_padding = 12
2024-06-10 16:14:37 +02:00
local t = frame.add ( { type = ' table ' , column_count = 4 } )
2020-06-28 14:40:39 +02:00
local buttons = {
t.add (
{
type = ' button ' ,
caption = ' Jail ' ,
name = ' jail ' ,
tooltip = ' Jails the player, they will no longer be able to perform any actions except writing in chat. '
}
) ,
2023-11-12 22:39:24 +01:00
t.add (
{
type = ' button ' ,
caption = ' Mute ' ,
name = ' mute ' ,
tooltip = ' Jails and mutes the player, they will no longer be able to chat. '
}
) ,
2024-06-10 16:14:37 +02:00
t.add ( { type = ' button ' , caption = ' Free ' , name = ' free ' , tooltip = ' Frees the player from jail. ' } ) ,
2020-06-28 14:40:39 +02:00
t.add (
{
type = ' button ' ,
caption = ' Bring Player ' ,
name = ' bring_player ' ,
tooltip = ' Teleports the selected player to your position. '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Make Enemy ' ,
name = ' enemy ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Sets the selected players force to enemy_players. \n DO NOT USE IN PVP MAPS!! '
2020-06-28 14:40:39 +02:00
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Make Ally ' ,
name = ' ally ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Sets the selected players force back to the default player force. \n DO NOT USE IN PVP MAPS!! '
2020-06-28 14:40:39 +02:00
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Go to Player ' ,
name = ' go_to_player ' ,
tooltip = ' Teleport yourself to the selected player. '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Spank ' ,
name = ' spank ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Hurts the selected player with minor damage. \n Can not kill the player. '
2020-06-28 14:40:39 +02:00
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Damage ' ,
name = ' damage ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Damages the selected player with greater damage. \n Can not kill the player. '
2020-06-28 14:40:39 +02:00
}
) ,
2024-06-10 16:14:37 +02:00
t.add ( { type = ' button ' , caption = ' Kill ' , name = ' kill ' , tooltip = ' Kills the selected player instantly. ' } )
2020-06-28 14:40:39 +02:00
}
for _ , button in pairs ( buttons ) do
button.style . font = ' default-bold '
--button.style.font_color = { r=0.99, g=0.11, b=0.11}
button.style . minimal_width = 106
end
2024-06-10 16:14:37 +02:00
local line = frame.add { type = ' line ' }
2020-06-28 14:40:39 +02:00
line.style . top_margin = 8
line.style . bottom_margin = 8
2024-06-10 16:14:37 +02:00
frame.add ( { type = ' label ' , caption = ' Global Actions: ' } )
local actionTable = frame.add ( { type = ' table ' , column_count = 4 } )
2021-03-24 17:36:07 +01:00
local bottomButtons = {
actionTable.add (
2020-06-28 14:40:39 +02:00
{
type = ' button ' ,
caption = ' Destroy global speakers ' ,
name = ' turn_off_global_speakers ' ,
tooltip = ' Destroys all speakers that are set to play sounds globally. '
}
) ,
2021-03-24 17:36:07 +01:00
actionTable.add (
2020-06-28 14:40:39 +02:00
{
type = ' button ' ,
caption = ' Delete blueprints ' ,
name = ' delete_all_blueprints ' ,
tooltip = ' Deletes all placed blueprints on the map. '
}
2023-11-12 22:39:24 +01:00
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Pause game tick ' ,
name = ' pause_game_tick ' ,
tooltip = ' Pauses the game tick. '
}
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Save game ' ,
name = ' save_game ' ,
tooltip = ' Saves the game. '
}
2023-11-24 19:38:17 +01:00
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Clear items on ground ' ,
name = ' clear_items_on_ground ' ,
tooltip = ' Clears all items on the ground. \n This might lag the game! '
}
2024-06-10 16:14:37 +02:00
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Remove biters ' ,
name = ' clear_biters ' ,
tooltip = ' Clears out all biters (friendly and enemy). \n This might lag the game! '
}
2020-06-28 14:40:39 +02:00
)
--- t.add({type = "button", caption = "Cancel all deconstruction orders", name = "remove_all_deconstruction_orders"})
}
2021-03-24 17:36:07 +01:00
for _ , button in pairs ( bottomButtons ) do
2020-06-28 14:40:39 +02:00
button.style . font = ' default-bold '
button.style . minimal_width = 80
end
2024-06-10 16:14:37 +02:00
local bottomLine = frame.add { type = ' line ' }
2021-03-24 17:36:07 +01:00
bottomLine.style . top_margin = 8
bottomLine.style . bottom_margin = 8
2020-06-28 14:40:39 +02:00
local histories = { }
2020-06-29 15:50:01 +02:00
if antigrief.capsule_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Capsule History ' )
2020-06-28 14:40:39 +02:00
end
2021-05-07 01:19:38 +02:00
if antigrief.message_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Message History ' )
2021-05-07 01:19:38 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.friendly_fire_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Friendly Fire History ' )
2020-06-28 14:40:39 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.mining_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Mining History ' )
2020-06-28 14:40:39 +02:00
end
2021-05-09 17:11:18 +02:00
if antigrief.whitelist_mining_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Mining Override History ' )
2021-05-09 17:11:18 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.landfill_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Landfill History ' )
2020-06-28 14:40:39 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.corpse_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Corpse Looting History ' )
2020-06-28 14:40:39 +02:00
end
2020-07-06 23:22:03 +02:00
if antigrief.cancel_crafting_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Cancel Crafting History ' )
2020-07-06 23:22:03 +02:00
end
2022-07-04 00:27:35 +02:00
if antigrief.deconstruct_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Deconstruct History ' )
2022-07-04 00:27:35 +02:00
end
2023-09-17 16:28:11 +02:00
if antigrief.scenario_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Scenario History ' )
2023-09-17 16:28:11 +02:00
end
2024-03-28 23:19:18 +01:00
if antigrief.whisper_history then
insert ( histories , ' Whisper History ' )
end
2020-06-28 14:40:39 +02:00
if # histories == 0 then
return
end
2024-06-10 16:14:37 +02:00
local search_table = frame.add ( { type = ' table ' , column_count = 3 } )
search_table.add ( { type = ' label ' , caption = ' Search: ' } )
local search_text = search_table.add ( { type = ' textfield ' } )
2024-01-31 22:19:48 +01:00
search_text.text = player_data.search_text or ' '
2020-07-01 19:35:38 +02:00
search_text.style . width = 140
2024-01-31 22:19:48 +01:00
local btn =
search_table.add {
2024-06-10 16:14:37 +02:00
type = ' sprite-button ' ,
tooltip = ' [color=blue]Info![/color] \n Searching does not filter the amount of pages shown. \n This is a limitation in the Factorio engine. \n Iterating over the whole table would lag the game. \n So when searching, you will still see the same amount of pages. \n And the results will be "janky". ' ,
sprite = ' utility/questionmark '
}
2024-01-31 22:19:48 +01:00
btn.style . height = 20
btn.style . width = 20
btn.enabled = false
btn.focus ( )
2020-07-01 19:35:38 +02:00
2024-06-10 16:14:37 +02:00
local bottomLine2 = frame.add ( { type = ' label ' , caption = ' ---------------------------------------------- ' } )
2021-03-24 17:36:07 +01:00
bottomLine2.style . font = ' default-listbox '
2024-06-10 16:14:37 +02:00
bottomLine2.style . font_color = { r = 0.98 , g = 0.66 , b = 0.22 }
2020-06-28 14:40:39 +02:00
2020-06-29 15:50:01 +02:00
local selected_index_2 = 1
2024-01-31 22:19:48 +01:00
if player_data and player_data.selected_history_index then
selected_index_2 = player_data.selected_history_index
2020-06-28 14:40:39 +02:00
end
2024-06-10 16:14:37 +02:00
local pagination_table = frame.add ( { type = ' table ' , column_count = 2 , name = ' pagination_table ' } )
2024-01-28 23:13:32 +01:00
2024-06-10 16:14:37 +02:00
local drop_down_2 = pagination_table.add ( { type = ' drop-down ' , name = ' admin_history_select ' , items = histories , selected_index = selected_index_2 } )
2020-06-29 15:50:01 +02:00
drop_down_2.style . right_padding = 12
drop_down_2.style . left_padding = 12
2020-06-28 14:40:39 +02:00
2024-01-28 23:13:32 +01:00
local history_index = {
[ ' Capsule History ' ] = antigrief.capsule_history ,
[ ' Message History ' ] = antigrief.message_history ,
[ ' Friendly Fire History ' ] = antigrief.friendly_fire_history ,
[ ' Mining History ' ] = antigrief.mining_history ,
[ ' Mining Override History ' ] = antigrief.whitelist_mining_history ,
[ ' Landfill History ' ] = antigrief.landfill_history ,
[ ' Corpse Looting History ' ] = antigrief.corpse_history ,
[ ' Cancel Crafting History ' ] = antigrief.cancel_crafting_history ,
[ ' Deconstruct History ' ] = antigrief.deconstruct_history ,
2024-03-28 23:19:18 +01:00
[ ' Scenario History ' ] = antigrief.scenario_history ,
[ ' Whisper History ' ] = antigrief.whisper_history
2024-01-28 23:13:32 +01:00
}
local history = frame.pagination_table . admin_history_select.items [ frame.pagination_table . admin_history_select.selected_index ]
2024-01-31 22:19:48 +01:00
create_pagination_buttons ( player_data , pagination_table , # history_index [ history ] )
2024-01-28 23:13:32 +01:00
2024-01-31 22:19:48 +01:00
player_data.frame = frame
2019-10-20 11:48:14 +02:00
2024-01-31 22:19:48 +01:00
draw_events ( player_data )
2021-03-25 23:49:57 +01:00
end
local create_admin_panel_token = Token.register ( create_admin_panel )
2019-10-20 11:48:14 +02:00
local admin_functions = {
2020-06-28 14:40:39 +02:00
[ ' jail ' ] = jail ,
2023-11-12 22:39:24 +01:00
[ ' mute ' ] = mute ,
2020-06-28 14:40:39 +02:00
[ ' free ' ] = free ,
[ ' bring_player ' ] = bring_player ,
[ ' spank ' ] = spank ,
[ ' damage ' ] = damage ,
[ ' kill ' ] = kill ,
[ ' enemy ' ] = enemy ,
[ ' ally ' ] = ally ,
[ ' go_to_player ' ] = go_to_player
}
2019-10-20 11:48:14 +02:00
2019-10-20 12:52:19 +02:00
local admin_global_functions = {
2020-06-28 14:40:39 +02:00
[ ' turn_off_global_speakers ' ] = turn_off_global_speakers ,
2023-11-12 22:39:24 +01:00
[ ' delete_all_blueprints ' ] = delete_all_blueprints ,
[ ' pause_game_tick ' ] = pause_game_tick ,
2023-11-24 19:38:17 +01:00
[ ' save_game ' ] = save_game ,
2024-06-10 16:14:37 +02:00
[ ' clear_items_on_ground ' ] = clear_items_on_ground ,
[ ' clear_biters ' ] = clear_biters
2020-06-28 14:40:39 +02:00
}
2019-10-20 12:52:19 +02:00
2020-06-29 15:50:01 +02:00
local function get_surface_from_string ( str )
if not str then
return
end
if str == ' ' then
return
end
str = string.lower ( str )
local start = string.find ( str , ' surface: ' )
local sname = string.len ( str )
local surface = string.sub ( str , start + 8 , sname )
if not surface then
return false
end
return surface
end
2019-10-20 11:48:14 +02:00
local function get_position_from_string ( str )
2020-06-28 14:40:39 +02:00
if not str then
return
end
if str == ' ' then
return
end
str = string.lower ( str )
local x_pos = string.find ( str , ' x: ' )
local y_pos = string.find ( str , ' y: ' )
if not x_pos then
return false
end
if not y_pos then
return false
end
x_pos = x_pos + 2
y_pos = y_pos + 2
local a = 1
for i = 1 , string.len ( str ) , 1 do
local s = string.sub ( str , x_pos + i , x_pos + i )
if not s then
break
end
if string.byte ( s ) == 32 then
break
end
a = a + 1
end
local x = string.sub ( str , x_pos , x_pos + a )
2021-03-24 16:46:00 +01:00
local a1 = 1
2020-06-28 14:40:39 +02:00
for i = 1 , string.len ( str ) , 1 do
local s = string.sub ( str , y_pos + i , y_pos + i )
if not s then
break
end
if string.byte ( s ) == 32 then
break
end
2021-03-24 16:46:00 +01:00
a1 = a1 + 1
2020-06-28 14:40:39 +02:00
end
2021-03-24 16:46:00 +01:00
local y = string.sub ( str , y_pos , y_pos + a1 )
2020-06-28 14:40:39 +02:00
x = tonumber ( x )
y = tonumber ( y )
2024-06-10 16:14:37 +02:00
local position = { x = x , y = y }
2020-06-28 14:40:39 +02:00
return position
end
2019-10-20 11:48:14 +02:00
local function on_gui_click ( event )
2021-03-25 23:49:57 +01:00
local element = event.element
if not element or not element.valid then
2020-06-28 14:40:39 +02:00
return
end
2021-03-25 23:49:57 +01:00
local player = game.get_player ( event.player_index )
2020-06-29 15:50:01 +02:00
2021-03-25 23:49:57 +01:00
local name = event.element . name
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2021-03-25 23:49:57 +01:00
if not frame then
return
end
2020-06-28 14:40:39 +02:00
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-06-29 15:50:01 +02:00
return
end
2022-04-05 19:28:08 +02:00
if name == ' mini_camera ' or name == ' mini_cam_element ' then
player.gui . center [ ' mini_camera ' ] . destroy ( )
2020-06-29 15:50:01 +02:00
return
end
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Gui Click ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2020-06-28 14:40:39 +02:00
if admin_functions [ name ] then
local target_player_name = frame [ ' admin_player_select ' ] . items [ frame [ ' admin_player_select ' ] . selected_index ]
if not target_player_name then
return
end
if target_player_name == ' Select Player ' then
2024-06-10 16:14:37 +02:00
player.print ( ' [AdminGui] No target player selected. ' , { r = 0.88 , g = 0.88 , b = 0.88 } )
2020-06-28 14:40:39 +02:00
return
end
local target_player = game.players [ target_player_name ]
if target_player.connected == true then
admin_functions [ name ] ( target_player , player )
end
return
end
if admin_global_functions [ name ] then
admin_global_functions [ name ] ( player )
return
end
if not frame then
return
end
2021-03-25 23:49:57 +01:00
if not element.caption then
2020-06-28 14:40:39 +02:00
return
end
2021-03-25 23:49:57 +01:00
local position = get_position_from_string ( element.caption )
2020-06-28 14:40:39 +02:00
if not position then
return
end
2021-03-25 23:49:57 +01:00
local surface = get_surface_from_string ( element.caption )
2020-06-29 15:50:01 +02:00
if not surface then
return
end
2020-06-28 14:40:39 +02:00
if player.gui . center [ ' mini_camera ' ] then
2021-03-25 23:49:57 +01:00
if player.gui . center [ ' mini_camera ' ] . caption == element.caption then
2020-06-28 14:40:39 +02:00
player.gui . center [ ' mini_camera ' ] . destroy ( )
return
end
end
2021-03-25 23:49:57 +01:00
create_mini_camera_gui ( player , element.caption , position , surface )
2019-10-20 11:48:14 +02:00
end
2024-01-31 22:19:48 +01:00
local function on_gui_closed ( event )
local player = game.get_player ( event.player_index )
get_player_data ( player , true )
end
2019-10-20 11:48:14 +02:00
local function on_gui_selection_state_changed ( event )
2021-12-05 22:26:18 +01:00
local player = game.get_player ( event.player_index )
2020-06-28 14:40:39 +02:00
local name = event.element . name
2019-10-20 11:48:14 +02:00
2020-06-28 14:40:39 +02:00
if name == ' admin_history_select ' then
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
player_data.selected_history_index = event.element . selected_index
2019-10-20 11:48:14 +02:00
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2020-06-28 14:40:39 +02:00
if not frame then
return
end
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-06-28 14:40:39 +02:00
return
end
2024-06-10 16:14:37 +02:00
Task.set_timeout_in_ticks ( 5 , delayed_last_page_token , { player_index = player.index , element = frame } )
2024-02-07 20:36:39 +01:00
2024-01-31 22:19:48 +01:00
player_data.current_page = 1
2024-01-28 23:13:32 +01:00
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Selection Changed ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2024-06-10 16:14:37 +02:00
local data = { player = player , frame = frame }
2021-03-25 23:49:57 +01:00
create_admin_panel ( data )
2020-06-29 15:50:01 +02:00
end
if name == ' admin_player_select ' then
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
player_data.filter_player = event.element . selected_index
2020-06-29 15:50:01 +02:00
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2020-06-29 15:50:01 +02:00
if not frame then
return
end
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-06-29 15:50:01 +02:00
return
end
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Player Select ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2024-06-10 16:14:37 +02:00
local data = { player = player , frame = frame }
2021-03-25 23:49:57 +01:00
create_admin_panel ( data )
2020-06-28 14:40:39 +02:00
end
end
2019-10-28 17:38:36 +01:00
2024-06-10 16:14:37 +02:00
Gui.add_tab_to_gui ( { name = module_name , caption = ' Admin ' , id = create_admin_panel_token , admin = true } )
2022-04-05 19:28:08 +02:00
Gui.on_click (
module_name ,
2024-06-10 16:14:37 +02:00
function ( event )
2022-04-05 19:28:08 +02:00
local player = event.player
Gui.reload_active_tab ( player )
end
)
2019-10-28 17:38:36 +01:00
2024-01-31 22:19:48 +01:00
function Public . contains_text ( history , search_text , target_player_name )
2023-11-24 19:38:17 +01:00
local antigrief = AntiGrief.get ( )
local history_index = {
[ ' Capsule History ' ] = antigrief.capsule_history ,
[ ' Message History ' ] = antigrief.message_history ,
[ ' Friendly Fire History ' ] = antigrief.friendly_fire_history ,
[ ' Mining History ' ] = antigrief.mining_history ,
[ ' Mining Override History ' ] = antigrief.whitelist_mining_history ,
[ ' Landfill History ' ] = antigrief.landfill_history ,
[ ' Corpse Looting History ' ] = antigrief.corpse_history ,
[ ' Cancel Crafting History ' ] = antigrief.cancel_crafting_history ,
[ ' Deconstruct History ' ] = antigrief.deconstruct_history ,
2024-03-28 23:19:18 +01:00
[ ' Scenario History ' ] = antigrief.scenario_history ,
[ ' Whisper History ' ] = antigrief.whisper_history
2023-11-24 19:38:17 +01:00
}
local remote_tbl = { }
2024-01-31 22:19:48 +01:00
if target_player_name and string.len ( target_player_name ) > 0 and game.get_player ( target_player_name ) ~= nil then
2023-11-24 19:38:17 +01:00
if not history_index or not history_index [ history ] or # history_index [ history ] <= 0 then
return
end
2024-01-31 22:19:48 +01:00
for i = # history_index [ history ] , 1 , - 1 do
if history_index [ history ] [ i ] : find ( target_player_name ) then
2023-11-24 19:38:17 +01:00
if search_text then
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if not success then
goto continue
end
end
2024-01-31 22:19:48 +01:00
remote_tbl [ # remote_tbl + 1 ] = history_index [ history ] [ i ]
2023-11-24 19:38:17 +01:00
:: continue ::
end
2024-01-31 22:19:48 +01:00
end
else
for i = # history_index [ history ] , 1 , - 1 do
if search_text then
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if not success then
goto continue
2023-11-24 19:38:17 +01:00
end
2024-01-31 22:19:48 +01:00
end
2023-11-24 19:38:17 +01:00
2024-01-31 22:19:48 +01:00
remote_tbl [ # remote_tbl + 1 ] = history_index [ history ] [ i ]
2023-11-24 19:38:17 +01:00
2024-01-31 22:19:48 +01:00
:: continue ::
2023-11-24 19:38:17 +01:00
end
end
2024-01-31 22:19:48 +01:00
return remote_tbl
2023-11-24 19:38:17 +01:00
end
2024-01-28 23:13:32 +01:00
Gui.on_click (
prev_button_name ,
2024-06-10 16:14:37 +02:00
function ( event )
2024-01-28 23:13:32 +01:00
local is_spamming = SpamProtection.is_spamming ( event.player , nil , ' Prev button click ' )
if is_spamming then
return
end
local player = event.player
if not player or not player.valid or not player.character then
return
end
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
2024-01-28 23:13:32 +01:00
local element = event.element
if not element or not element.valid then
return
end
2024-02-07 20:36:39 +01:00
local last_page = ceil ( player_data.table_count / rows_per_page )
2024-01-31 22:19:48 +01:00
if not player_data.current_page then
2024-02-07 20:36:39 +01:00
player_data.current_page = last_page
2024-01-28 23:13:32 +01:00
end
2024-01-31 22:19:48 +01:00
local current_page = player_data.current_page
2024-01-28 23:13:32 +01:00
if current_page == 1 then
current_page = 1
2024-01-31 22:19:48 +01:00
player_data.current_page = current_page
2024-01-28 23:13:32 +01:00
player.print ( ' [Admin] There are no more pages beyond this point. ' , Color.warning )
return
end
local shift = event.shift
if shift then
current_page = 1
else
current_page = max ( 1 , current_page - 1 )
end
2024-01-31 22:19:48 +01:00
player_data.current_page = current_page
2024-01-28 23:13:32 +01:00
2024-06-10 16:14:37 +02:00
local data = { player = player , frame = element.parent . parent.parent }
2024-01-28 23:13:32 +01:00
create_admin_panel ( data )
end
)
Gui.on_click (
next_button_name ,
2024-06-10 16:14:37 +02:00
function ( event )
2024-01-28 23:13:32 +01:00
local is_spamming = SpamProtection.is_spamming ( event.player , nil , ' Next button click ' )
if is_spamming then
return
end
local element = event.element
if not element or not element.valid then
return
end
local player = event.player
if not player or not player.valid then
return
end
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
local table_count = player_data.table_count
if not table_count then
2024-01-28 23:13:32 +01:00
return
end
2024-02-07 20:36:39 +01:00
local last_page = ceil ( table_count / rows_per_page )
2024-01-31 22:19:48 +01:00
if not player_data.current_page then
2024-02-07 20:36:39 +01:00
player_data.current_page = last_page
2024-01-28 23:13:32 +01:00
end
2024-01-31 22:19:48 +01:00
local current_page = player_data.current_page
2024-01-28 23:13:32 +01:00
if current_page == last_page then
current_page = last_page
2024-01-31 22:19:48 +01:00
player_data.current_page = current_page
2024-01-28 23:13:32 +01:00
player.print ( ' [Admin] There are no more pages beyond this point. ' , Color.warning )
return
end
local shift = event.shift
if shift then
current_page = last_page
else
current_page = min ( last_page , current_page + 1 )
end
2024-01-31 22:19:48 +01:00
player_data.current_page = current_page
2024-01-28 23:13:32 +01:00
2024-06-10 16:14:37 +02:00
local data = { player = player , frame = element.parent . parent.parent }
2024-01-28 23:13:32 +01:00
create_admin_panel ( data )
end
)
2024-01-29 08:06:24 +01:00
Gui.on_checked_state_changed (
listable_players_name ,
2024-06-10 16:14:37 +02:00
function ( event )
2024-01-29 08:06:24 +01:00
local is_spamming = SpamProtection.is_spamming ( event.player , nil , ' Listable players click ' )
if is_spamming then
return
end
local player = event.player
if not player or not player.valid then
return
end
2024-01-31 22:19:48 +01:00
local player_data = get_player_data ( player )
2024-01-29 08:06:24 +01:00
local element = event.element
if not element or not element.valid then
return
end
2024-01-31 22:19:48 +01:00
player_data.show_all_players = element.state
2024-01-29 08:06:24 +01:00
2024-06-10 16:14:37 +02:00
local data = { player = player , frame = element.parent }
2024-01-29 08:06:24 +01:00
create_admin_panel ( data )
end
)
2020-07-01 19:35:38 +02:00
Event.add ( defines.events . on_gui_text_changed , text_changed )
Event.add ( defines.events . on_gui_click , on_gui_click )
Event.add ( defines.events . on_gui_selection_state_changed , on_gui_selection_state_changed )
2024-01-31 22:19:48 +01:00
Event.add ( Gui.events . on_gui_closed_main_frame , on_gui_closed )
2023-11-24 19:38:17 +01:00
return Public