Skip to content

Commit

Permalink
Fixed remote-access issues
Browse files Browse the repository at this point in the history
Remote access was left out of SQL queries for adding / updateing realms.
Rewrote the RA socket class to be more user friendly and work with the
new database structure.
Fixes #43
  • Loading branch information
paintballrefjosh committed Apr 1, 2017
1 parent a9444d5 commit 80c6ab8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
34 changes: 16 additions & 18 deletions core/SDL/class.rasocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,16 @@ private function writeDebugLog()
Returns 2 if it's not authenticated
@param $command the command to enter on console
*/
public function executeCommand($type, $shost, $remote, $command)
public function executeCommand($type, $host, $port, $user, $pass, $command)
{
if($type == 0)
{
if(!$this->connect($shost, $remote[1]))
if(!$this->connect($host, $port))
{
return 0;
}

if(!$this->auth($remote[2], $remote[3]))
if(!$this->auth($user, $pass))
{
return 2;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public function executeCommand($type, $shost, $remote, $command)
}
else # type is SOAP
{
$client = $this->soapHandle($shost, $remote);
$client = $this->soapHandle($host, $port, $user, $pass);
// If multiple commands
if(is_array($command))
{
Expand Down Expand Up @@ -338,29 +338,29 @@ public function executeCommand($type, $shost, $remote, $command)

// ************************************************************
// Setups the Soap Handle
private function soapHandle($shost, $remote)
private function soapHandle($host, $port, $user, $pass)
{
global $mwe_config;
if($mwe_config['emulator'] == 'mangos')
{
$client = new SoapClient(NULL,
array(
"location" => "http://".$shost.":".$remote[1]."/",
"location" => "http://".$host.":".$port."/",
"uri" => "urn:MaNGOS",
"style" => SOAP_RPC,
"login" => $remote[2],
"password" => $remote[3]
"login" => $user,
"password" => $pass
));
}
else
{
$client = new SoapClient(NULL,
array(
"location" => "http://".$shost.":".$remote[1]."/",
"location" => "http://".$host.":".$port."/",
"uri" => "urn:TC",
"style" => SOAP_RPC,
"login" => $remote[2],
"password" => $remote[3]
"login" => $user,
"password" => $pass
));
}
return $client;
Expand All @@ -378,17 +378,15 @@ private function soapHandle($shost, $remote)
*/
function send($command, $realm)
{
global $RDB;
global $RDB, $DB;

// Get the remote access information from the realm database
$get_remote = $RDB->selectRow("SELECT * FROM `realmlist` WHERE id='".$realm."'");
$remote = explode(';', $get_remote['ra_info']);
$shost = $get_remote['address'];

$remote = $DB->selectRow("SELECT ra_type, ra_port, ra_user, ra_pass FROM `mw_realm` WHERE `realm_id`='".$realm."'");
$host = $RDB->selectCell("SELECT `address` FROM `realmlist` WHERE `id` = '$realm'");
// Make sure the remote access type is either 1 or 0
if($remote[0] == 0 || $remote[0] == 1)
if((int)$remote['ra_type'] == 0 || (int)$remote['ra_type'] == 1)
{
$result = $this->executeCommand($remote[0], $shost, $remote, $command);
$result = $this->executeCommand($remote['ra_type'], $host, $remote['ra_port'], $remote['ra_user'], $remote['ra_pass'], $command);
if($result != 1)
{
if($result == 0)
Expand Down
11 changes: 11 additions & 0 deletions inc/admin/script_files/admin.realms.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ function updateRealm()
if(empty($_POST['db_char_port']))
$_POST['db_char_port'] = 0;

if(empty($_POST['ra_port']))
$_POST['ra_port'] = 0;

if($realm > 0)
{
$DB->query("UPDATE `mw_realm` SET
Expand All @@ -53,6 +56,10 @@ function updateRealm()
`db_char_port` = '".$_POST['db_char_port']."',
`db_char_user` = '".$_POST['db_char_user']."',
`db_char_pass` = '".$_POST['db_char_pass']."',
`ra_type` = '".$_POST['ra_type']."',
`ra_port` = '".$_POST['ra_port']."',
`ra_user` = '".$_POST['ra_user']."',
`ra_pass` = '".$_POST['ra_pass']."',
`site_enabled` = '".$_POST['site_enabled']."'
WHERE `realm_id` = ".$_GET['id']."
");
Expand All @@ -70,6 +77,10 @@ function updateRealm()
`db_char_port` = '".$_POST['db_char_port']."',
`db_char_user` = '".$_POST['db_char_user']."',
`db_char_pass` = '".$_POST['db_char_pass']."',
`ra_type` = '".$_POST['ra_type']."',
`ra_port` = '".$_POST['ra_port']."',
`ra_user` = '".$_POST['ra_user']."',
`ra_pass` = '".$_POST['ra_pass']."',
`site_enabled` = '".$_POST['site_enabled']."',
`realm_id` = ".$_GET['id'].";
");
Expand Down

0 comments on commit 80c6ab8

Please sign in to comment.