package NET.worlds.core; import java.io.File; import java.io.InputStream; import java.net.InetAddress; import java.net.Socket; import java.util.Date; public class Std { private static String productName; private static int lastTime; static boolean syncTimeInited = false; static int syncTimeBase; static boolean offline = IniFile.override().getIniInt("Offline", 0) == 1; static boolean stopOnFault = IniFile.gamma().getIniInt("StopOnHttpFault", 0) == 1; static String timeServer = IniFile.override().getIniString("timeServer", "time.worlds.net"); public static void assertFail(String file, int line) { String msg = "Assertion failed: file " + file + ", line " + line; dumpStackTrace(); exit(); } public static String replaceStr(String in, String seek, String replace) { if (seek != null && replace != null) { int idx; while ((idx = in.indexOf(seek)) != -1) { String tmp = in.substring(0, idx) + replace + in.substring(idx + seek.length()); in = tmp; } return in; } else { return in; } } public static native void exit(); public static void dumpStackTrace() { try { throw new Error(""); } catch (Error var1) { var1.printStackTrace(System.out); } } public static String getProductName() { assert productName != null; return productName; } public static void initProductName() { assert productName == null; productName = IniFile.gamma().getIniString("PRODUCT_NAME", "Worlds.com - The 3D Entertainment Portal"); productName = IniFile.override().getIniString("productName", productName); } private static native int nativeGetMillis(); private static synchronized int getMillis() { return nativeGetMillis(); } public static native int getTimeZero(); public static native long getPerformanceFrequency(); public static native long getPerformanceCount(); public static boolean sleep(float seconds) { try { Thread.sleep((long)(seconds * 1000.0F)); return false; } catch (InterruptedException var2) { return true; } } public static int getFastTime() { if (lastTime == 0) { getRealTime(); } return lastTime; } public static int getRealTime() { lastTime = getMillis(); return lastTime; } public static int getSynchronizedTime() { initSyncTime(); return getFastTime() / 1000 + syncTimeBase; } static void initSyncTime() { if (!offline && !stopOnFault) { if (!syncTimeInited) { syncTimeInited = true; try { InetAddress ip = InetAddress.getByName(timeServer); Socket s = new Socket(ip, 37); InputStream is = s.getInputStream(); int b1 = is.read(); int b2 = is.read(); int b3 = is.read(); int b4 = is.read(); is.close(); long time = (b1 << 24) + (b2 << 16) + (b3 << 8) + b4; time -= -1141367296L; syncTimeBase = (int)time - getFastTime() / 1000; s.close(); } catch (Exception var9) { System.out.println("Error retrieving network time: " + var9); } } } else { syncTimeInited = true; syncTimeBase = 0; } } public static native boolean instanceOf(Object var0, Class var1); public static native String getenv(String var0); public static long GetDiskFreeSpace(String drive) { long value = -1L; try { if (drive == null) { drive = "."; } File f = new File(drive); value = f.getFreeSpace() / 1024L; } catch (Exception var4) { value = -1L; } return value; } public static long GetDiskFreeSpace() { return GetDiskFreeSpace(null); } public static void printThreads() { ThreadGroup tg = Thread.currentThread().getThreadGroup(); Thread[] ta = new Thread[100]; int n = tg.enumerate(ta); tg.list(); for (int i = 0; i < n; i++) { if (ta[i].isDaemon()) { System.out.println("is daemon"); } else { System.out.println("isn't daemon"); } } } public static void printlnOut(String msg) { System.out.println(msg); } public static native boolean byteArraysEqual(byte[] var0, byte[] var1); public static native String getBuildInfo(); public static native int getVersion(); public static native String getClientVersion(); private static native int getBuildYear(); private static native int getBuildMonth(); private static native int getBuildDay(); public static long getBuildDate() { return Date.UTC(getBuildYear(), getBuildMonth(), getBuildDay(), 0, 0, 0); } public static native int checkNativeHeap(); }