[Cherbot-commit] SF.net SVN: cherbot:[132] trunk/src
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-12 08:52:21
|
Revision: 132
http://cherbot.svn.sourceforge.net/cherbot/?rev=132&view=rev
Author: christianhujer
Date: 2008-12-12 08:52:10 +0000 (Fri, 12 Dec 2008)
Log Message:
-----------
Updated metaserver connection to work with current daimonin metaserver.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/metaserver/MetaServerEntry.java
trunk/src/prj/net/sf/cherbot/metaserver/MetaServerInfo.java
trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java
trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java
Modified: trunk/src/prj/net/sf/cherbot/metaserver/MetaServerEntry.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/metaserver/MetaServerEntry.java 2008-12-03 21:21:59 UTC (rev 131)
+++ trunk/src/prj/net/sf/cherbot/metaserver/MetaServerEntry.java 2008-12-12 08:52:10 UTC (rev 132)
@@ -20,56 +20,46 @@
private static final long serialVersionUID = 1L;
/** The pattern for parsing an entryString from the metaserver. */
- @NotNull private static final Pattern ENTRY_PATTERN = Pattern.compile("(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)");
+ @NotNull private static final Pattern ENTRY_PATTERN = Pattern.compile("(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)");
- /** The ip address of this entry. */
- @NotNull private final String ipaddress;
+ /** The count of this entry. */
+ private final int count;
- /** Unknown1. */
- @NotNull private final String unknown1;
+ /** The name of this entry. */
+ @NotNull private final String name;
- /** The host name of this entry. */
- @NotNull private final String hostname;
+ /** The address of this entry. */
+ @NotNull private final String address;
- /** The number of currently logged in players. */
- private final int playerCount;
+ /** The port of this entry. */
+ private final int port;
/** The version string of this entry's server. */
@NotNull private final String version;
+ /** The number of currently logged in players. */
+ private final int playerCount;
+
/** The description of this entry. */
@NotNull private final String description;
- /** Unknown2. */
- @NotNull private final String unknown2;
-
- /** Unknown3. */
- @NotNull private final String unknown3;
-
- /** Unknown4. */
- @NotNull private final String unknown4;
-
/** Create a MetaServerEntry.
- * @param ipaddress The ip address of this entry.
- * @param unknown1 Unknown1.
- * @param hostname The host name of this entry.
- * @param playerCount The number of currently logged in players.
+ * @param count Unknown value.
+ * @param name The name of the server.
+ * @param address The address of the server.
+ * @param port The port of the server.
* @param version The version string of this entry's server.
+ * @param playerCount The number of currently logged in players.
* @param description The description of this entry.
- * @param unknown2 Unknown2.
- * @param unknown3 Unknown3.
- * @param unknown4 Unknown4.
*/
- public MetaServerEntry(@NotNull final String ipaddress, @NotNull final String unknown1, @NotNull final String hostname, final int playerCount, @NotNull final String version, @NotNull final String description, @NotNull final String unknown2, @NotNull final String unknown3, @NotNull final String unknown4) {
- this.ipaddress = ipaddress;
- this.unknown1 = unknown1;
- this.hostname = hostname;
+ public MetaServerEntry(final int count, @NotNull final String name, @NotNull final String address, final int port, @NotNull final String version, final int playerCount, @NotNull final String description) {
+ this.count = count;
+ this.name = name.replaceAll("_", " ");
+ this.address = address;
+ this.port = port;
+ this.version = version.replaceAll("_", " ");
this.playerCount = playerCount;
- this.version = version;
- this.description = description;
- this.unknown2 = unknown2;
- this.unknown3 = unknown3;
- this.unknown4 = unknown4;
+ this.description = description.replaceAll("_", " ");
}
/** Creates a MetaServerEntry by parsing a single entry String as returned by the metaserer.
@@ -80,39 +70,37 @@
final Matcher matcher = ENTRY_PATTERN.matcher(entryString);
if (matcher.matches()) {
return new MetaServerEntry(
- matcher.group(1),
+ Integer.parseInt(matcher.group(1)),
matcher.group(2),
matcher.group(3),
Integer.parseInt(matcher.group(4)),
matcher.group(5),
- matcher.group(6),
- matcher.group(7),
- matcher.group(8),
- matcher.group(9)
+ Integer.parseInt(matcher.group(6)),
+ matcher.group(7)
);
}
- throw new IllegalArgumentException("supplied String is not a MetaServer string.");
+ throw new IllegalArgumentException("supplied String is not a MetaServer string:\"" + entryString + "\"");
}
- /** Returns the ip address of this entry.
- * @return The ip address of this entry.
+ /** Returns the name of this entry.
+ * @return The name of this entry.
*/
- @NotNull public String getIpaddress() {
- return ipaddress;
+ @NotNull public String getName() {
+ return name;
}
- /** Returns the Unkown1.
- * @return The Unknown1.
+ /** Returns the host name of this entry.
+ * @return The host name of this entry.
*/
- @NotNull public String getUnknown1() {
- return unknown1;
+ @NotNull public String getAddress() {
+ return address;
}
- /** Returns the host name of this entry.
- * @return The host name of this entry.
+ /** Returns the port of this entry.
+ * @return The port of this entry.
*/
- @NotNull public String getHostname() {
- return hostname;
+ public int getPort() {
+ return port;
}
/** Returns the number of currently logged in players.
@@ -136,30 +124,9 @@
return description;
}
- /** Returns the Unkown2.
- * @return The Unknown2.
- */
- @NotNull public String getUnknown2() {
- return unknown2;
- }
-
- /** Returns the Unkown3.
- * @return The Unknown3.
- */
- @NotNull public String getUnknown3() {
- return unknown3;
- }
-
- /** Returns the Unkown4.
- * @return The Unknown4.
- */
- @NotNull public String getUnknown4() {
- return unknown4;
- }
-
/** {@inheritDoc} */
@NotNull public String toString() {
- return hostname + " (" + version + ") " + playerCount + " players. (" + description + ")";
+ return name + "@" + address + ":" + port + " (" + version + ") " + playerCount + " players. (" + description + ")";
}
} // class MetaServerEntry
Modified: trunk/src/prj/net/sf/cherbot/metaserver/MetaServerInfo.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/metaserver/MetaServerInfo.java 2008-12-03 21:21:59 UTC (rev 131)
+++ trunk/src/prj/net/sf/cherbot/metaserver/MetaServerInfo.java 2008-12-12 08:52:10 UTC (rev 132)
@@ -29,7 +29,7 @@
private static final long serialVersionUID = 1L;
/** The default meta server. */
- @NotNull public static final String DEFAULT_META_SERVER_HOST = "damn.informatik.uni-bremen.de";
+ @NotNull public static final String DEFAULT_META_SERVER_HOST = "www.daimonin.com";
/** The default meta port. */
public static final int DEFAULT_META_SERVER_PORT = 13326;
Modified: trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java
===================================================================
--- trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java 2008-12-03 21:21:59 UTC (rev 131)
+++ trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java 2008-12-12 08:52:10 UTC (rev 132)
@@ -15,46 +15,42 @@
*/
public class MetaServerEntryTest {
- /** Tests the constructor {@link net.sf.cherbot.metaserver.MetaServerEntry#MetaServerEntry(String, String, String, int, String, String, String, String, String)} and all related getters. */
+ /** Tests the constructor {@link net.sf.cherbot.metaserver.MetaServerEntry#MetaServerEntry(int, String, String, int, String, int, String)} and all related getters. */
@Test public void testMetaServerEntry() {
- final MetaServerEntry testling = new MetaServerEntry("192.168.0.1", "177", "localhost", 20, "0.9.7", "My own Daimonin server.", "02", "03", "04");
- Assert.assertEquals("ipaddress must be stored.", "192.168.0.1", testling.getIpaddress());
- Assert.assertEquals("unknown1 must be stored.", "177", testling.getUnknown1());
- Assert.assertEquals("hostname must be stored.", "localhost", testling.getHostname());
- Assert.assertEquals("playercount must be stored.", 20, testling.getPlayerCount());
- Assert.assertEquals("version must be stored.", "0.9.7", testling.getVersion());
+ final MetaServerEntry testling = new MetaServerEntry(273, "Dummy Server", "192.168.0.1", 13327, "0.9.7.1", 2, "My_own_Daimonin_server.");
+ Assert.assertEquals("name must be stored.", "Dummy Server", testling.getName());
+ Assert.assertEquals("hostname must be stored.", "192.168.0.1", testling.getAddress());
+ Assert.assertEquals("port must be stored.", 13327, testling.getPort());
+ Assert.assertEquals("version must be stored.", "0.9.7.1", testling.getVersion());
+ Assert.assertEquals("playercount must be stored.", 2, testling.getPlayerCount());
Assert.assertEquals("description must be stored.", "My own Daimonin server.", testling.getDescription());
- Assert.assertEquals("unknown2 must be stored.", "02", testling.getUnknown2());
- Assert.assertEquals("unknown3 must be stored.", "03", testling.getUnknown3());
- Assert.assertEquals("unknown4 must be stored.", "04", testling.getUnknown4());
}
/** Tests the method {@link MetaServerEntry#parse(String)}. */
@Test public void testParse() {
- final MetaServerEntry testling = MetaServerEntry.parse("192.168.0.1|177|localhost|20|0.9.7|My own Daimonin server.|02|03|04");
- Assert.assertEquals("ipaddress must be stored.", "192.168.0.1", testling.getIpaddress());
- Assert.assertEquals("unknown1 must be stored.", "177", testling.getUnknown1());
- Assert.assertEquals("hostname must be stored.", "localhost", testling.getHostname());
+ final MetaServerEntry testling = MetaServerEntry.parse("273|Test_Server|62.75.168.180|13327|0.9.7.1|20|Foo_bar_server.");
+ Assert.assertEquals("name must be stored.", "Test Server", testling.getName());
+ Assert.assertEquals("hostname must be stored.", "62.75.168.180", testling.getAddress());
+ Assert.assertEquals("port must be stored.", 13327, testling.getPort());
+ Assert.assertEquals("version must be stored.", "0.9.7.1", testling.getVersion());
Assert.assertEquals("playercount must be stored.", 20, testling.getPlayerCount());
- Assert.assertEquals("version must be stored.", "0.9.7", testling.getVersion());
- Assert.assertEquals("description must be stored.", "My own Daimonin server.", testling.getDescription());
- Assert.assertEquals("unknown2 must be stored.", "02", testling.getUnknown2());
- Assert.assertEquals("unknown3 must be stored.", "03", testling.getUnknown3());
- Assert.assertEquals("unknown4 must be stored.", "04", testling.getUnknown4());
+ Assert.assertEquals("description must be stored.", "Foo bar server.", testling.getDescription());
}
/** Tests that {@link MetaServerEntry#parse(String)} throws an exception if the supplied string is not a metaserver entry. */
@Test(expected = IllegalArgumentException.class)
public void testParseException() {
- MetaServerEntry.parse("192.168.0.1_177|localhost|20|0.9.7|My own Daimonin server.|02|03|04");
+ MetaServerEntry.parse("273|Test_Server|62.75.168.180|13327|0.9.7.1|20Foo_bar_server.");
}
/** Tests that {@link MetaServerEntry#toString()} returns reasonable data. */
@Test
public void testToString() {
- final MetaServerEntry testling = MetaServerEntry.parse("192.168.0.1|177|localhost|20|0.9.7|My own Daimonin server.|02|03|04");
+ final MetaServerEntry testling = MetaServerEntry.parse("273|Test_Server|62.75.168.180|13327|0.9.7.1|20|Foo_bar_server.");
final String string = testling.toString();
- Assert.assertTrue(string.contains(testling.getHostname()));
+ Assert.assertTrue(string.contains(testling.getName()));
+ Assert.assertTrue(string.contains(testling.getAddress()));
+ Assert.assertTrue(string.contains(Integer.toString(testling.getPort())));
Assert.assertTrue(string.contains(testling.getVersion()));
Assert.assertTrue(string.contains(Integer.toString(testling.getPlayerCount())));
Assert.assertTrue(string.contains(testling.getDescription()));
Modified: trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java
===================================================================
--- trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java 2008-12-03 21:21:59 UTC (rev 131)
+++ trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java 2008-12-12 08:52:10 UTC (rev 132)
@@ -29,21 +29,19 @@
* @throws IOException in case of I/O problems (unexpected).
*/
@Test public void testParse() throws IOException {
- final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n"
- + "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
+ final String metaServerString = "195|Test_Server|62.75.168.180|13327|0.9.7.1|0|See_and_play_here_the_newest_maps_&_features!\n"
+ + "45|Daimonin|62.75.224.80|13327|0.9.7.1|1|Public_Daimonin_game_server_from_www.daimonin.com\n";
final MetaServerInfo testling = new MetaServerInfo();
testling.parse(new BufferedReader(new StringReader(metaServerString)));
Assert.assertEquals("MetaServerInfo now must contain 2 entries.", 2, testling.size());
- Assert.assertEquals("ip address of first entry must be 192.168.0.1.", "192.168.0.1", testling.get(0).getIpaddress());
- Assert.assertEquals("ip address of second entry must be 192.168.0.2.", "192.168.0.2", testling.get(1).getIpaddress());
}
/** Tests whether parsing from a BufferedReader deletes previous entries.
* @throws IOException in case of I/O problems (unexpected).
*/
@Test public void testParseDeletes() throws IOException {
- final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n"
- + "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
+ final String metaServerString = "195|Test_Server|62.75.168.180|13327|0.9.7.1|0|See_and_play_here_the_newest_maps_&_features!\n"
+ + "45|Daimonin|62.75.224.80|13327|0.9.7.1|1|Public_Daimonin_game_server_from_www.daimonin.com\n";
final MetaServerInfo testling = new MetaServerInfo();
testling.parse(new BufferedReader(new StringReader(metaServerString)));
Assert.assertEquals("MetaServerInfo now must contain 2 entries.", 2, testling.size());
@@ -55,13 +53,11 @@
* @throws IOException in case of I/O problems (unexpected).
*/
@Test public void testUpdate() throws IOException {
- final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n"
- + "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
+ final String metaServerString = "195|Test_Server|62.75.168.180|13327|0.9.7.1|0|See_and_play_here_the_newest_maps_&_features!\n"
+ + "45|Daimonin|62.75.224.80|13327|0.9.7.1|1|Public_Daimonin_game_server_from_www.daimonin.com\n";
final MetaServerInfo testling = new MetaServerInfo("", 0);
testling.parse(new BufferedReader(new StringReader(metaServerString)));
Assert.assertEquals("MetaServerInfo now must contain 2 entries.", 2, testling.size());
- Assert.assertEquals("ip address of first entry must be 192.168.0.1.", "192.168.0.1", testling.get(0).getIpaddress());
- Assert.assertEquals("ip address of second entry must be 192.168.0.2.", "192.168.0.2", testling.get(1).getIpaddress());
try {
testling.update();
Assert.fail("Exception expected but not thrown.");
@@ -70,8 +66,6 @@
}
// Verify that the failed update() didn't destroy information.
Assert.assertEquals("MetaServerInfo now still must contain 2 entries.", 2, testling.size());
- Assert.assertEquals("ip address of first entry still must be 192.168.0.1.", "192.168.0.1", testling.get(0).getIpaddress());
- Assert.assertEquals("ip address of second entry still must be 192.168.0.2.", "192.168.0.2", testling.get(1).getIpaddress());
}
} // class MetaServerInfoTest
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|