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]",
" ");