summaryrefslogtreecommitdiff
path: root/NET/worlds/network/ServerURL.java
blob: 9461ee5c2af76ad245cb099ff38dc77654bf81d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
   }
}