RegisterRegister    Log inLog in    SearchSearch   

Post new topic   Reply to topic
Goto page 1, 2  Next 
View previous topic :: View next topic  
Author Message
carlino1994



PostPosted: Wed Mar 31, 2010 5:10 am    Post subject: Some problem with Web Services Reply with quote

Hello, I have two problem with web services:

1) There isn't a method for remove a subdomain, only for create;


2) I have some problem with "ModifyServer" method of "MakeBooking" web services.
I am creating a PHP software with POST methods for comunicate with GC web services. My problem is with "propertyValues" parameter.

Can anyone do an example of "ModifyServer" method with POST?



Thanks very much, and exescume for my bad english.
Back to top
View user's profile Send private message
adbot



PostPosted: Thu Mar 31, 2011 3:57 am 

Andrew
Mammoth


PostPosted: Wed Mar 31, 2010 8:56 am    Post subject: Reply with quote

Hi,

1) Thanks, I've put this down as a feature request.

2) The 'property values' field is a 'Url Encoded' Key/Value Pair (joined by the equals (=) symbol), and pairs are joined by the ampersand (&) symbol.

In PHP code, this would be equivalent:

Code:

function CreatePropertyValues($dict)
{
   $pairs = array();
   
   foreach($dict As $key => $value)
      $pairs[] = urlencode($key) . '=' . urlencode($value);
      
   return join('&', $pairs);
}

$config = array();
$config['password'] = 'join password';
$config['map'] = 'cs_italy';
$config['rcon_password'] = 'admin123';

$propertyValues = CreatePropertyValues($config);

$propertyValues == password=join+password&map=cs_italy&rcon_password=admin123
Back to top
View user's profile Send private message
carlino1994



PostPosted: Wed Mar 31, 2010 7:42 pm    Post subject: Reply with quote

I have created a class with this method for modify a server and I have applied your changes, but the result is always "false".
Code:
function http_modifyserver($username, $password, $serverId, $name, $propertyValues, $templateIds = '') {
   $fp = @fsockopen($this->domain_url, 80, $errno, $errstr, 30);
   if (!$fp) return false;
   
   $new_propertyValues = array();
   
   foreach($propertyValues as $key => $value) {
      $new_propertyValues[] = urlencode($key) . '=' . urlencode($value);
   }
   
   unset($propertyValues);
   $propertyValues = implode('&', $new_propertyValues);
   $params = "username={$username}&password={$password}&serverId={$serverId}&name={$name}&propertyValues={$propertyValues}&templateIds=";
   
   $headers = $xml = '';
   $headers .= "POST /bookings/MakeBooking.asmx/ModifyServer HTTP/1.0\r\n";
   $headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
   $headers .= "Content-Length: " . strlen($params) . "\r\n";
   $headers .= "Host: {$this->domain_url}\r\n\r\n";
   $headers .= $params;
   
   fputs($fp, $headers);
   while(!feof($fp)) $xml .= fgets($fp, 2048);
   fclose($fp);
   
   return $xml;
}


Example of use:
Code:
$xml_response = $gamecreate->http_modifyserver($params["configoption3"], $params["configoption4"], $params["customfields"]["serverid"], $data["hostname"], array('rcon_password' => $data['rcon_password'], 'gamemodes' => $config));



And this is the xml response (with output headers):
Code:
HTTP/1.1 200 OK
Date: Wed, 31 Mar 2010 09:37:10 GMT
Server: Apache
Content-Length: 91
Cache-Control: private
Connection: close
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>



EDIT:
This is an example of POST query string generated ($param var in the method).
Code:
username=MyUsername&password=MyPassword&serverId=000000&name=GTA: San Andreas&propertyValues=rcon_password=&gamemodes=gamemode0+lvdm+1%0D%0Agamemode1+rivershell+1%0D%0Agamemode2+sniper+1%0D%0Agamemode3+barron+1%0D%0Agamemode4+sftdm+1&templateIds=
Back to top
View user's profile Send private message
Andrew
Mammoth


PostPosted: Wed Mar 31, 2010 8:27 pm    Post subject: Reply with quote

You should use PHP SoapClient to interact with GameCreate instead of constructing a HTTP post yourself.

See http://au2.php.net/soapclient

You can view the WSDL file that you will need at http://world.gamecreate.com/admin/Remote.asmx?wsdl
Back to top
View user's profile Send private message
carlino1994



PostPosted: Wed Mar 31, 2010 9:40 pm    Post subject: Reply with quote

Ok, but now have some problems too.

Code used:
Code:
$gamecreate = new SoapClient("http://mydomain.eu.gamecreate.com/bookings/MakeBooking.asmx?wsdl");

$response = $gamecreate->ModifyServer($params["configoption3"], $params["configoption4"], ((int) $params["customfields"]["serverid"]), $data["hostname"], "rcon_password={$data['rcon_password']}&gamemodes={$data['gamemodes']}", '');

echo $response;


But, I have this output:
Quote:
<b>Fatal error</b>: Uncaught SoapFault exception: [soap:Server] Argument 2 is not valid in SqlBuilder in /var/www/modules/gcsamp.php:359
Stack trace:
#0 /var/www/modules/gcsamp.php(359): SoapClient->__soapCall('ModifyServer', Array)
[...]
thrown in <b>/var/www/modules/gcsamp.php</b> on line <b>359</b><br />


I have replaced some error output with [...].
Back to top
View user's profile Send private message
Andrew
Mammoth


PostPosted: Thu Apr 01, 2010 8:33 am    Post subject: Reply with quote

Can you please give me the output of this command:

var_dump($params);
var_dump($data);

So we can see what data you are sending, I suspect its malformed.
Back to top
View user's profile Send private message
carlino1994



PostPosted: Thu Apr 01, 2010 4:13 pm    Post subject: Reply with quote

$params is an array passed to a function from WHMCS (I am creating a WHMCS module) and it's correct, because I use it with other function (start, stop, restarting, get server status, create server, ecc...).

Instead, the $data array, is the $_POST array ($data = $_POST) with the data inserted in the configuration form.

$data
Code:
array(10) {
  ["hostname"]=>
  string(16) "GTA: San Andreas"
  ["gamemodes"]=>
  string(99) "gamemode0 lvdm 1
gamemode1 rivershell 1
gamemode2 sniper 1
gamemode3 barron 1
gamemode4 sftdm 1"
  ["filterscripts"]=>
  string(0) ""
  ["plugins"]=>
  string(0) ""
  ["rcon_password"]=>
  string(0) ""
  ["mapname"]=>
  string(0) ""
  ["weburl"]=>
  string(0) ""
  ["id"]=>
  string(2) "52"
  ["modop"]=>
  string(6) "custom"
  ["a"]=>
  string(11) "save_config"
}
Back to top
View user's profile Send private message
Andrew
Mammoth


PostPosted: Thu Apr 01, 2010 4:38 pm    Post subject: Reply with quote

I just used this function fine.

Can you please show me the output of the $params array.

Also, its invalid to pass in "rcon_password={$data['rcon_password']}&gamemodes={$data['gamemodes']}""

Both your 'game modes' and rcon password values have not been url encoded as required.

You need to use the CreatePropertyValues function as shown above.

Replace that with:

$params = CreatePropertyValues($data);

Then supply $params as the 5th argument.

Also try setting the last argument to '0' (quoted zero).
Back to top
View user's profile Send private message
carlino1994



PostPosted: Thu Apr 01, 2010 6:34 pm    Post subject: Reply with quote

Andrew wrote:
You need to use the CreatePropertyValues function as shown above.

Replace that with:

$params = CreatePropertyValues($data);

Then supply $params as the 5th argument.

Also try setting the last argument to '0' (quoted zero).

Done, but the problem isn't resolved.

This is the output of $params:
Code:
Array
(
    [accountid] => 52
    [serviceid] => 52
    [domain] =>
    [username] => account_xxx
    [password] => account_xxx
    [packageid] => 2
    [pid] => 2
    [serverid] => 2
    [customfields] => Array
        (
            [ip_port] => 94.xxx.xxx.xxx:7817
            [serverid] => 9428xxx
            [subdomainid] => 9xxx
            [hostname] => GTA: San Andreas
            [gamemodes] => gamemode0 lvdm 1
gamemode1 rivershell 1
gamemode2 sniper 1
gamemode3 barron 1
gamemode4 sftdm 1
            [filterscripts] =>
            [plugins] =>
            [rcon_password] =>
            [password] =>
            [service_status] => 1
        )

    [configoptions] => Array
        (
            [slots] => 11
        )

    [type] => other
    [producttype] => other
    [moduletype] => gcsamp
    [configoption1] => xxx.eu.gamecreate.com
    [configoption2] => 91xx
    [configoption3] => gc_MyUsername
    [configoption4] => gc_MyPassword
    [configoption5] => /root/gamecreate/
    [configoption6] => 17
    [configoption7] => 5
    [configoption8] => 6
    [configoption9] => 7
    [configoption10] => 8
    [configoption11] => 9
    [configoption12] => 10
    [configoption13] => 11
    [configoption14] => 12
    [configoption15] => 13
    [configoption16] =>
    [configoption17] =>
    [configoption18] =>
    [configoption19] =>
    [configoption20] =>
    [configoption21] =>
    [configoption22] =>
    [configoption23] =>
    [configoption24] =>
    [clientsdetails] => Array
        (
            [userid] => 1
            [id] => 1
            [firstname] => xxx
            [lastname] => xxx
            [companyname] =>
            [email] => xxx@xxx.it
            [address1] => xxx xxx xx
            [address2] =>
            [city] => xxx
            [state] => xxx
            [postcode] => xxxxx
            [country] => xx
            [countryname] => xxx
            [phonenumber] => 0000000000
            [notes] =>
            [password] => MyWHMCSpassword
            [currency] => 1
            [cctype] =>
            [cclastfour] =>
            [securityqid] => 0
            [securityqans] =>
            [groupid] => 0
            [status] => Active
            [credit] => 0.00
            [taxexempt] =>
            [latefeeoveride] =>
            [overideduenotices] =>
            [language] =>
            [lastlogin] => Date: 01/04/2010 01:08<br>IP Address: xxx.xxx.xxx.xxx<br>Host: xxx.xxxx.xxx
            [billingcid] => 0
        )

    [server] => 1
    [serverip] => 94.xxx.xxx.xxx
    [serverhostname] => s1.xxx.xx
    [serverusername] => DomainIDhere
    [serverpassword] =>
    [serveraccesshash] =>
    [serversecure] =>
)


I have masked some personal information.
Back to top
View user's profile Send private message
Andrew
Mammoth


PostPosted: Thu Apr 01, 2010 7:26 pm    Post subject: Reply with quote

Hi,

I notice 'serverid' is 2, thats not a GameCreate Server Id Smile

The Server Id is found when you visit the Server Overview page for a server, and you see it in the address bar: Server.aspx?id=XXX

If this is an order processing system, do you mean to use the CreateServerOnBestHost service call?

This will handle installing the game and picking a host (from a list you provide) for you.

See http://world.gamecreate.com/admin/Remote.asmx?op=CreateServerOnBestHost for the arguments - note that its Remote.asmx for this web service, not MakeBooking.asmx

An example:

actorUsername and actorPassword: An account with Full System permission in GameCreate
domainId: Domain Id to create this server under. If this is a rental environment, you probably want to create a subdomain (we recommend it - subdomain users are isolated from each other, and each get their own game installation).

You need to create a Domain and use its Id here. To create a subdomain, use the http://world.gamecreate.com/admin/Remote.asmx?op=CreateSubdomain method.

gameId: Id of the Game you want a server created for.

name: Initial server name to use

players: Max Players value

startPort: Port number to begin creating new servers from, for example, 2000 (the next server will receive the next free port etc automatically)

--

If you want to edit an existing server, then use your Modify Server call but supply a valid GameCreate Server Id.
Back to top
View user's profile Send private message
carlino1994



PostPosted: Thu Apr 01, 2010 7:51 pm    Post subject: Reply with quote

Andrew wrote:
I notice 'serverid' is 2, thats not a GameCreate Server Id Smile
The Server Id is found when you visit the Server Overview page for a server, and you see it in the address bar: Server.aspx?id=XXX

The "serverid" is the server ID on WHMCS. I get from "serverusername" the server ID on GC.

Andrew wrote:
If this is an order processing system, do you mean to use the CreateServerOnBestHost service call?

I create a server with CreateServer service by passing it the GC host ID from "serverusername" key of $params.

Andrew wrote:
If you want to edit an existing server, then use your Modify Server call but supply a valid GameCreate Server Id.

And I have passed it the valid GC Server ID.


This do the ModifyServer request:
Code:
$response = $gamecreate->ModifyServer($params["configoption3"], $params["configoption4"], ((int) $params["customfields"]["serverid"]), $data["hostname"], "rcon_password={$data["rcon_password"]}&gamemodes={$config}", '0');


Where $params["configoption3"] e $params["configoption4"] are my GC username and password, $params["customfields"]["serverid"] the server ID, ...
Back to top
View user's profile Send private message
Andrew
Mammoth


PostPosted: Thu Apr 01, 2010 8:22 pm    Post subject: Reply with quote

Hi,

Sorry, skimmed over that.

Can you create a new user account with a test username and password and assign them System permission on your GameCreate domain?

Then send me (PM is fine) a working PHP example of the web service call not working (with all the details filled in) so I can just run the example and see the error like you see (either as a command line program or simple web page is fine - it doesn't need to be pretty Smile )

I can then verify what's going on, as I was able to modify a server fine on a different domain than yours.
Back to top
View user's profile Send private message
carlino1994



PostPosted: Thu Apr 01, 2010 8:53 pm    Post subject: Reply with quote

PM Sended. Very Happy
Back to top
View user's profile Send private message
Andrew
Mammoth


PostPosted: Fri Apr 02, 2010 10:22 am    Post subject: Reply with quote

Hi,

Thanks for the PM.

So the reason this wasn't working was because PHP's SoapClient does not appear to send the parameters correctly if you don't specify their names.

So you need to use this:

Code:

$response = $gamecreate->ModifyServer(array('username' => $params["configoption3"], 'password' => $params["configoption4"], 'serverId' => $params["customfields"]["serverid"], 'name' => $data["hostname"], 'propertyValues' => "rcon_password={$data["rcon_password"]}&gamemodes={$config}", 'templateIds' => '0'));


Pass in a key/value pair of the parameter names to values.

The parameter names are found on the test page: http://samp52.sampitalia.eu.gamecreate.com/bookings/MakeBooking.asmx?page=op&op=ModifyServer&bnd=MakeBooking_asmxSoap&tab=test

It's worked for me now.

Also note that you don't urlencode() the 'name' parameter.
Back to top
View user's profile Send private message
carlino1994



PostPosted: Sat Apr 03, 2010 12:01 am    Post subject: Reply with quote

The php example which I send you, with your edit, now work for me too and change the server config. Very Happy



My WHMCS script now work, but the value of 'ModifyServerResult' is empty and not change server config. Sad

Code:
stdClass Object
(
    [ModifyServerResult] =>
)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic All times are GMT + 10 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum powered by phpBB © 2001, 2005 phpBB Group
GameCreate Service Terms | Privacy Policy | © Copyright Mammoth Media 2001-2007
GameCreate™ is a trademark of Mammoth Media Pty Ltd. GameCreate® is a registered trademark in Australia.