Complete OGP removal from both Windows and Linux agents

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-09-05 22:23:27 +00:00
parent 3c3b9ad867
commit 8234afaad1

View file

@ -293,7 +293,7 @@ open(PID, '>', AGENT_PID_FILE)
print PID "$$\n"; print PID "$$\n";
close(PID); close(PID);
logger "Open Game Panel - Agent started - " logger "Game Server Agent started - "
. AGENT_VERSION . AGENT_VERSION
. " - port " . " - port "
. AGENT_PORT . AGENT_PORT
@ -385,7 +385,7 @@ my $d = Frontier::Daemon::OGP::Forking->new(
LocalPort => AGENT_PORT, LocalPort => AGENT_PORT,
LocalAddr => AGENT_IP, LocalAddr => AGENT_IP,
ReuseAddr => '1' ReuseAddr => '1'
) or die "Couldn't start OGP Agent: $!"; ) or die "Couldn't start Game Server Agent: $!";
sub backup_home_log sub backup_home_log
{ {
@ -532,13 +532,13 @@ sub get_home_pids
sub create_screen_id sub create_screen_id
{ {
my ($screen_type, $home_id) = @_; my ($screen_type, $home_id) = @_;
return sprintf("OGP_%s_%09d", $screen_type, $home_id); return sprintf("GS_%s_%09d", $screen_type, $home_id);
} }
sub create_screen_cmd sub create_screen_cmd
{ {
my ($screen_id, $exec_cmd) = @_; my ($screen_id, $exec_cmd) = @_;
$exec_cmd = replace_OGP_Env_Vars($screen_id, "", "", $exec_cmd); $exec_cmd = replace_Env_Vars($screen_id, "", "", $exec_cmd);
return return
sprintf('export WINEDEBUG="fixme-all" && export DISPLAY=:1 && screen -d -m -t "%1$s" -c ' . SCREENRC_FILE . ' -S %1$s %2$s', sprintf('export WINEDEBUG="fixme-all" && export DISPLAY=:1 && screen -d -m -t "%1$s" -c ' . SCREENRC_FILE . ' -S %1$s %2$s',
$screen_id, $exec_cmd); $screen_id, $exec_cmd);
@ -550,7 +550,7 @@ sub create_screen_cmd_loop
my ($screen_id, $exec_cmd, $envVars, $skipLoop) = @_; my ($screen_id, $exec_cmd, $envVars, $skipLoop) = @_;
my $server_start_bashfile = "start_server.sh"; my $server_start_bashfile = "start_server.sh";
$exec_cmd = replace_OGP_Env_Vars($screen_id, "", "", $exec_cmd); $exec_cmd = replace_Env_Vars($screen_id, "", "", $exec_cmd);
# Allow file to be overwritten # Allow file to be overwritten
if(-e $server_start_bashfile){ if(-e $server_start_bashfile){
@ -613,8 +613,8 @@ sub create_screen_cmd_loop
sub handle_lock_command_line{ sub handle_lock_command_line{
my ($command) = @_; my ($command) = @_;
if(defined $command && $command ne ""){ if(defined $command && $command ne ""){
if ($command =~ m/{OGP_LOCK_FILE}/) { if ($command =~ m/{LOCK_FILE}/) {
$command =~ s/{OGP_LOCK_FILE}\s*//g; $command =~ s/{LOCK_FILE}\s*//g;
return secure_path_without_decrypt("chattr+i", $command); return secure_path_without_decrypt("chattr+i", $command);
} }
} }
@ -622,7 +622,7 @@ sub handle_lock_command_line{
return 0; return 0;
} }
sub replace_OGP_Env_Vars{ sub replace_Env_Vars{
# This function replaces constants from environment variables set in the XML # This function replaces constants from environment variables set in the XML
my ($screen_id, $homeid, $homepath, $exec_cmd, $game_key) = @_; my ($screen_id, $homeid, $homepath, $exec_cmd, $game_key) = @_;
@ -636,7 +636,7 @@ sub replace_OGP_Env_Vars{
# If the install file exists, the game can be auto updated, else it will be ignored by the game for improper syntax # If the install file exists, the game can be auto updated, else it will be ignored by the game for improper syntax
# To generate the install file, the "Install/Update via Steam" button must be clicked on at least once! # To generate the install file, the "Install/Update via Steam" button must be clicked on at least once!
if(-e $fullPath){ if(-e $fullPath){
$exec_cmd =~ s/{OGP_STEAM_CMD_DIR}/$steamCMDPath/g; $exec_cmd =~ s/{STEAM_CMD_DIR}/$steamCMDPath/g;
$exec_cmd =~ s/{STEAMCMD_INSTALL_FILE}/$steamInsFile/g; $exec_cmd =~ s/{STEAMCMD_INSTALL_FILE}/$steamInsFile/g;
} }
} }
@ -644,7 +644,7 @@ sub replace_OGP_Env_Vars{
# Handle home directory replacement # Handle home directory replacement
if(defined $homepath && $homepath ne ""){ if(defined $homepath && $homepath ne ""){
$exec_cmd =~ s/{OGP_HOME_DIR}/$homepath/g; $exec_cmd =~ s/{HOME_DIR}/$homepath/g;
} }
# Handle global game shared directory replacement # Handle global game shared directory replacement
@ -656,7 +656,7 @@ sub replace_OGP_Env_Vars{
{ {
logger "Could not create " . $shared_path . " directory $!.", 1; logger "Could not create " . $shared_path . " directory $!.", 1;
} }
$exec_cmd =~ s/{OGP_GAME_SHARED_DIR}/$shared_path/g; $exec_cmd =~ s/{GAME_SHARED_DIR}/$shared_path/g;
} }
return $exec_cmd; return $exec_cmd;
@ -840,11 +840,11 @@ sub universal_start_without_decrypt
my $owner = SERVER_RUNNER_USER; my $owner = SERVER_RUNNER_USER;
my $group = SERVER_RUNNER_USER; my $group = SERVER_RUNNER_USER;
my $ogpAgentGroup = `whoami`; my $agentGroup = `whoami`;
my $screen_id = create_screen_id(SCREEN_TYPE_HOME, $home_id); my $screen_id = create_screen_id(SCREEN_TYPE_HOME, $home_id);
chomp $ogpAgentGroup; chomp $agentGroup;
if(defined LINUX_USER_PER_GAME_SERVER && LINUX_USER_PER_GAME_SERVER eq "1"){ if(defined LINUX_USER_PER_GAME_SERVER && LINUX_USER_PER_GAME_SERVER eq "1"){
$owner = "gamehome" . $home_id; $owner = "gamehome" . $home_id;
@ -862,12 +862,12 @@ sub universal_start_without_decrypt
} }
} }
# Fix perms on ogp_agent user's homedir so that other users can access their owned files within this dir # Fix perms on agent user's homedir so that other users can access their owned files within this dir
my $fixOGPHomeDirCommand = 'chmod -R ug+rwx $( getent passwd "' . $ogpAgentGroup . '" | cut -d: -f6 )'; my $fixHomeDirCommand = 'chmod -R ug+rwx $( getent passwd "' . $agentGroup . '" | cut -d: -f6 )';
sudo_exec_without_decrypt($fixOGPHomeDirCommand); sudo_exec_without_decrypt($fixHomeDirCommand);
$fixOGPHomeDirCommand = 'find "$( getent passwd "' . $ogpAgentGroup . '" | cut -d: -f6 )" -type d -print0 | xargs -0 chmod o+x'; $fixHomeDirCommand = 'find "$( getent passwd "' . $agentGroup . '" | cut -d: -f6 )" -type d -print0 | xargs -0 chmod o+x';
sudo_exec_without_decrypt($fixOGPHomeDirCommand); sudo_exec_without_decrypt($fixHomeDirCommand);
# Some game require that we are in the directory where the binary is. # Some game require that we are in the directory where the binary is.
my $game_binary_dir = Path::Class::Dir->new($home_path, $run_dir); my $game_binary_dir = Path::Class::Dir->new($home_path, $run_dir);
@ -904,7 +904,7 @@ sub universal_start_without_decrypt
my @prestartenvvars = split /[\r\n]+/, $envVars; my @prestartenvvars = split /[\r\n]+/, $envVars;
my $envVarStr = ""; my $envVarStr = "";
foreach my $line (@prestartenvvars) { foreach my $line (@prestartenvvars) {
$line = replace_OGP_Env_Vars("", $home_id, $home_path, $line, $game_key); $line = replace_Env_Vars("", $home_id, $home_path, $line, $game_key);
if($line ne ""){ if($line ne ""){
logger "Configuring environment variable: $line"; logger "Configuring environment variable: $line";
$envVarStr .= "$line\n"; $envVarStr .= "$line\n";
@ -959,8 +959,8 @@ sub universal_start_without_decrypt
my $command; my $command;
my $run_before_start; my $run_before_start;
# Replace any OGP variables found in the command line # Replace any variables found in the command line
$startup_cmd = replace_OGP_Env_Vars($screen_id, $home_id, $home_path, $startup_cmd, $game_key); $startup_cmd = replace_Env_Vars($screen_id, $home_id, $home_path, $startup_cmd, $game_key);
if($file_extension eq ".exe" or $file_extension eq ".bat") if($file_extension eq ".exe" or $file_extension eq ".bat")
{ {
@ -971,7 +971,7 @@ sub universal_start_without_decrypt
$command = "taskset -c $cpu wine $server_exe $startup_cmd"; $command = "taskset -c $cpu wine $server_exe $startup_cmd";
} }
if(defined($Cfg::Preferences{ogp_autorestart_server}) && $Cfg::Preferences{ogp_autorestart_server} eq "1"){ if(defined($Cfg::Preferences{autorestart_server}) && $Cfg::Preferences{autorestart_server} eq "1"){
deleteStoppedStatFile($home_path); deleteStoppedStatFile($home_path);
$cli_bin = create_screen_cmd_loop($screen_id, $command, $envVars); $cli_bin = create_screen_cmd_loop($screen_id, $command, $envVars);
}else{ }else{
@ -987,7 +987,7 @@ sub universal_start_without_decrypt
$command = "taskset -c $cpu $startup_cmd"; $command = "taskset -c $cpu $startup_cmd";
} }
if(defined($Cfg::Preferences{ogp_autorestart_server}) && $Cfg::Preferences{ogp_autorestart_server} eq "1"){ if(defined($Cfg::Preferences{autorestart_server}) && $Cfg::Preferences{autorestart_server} eq "1"){
deleteStoppedStatFile($home_path); deleteStoppedStatFile($home_path);
$cli_bin = create_screen_cmd_loop($screen_id, $command, $envVars); $cli_bin = create_screen_cmd_loop($screen_id, $command, $envVars);
}else{ }else{
@ -1003,7 +1003,7 @@ sub universal_start_without_decrypt
$command = "taskset -c $cpu ./$server_exe $startup_cmd"; $command = "taskset -c $cpu ./$server_exe $startup_cmd";
} }
if(defined($Cfg::Preferences{ogp_autorestart_server}) && $Cfg::Preferences{ogp_autorestart_server} eq "1"){ if(defined($Cfg::Preferences{autorestart_server}) && $Cfg::Preferences{autorestart_server} eq "1"){
deleteStoppedStatFile($home_path); deleteStoppedStatFile($home_path);
$cli_bin = create_screen_cmd_loop($screen_id, $command, $envVars); $cli_bin = create_screen_cmd_loop($screen_id, $command, $envVars);
}else{ }else{
@ -1297,13 +1297,13 @@ sub stop_server_without_decrypt
} }
# Create file indicator that the game server has been stopped if defined # Create file indicator that the game server has been stopped if defined
if(defined($Cfg::Preferences{ogp_autorestart_server}) && $Cfg::Preferences{ogp_autorestart_server} eq "1"){ if(defined($Cfg::Preferences{autorestart_server}) && $Cfg::Preferences{autorestart_server} eq "1"){
# Get current directory and chdir into the game's home dir # Get current directory and chdir into the game's home dir
my $curDir = getcwd(); my $curDir = getcwd();
chdir $home_path; chdir $home_path;
# Create stopped indicator file used by autorestart of OGP if server crashes # Create stopped indicator file used by autorestart if server crashes
open(STOPFILE, '>', "SERVER_STOPPED"); open(STOPFILE, '>', "SERVER_STOPPED");
close(STOPFILE); close(STOPFILE);
@ -1997,7 +1997,7 @@ sub lock_additional_files_logic{
my $commandStr = ""; my $commandStr = "";
$filesToLock = startup_comma_format_to_multiline($filesToLock); $filesToLock = startup_comma_format_to_multiline($filesToLock);
$filesToLock = replace_OGP_Env_Vars("", "", $homedir, $filesToLock); $filesToLock = replace_Env_Vars("", "", $homedir, $filesToLock);
my @filesToProcess = split /[\r\n]+/, $filesToLock; my @filesToProcess = split /[\r\n]+/, $filesToLock;
foreach my $line (@filesToProcess) { foreach my $line (@filesToProcess) {
my $fullPath = $homedir . "/" . $line; my $fullPath = $homedir . "/" . $line;
@ -2038,7 +2038,7 @@ sub run_before_start_commands
{ {
logger "Running pre-start XML commands before starting server ID $server_id with a home directory of $homedir."; logger "Running pre-start XML commands before starting server ID $server_id with a home directory of $homedir.";
my @prestartcmdlines = split /[\r\n]+/, $beforestartcmd; my @prestartcmdlines = split /[\r\n]+/, $beforestartcmd;
my $prestartcmdfile = $homedir."/".'prestart_ogp.sh'; my $prestartcmdfile = $homedir."/".'prestart.sh';
open FILE, '>', $prestartcmdfile; open FILE, '>', $prestartcmdfile;
print FILE "#!/bin/bash" . "\n"; print FILE "#!/bin/bash" . "\n";
print FILE "cd $homedir\n"; print FILE "cd $homedir\n";
@ -2061,7 +2061,7 @@ sub multiline_to_startup_comma_format{
my ($multiLineVar) = @_; my ($multiLineVar) = @_;
$multiLineVar =~ s/,//g; # commas are invalid anyways in bash $multiLineVar =~ s/,//g; # commas are invalid anyways in bash
$multiLineVar =~ s/[\r]+//g; $multiLineVar =~ s/[\r]+//g;
$multiLineVar =~ s/[\n]+/{OGPNEWLINE}/g; $multiLineVar =~ s/[\n]+/{NEWLINE}/g;
return $multiLineVar; return $multiLineVar;
} }
@ -2073,7 +2073,7 @@ sub multiline_to_bash_commands{
sub startup_comma_format_to_multiline{ sub startup_comma_format_to_multiline{
my ($multiLineVar) = @_; my ($multiLineVar) = @_;
$multiLineVar =~ s/{OGPNEWLINE}/\n/g; $multiLineVar =~ s/{NEWLINE}/\n/g;
return $multiLineVar; return $multiLineVar;
} }
@ -3216,7 +3216,7 @@ sub ftp_mgr
$password =~ s/('+)/'\"$1\"'/g; $password =~ s/('+)/'\"$1\"'/g;
$home_path =~ s/('+)/'\"$1\"'/g; $home_path =~ s/('+)/'\"$1\"'/g;
if(!defined($Cfg::Preferences{ogp_manages_ftp}) || (defined($Cfg::Preferences{ogp_manages_ftp}) && $Cfg::Preferences{ogp_manages_ftp} eq "1")){ if(!defined($Cfg::Preferences{manages_ftp}) || (defined($Cfg::Preferences{manages_ftp}) && $Cfg::Preferences{manages_ftp} eq "1")){
if( defined($Cfg::Preferences{ftp_method}) && $Cfg::Preferences{ftp_method} eq "IspConfig") if( defined($Cfg::Preferences{ftp_method}) && $Cfg::Preferences{ftp_method} eq "IspConfig")
{ {
use constant ISPCONFIG_DIR => Path::Class::Dir->new(AGENT_RUN_DIR, 'IspConfig'); use constant ISPCONFIG_DIR => Path::Class::Dir->new(AGENT_RUN_DIR, 'IspConfig');
@ -3278,7 +3278,7 @@ sub ftp_mgr
chmod 0777, 'ehcp_ftp_log.txt'; chmod 0777, 'ehcp_ftp_log.txt';
# In order to access the FTP files, the vsftpd user needs to be added to the ogp group # In order to access the FTP files, the vsftpd user needs to be added to the group
sudo_exec_without_decrypt("usermod -a -G '$gid' ftp"); sudo_exec_without_decrypt("usermod -a -G '$gid' ftp");
sudo_exec_without_decrypt("usermod -a -G '$gid' vsftpd"); sudo_exec_without_decrypt("usermod -a -G '$gid' vsftpd");
sudo_exec_without_decrypt("usermod -a -G '$gidTwo' ftp"); sudo_exec_without_decrypt("usermod -a -G '$gidTwo' ftp");
@ -3798,19 +3798,19 @@ sub agent_restart
if ($dec_check eq 'restart') if ($dec_check eq 'restart')
{ {
chdir AGENT_RUN_DIR; chdir AGENT_RUN_DIR;
if(-e "ogp_agent_run.pid") if(-e "agent_run.pid")
{ {
my $init_pid = `cat ogp_agent_run.pid`; my $init_pid = `cat agent_run.pid`;
chomp($init_pid); chomp($init_pid);
if(kill 0, $init_pid) if(kill 0, $init_pid)
{ {
my $or_exist = ""; my $or_exist = "";
my $rm_pid_file = ""; my $rm_pid_file = "";
if(-e "ogp_agent.pid") if(-e "agent.pid")
{ {
$rm_pid_file = " ogp_agent.pid"; $rm_pid_file = " agent.pid";
my $agent_pid = `cat ogp_agent.pid`; my $agent_pid = `cat agent.pid`;
chomp($agent_pid); chomp($agent_pid);
if( kill 0, $agent_pid ) if( kill 0, $agent_pid )
{ {
@ -3819,13 +3819,13 @@ sub agent_restart
} }
open (AGENT_RESTART_SCRIPT, '>', 'tmp_restart.sh'); open (AGENT_RESTART_SCRIPT, '>', 'tmp_restart.sh');
my $restart = "echo -n \"Stopping OGP Agent...\"\n". my $restart = "echo -n \"Stopping Game Server Agent...\"\n".
"kill $init_pid\n". "kill $init_pid\n".
"while [ -e /proc/$init_pid $or_exist ];do echo -n .;sleep 1;done\n". "while [ -e /proc/$init_pid $or_exist ];do echo -n .;sleep 1;done\n".
"rm -f ogp_agent_run.pid $rm_pid_file\necho \" [OK]\"\n". "rm -f agent_run.pid $rm_pid_file\necho \" [OK]\"\n".
"echo -n \"Starting OGP Agent...\"\n". "echo -n \"Starting Game Server Agent...\"\n".
"screen -d -m -t \"ogp_agent\" -c \"" . SCREENRC_FILE . "\" -S ogp_agent bash ogp_agent_run -pidfile ogp_agent_run.pid\n". "screen -d -m -t \"agent\" -c \"" . SCREENRC_FILE . "\" -S agent bash agent_run -pidfile agent_run.pid\n".
"while [ ! -e ogp_agent_run.pid -o ! -e ogp_agent.pid ];do echo -n .;sleep 1;done\n". "while [ ! -e agent_run.pid -o ! -e agent.pid ];do echo -n .;sleep 1;done\n".
"echo \" [OK]\"\n". "echo \" [OK]\"\n".
"rm -f tmp_restart.sh\n". "rm -f tmp_restart.sh\n".
"exit 0\n"; "exit 0\n";
@ -4646,7 +4646,7 @@ sub generate_post_install_scripts
' fi'."\n". ' fi'."\n".
' fi'."\n". ' fi'."\n".
' if [ ! -d "${mods_info_path}" ];then mkdir -p "${mods_info_path}";fi'."\n". ' if [ ! -d "${mods_info_path}" ];then mkdir -p "${mods_info_path}";fi'."\n".
' echo "${mod_name[$i]}" > "${mods_info_path}${mod_string[$i]}.ogpmod"'."\n". ' echo "${mod_name[$i]}" > "${mods_info_path}${mod_string[$i]}.modinfo"'."\n".
' i=$(expr $i + 1)'."\n". ' i=$(expr $i + 1)'."\n".
'done'."\n"; 'done'."\n";
return "$post_install_scripts"; return "$post_install_scripts";
@ -4664,7 +4664,7 @@ sub get_workshop_mods_info()
my @mods_info; my @mods_info;
while(my $mod_info_file = readdir(MODS_INFO_DIR)) while(my $mod_info_file = readdir(MODS_INFO_DIR))
{ {
if($mod_info_file =~ /\.ogpmod$/) if($mod_info_file =~ /\.modinfo$/)
{ {
my $mod_info_file_path = Path::Class::File->new($mods_info_dir_path, $mod_info_file); my $mod_info_file_path = Path::Class::File->new($mods_info_dir_path, $mod_info_file);
if(open(my $fh, '<:encoding(UTF-8)', $mod_info_file_path)) if(open(my $fh, '<:encoding(UTF-8)', $mod_info_file_path))
@ -4673,7 +4673,7 @@ sub get_workshop_mods_info()
chomp $row; chomp $row;
if($row ne "") if($row ne "")
{ {
my ($string_name, $ext) = split(/\.ogp/, $mod_info_file); my ($string_name, $ext) = split(/\.mod/, $mod_info_file);
push @mods_info, "$string_name:$row"; push @mods_info, "$string_name:$row";
} }
close($fh); close($fh);