reverted the new updates

This commit is contained in:
Frank Harris 2026-01-16 02:57:05 -06:00
parent 9c04036ac0
commit 49600d1cfd
5 changed files with 532 additions and 748 deletions

View file

@ -21,167 +21,312 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
require_once('includes/lib_remote.php');
require_once('modules/config_games/server_config_parser.php');
require_once('modules/steam_workshop/lib/Workshop.php');
require_once('modules/steam_workshop/functions.php');
require_once("includes/lib_remote.php");
require_once("modules/config_games/server_config_parser.php");
require_once("modules/steam_workshop/functions.php");
require_once('includes/form_table_class.php');
echo '<link rel="stylesheet" type="text/css" href="css/xbbcode/xbbcode.css">'."\n".
'<script type="text/javascript" src="js/xbbcode/xbbcode.js"></script>'."\n".
'<script type="text/javascript" src="js/modules/steam_workshop.js"></script>';
function exec_ogp_module()
{
global $db, $view, $settings;
Global $db,$view,$settings;
echo '<h2>Steam Workshop</h2>';
if (!isset($_GET['home_id-mod_id-ip-port']) || $_GET['home_id-mod_id-ip-port'] === '') {
print_failure(sw_text('no_game_servers_assigned'));
define('CONFIGS', "modules/steam_workshop/game_configs/");
if(isset($_GET['home_id-mod_id-ip-port']) && $_GET['home_id-mod_id-ip-port'] != "")
list($home_id, $mod_id, $ip, $port) = explode("-", $_GET['home_id-mod_id-ip-port']);
else
{
print_failure(get_lang('no_game_servers_assigned'));
return;
}
list($homeId, $modId) = explode('-', $_GET['home_id-mod_id-ip-port']);
$isAdmin = $db->isAdmin($_SESSION['user_id']);
$homeCfg = $isAdmin ? $db->getGameHome($homeId) : $db->getUserGameHome($_SESSION['user_id'], $homeId);
if (!$homeCfg) {
print_failure(sw_text('game_home_not_found'));
return;
if(!isset($_POST['workshop_mod_id']) and !isset($_GET['show_log']) and !isset($_POST['manual_workshop_mod_id']))
{
echo "<ul>".
"<li><a href='?m=steam_workshop&p=uninstall&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('uninstall_mods')."</a></li>".
"<li><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('back')."</a></li>".
"</ul>";
}
$serverXml = read_server_config(SERVER_CONFIG_LOCATION . '/' . $homeCfg['home_cfg_file']);
if ($serverXml === false) {
print_failure(sw_text('failed_reading_xml_file', SERVER_CONFIG_LOCATION . '/' . $homeCfg['home_cfg_file']));
return;
}
if (!isset($homeCfg['mods'][$modId]['mod_key'])) {
print_failure(sw_text('mod_id_does_not_exists_in_home', $modId, $homeId));
return;
}
$modKey = $homeCfg['mods'][$modId]['mod_key'];
$modXml = xml_get_mod($serverXml, $modKey);
if (!$modXml) {
print_failure(sw_text('mod_key_not_found_from_xml', $modKey));
return;
}
$configStore = new WorkshopConfigStore('modules/steam_workshop/data/configs.json');
$stateStore = new WorkshopStateStore('modules/steam_workshop/data');
$resolver = new WorkshopResolver();
$config = $configStore->get($homeId);
if ($config === null) {
$config = workshop_build_default_config($homeCfg, $modXml, $settings);
$configStore->put($homeId, $config);
}
$remote = new OGPRemoteLibrary($homeCfg['agent_ip'], $homeCfg['agent_port'], $homeCfg['encryption_key'], $homeCfg['timeout']);
if ($remote->status_chk() !== 1) {
print_failure(sw_text('remote_server_offline'));
return;
}
$syncService = new WorkshopSyncService($remote, $homeCfg, $configStore, $stateStore, $resolver);
$state = $stateStore->get($homeId);
$items = $resolver->resolveItems($config);
$details = $resolver->fetchItemDetails($items);
$message = '';
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'add_item':
if (isset($_POST['item_id']) && preg_match('/^[0-9]+$/', $_POST['item_id'])) {
$config['workshop_item_ids'][] = $_POST['item_id'];
$config['workshop_item_ids'] = array_values(array_unique(array_filter($config['workshop_item_ids'], 'strlen')));
$configStore->put($homeId, $config);
$items = $resolver->resolveItems($config);
$details = $resolver->fetchItemDetails($items);
$message = sw_text('mod_installation_started');
} else {
print_failure(sw_text('invalid_mod_id'));
$isAdmin = $db->isAdmin( $_SESSION['user_id'] );
if($isAdmin)
$home_cfg = $db->getGameHome($home_id);
else
$home_cfg = $db->getUserGameHome($_SESSION['user_id'],$home_id);
if($home_cfg)
{
$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_cfg['home_cfg_file']);
if($server_xml === FALSE)
{
print_failure(get_lang_f('failed_reading_xml_file', SERVER_CONFIG_LOCATION."/".$home_cfg['home_cfg_file']));
return;
}
if(!isset($home_cfg['mods'][$mod_id]['mod_key']))
{
print_failure(get_lang_f('mod_id_does_not_exists_in_home', $mod_id, $home_id));
return;
}
$modkey = $home_cfg['mods'][$mod_id]['mod_key'];
$mod_xml = xml_get_mod($server_xml, $modkey);
if (!$mod_xml)
{
print_failure(get_lang_f('mod_key_not_found_from_xml', $modkey));
return;
}
if(preg_match('/(linux|win)(32|64)?/i', $home_cfg['game_key'], $matches))
{
$os = "";
if(strtolower($matches[1]) == 'linux')
$os = "Linux";
elseif(strtolower($matches[1]) == 'win')
$os = "Windows";
}
else
{
print_failure(get_lang_f('unable_to_get_os_from_game_key', $home_cfg['game_key']));
return;
}
$xml_file = CONFIGS.$mod_xml->installer_name."_".$os.".xml";
if(!file_exists($xml_file))
{
print_failure(get_lang('workshop_configuration_not_found'));
return;
}
$dom = new DOMDocument();
if ( @$dom->load($xml_file) === FALSE )
{
print_failure(get_lang('workshop_configuration_file_has_bad_format'));
return;
}
$xml = simplexml_load_file($xml_file);
if($xml !== false)
{
$remote = new OGPRemoteLibrary($home_cfg['agent_ip'],$home_cfg['agent_port'],$home_cfg['encryption_key'], $home_cfg['timeout']);
if($remote->status_chk() !== 1)
{
print_failure(get_lang('remote_server_offline'));
}
if(isset($_GET['show_log']))
{
$update_active = $remote->get_log(OGP_SCREEN_TYPE_UPDATE,$home_id,clean_path($home_cfg['home_path']),$log_txt);
if ( $update_active == 1 )
{
if(isset($_POST['sgc']))
{
$remote->send_steam_guard_code($home_id, $_POST['sgc']);
return;
}
echo "<p class='note'>". get_lang("update_in_progress") ."</p>\n";
echo "<pre>".$log_txt."</pre>\n</script>\n<div id='dialog' ></div>\n";
if(preg_match('/Two-factor code:$/m', $log_txt) and !isset($_GET['get_sgc']))
{
$view->refresh("?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."&get_sgc=show&show_log",0);
return;
}
if(isset($_GET['get_sgc']) && $_GET['get_sgc'] == 'show')
return;
echo "<p><a href=\"?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."&show_log\">";
echo get_lang("refresh_steam_workshop_status") ."</a></p>";
$view->refresh("?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."&show_log",5);
}
break;
case 'add_collection':
if (isset($_POST['collection_id']) && preg_match('/^[0-9]+$/', $_POST['collection_id'])) {
$config['collection_ids'][] = $_POST['collection_id'];
$config['collection_ids'] = array_values(array_unique(array_filter($config['collection_ids'], 'strlen')));
$configStore->put($homeId, $config);
$items = $resolver->resolveItems($config);
$details = $resolver->fetchItemDetails($items);
$message = sw_text('settings_updated');
} else {
print_failure(sw_text('invalid_mod_id'));
else
{
print_success( get_lang("update_completed") );
echo "<pre>".$log_txt."</pre>\n";
echo "<table class='center'><tr><td><a href='?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'><< ". get_lang("back") ."</a></td></tr></table>";
}
break;
case 'remove_item':
if (isset($_POST['item_id'])) {
$config['workshop_item_ids'] = array_values(array_filter($config['workshop_item_ids'], function ($id) {
return isset($_POST['item_id']) ? ($id !== $_POST['item_id']) : true;
}));
$configStore->put($homeId, $config);
$items = $resolver->resolveItems($config);
$details = $resolver->fetchItemDetails($items);
$message = sw_text('settings_updated');
}
else
{
if(isset($_POST['workshop_mod_id']) OR isset($_POST['manual_workshop_mod_id']))
{
$failure = false;
if(isset($_POST['manual_workshop_mod_id']) and $_POST['manual_workshop_mod_id'] != "" and preg_match('/^([0-9]+,?)+$/', $_POST['manual_workshop_mod_id']))
{
$mods_list = $_POST['manual_workshop_mod_id'];
$mod_id_array = explode(',', $mods_list);
foreach($mod_id_array as $workshop_mod_id)
{
$exist = false;
foreach($xml->mods->mod as $mod)
{
if($mod['id'] == $workshop_mod_id)
{
$exist = true;
break;
}
}
if(belongs_to_workshop($workshop_mod_id, $xml->workshop_id))
{
if(!$exist)
{
list($mod_title, $mod_description, $mod_image_url, $download_url, $filename, $file_size) = get_mod_info($workshop_mod_id);
//add mods to the xml
$mod = new SimpleXMLElement('<mod/>');
$mod->addAttribute('id', $workshop_mod_id);
$mod->addChild('name', $mod_title);
$mod->addChild('description', base64_encode($mod_description));
$mod->addChild('image_url', $mod_image_url);
$mod->addChild('download_url', $download_url);
$mod->addChild('filename', $filename);
$mod->addChild('file_size', $file_size);
$moddom = dom_import_simplexml($mod)->ownerDocument;
$moddom->formatOutput = true;
$mod_string = $moddom->saveXML($moddom->documentElement);
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
$mods = $dom->getElementsByTagName('mods')->item(0);
$f = $dom->createDocumentFragment();
$f->appendXML($mod_string."\n");
$mods->appendChild($f);
file_put_contents($xml_file, $dom->saveXML());
$xml = simplexml_load_file($xml_file);
}
}
else
{
print_failure(get_lang_f('mod_does_not_belong_to_workshop', $workshop_mod_id));
$failure = true;
}
}
}
elseif(isset($_POST['workshop_mod_id']))
{
$mods_list = implode(',',$_POST['workshop_mod_id']);
}
if(isset($_POST['install']) and !$failure and isset($mods_list) and preg_match('/^([0-9]+,?)+$/', $mods_list))
{
$config = $xml->config;
$anonymous_login = $xml->anonymous_login;
$download_method = $xml->download_method;
$user = $settings['steam_user'];
$pass = $settings['steam_pass'];
$regex = $config->regex;
$mods_backreference_index = (int)$config->mods_backreference_index;
$variable = $config->variable;
$place_after = $config->place_after;
$mod_string = $config->mod_string;
$string_separator = $config->string_separator;
$config_file_path = clean_path($home_cfg['home_path']."/".$config->filepath);
$post_install = $xml->post_install;
$mod_names_list = get_mod_names_list($mods_list, $xml->mods->mod);
$mods_full_path = clean_path($home_cfg['home_path'].'/'.$xml->mods_path);
$workshop_id = $xml->workshop_id;
$url_list = "";
$filename_list = "";
if($download_method == "steamapi")
{
foreach(explode(',', $mods_list) as $workshop_mod_id)
{
foreach($xml->mods->mod as $mod)
{
if($mod['id'] == $workshop_mod_id)
{
$separator = $url_list == ""?"":",";
$url_list .= $separator.$mod->download_url;
$filename_list .= $separator.$mod->filename;
}
}
}
}
$steam_out = $remote->steam_workshop($home_id, $mods_full_path,
$workshop_id, $mods_list,
$regex, $mods_backreference_index,
$variable, $place_after, $mod_string,
$string_separator, $config_file_path,
$post_install, $mod_names_list,
$anonymous_login, $user, $pass,
$download_method, $url_list, $filename_list);
if ( $steam_out === 1 )
{
print_success( get_lang("mod_installation_started") );
$view->refresh("?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."&show_log", 2);
}
elseif( $steam_out === 0 )
{
print_failure( get_lang("failed_to_start_steam_workshop") );
return;
}
elseif ( $steam_out === -1 )
{
print_failure( get_lang("connection_error") );
}
}
if(isset($_POST['show_info']) and !$failure and isset($mods_list) and preg_match('/^([0-9]+,?)+$/', $mods_list))
{
$mod_id_array = explode(',', $mods_list);
echo "<table>";
foreach($xml->mods->mod as $mod)
{
if(in_array($mod['id'],$mod_id_array))
{
echo "<tr><td><h4>".$mod->name."</h4>".
"<div><img width='240px' style='float:left;' src='".$mod->image_url."'>".
"<div class='bbcode_container' style='padding-left:245px;'>".htmlentities(base64_decode($mod->description))."</div></div><td><tr>";
}
}
echo "</table><a href='?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('back')."</a>";
}
}
break;
case 'sync_now':
$result = $syncService->sync($homeId);
if ($result->success) {
print_success($result->message);
} else {
print_failure($result->message);
else
{
$ft = new FormTable();
$ft->start_form("?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port'], "post", "onsubmit='return isValidForm(this)' data-form-error='".get_lang('select_at_least_one_mod_or_enter_mod_id')."'");
$ft->start_table();
if(count($xml->mods->mod) > 0)
{
echo '<tr><td colspan=2><div id="uninstall_scrolling_checkbox">';
foreach($xml->mods->mod as $mod)
echo "<input type='checkbox' id='select_mod_$mod[id]' name='workshop_mod_id[]' value='$mod[id]'><label for='select_mod_$mod[id]'>".$mod->name."</label><br>";
echo '</div></td></tr>';
}
$ft->add_field('string', 'manual_workshop_mod_id','');
$ft->end_table();
$ft->add_button("submit", "install", get_lang('install_mod'));
$ft->add_button("submit", "show_info", get_lang('show_mod_info'));
$ft->end_form();
}
$state = $stateStore->get($homeId);
break;
}
}
else
{
print_failure(get_lang('workshop_configuration_file_has_bad_format'));
return;
}
}
if ($message !== '') {
print_success($message);
else
{
print_failure(get_lang('game_home_not_found'));
return;
}
echo '<div class="panel">';
echo '<h3>' . sw_text('installed_mods') . '</h3>';
if (empty($items)) {
echo '<p>' . sw_text('no_mods_found') . '</p>';
} else {
echo '<table class="table table-bordered">';
echo '<tr><th>ID</th><th>' . sw_text('name') . '</th><th>' . sw_text('status') . '</th><th></th></tr>';
foreach ($items as $id) {
$name = isset($details[$id]['title']) ? htmlentities($details[$id]['title']) : $id;
$status = isset($state['items'][$id]) ? sw_text('installed') : sw_text('pending');
echo '<tr>';
echo '<td>' . $id . '</td>';
echo '<td>' . $name . '</td>';
echo '<td>' . $status . '</td>';
echo '<td>';
echo '<form method="post" style="display:inline">';
echo '<input type="hidden" name="item_id" value="' . $id . '">';
echo '<button class="btn btn-xs btn-danger" name="action" value="remove_item">' . sw_text('remove') . '</button>';
echo '</form>';
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
echo '</div>';
echo '<div class="panel">';
echo '<h3>' . sw_text('add_mod') . '</h3>';
echo '<form method="post">';
echo '<input type="text" name="item_id" placeholder="' . sw_text('workshop_id') . '"> ';
echo '<button class="btn btn-primary" name="action" value="add_item">' . sw_text('add') . '</button>';
echo '</form>';
echo '<form method="post" style="margin-top:10px">';
echo '<input type="text" name="collection_id" placeholder="' . sw_text('collection_id') . '"> ';
echo '<button class="btn btn-primary" name="action" value="add_collection">' . sw_text('add') . '</button>';
echo '</form>';
echo '</div>';
echo '<div class="panel">';
echo '<h3>' . sw_text('actions') . '</h3>';
echo '<form method="post">';
echo '<button class="btn btn-success" name="action" value="sync_now">' . sw_text('refresh_steam_workshop_status') . '</button>';
echo '</form>';
echo '</div>';
}
?>