Getting RSW turn info and game reports via XML over the web

A place for general chatter about games in progress, games completed, strategy advice, bug reports, or really anything at all that relates in some vague way to RSW.
Post Reply
drwr
Posts: 641
Joined: Sat Dec 10, 2005 10:56 am
Location: Glendale, CA
Contact:

Getting RSW turn info and game reports via XML over the web

Post by drwr »

The RSW server has always supported an XML-based backchannel communication, to extract all kinds of information from the game server, including turn due date information and complete turn reports. It is also possible to submit order sheets or messages via this same communication system. In fact, this is exactly the mechanism that the RSW client uses to download turn reports and submit orders; so anything the RSW client can do, you can in principle write your own scripts to do too.

One of our RSW players has written an app that takes advantage of this to report how many players a particular game is still waiting on; see this thread.

In general, you can do this by POSTing an XML-formatted request to the URL address https://rswgame.com/xml . The request format is simple, and looks like this:

<request command="c">
<parameter keyword="k" value="v" />
</request>

where "c" is the particular command to issue, and "k" and "v" are keyword/value pairs to send to the command. The <parameter> element may appear zero or more times, once for each parameter required.

For a list of available commands, and the parameters supported by each, send the command "help", with no parameters.

You can also do this easily from a command line prompt with this Python script (Windows users will need to install Python first to run it): http://rswgame.com/rsw_remote.py, and if you are comfortable reading Python, you can inspect this simple script for more specifics about the URL posting.

The response to your request will be formatted in XML as well. There is little specific documentation on the response format, but it should be apparent by inspection. Please feel free to ask if you have questions.

David
Bubble
Posts: 9
Joined: Fri Oct 30, 2009 2:41 am

Re: Getting RSW turn info and game reports via XML over the web

Post by Bubble »

Cool !

I'm giving it a try, in C# and it Ok with an empty query. BUt I always get a Bad Request error from the RSW server, as soon as I add xml to the request. If anyone sees what's wrong with this code, I'll appreciate any help. :)

Code: Select all

			HttpWebRequest webRequest= (HttpWebRequest)WebRequest.Create(serverUri);
			webRequest.KeepAlive=false;
			string request = "<?xml version=\"1.0\">\n";
/*			request+="<request command=\""+c+"\">\n";
			if(args != null)
				foreach(KeyValuePair<string, string> arg in args)
				{
					request+="<parameter keyword=\""+arg.Key+"\""+(arg.Value.Equals("")?"":(" value=\""+arg.Value+"\""))+" />\n";
				}
			request+="</request>\n";*/			request+="<request command=\"help\" />\n";
			Encoding encoding=new ASCIIEncoding();
			byte[] data=encoding.GetBytes(request);
			webRequest.Method="POST";
			webRequest.ContentLength=data.Length;
			webRequest.ContentType="text/xml";
			
			Stream reqStream = webRequest.GetRequestStream();
			reqStream.Write(data,0,data.Length);
			reqStream.Close();
			WebResponse resp= (HttpWebResponse)webRequest.GetResponse();
			StreamReader read= new StreamReader(resp.GetResponseStream());
			string res= read.ReadToEnd();
			read.Close();
drwr
Posts: 641
Joined: Sat Dec 10, 2005 10:56 am
Location: Glendale, CA
Contact:

Re: Getting RSW turn info and game reports via XML over the web

Post by drwr »

Hmm, I certainly don't see anything wrong. A 400 (Bad Request) error in this case means either that the XML file was badly formed, or it didn't contain a single <request> element with zero or more <parameter>'s. Could it be that the C# library is mucking with the data you're posting somehow? You could try setting webRequest.ContentType = 'text/xml'; maybe the C# library is trying to be smart and massaging the data that it assumes is www-form-urlencoded.

I've just added some more logging to the server, so it will log the XML data that it received from you when it reports a 400. Try it again, and I'll let you know exactly what the server received, and then we can figure out what went wrong.

David
Bubble
Posts: 9
Joined: Fri Oct 30, 2009 2:41 am

Re: Getting RSW turn info and game reports via XML over the web

Post by Bubble »

I'm guilty !

<?xml version="1.0"> is not the same as <?xml version="1.0"?>

Sorry for the time you lost on this, and thank you for the additional logging. :oops:

I went as far as using socket and using different proxies, and the error was between my chair and my keyboard. Shame ...
drwr
Posts: 641
Joined: Sat Dec 10, 2005 10:56 am
Location: Glendale, CA
Contact:

Re: Getting RSW turn info and game reports via XML over the web

Post by drwr »

No worries. I didn't see the problem either, and you posted the code. :)

David
Post Reply