Quake tools with Java and UDP ... continued
Author: vglass@jfind.com, Van Glass
To retrieve this data call the getData() method. This will return a byte array of the
response which can then be converted into a String.
The format of a "getstatus" response from a Quake server is a tokenized String delimited by
the "\" character. Every token value pair except for the last token gives information about how
the Quake server is configured.
To parse out the server config information simply use the StringTokenizer class and print the results to the
console. The last token lists current player stats including ping time, frags, and playername.
Again use a StringTokenizer to parse out this information, however change the delimiters to parse
it out properly.
StringTokenizer st = new StringTokenizer(message,"\\");
counter = st.countTokens();
/* Strip off first token */
st.nextToken();
count++;
/* Parse out server variables */
while(st.hasMoreTokens())
{
key = st.nextToken();
value = st.nextToken();
count+=2;
/* Print out player information */
/* Last token found ... change parsing rules */
if(count == counter)
{
String frags;
String ping_time;
String username;
StringTokenizer users = new StringTokenizer(value);
users.nextToken();
while(users.hasMoreTokens())
{
frags = users.nextToken(space);
ping_time = users.nextToken(space);
username = users.nextToken("\r\n");
System.out.print("Frags: " + frags);
System.out.print(" Ping: " + ping_time);
System.out.print(" Player: " + username + "\n");
}
}
/* Print out configuration variables key/value format */
else
{
System.out.println(key + "=" + value);
}
}
[Download Source Code]
The following class was written as a Java application. With slight modifications it could easily
be converted to be used as a Java servlet, making a great web based status tool for any of the clan sites
out there. I hope this article has provided some useful information. Next week I will investigate using
Java to parse out an HTML document into its entities. Until then.
| Sponsored Links - please visit our sponsors |
| Java FTP Component | | Easily add FTP to your Java apps. | | http://www.jscape.com/inetfactory/ftp.html |
| Learn Java Server Faces! | | Use WebGalileo Faces JSF components to quickly create Java based web apps. | | http://www.jscape.com/webgalileofaces/ |
| Java SMTP Component | | Easily add SMTP to your Java apps | | http://www.jscape.com/inetfactory/smtp.html |
| SSH Factory | | automate telnet and SSH tasks | | http://www.jscape.com/sshfactory/ |
| Secure FTP Applet | | Connect to FTP securely from within your browser. | | http://www.jscape.com/sftpapplet/ |
| FTP Applet | | Add file transfer capabilities to your web pages. | | http://www.jscape.com/ftpapplet/index.html |
Sponsor this site
| |