Jump to content

[9466] MaNGOS SOAP services


Auntie Mangos

Recommended Posts

Hi everyone :)

as mentioned here, I was working on implementing SOAP in MaNGOS.

So once again, what is it all about?

There are several cases, in which an automated interaction with mangosd is desirable, started from sending items to players up to sending ingame announces from a mobile phone. Up to this patch, there was just the RA console, which was quite uncomfortable. You had to write everything in a socket (including authentication) and then wait for a response - but you didn't know when the response was complete. Was it just a one line response? Are there further lines coming? Has the server gone away?

Additionally, the RA console only allowed one connection at a time. So if you want to perform automated actions, you might either have luck and got served, or you got that ugly "Server is busy" message.

This patch takes care of these issues :)

  • * Remove only-one-login limitation from RA
    * Add a gsoap based SOAP service to mangos
    * A soap example client script (have a look at the contrib folder)
    * Some minor fixes on the console experience (print that "mangos>" after the command has finished)

As a site note, this patches makes polling tables - as suggested for the "send items per mail from extern" problem - superfluous. Thanks to the wide spread implementation of SOAP, solving this problem boils down to

$username = 'ADMINISTRATOR';
$password = 'ADMINISTRATOR';
$host = "localhost";
$soapport = 7878;
$command = 'send items Playernumberone "Your items" "Hello Playernumberone, here are your items. Have fun." 192';

$client = new SoapClient(NULL,
array(
   "location" => "http://$host:$soapport/",
   "uri" => "urn:MaNGOS",
   "style" => SOAP_RPC,
   'login' => $username,
   'password' => $password
));

try {
   $result = $client->executeCommand(new SoapParam($command, "command"));

   echo "Command succeeded! Output:
\\n";
   echo $result;
}
catch (Exception $e) 
{
   echo "Command failed! Reason:
\\n";
   echo $e->getMessage();
}

The patch is now (from my point of view) feature complete and tested on *nix, but untested on windows.

You can get it either by pulling my mangossoap branch or by downloading the patch file if you are not that much git enthusiastic.

Any feedback, especially concerning running this patch on windows, is welcome ;)

Link to comment
Share on other sites

  • 40 years later...

Hello,

i tried it on my local machine (Win 7).

Command is send successfull and a simple "announce test" works fine (correct output ingame).

But i got no "output" on the website:

Command succeeded! Output:

Very nice feature, thank you for that :)

Any idea why there is no output in php?

Greetings Maik

Link to comment
Share on other sites

Thanks for testing Maik, the output is the command specific return value. The announce command simply lacks of this - in contrast to "server info" or "lookup item". It's always the text a GM char would see ingame :)

You quite sure this works? I have the exact same problem now on the 0.12 branch which just got your patch included - both in my JAVA implementation as well as using the default PHP example file. I get the "Command succeeded" message just fine, but both the $result variable as well as $client -> __getLastResponse() are empty / null respectively. Tried both the default 'server info' as well as some other commands (like lookup item).

Testing (of course) with the very latest 0.12 release as we speak.

//edit

If it helps, this is what my logs are showing:

MaNGOSsoap: accepted connection from IP=127.0.0.1

MaNGOSsoap: got command 'server info'

CLI command under processing...

If I send an announce command, I do see the result ingame, so at least that part is working :D

Link to comment
Share on other sites

You quite sure this works? I have the exact same problem now on the 0.12 branch which just got your patch included - both in my JAVA implementation as well as using the default PHP example file. I get the "Command succeeded" message just fine, but both the $result variable as well as $client -> __getLastResponse() are empty / null respectively. Tried both the default 'server info' as well as some other commands (like lookup item).

Testing (of course) with the very latest 0.12 release as we speak.

I couldn't reproduce that problem under linux with mangos-0.12 at a208fd2a8264b1142cac0249dc9be064955cc7c6. What OS do you use?

Link to comment
Share on other sites

Thanks for checking it out! Using windows 2003 here as server, visual studio 2008 (so using the mangosdVC90 project file).

If it helps, the response body I get back (for a server info command):

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:MaNGOS" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
 <SOAP-ENV:Header/>
 <SOAP-ENV:Body>
   <ns1:executeCommandResponse>
     <result/>
   </ns1:executeCommandResponse>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Looks allright, just completely empty in the response part :D Also tried doing a completely new checkout and clean + recompile earlier, but that did not fix it either :(

Link to comment
Share on other sites

Won't compile, changed 'sleep' -> 'Sleep', will compile, but still no response. Changed duration from 2 to 100 and now I do get a response :D

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:MaNGOS" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
 <SOAP-ENV:Header/>
 <SOAP-ENV:Body>
   <ns1:executeCommandResponse>
     <result>
       MaNGOS/0.12.1 (2010-02-28 14:34:42 Revision 8569 - a208fd2a8264b1142cac0249dc9be064955cc7c6) for Win32 (little-endian)
       Using script library: Default MaNGOS scripting library
       Using World DB: TBCDB 0.0.2.2 'I... am... UNLEASHED' for MaNGOS-0.12 076 with SD2 SQL for rev. 1478
       Using creature EventAI: ACID 2.0.0 - Full Release for Mangos (2.4.3 Client)
       Online players: 0 (max: 0) Queued players: 0 (max: 0)
       Server uptime: 16 Second(s).
     </result>
   </ns1:executeCommandResponse>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Using 32bit version of windows by the way.

Link to comment
Share on other sites

That seems to fix it. Reset my local copy, added your patch, recompiled and now it works! :) Will try a clean + rebuild as well just to be sure, but that'll take half an hour or so, development server is a bit sluggish.

//edit

Jup, still works, if I'm any judge I'd say that fixed it, great! A simple soap interface class I just wrote now does in 40 lines what it took my socket connection class for the RA interface 200 lines, and that one was hell'a buggy.. :D

Link to comment
Share on other sites

You quite sure this works? I have the exact same problem now on the 0.12 branch which just got your patch included - both in my JAVA implementation as well as using the default PHP example file. I get the "Command succeeded" message just fine, but both the $result variable as well as $client -> __getLastResponse() are empty / null respectively. Tried both the default 'server info' as well as some other commands (like lookup item).

Hello FragFrog,

i'm interested in your java example using this service. Could you post it?

Thank you in advance :)

Greetings

Maik

Link to comment
Share on other sites

Indeed, though keep in mind I'm still finetuning it a bit - not overly happy at the moment with the way the reply is parsed (pretty sure there is a way to use the xpath directly instead of grabbing the first childnode of the first childenode in the response body) and I think there's a few superflous calls in the way I create the original message. So far I only worked with SOAP in PHP, and those libraries are a lot more intuitive to use.

//edit

Polished it up a bit, still a few spots that might need changing but I think overall it should be a good starting point now :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use