ip = "127.0.0.1"; $RCCServiceSoap->url = $RCCServiceSoap->ip . ":64989"; $RCCServiceSoap->access = UUID::v5('42078d04-4a0d-11ea-aca5-e759e6572da7', $RCCServiceSoap->url); class RCCService { public static function verifyAccessKey($accessKey) { //global $RCCServiceSoap; global $database; // Find service with the exact same access key and compare IPs $RCCServiceSoap = $database->findRow("cloud", ["access" => $accessKey], ["ip", "port"]); if ($RCCServiceSoap && $RCCServiceSoap->rowCount() > 0 && $RCCServiceSoap->rowCount() !== null) { $RCCServiceSoap = $RCCServiceSoap->fetch(PDO::FETCH_OBJ); }else { return false; } // assemble the url $RCCServiceSoap->url = $RCCServiceSoap->ip . ":" . $RCCServiceSoap->port; if ($_SERVER['REMOTE_ADDR'] == $RCCServiceSoap->ip || $_SERVER['HTTP_X_FORWARDED_FOR'] == $RCCServiceSoap->ip) { return true; }else { return false; } } } //Global variables?? $valueTypes = array( //this array kinda works as a function by converting PHP value types to Lua 'NULL' => 'LUA_TNIL', 'boolean' => 'LUA_TBOOLEAN', 'integer' => 'LUA_TNUMBER', 'string' => 'LUA_TSTRING', 'array' => 'LUA_TTABLE' ); /*LuaValue types consist of LUA_TNIL LUA_TBOOLEAN LUA_TNUMBER LUA_TSTRING LUA_TTABLE */ //TODO: Add support for Lua tables. For now RCCService should just throw an error. function argumentParser($args) { //new and improved! global $valueTypes; $data = ""; $argAmmount = count($args); for($i = 0; $i < $argAmmount; $i++){ //for each argument, append its value if (gettype($args[$i]) == 'string') { // html encode for strings $args[$i] = htmlentities($args[$i], ENT_QUOTES); } $data = $data . " ".$valueTypes[gettype($args[$i])]." ".$args[$i]." "; } return $data; } class SOAP { public static function post($content, $action, $service) { $header = array( "Content-type: text/xml; charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: ".$action, "Content-length: ".strlen($content), ); $content = ' '.$content; $content = $content.' '; $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $service->url ); curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($soap_do, CURLOPT_TIMEOUT, 30); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $content); curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header); $curl_response = curl_exec($soap_do); if($curl_response === false) { curl_close($soap_do); return false; } else { curl_close($soap_do); return $curl_response; } return false; } } /* DEPRECATED Name: New Script Raw Description: This function directly pings RCCService with a POST request. Parameters: [ "scriptName" => "The name for the script that's going to be executed. It's also used as the SOAPAction in the header.", "baseScript" => "The code that's going to be executed by RCCService.", "jobId" => "The ID used when creating a job for RCCService." ] DEPRECATED */ /* function NewScriptRaw($scriptName, $baseScript, $jobId) { //This way the job never expires. :D $soap_request = ' '.jobId.' '.$scriptName.' '.$baseScript.' '; $header = array( "Content-type: text/xml; charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: {$scriptName}", "Content-length: ".strlen($soap_request), ); $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, "127.0.0.1:64989" ); curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($soap_do, CURLOPT_TIMEOUT, 10); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request); curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header); header('Content-Type: text/plain'); if(curl_exec($soap_do) === false) { curl_close($soap_do); return false; } else { curl_close($soap_do); return true; } return false; } */ /* DEPRECATED Name: New Script Description: This function uses the given argument names to create a Lua function which is then executed with the $args variable. Parameters: [ "scriptName" => "The name for the script that's going to be executed.", "baseScript" => "The code that's going to be inserted into the new function.", "jobId" => "The ID used when creating a job for RCCService.", "args" => "These are the parameters used when building and executing the Lua function. ex: array( 'url' => 'http://sitetest1.roblonium.com/Asset/?id=100', 'baseUrl' => 'http://sitetest1.roblonium.com/', 'fileType' => 'PNG', 'width' => 420, 'height' => 420, 'scriptIcon' => 'http:/roblonium.com/Thumbs/Script.png', 'toolIcon' => 'http:/roblonium.com/Thumbs/Tool.png' )" ] DEPRECATED */ /* function NewScript($scriptName, $jobId, $baseScript, $args) { function argumentParser($args, $nameOnly) { $data = ""; $argAmmount = count($args); if ($nameOnly !== true) { for($i = 0; $i <= $argAmmount; $i++){ //for each argument, append its value $data = $data . ", " . $args[$i]; } }else { for($i = 0; $i <= $argAmmount; $i++){ //for each argument, append its name $data = $data . ", " . key($args); next($args); } } return $data; } //This uses a more basic script execution function to trim down the amount of space it takes up $functionBase = ' function start('.argumentParser($args, true).') '.$baseScript.' end start('.argumentParser($args, false).')'; return NewScriptRaw($scriptName, $functionBase, $jobId); } */ /* Name: Execute Script Description: This function uses the given arguments to execute a script inside an existing job. Do not try to execute a script inside a non-existent job!!! Parameters: [ "scriptName" => "The name for the script that's going to be executed.", "baseScript" => "The code that's going to be executed.", "jobId" => "The ID of the job in which the script is executed.", "args" => "These are the parameters that RCCService uses when building and executing the Lua script. ex: array('http://sitetest1.roblonium.com/Asset/?id=100', 'http://sitetest1.roblonium.com/', 'PNG', 420, 420, 'http:/roblonium.com/Thumbs/Script.png', 'http:/roblonium.com/Thumbs/Tool.png') RCCService would do the following to the script: 'url, ext, h, v, scriptIcon, toolIcon = ...' (These are set by RCCService based on the order of the given parameters.) 'print({0}..{1}..{2}..{3})' (This would print 'http://sitetest1.roblonium.com/Asset/?id=100http://sitetest1.roblonium.com/PNG420') (This is exclusive to RCCService Arbiter's String.Format function. Though it could be implemented with PHP's sprintf function.) " ] */ function ExecuteScript($service, $scriptName, $baseScript, $jobId, $args) { $contents = ' '.$jobId.' '.$scriptName.' '.$baseScript.' '.argumentParser($args).' '; SOAP::post($contents, "Execute", $service); } /* Name: Open Job Description: This function opens a job in accordance with the given arguments. Parameters: [ "scriptName" => "The name for the script that's going to be executed.", "baseScript" => "The code that's going to be executed.", "args" => "These are the parameters that RCCService uses when building and executing the Lua script. This is an array.", "expirationInSeconds" (300) => "The amount of time before the job is terminated.", "category" (0) => "According to carrot this is the placeId. thx :)", "cores" => (1) "An unknown variable that RCCService requires. This might control the amount of resources that're allocated to the job." ] */ function OpenJob($service, $scriptName, $baseScript, $args = [], $expirationInSeconds = 300 /*(5 minutes) the default time for thumbnails*/, $category = 0, $cores = 1) { $jobId = UUID::v5('518383a0-66f5-416e-9722-03c8ba625034', $scriptName . $service->url . time()); $contents = ' '.$jobId.' '.$expirationInSeconds.' '.$category.' '.$cores.' '.$scriptName.' '.argumentParser($args).' '; //return $contents; if (!(SOAP::post($contents, "OpenJob", $service) === FALSE)) { $scriptInfo = explode("-", $scriptName); // only add gameserver jobs to the database as thumbnails and stuff like that expire/finish in a matter of seconds if ($scriptInfo[0] == "GameServer" || substr($scriptName, 0, 10) == "GameServer") { global $database; $database->insertRow("jobs", [ // add the job to the jobs database "category" => $scriptInfo[1], "jobId" => $jobId, "ip" => $args[0], "port" => $args[1], "serviceId" => $service->access ], "category"); } return true; }else { return false; } } ?>