summaryrefslogtreecommitdiff
path: root/NET/worlds/network/AutoServer.java
blob: e4f84cf03ec612df33c24611498fcd4ef4f7de9a (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package NET.worlds.network;

import NET.worlds.console.Console;

public class AutoServer extends WorldServer {
   private static int counter = 0;

   public AutoServer() {
      if (counter++ > 0) {
         System.out.println("DEBUG: Created second AutoServer class.");
         Galaxy.printDebugging();
         new Exception().printStackTrace(System.out);
      }
   }

   @Override
   public synchronized void incRefCnt(Object referrer) {
      super.incRefCnt(referrer);
      this.startConnect();
   }

   protected void state_Authprompt() {
      this._state.setState(3);
   }

   @Override
   protected void state_XMIT_SI() {
      WorldServer newServer = null;
      int servType = this.getServerType();
      if ((getDebugLevel() & 32) > 0) {
         System.out.println(this + ": AutoServer detected server type " + servType);
      }

      switch (servType) {
         case 1:
            newServer = new UserServer();
            break;
         case 2:
            newServer = new AnonUserServer();
            break;
         case 3:
            Console.println(this + Console.message("Error-in-server"));
            Console.println(this + Console.message("Error-user-server"));
            newServer = null;
            break;
         case 4:
            newServer = new AnonRoomServer();
            break;
         default:
            assert false;
      }

      if (newServer != null) {
         newServer.reuseConnection(this);
         newServer.initInstance(this._galaxy, this._serverURL);
         newServer.propertyUpdate(this._propList);
      }

      this._galaxy.killServer(this);
      this._galaxy.swapServer(this, newServer);
      this._galaxy.setGalaxyType(servType);
      if (this._refCnt - this._tmpRefCnt != 0) {
         System.out.println(this + ": bad reference counts.  DEBUG INFO:");
         System.out.println("\t_refCnt = " + this._refCnt);
         System.out.println("\t_tmpRefCnt = " + this._tmpRefCnt);
         this.printReferrers();
      }

      assert this._refCnt - this._tmpRefCnt == 0;

      this._state.setState(17);
   }

   @Override
   public String toString() {
      return "AutoServer(" + super.toString() + ")";
   }

   @Override
   void goOnline() {
      super.goOnline();
      System.out.println("DEBUG: AutoServer going online!");
      new Exception().printStackTrace(System.out);
   }
}