diff options
Diffstat (limited to 'NET/worlds/network/ServerURL.java')
| -rw-r--r-- | NET/worlds/network/ServerURL.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/NET/worlds/network/ServerURL.java b/NET/worlds/network/ServerURL.java new file mode 100644 index 0000000..9461ee5 --- /dev/null +++ b/NET/worlds/network/ServerURL.java @@ -0,0 +1,59 @@ +package NET.worlds.network; + +public class ServerURL { + private String _serverType = null; + private String _serverHost = null; + private String _serverOptions = null; + + public String getHost() { + return this._serverHost; + } + + public String getType() { + return this._serverType; + } + + public ServerURL(String serverURL) throws InvalidServerURLException { + String origServerURL = serverURL; + int txtPos = serverURL.indexOf("://"); + if (txtPos >= 0) { + String protocol = serverURL.substring(0, txtPos); + + assert protocol.equals("worldserver"); + + serverURL = serverURL.substring(txtPos + 3); + } + + int typePos = serverURL.indexOf(47); + if (typePos >= 0) { + this._serverHost = serverURL.substring(0, typePos); + serverURL = serverURL.substring(typePos + 1); + } else { + this._serverHost = serverURL; + serverURL = "AutoServer"; + } + + int optPos = serverURL.indexOf(47); + if (optPos >= 0) { + this._serverType = serverURL.substring(0, optPos); + serverURL = serverURL.substring(optPos + 1); + } else { + this._serverType = serverURL; + serverURL = ""; + } + + this._serverOptions = serverURL; + if (this._serverHost.length() == 0) { + throw new InvalidServerURLException("Invalid server URL: " + origServerURL); + } else { + if (this._serverType.length() == 0) { + this._serverType = "AutoServer"; + } + } + } + + @Override + public String toString() { + return "worldserver://" + this._serverHost + "/" + this._serverType + "/" + this._serverOptions; + } +} |