 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.metaserver;
26 import java.io.IOException;
27 import java.util.regex.Pattern;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
142 if (entries.length != 11) {
160 players = Integer.parseInt(entries[2]);
163 bytesIn = Long.parseLong(entries[5]);
164 bytesOut = Long.parseLong(entries[6]);
169 }
catch (
final NumberFormatException ignored) {
173 return new MetaserverEntry(
updateSeconds,
hostname,
players,
version,
comment,
bytesIn,
bytesOut,
uptimeSeconds,
archBase,
codeBase,
mapBase);
185 if (line.equals(
"END_SERVER_DATA")) {
188 System.err.println(
"Warning: metaserver response missing hostname field, skipping");
189 metaserverEntry =
null;
191 metaserverEntry =
new MetaserverEntry(
updateSeconds,
port == 13327 ?
hostname :
hostname+
":"+
port,
players,
version,
comment,
bytesIn,
bytesOut,
uptimeSeconds,
archBase,
mapBase,
codeBase);
195 return metaserverEntry;
197 final String[] tmp = line.split(
"=", 2);
198 if (tmp.length == 2) {
199 final String key = tmp[0];
200 final String value = tmp[1];
259 final long now = (System.currentTimeMillis()+500)/1000;
268 System.err.println(
"Ignoring unknown key: "+key);
272 throw new IOException(
"syntax error: "+line);
275 if (line.equals(
"START_SERVER_DATA")) {
278 throw new IOException(
"syntax error: "+line);
312 return entry.getUpdateSeconds()+
"|"+
replace(entry.getHostname())+
"|"+entry.getPlayers()+
"|"+
replace(entry.getVersion())+
"|"+
replace(entry.getComment())+
"|"+entry.getBytesIn()+
"|"+entry.getBytesOut()+
"|"+entry.getUptimeSeconds()+
"|"+
replace(entry.getArchBase())+
"|"+
replace(entry.getCodeBase())+
"|"+
replace(entry.getMapBase());
321 private static String
replace(@NotNull
final String str) {
322 return str.replaceAll(
"[|\r\n]",
" ");
Represents a response line from the metaserver.
void clear()
Resets values for the current server entry.
String hostname
The "hostname" value for the current server entry.
long bytesOut
The "bytes out" value for the current server entry.
static MetaserverEntry parseEntry(@NotNull final CharSequence entry)
Parses a metaserver response line.
MetaserverEntryParser()
Creates a new instance.
int updateSeconds
The "update seconds" value for the current server entry.
static final Pattern FIELD_SEPARATOR_PATTERN
The pattern to split a metaserver response line into fields.
String codeBase
The "code base" value for the current server entry.
String version
The "server version" value for the current server entry.
Utility class for parsing strings into numbers.
String archBase
The "archetype base" value for the current server entry.
static final String DEFAULT_BASE
The default for arch base, map base, and code base if none specified.
static long parseLong(@NotNull final String string, final long defaultValue)
Converts a string into a long value.
long bytesIn
The "bytes in" value for the current server entry.
static int parseInt(@NotNull final String string, final int defaultValue)
Converts a string into an int value.
MetaserverEntry parseLine(@NotNull final String line)
Parses a metaserver response line.
Parser for response lines of metaserver response lines.
static final String UNKNOWN_VERSION
The default server version if none specified.
String comment
The "comment" value for the current server entry.
static String format(@NotNull final MetaserverEntry entry)
Formats a metaserver entry that returns the metaserver entry when parse with parseEntry(CharSequence)...
String mapBase
The "map base" value for the current server entry.
int uptimeSeconds
The "uptime seconds" value for the current server entry.
int port
The "port" value for the current server entry.
boolean inSection
Whether response parsing is withing a server entry.
int players
The "players" value for the current server entry.
static String replace(@NotNull final String str)
Replaces characters with may cause parsing issues.