Online Game Service – Part 1

I haven’t blogged in a week, but there’s a good reason for it. Apart from being in college, far away from my PC and UDK, I was also working on an online game service. Eventually, I hope to be able to scale it to support any type of game that comes its way, but at the moment it’s pretty much a primitive data dump.

See it here: http://netgameserver1.appspot.com/

Looks like just five lines of text, right? But right-click on the page and select “View Source”, and you’ll see that there are actually hidden forms on the page. This enables a TCP link from a program like *cough* UDK *cough* to post/get data from the page, but prevents users from tampering with information.

Each line of text is supposed to be a series of parameters, data for a gametype, etc. For example, you could post something like: 134526, 22345, 2341. And this would mean: 134526 people are online, 22345 are playing Deathmatch, and 2341 are playing CTF. Changing the values would be as simple as adding another post (Note: at the moment only 5 are visible for testing purposes, but I expect to expose as many as 20 in order to run the game I’m working on).

But how do we actually do the posting and getting? Since I’m on a Mac, I initially did it the hard way, from the Terminal. POST: curl -v –data “content=Message&subnet=Post+Greeting” http://netgameserver1.appspot.com/sign and GET: curl -v http://netgameserver1.appspot.com/. This would post “Message” to the feed. For a longer message like “Dude, this is cool”, just do “Dude,+this+is+cool”, replacing spaces with + signs.

Wait a minute…UDK isn’t anything like Terminal. So how do we actually test a TCP link without access to a PC? The answer is from Java (which is ideal considering the game service itself is written in Java). The cool thing about working in Java, as opposed to dealing with Terminal stupidity, is that you can actually parse the data sent from the server. Doing this:

public static void parseGet(String toParse) {
 toParse = toParse.replaceAll("</p>", "");
 String[] array = toParse.split("<p>");
 int i;
 for(i=1; i < array.length; i++) {
  if(i == array.length - 1)
   array[i] = array[i].substring(0,array[i].indexOf("<form"));
  System.out.println(array[i].trim());
 }
}

was enough to get each of the five messages in a separate string, ready to be further parsed into relevant game information. Of course, once I actually get back onto UDK I will turn this Java code into UnrealScript.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s