diff --git a/Panel/js/modules/addonsmanager.js b/Panel/js/modules/addonsmanager.js index a8856049..dce93ed6 100644 --- a/Panel/js/modules/addonsmanager.js +++ b/Panel/js/modules/addonsmanager.js @@ -11,14 +11,16 @@ $(function() { download_zip: ['#scm-row-url', '#scm-row-path'], steam_workshop: ['#scm-row-workshop-xml-info'], post_script: ['#scm-row-post-script'], - config_edit: ['#scm-row-path', '#scm-row-config-edit-rule'] + config_edit: ['#scm-row-path', '#scm-row-config-edit-rule'], + server_app: ['.scm-row-server-app'] }; var allRows = [ '#scm-row-url', '#scm-row-path', '#scm-row-workshop-xml-info', '#scm-row-post-script', - '#scm-row-config-edit-rule' + '#scm-row-config-edit-rule', + '.scm-row-server-app' ]; var $method = $('#scm-install-method'); var $help = $('#scm-install-method-help'); diff --git a/Panel/modules/addonsmanager/addons_installer.php b/Panel/modules/addonsmanager/addons_installer.php index e5319d0a..67b94521 100644 --- a/Panel/modules/addonsmanager/addons_installer.php +++ b/Panel/modules/addonsmanager/addons_installer.php @@ -171,7 +171,7 @@ function exec_ogp_module() { { $addon_id = (int)$_REQUEST['addon_id']; - $addons_rows = $db->resultQuery("SELECT url, path, post_script, addon_type, install_method, content_version, requires_stop, restart_after_install, workshop_item_id, workshop_app_id, target_path_template, optional_folder_name, config_edit_rule, launch_param_additions, name FROM OGP_DB_PREFIXaddons WHERE addon_id=".$addon_id.$query_groups); + $addons_rows = $db->resultQuery("SELECT url, path, post_script, addon_type, install_method, content_version, requires_stop, restart_after_install, workshop_item_id, workshop_app_id, target_path_template, optional_folder_name, config_edit_rule, launch_param_additions, name, hook_name, hook_enabled, hook_platform, hook_working_dir, hook_start_command, hook_stop_command, hook_start_timing, hook_stop_with_server, hook_watch, hook_critical, hook_kill_game_if_app_exits, hook_restart_app_if_exits, hook_pid_name, hook_app_name, hook_description FROM OGP_DB_PREFIXaddons WHERE addon_id=".$addon_id.$query_groups); if (!is_array($addons_rows)) { $addons_rows = []; } @@ -183,6 +183,15 @@ function exec_ogp_module() { } $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']); + if ($state == "start") { + $gsp_content_base = rtrim((string)$home_info['home_path'], '/\\') . '/_gsp_content'; + $remote->exec( + 'mkdir -p ' . + scm_remote_shell_quote($gsp_content_base . '/hooks') . ' ' . + scm_remote_shell_quote($gsp_content_base . '/generated') . ' ' . + scm_remote_shell_quote($gsp_content_base . '/runtime') + ); + } $addon_info = $addons_rows[0]; $install_method = scm_get_install_method_default(isset($addon_info['install_method']) ? $addon_info['install_method'] : 'download_zip'); @@ -393,6 +402,44 @@ function exec_ogp_module() { echo "
"; return; } + if ($install_method === 'server_app') { + $hook_message = ''; + $hook_ok = scm_install_server_app_hook($remote, $home_info, $addon_info, $hook_message); + if ($hook_ok) { + scm_record_install_done($db, (int)$history_id, 'installed', 0, 'hook_manifest=' . $hook_message); + scm_upsert_manifest($db, $home_id, $addon_id, array( + 'install_method' => $install_method, + 'content_version' => $content_version, + 'install_state' => 'installed', + 'source_url' => '', + 'installed_by' => $user_id, + )); + scm_log_content_install_action(array( + 'addon_id' => (int)$addon_id, + 'addon_name' => isset($addon_info['name']) ? $addon_info['name'] : '', + 'content_type' => $install_method, + 'home_id' => (int)$home_id, + 'home_cfg_id' => (int)$home_info['home_cfg_id'], + 'target_path' => $hook_message, + 'action' => 'succeeded', + )); + print_success('Server-side application hook installed.'); + } else { + scm_record_install_done($db, (int)$history_id, 'failed', 1, $hook_message); + scm_log_content_install_action(array( + 'addon_id' => (int)$addon_id, + 'addon_name' => isset($addon_info['name']) ? $addon_info['name'] : '', + 'content_type' => $install_method, + 'home_id' => (int)$home_id, + 'home_cfg_id' => (int)$home_info['home_cfg_id'], + 'action' => 'failed', + 'error' => $hook_message, + )); + print_failure($hook_message); + } + echo ""; + return; + } if ($install_method === 'config_edit' || $install_method === 'create_folder') { $placeholder_map = scm_build_placeholder_map($home_info, array('exe_location' => (string)$server_xml->exe_location)); $target_template = trim((string)$addon_info['path']); diff --git a/Panel/modules/addonsmanager/addons_manager.php b/Panel/modules/addonsmanager/addons_manager.php index fd254d58..08003875 100644 --- a/Panel/modules/addonsmanager/addons_manager.php +++ b/Panel/modules/addonsmanager/addons_manager.php @@ -72,6 +72,21 @@ function exec_ogp_module() { $fields['optional_folder_name']= ''; $fields['config_edit_rule'] = isset($_POST['config_edit_rule']) ? trim((string)$_POST['config_edit_rule']) : ''; $fields['launch_param_additions'] = ''; + $fields['hook_name'] = isset($_POST['hook_name']) ? trim((string)$_POST['hook_name']) : ''; + $fields['hook_enabled'] = !empty($_POST['hook_enabled']) ? 1 : 0; + $fields['hook_platform'] = scm_normalize_hook_platform(isset($_POST['hook_platform']) ? $_POST['hook_platform'] : 'both'); + $fields['hook_working_dir'] = isset($_POST['hook_working_dir']) ? trim((string)$_POST['hook_working_dir']) : ''; + $fields['hook_start_command'] = isset($_POST['hook_start_command']) ? trim((string)$_POST['hook_start_command']) : ''; + $fields['hook_stop_command'] = isset($_POST['hook_stop_command']) ? trim((string)$_POST['hook_stop_command']) : ''; + $fields['hook_start_timing'] = scm_normalize_hook_start_timing(isset($_POST['hook_start_timing']) ? $_POST['hook_start_timing'] : 'before_server'); + $fields['hook_stop_with_server'] = !empty($_POST['hook_stop_with_server']) ? 1 : 0; + $fields['hook_watch'] = !empty($_POST['hook_watch']) ? 1 : 0; + $fields['hook_critical'] = !empty($_POST['hook_critical']) ? 1 : 0; + $fields['hook_kill_game_if_app_exits'] = !empty($_POST['hook_kill_game_if_app_exits']) ? 1 : 0; + $fields['hook_restart_app_if_exits'] = !empty($_POST['hook_restart_app_if_exits']) ? 1 : 0; + $fields['hook_pid_name'] = isset($_POST['hook_pid_name']) ? trim((string)$_POST['hook_pid_name']) : ''; + $fields['hook_app_name'] = isset($_POST['hook_app_name']) ? trim((string)$_POST['hook_app_name']) : ''; + $fields['hook_description'] = isset($_POST['hook_description']) ? trim((string)$_POST['hook_description']) : ''; $fields['addon_type'] = scm_get_addon_type_from_install_method($fields['install_method']); if ($fields['install_method'] === 'steam_workshop') { $fields['url'] = ''; @@ -102,6 +117,21 @@ function exec_ogp_module() { 'target_path_template' => $fields['target_path_template'], 'post_script' => $fields['post_script'], 'config_edit_rule' => $fields['config_edit_rule'], + 'hook_name' => $fields['hook_name'], + 'hook_enabled' => $fields['hook_enabled'], + 'hook_platform' => $fields['hook_platform'], + 'hook_working_dir' => $fields['hook_working_dir'], + 'hook_start_command' => $fields['hook_start_command'], + 'hook_stop_command' => $fields['hook_stop_command'], + 'hook_start_timing' => $fields['hook_start_timing'], + 'hook_stop_with_server' => $fields['hook_stop_with_server'], + 'hook_watch' => $fields['hook_watch'], + 'hook_critical' => $fields['hook_critical'], + 'hook_kill_game_if_app_exits' => $fields['hook_kill_game_if_app_exits'], + 'hook_restart_app_if_exits' => $fields['hook_restart_app_if_exits'], + 'hook_pid_name' => $fields['hook_pid_name'], + 'hook_app_name' => $fields['hook_app_name'], + 'hook_description' => $fields['hook_description'], ); $validation_message = ''; if (!scm_validate_install_method_payload($fields['install_method'], $validation_payload, $validation_message)) @@ -133,6 +163,21 @@ function exec_ogp_module() { $is_cacheable = isset($_POST['is_cacheable']) ? (int)$_POST['is_cacheable'] : 0; $description = isset($_POST['description']) ? $_POST['description'] : ""; $config_edit_rule = isset($_POST['config_edit_rule']) ? $_POST['config_edit_rule'] : ""; + $hook_name = isset($_POST['hook_name']) ? $_POST['hook_name'] : ""; + $hook_enabled = isset($_POST['hook_enabled']) ? (int)$_POST['hook_enabled'] : 1; + $hook_platform = isset($_POST['hook_platform']) ? $_POST['hook_platform'] : "both"; + $hook_working_dir = isset($_POST['hook_working_dir']) ? $_POST['hook_working_dir'] : ""; + $hook_start_command = isset($_POST['hook_start_command']) ? $_POST['hook_start_command'] : ""; + $hook_stop_command = isset($_POST['hook_stop_command']) ? $_POST['hook_stop_command'] : ""; + $hook_start_timing = isset($_POST['hook_start_timing']) ? $_POST['hook_start_timing'] : "before_server"; + $hook_stop_with_server = isset($_POST['hook_stop_with_server']) ? (int)$_POST['hook_stop_with_server'] : 1; + $hook_watch = isset($_POST['hook_watch']) ? (int)$_POST['hook_watch'] : 1; + $hook_critical = isset($_POST['hook_critical']) ? (int)$_POST['hook_critical'] : 0; + $hook_kill_game_if_app_exits = isset($_POST['hook_kill_game_if_app_exits']) ? (int)$_POST['hook_kill_game_if_app_exits'] : 0; + $hook_restart_app_if_exits = isset($_POST['hook_restart_app_if_exits']) ? (int)$_POST['hook_restart_app_if_exits'] : 1; + $hook_pid_name = isset($_POST['hook_pid_name']) ? $_POST['hook_pid_name'] : ""; + $hook_app_name = isset($_POST['hook_app_name']) ? $_POST['hook_app_name'] : ""; + $hook_description = isset($_POST['hook_description']) ? $_POST['hook_description'] : ""; if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['edit'])) { @@ -156,6 +201,21 @@ function exec_ogp_module() { $is_cacheable = isset($addon_info['is_cacheable']) ? (int)$addon_info['is_cacheable'] : 0; $description = isset($addon_info['description']) ? $addon_info['description'] : ""; $config_edit_rule = isset($addon_info['config_edit_rule']) ? $addon_info['config_edit_rule'] : ""; + $hook_name = isset($addon_info['hook_name']) ? $addon_info['hook_name'] : ""; + $hook_enabled = isset($addon_info['hook_enabled']) ? (int)$addon_info['hook_enabled'] : 1; + $hook_platform = isset($addon_info['hook_platform']) ? $addon_info['hook_platform'] : "both"; + $hook_working_dir = isset($addon_info['hook_working_dir']) ? $addon_info['hook_working_dir'] : ""; + $hook_start_command = isset($addon_info['hook_start_command']) ? $addon_info['hook_start_command'] : ""; + $hook_stop_command = isset($addon_info['hook_stop_command']) ? $addon_info['hook_stop_command'] : ""; + $hook_start_timing = isset($addon_info['hook_start_timing']) ? $addon_info['hook_start_timing'] : "before_server"; + $hook_stop_with_server = isset($addon_info['hook_stop_with_server']) ? (int)$addon_info['hook_stop_with_server'] : 1; + $hook_watch = isset($addon_info['hook_watch']) ? (int)$addon_info['hook_watch'] : 1; + $hook_critical = isset($addon_info['hook_critical']) ? (int)$addon_info['hook_critical'] : 0; + $hook_kill_game_if_app_exits = isset($addon_info['hook_kill_game_if_app_exits']) ? (int)$addon_info['hook_kill_game_if_app_exits'] : 0; + $hook_restart_app_if_exits = isset($addon_info['hook_restart_app_if_exits']) ? (int)$addon_info['hook_restart_app_if_exits'] : 1; + $hook_pid_name = isset($addon_info['hook_pid_name']) ? $addon_info['hook_pid_name'] : ""; + $hook_app_name = isset($addon_info['hook_app_name']) ? $addon_info['hook_app_name'] : ""; + $hook_description = isset($addon_info['hook_description']) ? $addon_info['hook_description'] : ""; } ?>