diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/network/RoomMgr.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/network/RoomMgr.java')
| -rw-r--r-- | NET/worlds/network/RoomMgr.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/NET/worlds/network/RoomMgr.java b/NET/worlds/network/RoomMgr.java new file mode 100644 index 0000000..24d366f --- /dev/null +++ b/NET/worlds/network/RoomMgr.java @@ -0,0 +1,82 @@ +package NET.worlds.network; + +import NET.worlds.core.Std; +import java.util.Enumeration; +import java.util.Hashtable; + +class RoomMgr { + Hashtable<Integer, NetworkRoom> _roomFRoomID = new Hashtable<Integer, NetworkRoom>(); + Hashtable<String, NetworkRoom> _requestList = null; + int _requestCount = 0; + + public RoomMgr() { + } + + public synchronized void addRequest(String roomName, NetworkRoom room) { + if (this._requestCount == 0) { + this._requestList = new Hashtable<String, NetworkRoom>(); + } + + assert this._requestList.get(roomName) == null; + + this._requestList.put(roomName, room); + this._requestCount++; + } + + public synchronized void delRequest(String roomName) { + if (this._requestList == null) { + System.out.println(this + ": delRequest() - " + roomName); + new Exception().printStackTrace(System.out); + } else { + this._requestCount--; + this._requestList.remove(roomName); + if (this._requestCount == 0) { + this._requestList = null; + } + } + } + + public synchronized NetworkRoom getRequest(String roomName) { + if (this._requestList == null) { + return null; + } else { + NetworkRoom tmpRoom = this._requestList.get(roomName); + if (tmpRoom != null) { + this.delRequest(roomName); + } + + return tmpRoom; + } + } + + public void regRoomID(int roomID, NetworkRoom room) { + NetworkRoom noRoom = this._roomFRoomID.get(new Integer(roomID)); + if (noRoom != null && noRoom != room) { + System.out.println("[" + Std.getRealTime() + "]: Weird - room is already registered."); + System.out.println("new roomID = " + roomID + ", new room = " + room); + System.out.println(room.debugStuff()); + System.out.println("old room is " + noRoom); + System.out.println(noRoom.debugStuff()); + new Exception().printStackTrace(System.out); + } + + this._roomFRoomID.put(new Integer(roomID), room); + } + + public void delRoomID(int roomID, NetworkRoom delRoom) { + NetworkRoom room = this._roomFRoomID.remove(new Integer(roomID)); + if (room == null) { + System.out.println("Error - deleting a bad roomID: " + roomID); + System.out.println(delRoom.debugStuff()); + new Exception().printStackTrace(System.out); + } + } + + public NetworkRoom getRoom(int roomID) { + return roomID == 0 ? null : this._roomFRoomID.get(new Integer(roomID)); + } + + public Enumeration<NetworkRoom> rooms() { + return this._roomFRoomID.elements(); + } +} |