diff options
Diffstat (limited to 'NET/worlds/network/NetworkRoom.java')
| -rw-r--r-- | NET/worlds/network/NetworkRoom.java | 711 |
1 files changed, 711 insertions, 0 deletions
diff --git a/NET/worlds/network/NetworkRoom.java b/NET/worlds/network/NetworkRoom.java new file mode 100644 index 0000000..d5e13b6 --- /dev/null +++ b/NET/worlds/network/NetworkRoom.java @@ -0,0 +1,711 @@ +/* */ package NET.worlds.network; +/* */ +/* */ import NET.worlds.console.Console; +/* */ import NET.worlds.core.IniFile; +/* */ import NET.worlds.core.Std; +/* */ import NET.worlds.scape.Room; +/* */ import NET.worlds.scape.RoomSubscribeInfo; +/* */ import NET.worlds.scape.Sharer; +/* */ import NET.worlds.scape.World; +/* */ import java.io.PrintStream; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class NetworkRoom +/* */ implements NetworkObject, ConnectionWaiter +/* */ { +/* */ private static final int STATE_DISCONNECTED = 0; +/* */ private static final int STATE_CONNECTING = 1; +/* */ private static final int STATE_GETTINGROOMID = 2; +/* */ private static final int STATE_CONNECTED = 3; +/* */ private static final int STATE_SUBSCRIBED = 4; +/* */ private static int _debugLevel; +/* */ Room _room; +/* */ String _worldName; +/* */ String _roomName; +/* */ String _longID; +/* */ Galaxy _galaxy; +/* */ String _debug1; +/* */ String _debug2; +/* */ +/* */ static +/* */ { +/* 50 */ _debugLevel = IniFile.gamma().getIniInt("roomdebug", 0); +/* 51 */ if (_debugLevel > 0) { +/* 52 */ System.out.println("ROOM DEBUGGING LEVEL = " + _debugLevel); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public NetworkRoom(Room room) +/* */ { +/* 75 */ this._room = room; +/* */ +/* 77 */ this._debug1 = ""; +/* 78 */ this._debug2 = ""; +/* */ +/* */ +/* 81 */ this._galaxy = room.getGalaxy(); +/* */ +/* 83 */ initNames(); +/* 84 */ register(); +/* */ } +/* */ +/* */ synchronized void initNames() +/* */ { +/* 89 */ this._roomName = this._room.getName(); +/* 90 */ World world = this._room.getWorld(); +/* 91 */ this._worldName = world.getName(); +/* 92 */ Galaxy galaxy = this._room.getGalaxy(); +/* 93 */ String channel = galaxy.getChannel(); +/* 94 */ if (channel.length() != 0) +/* 95 */ channel = "<" + channel + ">"; +/* 96 */ this._longID = (this._worldName + "#" + this._roomName + channel); +/* */ } +/* */ +/* */ public Room getRoom() { +/* 100 */ return this._room; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void setName(String newName) +/* */ { +/* 108 */ assert (newName != this._roomName); +/* */ +/* */ +/* */ +/* 112 */ unregister(); +/* */ +/* */ +/* 115 */ initNames(); +/* */ +/* */ +/* 118 */ register(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ void unregister() +/* */ { +/* 132 */ Galaxy tmpGalaxy = this._room.getGalaxy(); +/* 133 */ assert (tmpGalaxy != null); +/* */ +/* */ +/* 136 */ assert (this._galaxy == tmpGalaxy); +/* */ +/* 138 */ tmpGalaxy.delObject(this._longID); +/* 139 */ if (this._roomID != 0) +/* 140 */ tmpGalaxy.delRoomID(this._roomID, this); +/* 141 */ this._debug2 = ""; +/* 142 */ this._roomID = 0; +/* */ } +/* */ +/* */ +/* */ +/* */ public synchronized void detach() +/* */ { +/* 149 */ unregister(); +/* */ +/* 151 */ this._galaxy = null; +/* */ +/* 153 */ this._room = null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public String getLongID() +/* */ { +/* 161 */ return this._longID; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public int getRoomID() +/* */ { +/* 169 */ return this._roomID; +/* */ } +/* */ +/* */ public boolean isServed() { +/* 173 */ return this._serverState == 4; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void serverRedirect(WorldServer serv, String roomName, ServerURL serverURL) +/* */ { +/* 183 */ if (this._server == null) { +/* 184 */ return; +/* */ } +/* 186 */ if (serv.getGalaxy() != this._server.getGalaxy()) +/* 187 */ return; +/* 188 */ if (!roomName.equals(this._longID)) { +/* 189 */ return; +/* */ } +/* */ +/* 192 */ if ((_debugLevel & 0x2) > 0) { +/* 193 */ System.out.println(this._room.getName() + ": serverRedirect(" + +/* 194 */ serverURL + ")"); +/* */ } +/* */ +/* */ +/* 198 */ this._serverState = 3; +/* */ +/* */ +/* 201 */ int tmpRoomID = this._roomID; +/* 202 */ disconnect(); +/* */ +/* */ +/* */ +/* */ +/* 207 */ assert (this._server == null); +/* 208 */ this._roomID = tmpRoomID; +/* 209 */ this._debug2 = +/* 210 */ (this._debug2 + "; [" + Std.getRealTime() + "]: serverDirect(" + serv + ")"); +/* 211 */ this._serverURL = URL.make(serverURL.toString()); +/* 212 */ if (this._roomID != 0) +/* 213 */ this._room.getGalaxy().setRoomID(this._roomID, this); +/* 214 */ if (this._wantsToBeSubscribed) { +/* 215 */ acquireServer(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void setRoomID(WorldServer serv, int roomID, String roomName, boolean willRedirect) +/* */ { +/* 226 */ assert (serv != null); +/* */ +/* */ +/* 229 */ if ((_debugLevel & 0x2) > 0) { +/* 230 */ System.out.println(this._longID + ": setRoomID(" + serv + ", " + +/* 231 */ roomID + ", " + roomName + ", " + willRedirect + ")"); +/* 232 */ System.out.println("last request made: " + this._debug1); +/* */ } +/* 234 */ if (serv.getGalaxy() != this._server.getGalaxy()) { +/* 235 */ System.out.println(this._longID + ": setRoomID(" + serv + ", " + +/* 236 */ roomID + ", " + roomName + ", " + willRedirect + ")"); +/* 237 */ System.out.println("\twas expecting server " + this._server); +/* 238 */ System.out.println("last request made: " + this._debug1); +/* 239 */ new Exception().printStackTrace(System.out); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* 246 */ if (serv.getGalaxy() != this._server.getGalaxy()) +/* 247 */ return; +/* 248 */ if (!roomName.equals(this._longID)) +/* 249 */ return; +/* 250 */ if (roomID == 0) +/* */ { +/* */ +/* */ +/* 254 */ this._serverState = 0; +/* 255 */ reacquireServer(serv); +/* 256 */ return; +/* */ } +/* 258 */ if (this._roomID == 0) { +/* 259 */ this._roomID = roomID; +/* 260 */ this._debug2 = +/* 261 */ (this._debug2 + "; [" + Std.getRealTime() + "]: setRoomID(" + serv + ", " + willRedirect + ")"); +/* */ } +/* 263 */ assert (this._roomID == roomID); +/* 264 */ this._serverState = 3; +/* 265 */ if (!willRedirect) +/* */ { +/* */ +/* 268 */ if (this._wantsToBeSubscribed) { +/* 269 */ assert (this._lastRSInfo != null); +/* 270 */ subscribe(); +/* */ } +/* */ else { +/* 273 */ disconnect(); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 292 */ private RoomSubscribeInfo _lastRSInfo = null; +/* 293 */ private URL _serverURL = null; +/* */ +/* */ +/* */ +/* */ +/* */ +/* 299 */ private WorldServer _server = null; +/* 300 */ private int _roomID = 0; +/* 301 */ private boolean _wantsToBeSubscribed = false; +/* 302 */ private int _serverState = 0; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void subscribe(RoomSubscribeInfo info) +/* */ { +/* 313 */ assert (this._galaxy == this._room.getGalaxy()); +/* */ +/* */ +/* 316 */ if ((_debugLevel & 0x1) > 0) { +/* 317 */ System.out.println(this._room.getName() + ": subscribe(Info)"); +/* */ } +/* 319 */ assert (this._room.getWorld() != null); +/* 320 */ assert (this._serverState != 4); +/* 321 */ this._lastRSInfo = info; +/* 322 */ this._wantsToBeSubscribed = true; +/* 323 */ switch (this._serverState) { +/* */ case 0: +/* 325 */ acquireServer(); +/* 326 */ break; +/* */ case 3: +/* 328 */ subscribe(); +/* */ } +/* */ +/* */ } +/* */ +/* */ private void subscribe() +/* */ { +/* 335 */ if ((_debugLevel & 0x1) > 0) { +/* 336 */ System.out.println(this._room.getName() + ": subscribe()"); +/* */ } +/* 338 */ assert (this._server != null); +/* 339 */ assert (this._wantsToBeSubscribed); +/* 340 */ assert (this._lastRSInfo != null); +/* 341 */ assert (this._roomID != 0); +/* 342 */ assert (this._serverState == 3); +/* 343 */ assert (this._room.getWorld() != null); +/* */ +/* */ +/* 346 */ this._serverState = 4; +/* 347 */ sendNetworkMsg(new SubscribeRoomCmd(this._lastRSInfo, this._roomID)); +/* */ } +/* */ +/* */ private void sendNetworkMsg(netPacket msg) +/* */ { +/* 352 */ assert (this._server != null); +/* */ try { +/* 354 */ this._server.sendNetworkMsg(msg); +/* */ } catch (InfiniteWaitException e) { +/* 356 */ disconnect(); +/* */ } catch (PacketTooLargeException e) { +/* 358 */ if (!$assertionsDisabled) throw new AssertionError(); +/* */ } +/* */ } +/* */ +/* */ public synchronized void subscribeDist(RoomSubscribeInfo info) { +/* 363 */ this._lastRSInfo = info; +/* 364 */ assert (this._wantsToBeSubscribed); +/* 365 */ assert (this._room.getWorld() != null); +/* 366 */ if (this._serverState == 4) { +/* 367 */ sendNetworkMsg(new SubscribeDistCmd(info.d, this._roomID)); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void unsubscribe() +/* */ { +/* 377 */ if ((_debugLevel & 0x1) > 0) { +/* 378 */ System.out.println(this._room.getName() + ": unsubscribe()"); +/* */ } +/* 380 */ assert (this._wantsToBeSubscribed); +/* 381 */ this._wantsToBeSubscribed = false; +/* 382 */ this._lastRSInfo = null; +/* 383 */ switch (this._serverState) +/* */ { +/* */ +/* */ case 2: +/* 387 */ disconnect(); +/* 388 */ break; +/* */ case 4: +/* 390 */ sendNetworkMsg(new UnsubscribeRoomCmd(this._roomID)); +/* 391 */ disconnect(); +/* 392 */ break; +/* */ case 1: +/* 394 */ assert (this._server != null); +/* 395 */ this._server.abortWaitForConnection(this); +/* 396 */ disconnect(); +/* 397 */ break; +/* */ } +/* */ +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private synchronized void disconnect() +/* */ { +/* 409 */ if ((_debugLevel & 0x2) > 0) { +/* 410 */ System.out.println(this._room.getName() + ": disconnect()"); +/* */ } +/* */ +/* 413 */ switch (this._serverState) +/* */ { +/* */ case 2: +/* 416 */ this._server.delRoomRequest(this._longID); +/* */ +/* 418 */ if (this._debug1 == null) +/* 419 */ this._debug1 = ""; +/* 420 */ this._debug1 = +/* 421 */ (this._debug1 + "; [" + Std.getRealTime() + "]: deleted request for " + this._longID); +/* */ +/* 423 */ break; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 434 */ this._serverURL = null; +/* 435 */ if ((this._server != null) && (this._roomID != 0)) +/* 436 */ this._server.delRoomID(this._roomID, this); +/* 437 */ this._roomID = 0; +/* 438 */ this._debug2 = ""; +/* */ +/* 440 */ if (this._server != null) { +/* 441 */ this._server.decRefCnt(this); +/* 442 */ this._server = null; +/* 443 */ this._serverState = 0; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 452 */ assert (this._serverState == 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private synchronized void acquireServer() +/* */ { +/* 461 */ if ((_debugLevel & 0x2) > 0) { +/* 462 */ System.out.println(this._room.getName() + ": acquireServer() - " + +/* 463 */ this._serverURL); +/* */ } +/* */ +/* 466 */ assert (this._serverState == 0); +/* 467 */ if (this._server == null) { +/* 468 */ World world = this._room.getWorld(); +/* 469 */ assert (world != null); +/* 470 */ Galaxy galaxy = world.getConsole().getGalaxy(); +/* 471 */ assert (galaxy != null); +/* */ +/* 473 */ if (this._serverURL == null) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* */ +/* 480 */ this._serverURL = world.getConsole().getGalaxyURL(); +/* 481 */ if (this._serverURL == null) +/* 482 */ return; +/* */ } +/* */ try { +/* 485 */ this._server = galaxy.getServer(this._serverURL); +/* */ } catch (InvalidServerURLException e) { +/* 487 */ Console.println(">> " + e.getMessage()); +/* 488 */ this._serverURL = null; +/* 489 */ return; +/* */ } +/* 491 */ if (this._server == null) +/* 492 */ return; +/* 493 */ this._server.incRefCnt(this); +/* */ } +/* 495 */ this._serverState = 1; +/* 496 */ this._server.waitForConnection(this); +/* */ } +/* */ +/* */ public void connectionCallback(Object caller, boolean connected) { +/* 500 */ if (!(caller instanceof WorldServer)) +/* 501 */ return; +/* 502 */ WorldServer serv = (WorldServer)caller; +/* */ +/* 504 */ if ((_debugLevel & 0x2) > 0) { +/* 505 */ System.out.println(this._room.getName() + ": connectionCallback(" + +/* 506 */ serv + ", connected=" + connected + ") _server=" + +/* 507 */ this._server); +/* */ } +/* 509 */ if (this._server != serv) +/* 510 */ return; +/* 511 */ if (!connected) +/* */ { +/* */ +/* 514 */ disconnect(); +/* */ +/* */ +/* */ +/* 518 */ return; +/* */ } +/* 520 */ if (this._roomID == 0) { +/* 521 */ synchronized (this) { +/* 522 */ this._serverState = 2; +/* 523 */ serv.requestRoomID(this._longID, this); +/* 524 */ this._debug1 = +/* 525 */ ("[" + Std.getRealTime() + "] " + serv + ": requested roomID for " + this._longID); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 535 */ setRoomID(serv, this._roomID, this._longID, false); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void property(OldPropertyList propList) +/* */ { +/* 547 */ for (int i = 0; i < propList.size(); i++) { +/* 548 */ netProperty p = propList.elementAt(i); +/* */ +/* */ +/* */ +/* 552 */ byte[] data = p.value().getBytes(); +/* */ +/* 554 */ this._room.getSharer().setFromNetData(p.property(), data); +/* */ } +/* */ } +/* */ +/* */ public void propertyUpdate(PropertyList propList) { +/* 559 */ for (int i = 0; i < propList.size(); i++) { +/* 560 */ net2Property p = propList.elementAt(i); +/* 561 */ this._room.getSharer().setFromNetData(p.property(), p.data()); +/* */ } +/* */ } +/* */ +/* */ public WorldServer getServer() { +/* 566 */ return this._server; +/* */ } +/* */ +/* */ public void register() +/* */ { +/* 571 */ if ((_debugLevel & 0x2) > 0) { +/* 572 */ System.out.println(this._room.getName() + ": register()"); +/* */ } +/* */ +/* */ +/* 576 */ assert (this._room.getWorld() != null); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 583 */ Galaxy tmpGalaxy = this._room.getGalaxy(); +/* 584 */ assert (tmpGalaxy != null); +/* 585 */ tmpGalaxy.regObject(this._longID, this); +/* */ +/* */ +/* 588 */ this._galaxy = tmpGalaxy; +/* */ +/* */ +/* */ +/* 592 */ if (this._serverState != 0) { +/* 593 */ disconnect(); +/* */ } +/* */ +/* 596 */ this._serverURL = null; +/* */ +/* 598 */ if (this._wantsToBeSubscribed) { +/* 599 */ acquireServer(); +/* */ } +/* */ } +/* */ +/* */ public void galaxyDisconnected() +/* */ { +/* 605 */ if ((_debugLevel & 0x2) > 0) { +/* 606 */ System.out.println(this._room.getName() + ": galaxyDisconnected()"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 617 */ synchronized (this) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* 623 */ if (this._server != null) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* 629 */ reacquireServer(this._server); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void reacquireServer(WorldServer oldServ) +/* */ { +/* 642 */ if (this._debug1 == null) +/* 643 */ this._debug1 = ""; +/* 644 */ this._debug1 = +/* 645 */ (this._debug1 + "; [" + Std.getRealTime() + "]: reacquireServer(" + this._server + ", " + oldServ + ")"); +/* */ +/* */ +/* 648 */ if (this._server != oldServ) { +/* 649 */ return; +/* */ } +/* */ +/* 652 */ if ((_debugLevel & 0x2) > 0) { +/* 653 */ System.out.println(this._room.getName() + ": reacquireServer()"); +/* */ } +/* */ +/* 656 */ disconnect(); +/* 657 */ if (this._wantsToBeSubscribed) { +/* 658 */ acquireServer(); +/* */ } +/* */ } +/* */ +/* */ public synchronized void changeChannel(Galaxy tmpGalaxy, String oldChannel, String newChannel) +/* */ { +/* 664 */ if ((_debugLevel & 0x2) > 0) { +/* 665 */ System.out.println(this._room.getName() + ": changeChannel(" + +/* 666 */ oldChannel + " -> " + newChannel + ")"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 672 */ boolean wantsToBeSubscribed = this._wantsToBeSubscribed; +/* 673 */ RoomSubscribeInfo lastRSInfo = this._lastRSInfo; +/* 674 */ if (wantsToBeSubscribed) { +/* 675 */ unsubscribe(); +/* */ } +/* */ +/* */ +/* */ +/* 680 */ tmpGalaxy.delObject(this._longID); +/* */ +/* */ +/* 683 */ initNames(); +/* */ +/* 685 */ register(); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 693 */ if (wantsToBeSubscribed) { +/* 694 */ subscribe(lastRSInfo); +/* */ } +/* */ } +/* */ +/* */ public String toString() { +/* 699 */ return "NetworkRoom[" + this._room.getName() + "]"; +/* */ } +/* */ +/* */ public String debugStuff() { +/* 703 */ return this + ": debug1 = " + this._debug1 + "\n\tdebug2 = " + this._debug2; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\NetworkRoom.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |