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 _tsEntries = new Hashtable(); 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; } }