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/DirTimeStamp.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/network/DirTimeStamp.java')
| -rw-r--r-- | NET/worlds/network/DirTimeStamp.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/NET/worlds/network/DirTimeStamp.java b/NET/worlds/network/DirTimeStamp.java new file mode 100644 index 0000000..235a4b4 --- /dev/null +++ b/NET/worlds/network/DirTimeStamp.java @@ -0,0 +1,102 @@ +package NET.worlds.network; + +import NET.worlds.core.IniFile; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URLConnection; +import java.util.Hashtable; + +public class DirTimeStamp { + private static Hashtable<URL, DirTimeStamp> _tsEntries = new Hashtable<URL, DirTimeStamp>(); + private URL _name; + private long _mtime; + private boolean _loaded = false; + + private DirTimeStamp(URL url) { + this._name = url; + + assert url.isRemote(); + } + + private static synchronized DirTimeStamp lookup(URL url) { + DirTimeStamp t = _tsEntries.get(url); + if (t == null) { + t = new DirTimeStamp(url); + _tsEntries.put(url, t); + } + + return t; + } + + private void getMTime() { + this._mtime = 0L; + + try { + int r = (int)(Math.random() * 1000000.0); + int retryCount = IniFile.gamma().getIniInt("NetCacheRetries", 1); + boolean offline = CacheEntry.getOffline(); + if (offline) { + this._loaded = true; + return; + } + + if (offline) { + retryCount = 1; + } + + java.net.URL u = DNSLookup.lookup(new java.net.URL(this._name.unalias() + "?" + r)); + + while (true) { + try { + URLConnection uc = u.openConnection(); + this._mtime = uc.getLastModified(); + break; + } catch (IOException var7) { + if (--retryCount <= 0 || var7 instanceof FileNotFoundException) { + throw var7; + } + + System.out.println("Exception " + var7 + " querying " + this._name + ", retrying..."); + } + } + + this._loaded = true; + } catch (FileNotFoundException var8) { + System.out.println("Warning: timestamp " + this._name + " not found."); + this._loaded = true; + } catch (Exception var9) { + System.out.println("Timestamp query error: " + var9 + " accessing " + this._name); + this._loaded = true; + } + } + + public static long request(URL url) { + URL tsURL = URL.make(url, "timestamp.dir"); + String u = url.getInternal(); + int i = u.lastIndexOf(47); + if (i > 0) { + int j = u.lastIndexOf(47, i - 1) + 1; + if (j > 11) { + String par = u.substring(j, i); + if (url.endsWith("upgrades.lst")) { + if (!par.equals("gdkup") && !par.equals("newup") && !par.equals("3DCDup")) { + tsURL = URL.make(u.substring(0, j) + "timestamp.upgrades"); + } else { + tsURL = URL.make(url, "timestamp.upgrades"); + } + } else if (par.equals("cgi-bin")) { + return 0L; + } + } + } + + DirTimeStamp t = lookup(tsURL); + synchronized (t) { + if (!t._loaded) { + t.getMTime(); + } + } + + return t._mtime; + } +} |