Browse Source

Setting Up to Fix https://github.com/OpenGamePanel/Module-Cron/issues/13

own3mall 8 năm trước cách đây
mục cha
commit
fc47272997

+ 1 - 0
includes/lib_remote.php

@@ -575,6 +575,7 @@ class OGPRemoteLibrary
 	/// \return -1 If connection could not be established.
 	/// \return -2 In other errors.
 	/// \todo Other return values?
+	// Starts game server
 	public function universal_start($home_id, $game_home, $game_binary, $run_dir, $startup_cmd,
 		$server_port, $server_ip, $cpu, $nice, $preStart, $envVars, $game_key)
 	{

+ 6 - 2
modules/config_games/server_config_parser.php

@@ -42,8 +42,12 @@ function read_server_config( $filename )
     }
 
     $xml = simplexml_load_file($filename);
-    $xml->addChild('home_cfg_file',basename($filename));
-    return $xml;
+    if($xml !== false){
+		$xml->addChild('home_cfg_file',basename($filename));
+		return $xml;
+	}
+	
+	return false;
 }
 
 function xml_get_mod( $server_xml, $mod_key )

+ 25 - 11
modules/gamemanager/home_handling_functions.php

@@ -29,10 +29,17 @@ function get_query_port($server_xml, $server_port)
 	return $server_port;
 }
 
-function get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$os)
+function get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$db)
 {	
 	$last_param = json_decode($home_info['last_param'], True);
 	
+	$os = $remote->what_os();
+	
+	$isAdmin = false;
+	if(hasValue($_SESSION['user_id'])){
+		$isAdmin = $db->isAdmin($_SESSION['user_id']);
+	}
+	
 	$cli_param_data['GAME_TYPE'] = $home_info['mods'][$mod_id]['mod_key'];
 	$cli_param_data['IP'] = $ip;
 	$cli_param_data['PORT'] = $port;
@@ -137,11 +144,14 @@ function get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$os)
 		}
 	}
 
-	// No need to check the access_rights for params and extra params
-	// because, even if the user have no access rights, last_param could be
-	// set by admin or just empty ($last_param === NULL).
-
-	if ( $last_param !== NULL and isset($server_xml->server_params->param) )
+	if ( $isAdmin )
+	{
+		$home_info['access_rights'] = "ufpet";
+	}
+						
+	$param_access_enabled = preg_match("/p/",$home_info['access_rights']) > 0 ? TRUE : FALSE; 
+	
+	if ($param_access_enabled && $last_param !== NULL and isset($server_xml->server_params->param) )
 	{
 		foreach($server_xml->server_params->param as $param)
 		{						
@@ -178,10 +188,14 @@ function get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$os)
 		} 
 	}
 	
-	$extra = ($last_param !== NULL and array_key_exists('extra', $last_param) and $last_param['extra'] != "") ? 
-			  $last_param['extra'] : $home_info['mods'][$mod_id]['extra_params'];
+	$extra_param_access_enabled = preg_match("/e/",$home_info['access_rights']) > 0 ? TRUE:FALSE;
+			
+	if ( array_key_exists('extra', $last_param) && $extra_param_access_enabled )
+		$extra_default = $last_param['extra'];
+	else
+		$extra_default = $home_info['mods'][$mod_id]['extra_params'];
 		
-	$start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($extra, $server_xml->cli_allow_chars));
+	$start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($extra_default, $server_xml->cli_allow_chars));
 
 	return $start_cmd;
 }
@@ -268,7 +282,7 @@ function exec_operation( $action, $home_id, $mod_id, $ip, $port )
 	}
 	elseif ( $action == "restart" AND $screen_running )
 	{
-		$start_cmd = get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$os);
+		$start_cmd = get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$db);
 		// Do text replacements in cfg file
 		if( $server_xml->replace_texts )
 		{
@@ -331,7 +345,7 @@ function exec_operation( $action, $home_id, $mod_id, $ip, $port )
 	}
 	elseif ( $action == "start" AND ! $screen_running )
 	{
-		$start_cmd = get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$os);
+		$start_cmd = get_start_cmd($remote,$server_xml,$home_info,$mod_id,$ip,$port,$db);
 		// Do text replacements in cfg file
 		if( $server_xml->replace_texts )
 		{

+ 3 - 166
modules/gamemanager/restart_server.php

@@ -47,6 +47,8 @@ function exec_ogp_module() {
 
 	require_once('includes/lib_remote.php');
 	$remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
+	
+	$os = $remote->what_os();
 
     if ( $home_info === FALSE )
     {
@@ -208,172 +210,7 @@ function exec_ogp_module() {
 			$control_type = isset($server_xml->control_protocol_type) ? $server_xml->control_protocol_type : "";
 			$run_dir = isset($server_xml->exe_location) ? $server_xml->exe_location : "";
 			
-			$last_param = json_decode($home_info['last_param'], True);
-			
-			$cli_param_data['GAME_TYPE'] = $home_info['mods'][$mod_id]['mod_key'];
-			$cli_param_data['IP'] = $ip;
-			$cli_param_data['PORT'] = $port;
-			$cli_param_data['HOSTNAME'] = $home_info['home_name'];
-			$cli_param_data['PID_FILE'] = "ogp_game_startup.pid";
-			
-			$os = $remote->what_os();
-			// Linux
-			if( preg_match("/Linux/", $os) )
-			{
-				if(preg_match("/_win(32|64)?$/", $home_info['game_key']))
-				{
-					$home_path_wine = $remote->exec("winepath -w ".$home_info['home_path']);
-					$home_path_wine = str_replace("\\","\\\\", $home_path_wine);
-					$home_path_wine = trim($home_path_wine);
-					$cli_param_data['BASE_PATH'] = $home_path_wine;
-					$cli_param_data['HOME_PATH'] = $home_path_wine;
-					$cli_param_data['SAVE_PATH'] = $home_path_wine;
-					$cli_param_data['OUTPUT_PATH'] = $home_path_wine;
-					$cli_param_data['USER_PATH'] = $home_path_wine;
-				}
-				else
-				{
-					$cli_param_data['BASE_PATH'] = $home_info['home_path'];
-					$cli_param_data['HOME_PATH'] = $home_info['home_path'];
-					$cli_param_data['SAVE_PATH'] = $home_info['home_path'];
-					$cli_param_data['OUTPUT_PATH'] = $home_info['home_path'];
-					$cli_param_data['USER_PATH'] = $home_info['home_path'];
-				}
-			}
-			// Windows
-			elseif( preg_match("/CYGWIN/", $os) )
-			{
-				$home_path_win = $remote->exec("cygpath -w ".$home_info['home_path']);
-				$home_path_win = str_replace("\\","\\\\", $home_path_win);
-				$home_path_win = trim($home_path_win);
-				$cli_param_data['BASE_PATH'] = $home_path_win;
-				$cli_param_data['HOME_PATH'] = $home_path_win;
-				$cli_param_data['SAVE_PATH'] = $home_path_win;
-				$cli_param_data['OUTPUT_PATH'] = $home_path_win;
-				$cli_param_data['USER_PATH'] = $home_path_win;
-			}
-			
-			if ($server_xml->protocol == "gameq")
-			{
-				$cli_param_data['QUERY_PORT'] = get_query_port ($server_xml, $port);
-			}
-			elseif ($server_xml->protocol == "lgsl")
-			{
-				require('protocol/lgsl/lgsl_protocol.php');
-				$get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $port, "", "");
-				$cli_param_data['QUERY_PORT'] = $get_ports['1'];
-			}
-			elseif ($server_xml->protocol == "teamspeak3")
-			{
-				$cli_param_data['QUERY_PORT'] = "10011";
-			}
-			
-			$cli_param_data['MAP'] = empty($last_param['map']) ?  "" : $last_param['map'];
-			$cli_param_data['PLAYERS'] = empty($last_param['players']) ? $home_info['mods'][$mod_id]['max_players'] : $last_param['players'];
-			$cli_param_data['CONTROL_PASSWORD'] = $home_info['control_password'];
-			
-			$start_cmd = "";
-			// If the template is empty then these are not needed.
-			if ( $server_xml->cli_template )
-			{
-				$start_cmd = $server_xml->cli_template;
-				if ( $server_xml->cli_params )
-				{
-					foreach ( $server_xml->cli_params->cli_param as $cli )
-					{
-						// If s is found the param is seperated with space
-						$add_space = preg_match( "/s/", $cli['options'] ) > 0 ? " " : "";
-						$cli_value = $cli_param_data[(string) $cli['id'] ];
-						// If q is found we add quotes around the value.
-						if ( preg_match( "/q/", $cli['options'] ) > 0 )
-						{
-							$cli_value = "\"".$cli_value."\"";
-						}
-						$start_cmd = preg_replace( "/%".$cli['id']."%/",
-							$cli['cli_string'].$add_space.$cli_value, $start_cmd );
-					}
-				}
-				if ( $server_xml->reserve_ports )
-				{
-					foreach ( $server_xml->reserve_ports->port as $reserve_port )
-					{
-						// If s is found the param is seperated with space
-						$add_space = preg_match( "/s/", $reserve_port['options'] ) > 0 ? " " : "";
-						
-						if(isset($server_home['port']) && !empty($server_home['port'])){
-							$cli_value = $reserve_port['type'] == "add" ? $server_home['port'] + (string) $reserve_port: 
-																		  $server_home['port'] - (string) $reserve_port;
-						}else if(isset($port)){
-							$cli_value = $reserve_port['type'] == "add" ? $port + (string) $reserve_port: 
-																		  $port - (string) $reserve_port;
-						}else{
-							// Should never hit here, but we'll throw in a default.
-							$cli_value = $reserve_port;
-						}
-						
-						// If q is found we add quotes around the value.
-						if ( preg_match( "/q/", $reserve_port['options'] ) > 0 )
-						{
-							$cli_value = "\"".$cli_value."\"";
-						}
-						$start_cmd = preg_replace( "/%".$reserve_port['id']."%/",
-							$reserve_port['cli_string'].$add_space.$cli_value, $start_cmd );
-					}
-				}
-			}
-			
-			if ( $isAdmin )
-			{
-				$home_info['access_rights'] = "ufpet";
-			}
-						
-			$param_access_enabled = preg_match("/p/",$home_info['access_rights']) > 0 ? TRUE : FALSE;
-						
-			if ( $param_access_enabled && isset($last_param) )
-			{
-				foreach($server_xml->server_params->param as $param)
-				{						
-					foreach ($last_param as $paramKey => $paramValue)
-					{
-						if (!isset($paramValue))
-							$paramValue = (string)$param->default;
-						
-						if ($param['key'] == $paramKey)
-						{	
-							if (0 == strlen($paramValue))
-								continue;
-							if ($param['key'] == $paramValue) // it's a checkbox
-								$new_param = $paramKey;
-							elseif($param->option == "ns" or $param->options == "ns")
-								$new_param = $paramKey . clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
-							elseif($param->option == "q" or $param->options == "q")
-								$new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"';
-							elseif($param->option == "s" or $param->options == "s")
-								$new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
-							else
-								$new_param = $paramKey . ' "' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"';
-						  
-							if ($param['id'] == NULL || $param['id'] == "")
-								$start_cmd .= ' '.$new_param;
-							else
-								$start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd );
-						}			  
-					}
-					
-					if ($param['id'] != NULL && $param['id'] != ""){
-						$start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
-					}
-				} 
-			}
-
-			$extra_param_access_enabled = preg_match("/e/",$home_info['access_rights']) > 0 ? TRUE:FALSE;
-			
-			if ( array_key_exists('extra', $last_param) && $extra_param_access_enabled )
-				$extra_default = $last_param['extra'];
-			else
-				$extra_default = $home_info['mods'][$mod_id]['extra_params'];
-
-			$start_cmd .= " ".$extra_default;
+			$start_cmd = get_start_cmd($remote, $server_xml, $home_info, $mod_id, $ip, $port, $db);
 			
 			// Run pre-start commands
 			if(isset($server_xml->pre_start) && !empty($server_xml->pre_start)){

+ 211 - 89
ogp_api.php

@@ -35,9 +35,10 @@ function outPutJSON($result){
 	exit();
 }
 
-function runSteamAutoUpdate(){
-	global $settings, $db, $remote, $server_xml, $mod_xml, $server_home, $mod_key, $mod_id, $appId, $home_ip_ports;
+function runRemoteAction($action){
+	global $settings, $db, $remote, $server_xml, $mod_xml, $server_home, $mod_key, $mod_id, $appId, $home_ip_ports, $homeId, $resultOp;
 	
+	// Load XML and server options
 	$installer_name = isset($mod_xml->installer_name) ? $mod_xml->installer_name : $mod_key;
 
 	$modname = $installer_name == '90' ? $mod_key : '';
@@ -54,32 +55,156 @@ function runSteamAutoUpdate(){
 	$lockFiles = !empty($server_xml->lock_files) ? trim($server_xml->lock_files) : '';
 	$preStart = !empty($server_xml->pre_start) ? trim($server_xml->pre_start) : '';
 	$envVars = !empty($server_xml->environment_variables) ? trim($server_xml->environment_variables) : '';
-	$startup_cmd = get_start_cmd($remote, $server_xml, $server_home, $mod_id, $home_ip_ports['ip'], $home_ip_ports['port'], $remote->what_os());
+	$startup_cmd = get_start_cmd($remote, $server_xml, $server_home, $mod_id, $home_ip_ports['ip'], $home_ip_ports['port'], $db);
 	
-	// Make the update call
-	$update = $remote->automatic_steam_update(
-		//generic
-		$homeId, $server_home['home_path'], $home_ip_ports['ip'], $home_ip_ports['port'], $exec_path, $exec_folder_path,
-							 
-		//stop
-		$server_xml->control_protocol, $server_home['control_password'], $server_xml->control_type,
-
-		//update
-		$appId, $modname, $betaname, $betapwd, $login, $pass, $settings['steam_guard'], $precmd, $postcmd, $cfg_os, $lockFiles,
-							  
-		//start
-		$startup_cmd, $server_home['mods'][$mod_id]['cpu_affinity'], $server_home['mods'][$mod_id]['nice'], $preStart, $envVars, $server_xml->game_key
-	);
-
-	if($update == 1){
+	switch($action){
+		case "steam_auto_update":
+	
+			// Make the update call
+			$remoteResult = $remote->automatic_steam_update(
+				//generic
+				$homeId, $server_home['home_path'], $home_ip_ports['ip'], $home_ip_ports['port'], $exec_path, $exec_folder_path,
+									 
+				//stop
+				$server_xml->control_protocol, $server_home['control_password'], $server_xml->control_type,
+
+				//update
+				$appId, $modname, $betaname, $betapwd, $login, $pass, $settings['steam_guard'], $precmd, $postcmd, $cfg_os, $lockFiles,
+									  
+				//start
+				$startup_cmd, $server_home['mods'][$mod_id]['cpu_affinity'], $server_home['mods'][$mod_id]['nice'], $preStart, $envVars, $server_xml->game_key
+			);
+			break;
+		case "restart_server":
+			$remoteResult = $remote->remote_restart_server($server_home['home_id'],
+														$home_ip_ports['ip'],
+														$home_ip_ports['port'],
+														$server_xml->control_protocol,
+														$server_home['control_password'],
+														$server_xml->control_protocol_type,
+														$server_home['home_path'],
+														$server_xml->server_exec_name,
+														$server_xml->exe_location,
+														$startup_cmd,
+														$server_home['mods'][$mod_id]['cpu_affinity'],
+														$server_home['mods'][$mod_id]['nice'],
+														$preStart,
+														$envVars,
+														$server_xml->game_key
+														);
+			break;
+		case "stop_server":
+			$remoteResult = $remote->remote_stop_server($server_home['home_id'],
+														$home_ip_ports['ip'],
+														$home_ip_ports['port'],
+														$server_xml->control_protocol,
+														$server_home['control_password'],
+														$server_xml->control_protocol_type,
+														$server_home['home_path']
+														);
+			break;
+		case "start_server":
+			$remoteResult = $remote->universal_start($server_home['home_id'],
+							$server_home['home_path'],
+							$server_xml->server_exec_name, 
+							$server_xml->exe_location,
+							$startup_cmd, 
+							$home_ip_ports['port'], 
+							$home_ip_ports['ip'],
+							$server_home['cpu_affinity'],
+							$server_home['nice'],
+							$preStart,
+							$envVars,
+							$server_xml->game_key);
+			break;
+		
+	}
+
+	if($remoteResult == 1){
 		return true;
-	}else if(hasValue($update, true)){
-		return $update;
+	}else if(hasValue($remoteResult, true)){
+		return $remoteResult;
 	}
 	
 	return false;
 }
 
+function callSteamAutoUpdate(){
+	global $settings, $db, $remote, $server_xml, $mod_xml, $server_home, $mod_key, $mod_id, $appId, $home_ip_ports, $resultOp;
+	
+	if($server_xml->installer == 'steamcmd') {
+		if($remote->rfile_exists($server_home['home_path'] . '/steamapps/appmanifest_' . $appId . '.acf') === 1){
+			$ourVersion = $remote->installed_steam_version($server_home['home_path'], $appId, 0);
+			$steamVersion = $remote->fetch_steam_version($appId, 0);
+			if($ourVersion != $steamVersion){
+				$success = runRemoteAction("steam_auto_update");
+				if($success == 1){
+					$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has been successfully auto-updated via SteamCMD and restarted.";
+					$resultOp["success"] = true;
+				}else if($success == 2){
+					$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has been successfully auto-updated via SteamCMD.";
+					$resultOp["success"] = true;
+				}else{
+					if(is_array($success)){
+						$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to auto-update. Agent returned: " . print_r($success, true);
+					}else{
+						$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to auto-update. Agent returned error code: " . $success;
+					}
+					$resultOp["success"] = false;
+				}
+			}else{
+				$resultOp["message"] = "Server is already up-to-date.";
+				$resultOp["success"] = false;
+			}
+		}else{
+			$resultOp["message"] = "Unable to find appmanifest.";
+			$resultOp["success"] = false;
+		}	
+	}else{
+		$resultOp["message"] = "Game server does NOT integrate directly with Steam.";
+		$resultOp["success"] = false;
+	}
+}
+
+function callRestartServer(){
+	global $settings, $db, $remote, $server_xml, $mod_xml, $server_home, $mod_key, $mod_id, $appId, $home_ip_ports, $resultOp;
+	
+	$success = runRemoteAction("restart_server");
+	if($success == 1){
+		$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has been successfully restarted.";
+		$resultOp["success"] = true;
+	}else{
+		$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to restart.";
+		$resultOp["success"] = false;
+	}
+}
+
+function callStartServer(){
+	global $settings, $db, $remote, $server_xml, $mod_xml, $server_home, $mod_key, $mod_id, $appId, $home_ip_ports, $resultOp;
+	
+	$success = runRemoteAction("start_server");
+	if($success == 1){
+		$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has been successfully started.";
+		$resultOp["success"] = true;
+	}else{
+		$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to start.";
+		$resultOp["success"] = false;
+	}
+}
+
+function callStopServer(){
+	global $settings, $db, $remote, $server_xml, $mod_xml, $server_home, $mod_key, $mod_id, $appId, $home_ip_ports, $resultOp;
+	
+	$success = runRemoteAction("stop_server");
+	if($success == 1){
+		$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has stopped successfully.";
+		$resultOp["success"] = true;
+	}else{
+		$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to stop.";
+		$resultOp["success"] = false;
+	}
+}
+
 /****************** *
 *  CODE APP START   *
 * ******************/
@@ -111,86 +236,83 @@ $settings = $db->getSettings();
 @$GLOBALS['panel_language'] = $settings['panel_language'];
 
 // Handle API Request
-if(isset($_REQUEST["action"])){
+if(hasValue($_REQUEST["action"]) && hasValue($_REQUEST["homeid"]) && hasValue($_REQUEST["controlpass"]) && is_numeric($_REQUEST["homeid"])){
+	
+	// Get the variables we need	
 	$action = $_REQUEST["action"];
-	switch($action){
-		case "autoUpdateSteamHome":
-			$homeId = $_REQUEST["homeid"];
-			$controlPass = $_REQUEST["controlpass"];
-			if(hasValue($homeId) && hasValue($controlPass) && is_numeric($homeId)){
-				$server_home = $db->getGameHome($homeId);
-				if(hasValue($server_home) && is_array($server_home) && count($server_home) > 0){
-					if(trim($server_home["control_password"]) == trim(strip_tags($controlPass))){
-						// Key matches what is stored in the database.
-						$getIpPorts = $db->getHomeIpPorts($homeId);
-						$home_ip_ports = $getIpPorts[0];
-						
-						$server_xml = read_server_config(SERVER_CONFIG_LOCATION . '/' . $server_home['home_cfg_file']);
-						if($server_xml->installer == 'steamcmd') {
-							$remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
-							$appId = (int)$server_xml->mods->mod->installer_name;
-							$mod_id = key($server_home['mods']);
-							$mod_key = $server_home['mods'][$mod_id]['mod_key'];
-							$mod_xml = xml_get_mod($server_xml, $mod_key);
-
-							if($remote->rfile_exists($server_home['home_path'] . '/steamapps/appmanifest_' . $appId . '.acf') === 1)
-							{
-								if($mod_xml !== false){
-									$ourVersion = $remote->installed_steam_version($server_home['home_path'], $appId, 0);
-									$steamVersion = $remote->fetch_steam_version($appId, 0);
-									if($ourVersion != $steamVersion){
-										$success = runSteamAutoUpdate($server_xml, $mod_xml, $server_home, $mod_key);
-										if($success == 1){
-											$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has been successfully auto-updated via SteamCMD and restarted.";
-											$resultOp["success"] = true;
-										}else if($success == 2){
-											$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" has been successfully auto-updated via SteamCMD.";
-											$resultOp["success"] = true;
-										}else{
-											if(is_array($success)){
-												$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to auto-update. Agent returned: " . print_r($success, true);
-											}else{
-												$resultOp["message"] = "Server \"" . $server_home["home_name"] . "\" failed to auto-update. Agent returned error code: " . $success;
-											}
-											$resultOp["success"] = false;
-										}
-									}else{
-										$resultOp["message"] = "Server is already up-to-date.";
-										$resultOp["success"] = false;
-									}
-								}else{
-									$resultOp["message"] = "Problem retrieving server mod XML.";
-									$resultOp["success"] = false;
-								}
-							}else{
-								$resultOp["message"] = "Unable to find appmanifest.";
-								$resultOp["success"] = false;
-							}	
-						}else{
-							$resultOp["message"] = "Game server does NOT integrate directly with Steam.";
+	$homeId = $_REQUEST["homeid"];
+	$controlPass = $_REQUEST["controlpass"];
+	
+	// Get home information
+	$server_home = $db->getGameHome($homeId);
+	
+	if(hasValue($server_home) && is_array($server_home) && count($server_home) > 0){
+		if(trim($server_home["control_password"]) == trim(strip_tags($controlPass))){
+			
+			// Set command server variables (home server XML, IPs, etc)
+			$server_xml = read_server_config(SERVER_CONFIG_LOCATION . '/' . $server_home['home_cfg_file']);
+			if($server_xml){
+				$getIpPorts = $db->getHomeIpPorts($homeId);
+				$home_ip_ports = $getIpPorts[0];
+				$remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
+				$appId = (int)$server_xml->mods->mod->installer_name;
+				$mod_id = key($server_home['mods']);
+				$mod_key = $server_home['mods'][$mod_id]['mod_key'];
+				$mod_xml = xml_get_mod($server_xml, $mod_key);
+				if($mod_xml !== false){
+				
+					/****************************************/
+					//           Actual API Logic :)         /
+					/****************************************/
+					
+					// Handle API Action
+					switch($action){
+						case "autoUpdateSteamHome":
+							callSteamAutoUpdate();
+							break;
+						case "restartServer":
+							callRestartServer();
+							break;
+						case "startServer":
+							callStartServer();
+							break;
+						case "stopServer":
+							callStopServer();
+							break;
+						default: 
+							$resultOp["message"] = "Invalid action specified.";
 							$resultOp["success"] = false;
-						}
-					}else{
-						$resultOp["message"] = "Server home key does not match stored information.";
-						$resultOp["success"] = false;
 					}
+					
+					/****************************************/
+					//       End Actual API Logic :)         /
+					/****************************************/
+					
 				}else{
-					$resultOp["message"] = "Unable to find game server home.";
+					$resultOp["message"] = "Problem retrieving server mod XML.";
 					$resultOp["success"] = false;
 				}
 			}else{
-				$resultOp["message"] = "Invalid inputs.";
+				$resultOp["message"] = "Failed to read server XML.";
 				$resultOp["success"] = false;
 			}
-			break;
+		}else{
+			$resultOp["message"] = "Server home key does not match stored information.";
+			$resultOp["success"] = false;
+		}
+	}else{
+		$resultOp["message"] = "Unable to find game server home.";
+		$resultOp["success"] = false;
 	}
+}else{
+	$resultOp["message"] = "Invalid inputs.";
+	$resultOp["success"] = false;
+}
 	
-	// Output JSON
-	if(hasValue($resultOp["message"]) && hasValue($resultOp["success"], true)){
-		outPutJSON($resultOp);
-	}
+// Output JSON
+if(hasValue($resultOp["message"]) && hasValue($resultOp["success"], true)){
+	outPutJSON($resultOp);
 }
 
 exit();
-
 ?>