From e1e781bb2135ef78592226f1a3eaba4925702f1f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 3 May 2021 16:38:41 -0700 Subject: :star: --- NET/worlds/network/ServerTracker.java | 328 ++++++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 NET/worlds/network/ServerTracker.java (limited to 'NET/worlds/network/ServerTracker.java') diff --git a/NET/worlds/network/ServerTracker.java b/NET/worlds/network/ServerTracker.java new file mode 100644 index 0000000..7f7e36e --- /dev/null +++ b/NET/worlds/network/ServerTracker.java @@ -0,0 +1,328 @@ +/* */ package NET.worlds.network; +/* */ +/* */ import java.io.PrintStream; +/* */ import java.util.Enumeration; +/* */ import java.util.Hashtable; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ class ServerTracker +/* */ { +/* 33 */ private Hashtable _serverHash = new Hashtable(); +/* */ +/* */ +/* 36 */ private Vector _pendingOpenServers = new Vector(); +/* */ +/* */ +/* 39 */ private Vector _activeServers = new Vector(); +/* */ +/* */ +/* 42 */ private Vector _pendingCloseServers = new Vector(); +/* */ +/* */ private Galaxy _galaxy; +/* */ +/* */ private ServerURL _serverURL; +/* */ +/* */ +/* */ protected ServerTracker(Galaxy parent) +/* */ { +/* 51 */ this._galaxy = parent; +/* 52 */ this._serverURL = this._galaxy.getServerURL(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized WorldServer getServer(String StrServerURL) +/* */ throws InvalidServerURLException +/* */ { +/* 68 */ if ((Galaxy.getDebugLevel() & 0x20) > 0) { +/* 69 */ System.out.println("Galaxy.getServer(" + StrServerURL + +/* 70 */ ") from " + this._galaxy); +/* */ } +/* */ +/* 73 */ ServerURL serverURL = new ServerURL(StrServerURL); +/* 74 */ WorldServer ws = null; +/* 75 */ if (this._serverURL.getHost().equals(serverURL.getHost())) +/* */ { +/* 77 */ ws = getServer(this._activeServers, this); +/* 78 */ if (ws == null) +/* 79 */ ws = getServer(this._pendingOpenServers, this); +/* */ } +/* 81 */ if (ws == null) +/* */ { +/* */ +/* 84 */ ws = findOrMake(serverURL, this); +/* */ } +/* */ +/* */ +/* 88 */ ws.tmpRefCnt(this); +/* 89 */ return ws; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected WorldServer getActive(Object referrer) +/* */ { +/* 98 */ return getServer(this._activeServers, referrer); +/* */ } +/* */ +/* */ protected synchronized WorldServer getServer(Vector list, Object referrer) { +/* 102 */ int lastServer = list.size() - 1; +/* 103 */ if (lastServer >= 0) { +/* 104 */ WorldServer ws = (WorldServer)list.elementAt(lastServer); +/* 105 */ ws.incRefCnt(referrer); +/* 106 */ return ws; +/* */ } +/* 108 */ return null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private synchronized WorldServer findOrMake(ServerURL serverURL, Object referrer) +/* */ throws InvalidServerURLException +/* */ { +/* 122 */ WorldServer ws = (WorldServer)this._serverHash.get(serverURL.getHost()); +/* 123 */ if (ws == null) { +/* 124 */ int _debugLevel = 0; +/* */ +/* 126 */ _debugLevel = Galaxy.getDebugLevel(); +/* 127 */ if ((_debugLevel & 0x20) > 0) { +/* 128 */ System.out.println(" Creating new server of type=" + +/* 129 */ serverURL.getType() + "."); +/* */ } +/* */ try { +/* 132 */ Class wsClass = Class.forName("NET.worlds.network." + +/* 133 */ serverURL.getType()); +/* 134 */ ws = (WorldServer)wsClass.newInstance(); +/* */ } +/* */ catch (Exception e) { +/* 137 */ if ((_debugLevel & 0x20) > 0) { +/* 138 */ synchronized (System.out) +/* */ { +/* 140 */ System.out.println(" Exception during class creation."); +/* 141 */ e.printStackTrace(System.out); +/* */ } +/* */ } +/* */ +/* 145 */ throw new InvalidServerURLException("Bad class: " + +/* 146 */ serverURL.getType()); +/* */ } +/* 148 */ this._serverHash.put(serverURL.getHost(), ws); +/* 149 */ ws.initInstance(this._galaxy, serverURL); +/* */ +/* */ } +/* 152 */ else if ((Galaxy.getDebugLevel() & 0x20) > 0) { +/* 153 */ System.out.println(" Found old server."); +/* */ } +/* */ +/* 156 */ ws.incRefCnt(referrer); +/* 157 */ return ws; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected synchronized void swapServer(WorldServer oldServ, WorldServer newServ) +/* */ { +/* 170 */ String oldURL = oldServ.getServerURL().getHost(); +/* 171 */ assert (oldURL.equals(newServ.getServerURL().getHost())); +/* */ +/* 173 */ String servName = oldServ.getServerURL().getHost(); +/* 174 */ this._serverHash.put(servName, newServ); +/* */ +/* */ +/* */ +/* */ +/* */ +/* 180 */ assert (!this._activeServers.contains(oldServ)); +/* */ } +/* */ +/* */ +/* */ protected synchronized boolean isActive() +/* */ { +/* 186 */ return (this._activeServers.size() > 0) || (this._pendingOpenServers.size() > 0) || ( +/* 187 */ this._pendingCloseServers.size() > 0); +/* */ } +/* */ +/* */ protected synchronized boolean addPendingServer(WorldServer ws) +/* */ { +/* 192 */ if ((Galaxy.getDebugLevel() & 0x8) > 0) { +/* 193 */ System.out.println(this._galaxy + ": addPendingServer(" + ws + ")"); +/* 194 */ System.out.println("\t_pendingOpen = " + this._pendingOpenServers); +/* 195 */ System.out.println("\t_activeServers = " + this._activeServers); +/* 196 */ System.out.println("\t_pendingClose = " + this._pendingCloseServers); +/* */ } +/* */ +/* 199 */ if (this._pendingOpenServers.indexOf(ws) < 0) { +/* 200 */ this._pendingOpenServers.addElement(ws); +/* */ } +/* 202 */ if ((this._pendingOpenServers.size() == 1) && (this._activeServers.size() == 0) && +/* 203 */ (this._pendingCloseServers.size() == 0)) { +/* 204 */ return true; +/* */ } +/* 206 */ return false; +/* */ } +/* */ +/* */ protected synchronized boolean addActiveServer(WorldServer ws) +/* */ { +/* 211 */ if ((Galaxy.getDebugLevel() & 0x8) > 0) { +/* 212 */ System.out.println(this._galaxy + ": addActiveServer(" + ws + ")"); +/* 213 */ System.out.println("\t_pendingOpen = " + this._pendingOpenServers); +/* 214 */ System.out.println("\t_activeServers = " + this._activeServers); +/* 215 */ System.out.println("\t_pendingClose = " + this._pendingCloseServers); +/* */ } +/* */ +/* */ +/* 219 */ this._pendingOpenServers.removeElement(ws); +/* 220 */ if (this._activeServers.indexOf(ws) < 0) { +/* 221 */ this._activeServers.addElement(ws); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 227 */ return (this._activeServers.size() == 1) && +/* 228 */ (this._pendingCloseServers.size() == 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected synchronized boolean addClosingServer(WorldServer ws) +/* */ { +/* 239 */ if ((Galaxy.getDebugLevel() & 0x8) > 0) { +/* 240 */ System.out.println(this._galaxy + ": addClosingServer(" + ws + ")"); +/* 241 */ System.out.println("\t_pendingOpen = " + this._pendingOpenServers); +/* 242 */ System.out.println("\t_activeServers = " + this._activeServers); +/* 243 */ System.out.println("\t_pendingClose = " + this._pendingCloseServers); +/* */ } +/* */ +/* */ +/* 247 */ this._pendingOpenServers.removeElement(ws); +/* 248 */ boolean wasActive = this._activeServers.removeElement(ws); +/* 249 */ if (this._pendingCloseServers.indexOf(ws) < 0) +/* 250 */ this._pendingCloseServers.addElement(ws); +/* 251 */ if ((wasActive) && (this._activeServers.size() == 0)) { +/* 252 */ return true; +/* */ } +/* 254 */ return false; +/* */ } +/* */ +/* */ protected synchronized void markClosedServer(WorldServer ws) +/* */ { +/* 259 */ if ((Galaxy.getDebugLevel() & 0x8) > 0) { +/* 260 */ System.out.println(this._galaxy + ": markClosedServer(" + ws + ")"); +/* 261 */ System.out.println("\t_pendingOpen = " + this._pendingOpenServers); +/* 262 */ System.out.println("\t_activeServers = " + this._activeServers); +/* 263 */ System.out.println("\t_pendingClose = " + this._pendingCloseServers); +/* */ } +/* */ +/* */ +/* 267 */ this._pendingOpenServers.removeElement(ws); +/* 268 */ this._pendingCloseServers.removeElement(ws); +/* 269 */ this._activeServers.removeElement(ws); +/* */ } +/* */ +/* */ +/* */ +/* */ protected synchronized void killServer(WorldServer ws) +/* */ { +/* 276 */ if ((Galaxy.getDebugLevel() & 0x8) > 0) { +/* 277 */ System.out.println(this._galaxy + ": killServer(" + ws + ")"); +/* 278 */ System.out.println("\t_pendingOpen = " + this._pendingOpenServers); +/* 279 */ System.out.println("\t_activeServers = " + this._activeServers); +/* 280 */ System.out.println("\t_pendingClose = " + this._pendingCloseServers); +/* */ } +/* */ +/* 283 */ this._pendingOpenServers.removeElement(ws); +/* 284 */ this._pendingCloseServers.removeElement(ws); +/* 285 */ this._activeServers.removeElement(ws); +/* 286 */ if (this._serverHash.get(ws.getServerURL().getHost()) == ws) +/* */ { +/* */ +/* */ +/* */ +/* */ +/* 292 */ this._serverHash.remove(ws.getServerURL().getHost()); +/* */ +/* */ +/* */ } +/* */ else +/* */ { +/* */ +/* */ +/* 300 */ System.out.println("DEBUG -- a server tried to murder another!"); +/* 301 */ System.out.println("Caller = " + ws); +/* 302 */ System.out.println("Victim = " + +/* 303 */ this._serverHash.get(ws.getServerURL().getHost())); +/* 304 */ new Exception().printStackTrace(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ protected Enumeration getAllServers() +/* */ { +/* 313 */ return this._serverHash.elements(); +/* */ } +/* */ +/* */ public String toString() +/* */ { +/* 318 */ return +/* */ +/* 320 */ "ServerTracker[\n\t_pendingOpen = " + this._pendingOpenServers + "\n\t_activeServers = " + this._activeServers + "\n\t_pendingClose = " + this._pendingCloseServers + "\n]"; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\ServerTracker.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */ \ No newline at end of file -- cgit v1.2.3