summaryrefslogtreecommitdiff
path: root/NET/worlds/core/Std.java
blob: 7ee2b6f7a37f74703e01bd4fc98718d7d22085e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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();
}