diff options
Diffstat (limited to 'NET/worlds/core')
| -rw-r--r-- | NET/worlds/core/Archive.java | 224 | ||||
| -rw-r--r-- | NET/worlds/core/ArchiveMaker.java | 376 | ||||
| -rw-r--r-- | NET/worlds/core/AssertionException.java | 12 | ||||
| -rw-r--r-- | NET/worlds/core/Debug.java | 13 | ||||
| -rw-r--r-- | NET/worlds/core/FastDataInput.java | 70 | ||||
| -rw-r--r-- | NET/worlds/core/Hashtable.java | 105 | ||||
| -rw-r--r-- | NET/worlds/core/IniFile.java | 55 | ||||
| -rw-r--r-- | NET/worlds/core/Recycler.java | 19 | ||||
| -rw-r--r-- | NET/worlds/core/RegKey.java | 50 | ||||
| -rw-r--r-- | NET/worlds/core/RegKeyNotFoundException.java | 12 | ||||
| -rw-r--r-- | NET/worlds/core/ServerTableManager.java | 278 | ||||
| -rw-r--r-- | NET/worlds/core/Sort.java | 91 | ||||
| -rw-r--r-- | NET/worlds/core/Std.java | 191 | ||||
| -rw-r--r-- | NET/worlds/core/Std_A.java | 4 | ||||
| -rw-r--r-- | NET/worlds/core/Std_B.java | 4 | ||||
| -rw-r--r-- | NET/worlds/core/Std_IA.java | 4 | ||||
| -rw-r--r-- | NET/worlds/core/Std_IB.java | 4 | ||||
| -rw-r--r-- | NET/worlds/core/SystemInfo.java | 114 | ||||
| -rw-r--r-- | NET/worlds/core/TestInstanceOf.java | 45 | ||||
| -rw-r--r-- | NET/worlds/core/Timer.java | 21 | ||||
| -rw-r--r-- | NET/worlds/core/TimerCallback.java | 5 |
21 files changed, 1697 insertions, 0 deletions
diff --git a/NET/worlds/core/Archive.java b/NET/worlds/core/Archive.java new file mode 100644 index 0000000..e5e32d0 --- /dev/null +++ b/NET/worlds/core/Archive.java @@ -0,0 +1,224 @@ +package NET.worlds.core; + +import NET.worlds.network.URL; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public class Archive { + public static final String archiveName = "content.zip"; + private static Object mutex = new Object(); + private static Object noArchive = new Object(); + private static java.util.Hashtable<String, Object> archives = new java.util.Hashtable<String, Object>(); + private static String homePrefix = URL.getHome().unalias(); + private ZipFile zip; + + public static boolean exists(String name) { + synchronized (mutex) { + String nname = name.toLowerCase().replace('\\', '/'); + if (nname.startsWith("./")) { + nname = homePrefix + nname.substring(2); + } + + if (nname.startsWith(homePrefix)) { + nname = nname.substring(homePrefix.length()); + Archive arch = getOrMake(""); + if (arch != null && arch.lookup(nname) != null) { + return true; + } + + int start = -1; + + int end; + while ((end = nname.indexOf(47, start + 1)) != -1) { + String path = nname.substring(0, end + 1); + arch = getOrMake(path); + if (arch != null) { + String file = nname.substring(end + 1); + if (arch.lookup(file) != null) { + return true; + } + } + + start = end; + } + } + + File f = new File(name); + int length = (int)f.length(); + return length != 0; + } + } + + private static void reallyRead(InputStream s, byte[] data) throws IOException { + int bytesRemaining = data.length; + int totalBytesRead = 0; + + while (bytesRemaining > 0) { + int bytesRead = s.read(data, totalBytesRead, bytesRemaining); + totalBytesRead += bytesRead; + if (bytesRead == -1) { + return; + } + + bytesRemaining -= bytesRead; + } + } + + public static byte[] readBinaryFile(String name) { + synchronized (mutex) { + try { + String nname = name.toLowerCase().replace('\\', '/'); + if (nname.startsWith("./")) { + nname = homePrefix + nname.substring(2); + } + + if (nname.startsWith(homePrefix)) { + nname = nname.substring(homePrefix.length()); + Archive arch = getOrMake(""); + ZipEntry entry; + if (arch != null && (entry = arch.lookup(nname)) != null) { + return arch.load(entry); + } + + int start = -1; + + int end; + while ((end = nname.indexOf(47, start + 1)) != -1) { + String path = nname.substring(0, end + 1); + arch = getOrMake(path); + if (arch != null) { + String file = nname.substring(end + 1); + if ((entry = arch.lookup(file)) != null) { + return arch.load(entry); + } + } + + start = end; + } + } + + File f = new File(name); + int length = (int)f.length(); + if (length != 0) { + FileInputStream fis = new FileInputStream(f); + byte[] data = new byte[length]; + reallyRead(fis, data); + fis.close(); + return data; + } + } catch (IOException var9) { + } + + return null; + } + } + + public static byte[] readTextFile(String name) { + byte[] data = readBinaryFile(name); + if (data != null) { + int count = 0; + + for (int i = 0; i < data.length; i++) { + if (data[i] == 13 && data[i + 1] == 10) { + i++; + count++; + } + } + + byte[] ret = new byte[data.length - count]; + int j = 0; + + for (int ix = 0; ix < data.length; ix++) { + if (data[ix] != 13 || data[ix + 1] != 10) { + ret[j++] = data[ix]; + } + } + + data = ret; + } + + return data; + } + + public static void flushAll() { + synchronized (mutex) { + Enumeration<Object> e = archives.elements(); + + while (e.hasMoreElements()) { + Object o = e.nextElement(); + if (o instanceof Archive) { + ((Archive)o).close(); + } + } + + archives.clear(); + } + } + + private static Archive getOrMake(String relPath) { + String archName = relPath + "content.zip"; + Object obj = archives.get(archName); + if (obj == null) { + try { + Archive arch = new Archive(archName); + archives.put(archName, arch); + return arch; + } catch (IOException var4) { + archives.put(archName, noArchive); + } + } else if (obj != noArchive) { + return (Archive)obj; + } + + return null; + } + + private Archive(String path) throws IOException { + this.zip = new ZipFile(homePrefix + path); + } + + private void close() { + try { + this.zip.close(); + } catch (IOException var2) { + } + } + + private ZipEntry lookup(String name) { + return this.zip.getEntry(name); + } + + private byte[] load(ZipEntry ent) throws IOException { + return load(this.zip, ent); + } + + static byte[] load(ZipFile zip, ZipEntry ent) throws IOException { + int size = (int)ent.getSize(); + byte[] data = new byte[size]; + InputStream is = zip.getInputStream(ent); + if (ent.getMethod() == 0) { + reallyRead(is, data); + } else { + BufferedInputStream bis = new BufferedInputStream(is, 4096); + int amt = 0; + + while (amt < size) { + amt += bis.read(data, amt, size - amt); + } + + bis.close(); + } + + return data; + } + + static Object getMutex() { + return mutex; + } +} diff --git a/NET/worlds/core/ArchiveMaker.java b/NET/worlds/core/ArchiveMaker.java new file mode 100644 index 0000000..5e025fb --- /dev/null +++ b/NET/worlds/core/ArchiveMaker.java @@ -0,0 +1,376 @@ +package NET.worlds.core; + +import NET.worlds.console.Console; +import NET.worlds.console.PolledDialog; +import NET.worlds.network.ProgressBar; +import NET.worlds.network.URL; +import NET.worlds.scape.FileList; +import NET.worlds.scape.Pilot; +import NET.worlds.scape.World; +import java.awt.Button; +import java.awt.Event; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Label; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Enumeration; +import java.util.Vector; +import java.util.zip.CRC32; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + +public class ArchiveMaker extends PolledDialog { + private static final long serialVersionUID = -7620030251122522576L; + private static final String extensions = "cmp;mov"; + private URL sourceURL; + private String path; + private Label status = new Label("", 0); + private Button goButton; + private Button closeButton = new Button(Console.message("Close")); + private ProgressBar progress = new ProgressBar(1); + private boolean start; + private boolean stop; + private boolean finished; + private boolean condense; + + public ArchiveMaker(boolean condense) { + super(Console.getFrame(), null, condense ? Console.message("Condense-Files") : Console.message("Expand-Files"), true); + this.condense = condense; + this.ready(); + } + + @Override + protected void build() { + String errStatus = null; + Pilot pilot = Pilot.getActive(); + if (pilot != null) { + World world = pilot.getWorld(); + if (world != null) { + this.sourceURL = world.getSourceURL(); + this.path = this.sourceURL.unalias(); + this.path = this.path.substring(0, this.path.lastIndexOf(47)); + String home = URL.getHome().unalias(); + if (this.path.startsWith(home)) { + File f = new File(URL.make(this.sourceURL, "content.zip").unalias()); + if (this.condense) { + if (f.exists()) { + errStatus = Console.message("Must-expand"); + } + } else if (!f.exists()) { + errStatus = Console.message("Must-condense"); + } + } else { + errStatus = Console.message("Not-a-home"); + } + } else { + errStatus = Console.message("Cant-access-world"); + } + } else { + errStatus = Console.message("Cant-access-pilot"); + } + + GridBagLayout gbag = new GridBagLayout(); + this.setLayout(gbag); + GridBagConstraints c = new GridBagConstraints(); + c.weightx = 0.0; + c.gridwidth = 1; + this.add(gbag, new Label(Console.message("Status"), 2), c); + c.weightx = 1.0; + c.gridwidth = 0; + c.fill = 2; + this.add(gbag, this.status, c); + c.fill = 0; + c.weightx = 0.0; + c.gridwidth = 0; + this.goButton = new Button(this.condense ? Console.message("Condense") : Console.message("Expand")); + this.add(gbag, this.goButton, c); + c.weightx = 1.0; + c.fill = 2; + Insets tmp = c.insets; + c.insets = new Insets(5, 5, 5, 5); + this.add(gbag, this.progress, c); + c.insets = tmp; + c.fill = 0; + c.weightx = 0.0; + this.add(gbag, this.closeButton, c); + if (errStatus != null) { + this.status.setText(errStatus); + this.goButton.setEnabled(false); + } else { + String name = this.sourceURL.getAbsolute(); + name = name.substring(0, name.lastIndexOf(47)); + Object[] arguments = new Object[]{new String(name)}; + if (this.condense) { + this.status.setText(MessageFormat.format(Console.message("condense-name"), arguments)); + } else { + this.status.setText(MessageFormat.format(Console.message("expand-name"), arguments)); + } + } + } + + @Override + public boolean action(Event event, Object what) { + Object target = event.target; + if (target == this.goButton) { + if (!this.start) { + this.start = true; + } else { + this.stop = true; + } + } else { + if (target != this.closeButton) { + return false; + } + + if (!this.start || this.finished) { + this.done(true); + } + } + + return true; + } + + @Override + protected void activeCallback() { + if (this.start && !this.finished) { + this.goButton.setLabel(Console.message("Stop")); + if (this.condense) { + this.doCondense(); + } else { + this.doExpand(); + } + } + } + + private void doCondense() { + this.status.setText(Console.message("Scanning-dir")); + Vector<String> dirs = new Vector<String>(); + getDirectories(dirs, this.path); + if (this.stop) { + this.cancelled(); + } else { + String d = ""; + int count = dirs.size(); + + for (int i = 0; i < count; i++) { + if (d.length() != 0) { + d = d + ";"; + } + + d = d + dirs.elementAt(i); + } + + Vector<String> files = new FileList(d, "cmp;mov").keepPathInfo().dontSort().getList(); + count = files.size(); + String[] list = new String[count]; + int start = this.path.length() + 1; + + for (int i = 0; i < count; i++) { + list[i] = files.elementAt(i).substring(start).replace('\\', '/').toLowerCase(); + } + + this.status.setText(Console.message("Sorting-files")); + Sort.sort(list); + if (this.stop) { + this.cancelled(); + } else { + this.status.setText(Console.message("Building-archive")); + String zipFileName = this.path + "/" + "content.zip"; + boolean deleteOnError = true; + + try { + FileOutputStream fos = new FileOutputStream(zipFileName); + ZipOutputStream zs = new ZipOutputStream(fos); + zs.setMethod(0); + double dlen = list.length; + + for (int i = 0; i < list.length && !this.stop; i++) { + Object[] arguments = new Object[]{new String(list[i])}; + this.status.setText(MessageFormat.format(Console.message("Reading-list"), arguments)); + File f = new File(this.path + "/" + list[i]); + int length = (int)f.length(); + byte[] data = new byte[length]; + FileInputStream fis = new FileInputStream(f); + fis.read(data); + fis.close(); + CRC32 crc = new CRC32(); + crc.update(data); + this.status.setText(MessageFormat.format(Console.message("Writing-list"), arguments)); + ZipEntry ze = new ZipEntry(list[i]); + ze.setSize(length); + ze.setTime(f.lastModified()); + ze.setCrc(crc.getValue()); + zs.putNextEntry(ze); + zs.write(data, 0, length); + zs.closeEntry(); + this.progress.setProgress((i + 1) / dlen); + } + + zs.finish(); + zs.close(); + if (!this.stop) { + deleteOnError = false; + this.goButton.setEnabled(false); + Archive.flushAll(); + + for (int i = 0; i < list.length; i++) { + Object[] arguments = new Object[]{new String(list[i])}; + this.status.setText(MessageFormat.format(Console.message("Deleting-list"), arguments)); + File f = new File(this.path + "/" + list[i]); + f.delete(); + this.progress.setProgress((i + 1) / dlen); + } + + this.status.setText(Console.message("Removing-empty")); + count = dirs.size(); + + for (int i = 0; i < count; i++) { + File f = new File(dirs.elementAt(i)); + if (f.list().length == 0) { + f.delete(); + } + } + + this.status.setText(Console.message("Done")); + this.finished = true; + return; + } + } catch (IOException var21) { + Object[] arguments = new Object[]{new String(this.status.getText())}; + this.status.setText(MessageFormat.format(Console.message("IO-Error"), arguments)); + } + + if (deleteOnError) { + File f = new File(zipFileName); + f.delete(); + } + + this.finished = true; + if (this.stop) { + this.cancelled(); + } + } + } + } + + private void doExpand() { + this.status.setText(Console.message("Scanning-archive")); + boolean deleteOnError = true; + Vector<File> written = new Vector<File>(); + + try { + String zipFileName = this.path + "/" + "content.zip"; + ZipFile zip = new ZipFile(zipFileName); + Enumeration<? extends ZipEntry> ents = zip.entries(); + int count = 0; + + while (ents.hasMoreElements() && !this.stop) { + count++; + ents.nextElement(); + } + + String lastDir = ""; + ents = zip.entries(); + int i = 0; + double dlen = count; + + while (ents.hasMoreElements() && !this.stop) { + ZipEntry ent = ents.nextElement(); + String name = ent.getName(); + Object[] arguments = new Object[]{new String(name)}; + this.status.setText(MessageFormat.format(Console.message("Checking-name"), arguments)); + String filePath = this.path + "/" + name; + File f = new File(filePath); + if (f.exists()) { + this.stop = true; + this.finished = true; + this.status.setText(MessageFormat.format(Console.message("File-exists"), arguments)); + break; + } + + int index = filePath.lastIndexOf(47); + if (index != -1) { + String dir = filePath.substring(0, index); + if (!dir.equals(lastDir)) { + this.status.setText(Console.message("Creating-dir")); + File dirs = new File(dir); + dirs.mkdirs(); + lastDir = dir; + } + } + + this.status.setText(MessageFormat.format(Console.message("Reading-list"), arguments)); + byte[] data = Archive.load(zip, ent); + this.status.setText(MessageFormat.format(Console.message("Writing-list"), arguments)); + FileOutputStream fos = new FileOutputStream(f); + written.addElement(f); + fos.write(data); + fos.close(); + i++; + this.progress.setProgress(i / dlen); + } + + zip.close(); + if (!this.stop) { + this.goButton.setEnabled(false); + deleteOnError = false; + synchronized (Archive.getMutex()) { + Archive.flushAll(); + new File(zipFileName).delete(); + } + + this.status.setText(Console.message("Done")); + this.finished = true; + return; + } + } catch (IOException var20) { + Object[] argumentsx = new Object[]{new String(this.status.getText())}; + this.status.setText(MessageFormat.format(Console.message("IO-Error"), argumentsx)); + } + + if (deleteOnError) { + Enumeration<File> e = written.elements(); + + while (e.hasMoreElements()) { + e.nextElement().delete(); + } + } + + if (!this.finished) { + this.finished = true; + if (this.stop) { + this.cancelled(); + } + } + } + + private void cancelled() { + this.finished = true; + this.status.setText(Console.message("Cancelled")); + } + + @Override + protected boolean done(boolean confirmed) { + return this.start && !this.finished ? true : super.done(confirmed); + } + + private static void getDirectories(Vector<String> dirs, String path) { + dirs.addElement(path); + File dir = new File(path); + String[] files = dir.list(); + + for (int i = 0; i < files.length; i++) { + String name = path + '/' + files[i]; + File f = new File(name); + if (f.isDirectory()) { + getDirectories(dirs, name); + } + } + } +} diff --git a/NET/worlds/core/AssertionException.java b/NET/worlds/core/AssertionException.java new file mode 100644 index 0000000..393fed4 --- /dev/null +++ b/NET/worlds/core/AssertionException.java @@ -0,0 +1,12 @@ +package NET.worlds.core; + +public class AssertionException extends RuntimeException { + private static final long serialVersionUID = -5738682100298167153L; + + public AssertionException() { + } + + public AssertionException(String str) { + super(str); + } +} diff --git a/NET/worlds/core/Debug.java b/NET/worlds/core/Debug.java new file mode 100644 index 0000000..9221c1d --- /dev/null +++ b/NET/worlds/core/Debug.java @@ -0,0 +1,13 @@ +package NET.worlds.core; + +public class Debug { + public static final boolean ON = true; + public static final boolean TRACEON = false; + + public static void LogDebug() { + LogDebug(""); + } + + public static synchronized void LogDebug(String string) { + } +} diff --git a/NET/worlds/core/FastDataInput.java b/NET/worlds/core/FastDataInput.java new file mode 100644 index 0000000..75a71e7 --- /dev/null +++ b/NET/worlds/core/FastDataInput.java @@ -0,0 +1,70 @@ +package NET.worlds.core; + +import java.io.DataInput; +import java.io.IOException; + +public class FastDataInput implements DataInput { + private int nativeInfo; + + public FastDataInput(String fileName) throws IOException { + nativeInit(); + this.read(fileName); + } + + public native void close(); + + @Override + public void readFully(byte[] b) throws IOException { + this.readFully(b, 0, b.length); + } + + public static native void nativeInit(); + + @Override + public native void readFully(byte[] var1, int var2, int var3) throws IOException; + + @Override + public native int skipBytes(int var1) throws IOException; + + @Override + public native boolean readBoolean() throws IOException; + + @Override + public native byte readByte() throws IOException; + + @Override + public native int readUnsignedByte() throws IOException; + + @Override + public native short readShort() throws IOException; + + @Override + public native int readUnsignedShort() throws IOException; + + @Override + public native char readChar() throws IOException; + + @Override + public native int readInt() throws IOException; + + @Override + public native long readLong() throws IOException; + + @Override + public native float readFloat() throws IOException; + + @Override + public native double readDouble() throws IOException; + + @Override + public String readLine() throws IOException { + assert false; + + return null; + } + + @Override + public native String readUTF() throws IOException; + + private native void read(String var1) throws IOException; +} diff --git a/NET/worlds/core/Hashtable.java b/NET/worlds/core/Hashtable.java new file mode 100644 index 0000000..adbc5fd --- /dev/null +++ b/NET/worlds/core/Hashtable.java @@ -0,0 +1,105 @@ +package NET.worlds.core; + +import NET.worlds.scape.Persister; +import NET.worlds.scape.Restorer; +import NET.worlds.scape.Saver; +import NET.worlds.scape.TooNewException; +import java.io.IOException; +import java.util.Enumeration; + +public class Hashtable<K, V> extends java.util.Hashtable<K, V> implements Persister { + private static final long serialVersionUID = 1133311923215053895L; + private static Object classCookie = new Object(); + + public Hashtable(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + public Hashtable(int initialCapacity) { + super(initialCapacity); + } + + public Hashtable() { + } + + public Object getKey(Object obj) { + Enumeration<K> e = this.keys(); + + while (e.hasMoreElements()) { + Object key = e.nextElement(); + if (this.get(key) == obj) { + return key; + } + } + + return null; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveVersion(0, classCookie); + int count = 0; + Enumeration<K> e = this.keys(); + + while (e.hasMoreElements()) { + Object key = e.nextElement(); + Object obj = this.get(key); + if ((key instanceof String || key instanceof Persister) && obj instanceof Persister) { + count++; + } + } + + s.saveInt(count); + e = this.keys(); + + while (e.hasMoreElements()) { + Object key = e.nextElement(); + Object obj = this.get(key); + if ((key instanceof String || key instanceof Persister) && obj instanceof Persister) { + if (key instanceof String) { + s.saveBoolean(true); + s.saveString((String)key); + } else { + s.saveBoolean(false); + s.save((Persister)key); + } + + s.save((Persister)obj); + } + } + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + int count = this.restoreCount(r); + + for (int i = 0; i < count; i++) { + this.restoreEntry(r); + } + } + + @Override + public void postRestore(int version) { + } + + public int restoreCount(Restorer r) throws IOException, TooNewException { + switch (r.restoreVersion(classCookie)) { + case 0: + return r.restoreInt(); + default: + throw new TooNewException(); + } + } + + public void restoreEntry(Restorer r) throws IOException, TooNewException { + K key; + if (r.restoreBoolean()) { + key = (K)r.restoreString(); + } else { + key = (K)r.restore(); + } + + V obj = (V)r.restore(); + this.put(key, obj); + } +} diff --git a/NET/worlds/core/IniFile.java b/NET/worlds/core/IniFile.java new file mode 100644 index 0000000..0502e08 --- /dev/null +++ b/NET/worlds/core/IniFile.java @@ -0,0 +1,55 @@ +package NET.worlds.core; + +public class IniFile { + String file; + String section; + static boolean initialized = false; + private static IniFile gamma_ = null; + private static IniFile override_ = null; + + public IniFile(String section) { + this.file = null; + this.section = section; + } + + public IniFile(String inifileName, String section) { + this.file = inifileName; + this.section = section; + } + + public static IniFile gamma() { + if (gamma_ == null) { + gamma_ = new IniFile("Gamma"); + } + + if (!initialized) { + nativeInit(); + initialized = true; + } + + return gamma_; + } + + public static IniFile override() { + if (!initialized) { + nativeInit(); + initialized = true; + } + + if (override_ == null) { + override_ = new IniFile(".\\override.ini", "Runtime"); + } + + return override_; + } + + public native int getIniInt(String var1, int var2); + + public native void setIniInt(String var1, int var2); + + public native String getIniString(String var1, String var2); + + public native void setIniString(String var1, String var2); + + public static native void nativeInit(); +} diff --git a/NET/worlds/core/Recycler.java b/NET/worlds/core/Recycler.java new file mode 100644 index 0000000..6b36f7e --- /dev/null +++ b/NET/worlds/core/Recycler.java @@ -0,0 +1,19 @@ +package NET.worlds.core; + +public class Recycler { + private Recycler() { + } + + public static Object alloc(String classType) { + return null; + } + + public static void free(Object old) { + String className = old.getClass().getName(); + System.out.println("Classname = " + className); + if (className.startsWith("[")) { + Object[] oldArr = (Object[])old; + System.out.println(" array[" + oldArr.length + "]"); + } + } +} diff --git a/NET/worlds/core/RegKey.java b/NET/worlds/core/RegKey.java new file mode 100644 index 0000000..86ebf91 --- /dev/null +++ b/NET/worlds/core/RegKey.java @@ -0,0 +1,50 @@ +package NET.worlds.core; + +public class RegKey { + public static final int CLASSES_ROOT = 0; + public static final int CURRENT_USER = 1; + public static final int LOCAL_MACHINE = 2; + public static final int USERS = 3; + public static final int KEYOPEN_READ = 0; + public static final int KEYOPEN_WRITE = 1; + public static final int KEYOPEN_CREATE = 2; + private int hKey; + + static { + nativeInit(); + } + + public static RegKey getRootKey(int type) throws RegKeyNotFoundException { + return new RegKey(getReservedKey(type)); + } + + public RegKey(RegKey base, String subKey, int mode) throws RegKeyNotFoundException { + if (mode == 2) { + this.hKey = createKey(base.hKey, subKey); + } else { + this.hKey = openKey(base.hKey, subKey, mode); + } + } + + public native String getStringValue(String var1); + + public native boolean setStringValue(String var1, String var2, boolean var3); + + public native int getIntValue(String var1); + + public native boolean setIntValue(String var1, int var2); + + public native void close(); + + private static native int getReservedKey(int var0) throws RegKeyNotFoundException; + + private static native int openKey(int var0, String var1, int var2) throws RegKeyNotFoundException; + + private static native int createKey(int var0, String var1); + + public static native void nativeInit(); + + private RegKey(int hKey) { + this.hKey = hKey; + } +} diff --git a/NET/worlds/core/RegKeyNotFoundException.java b/NET/worlds/core/RegKeyNotFoundException.java new file mode 100644 index 0000000..ce9234f --- /dev/null +++ b/NET/worlds/core/RegKeyNotFoundException.java @@ -0,0 +1,12 @@ +package NET.worlds.core; + +public class RegKeyNotFoundException extends Exception { + private static final long serialVersionUID = 3873901007988284311L; + + public RegKeyNotFoundException() { + } + + public RegKeyNotFoundException(String s) { + super(s); + } +} diff --git a/NET/worlds/core/ServerTableManager.java b/NET/worlds/core/ServerTableManager.java new file mode 100644 index 0000000..b7a525f --- /dev/null +++ b/NET/worlds/core/ServerTableManager.java @@ -0,0 +1,278 @@ +package NET.worlds.core; + +import NET.worlds.console.Gamma; +import NET.worlds.network.Cache; +import NET.worlds.network.CacheFile; +import NET.worlds.network.NetUpdate; +import NET.worlds.network.ProgressDialog; +import NET.worlds.network.URL; +import NET.worlds.scape.BGLoaded; +import NET.worlds.scape.BackgroundLoader; +import NET.worlds.scape.Room; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.io.StringReader; +import java.util.StringTokenizer; +import java.util.Vector; + +public class ServerTableManager implements BGLoaded { + private Hashtable<String, String[]> tables; + private String tableFile; + private int fileVersion = 0; + public static ServerTableManager theTableManager = null; + private static String tableStart = "private static String[] "; + private static String version = "VERSION"; + + public int getFileVersion() { + return this.fileVersion; + } + + public static ServerTableManager instance() { + if (theTableManager == null) { + theTableManager = new ServerTableManager(); + } + + return theTableManager; + } + + public String[] getTable(String tableName) { + Object table = this.tables.get(tableName); + if (table == null) { + System.out.println("Requested table " + tableName + " not found."); + } + + return (String[])table; + } + + private ServerTableManager() { + this.tables = new Hashtable<String, String[]>(); + this.tableFile = IniFile.override().getIniString("ServerTableFile", "tables/tables.dat"); + if (IniFile.gamma().getIniInt("encryptTables", 0) == 1) { + this.encryptTablesFile(); + } + + this.loadTableFile(); + } + + private boolean loadTableFile() { + URL tableURL = URL.make(NetUpdate.getUpgradeServerURL() + this.tableFile); + boolean syncLoad = IniFile.gamma().getIniInt("synchronousTableLoad", 1) == 1; + if (Gamma.loadProgress != null) { + Gamma.loadProgress.setMessage("Downloading global server information..."); + Gamma.loadProgress.advance(); + } + + if (syncLoad) { + CacheFile cf = Cache.getFile(tableURL); + cf.waitUntilLoaded(); + if (!cf.error()) { + this.syncBackgroundLoad(cf.getLocalName(), null); + } + } + + boolean ok = this.parseFile(); + if (!syncLoad) { + BackgroundLoader.get(this, tableURL); + } + + return ok; + } + + @Override + public synchronized Object asyncBackgroundLoad(String localName, URL remoteURL) { + return localName; + } + + @Override + public boolean syncBackgroundLoad(Object obj, URL remoteURL) { + String localName = (String)obj; + if (localName != null && new File(localName).exists()) { + ProgressDialog.copyFile(localName, this.tableFile); + } + + return false; + } + + @Override + public Room getBackgroundLoadRoom() { + return null; + } + + private boolean parseFile() { + BufferedReader buf = null; + + try { + RandomAccessFile fIn = new RandomAccessFile(this.tableFile, "r"); + byte[] encrypted = new byte[fIn.readInt()]; + fIn.readFully(encrypted); + fIn.close(); + String decrypted = this.decrypt(encrypted); + buf = new BufferedReader(new StringReader(decrypted)); + + String line; + while ((line = buf.readLine()) != null) { + line = line.trim(); + if (!line.startsWith("//") && line.length() != 0) { + if (line.startsWith(version)) { + StringTokenizer tok = new StringTokenizer(line); + String versionString = ""; + + while (tok.hasMoreTokens()) { + versionString = tok.nextToken(); + } + + if (versionString != "") { + this.fileVersion = Double.valueOf(versionString).intValue(); + } + } + + if (line.startsWith(tableStart)) { + String tableName = line.substring(tableStart.length()); + StringTokenizer tok = new StringTokenizer(tableName); + if (tok.hasMoreTokens()) { + this.parseTable(buf, tok.nextToken().trim()); + } + } + } + } + + buf.close(); + return true; + } catch (FileNotFoundException var8) { + System.out.println(var8); + return false; + } catch (IOException var9) { + System.out.println(var9); + return false; + } + } + + private String stripQuotes(String in) { + String out = new String(in); + if (out.charAt(0) == '"') { + out = out.substring(1); + } + + if (out.charAt(out.length() - 1) == '"') { + out = out.substring(0, out.length() - 1); + } + + int idx; + while ((idx = out.indexOf(34)) != -1) { + out = out.substring(0, idx) + out.substring(idx + 1); + } + + return out; + } + + private void parseTable(BufferedReader buf, String tableName) throws IOException { + String lastEntry = null; + Vector<String> strings = new Vector<String>(); + + String line; + while ((line = buf.readLine()) != null) { + line = line.trim(); + if (line.length() != 0 && !line.startsWith("//")) { + if (line.startsWith("};")) { + break; + } + + StringTokenizer tok = new StringTokenizer(line, ",\n\r"); + + while (tok.hasMoreTokens()) { + String token = tok.nextToken().trim(); + if (token.startsWith("+ \"")) { + if (lastEntry != null) { + token = token.substring(2); + lastEntry = lastEntry + this.stripQuotes(token); + strings.removeElement(strings.lastElement()); + strings.addElement(lastEntry); + } + } else { + String entry = this.stripQuotes(token); + lastEntry = entry; + strings.addElement(entry); + } + } + } + } + + int numStrings = strings.size(); + String[] table = new String[numStrings]; + + for (int i = 0; i < numStrings; i++) { + table[i] = strings.elementAt(i); + } + + System.out.println("Adding table " + tableName); + this.tables.put(tableName, table); + } + + private byte[] encrypt(String in) { + byte[] inBytes; + try { + inBytes = in.getBytes("UTF8"); + } catch (Exception var6) { + System.out.println("Error encoding to UTF8" + var6.toString()); + return null; + } + + byte[] outBytes = new byte[inBytes.length]; + int len = inBytes.length; + outBytes[0] = inBytes[0]; + + for (int idx = 1; idx < len; idx++) { + outBytes[idx] = (byte)(inBytes[idx] ^ outBytes[idx - 1]); + } + + return outBytes; + } + + private String decrypt(byte[] in) { + byte[] outBytes = new byte[in.length]; + int len = in.length; + outBytes[0] = in[0]; + + for (int idx = 1; idx < len; idx++) { + outBytes[idx] = (byte)(in[idx] ^ in[idx - 1]); + } + + try { + return new String(outBytes, "UTF8"); + } catch (Exception var6) { + System.out.println("Error encoding UTF8 " + var6.toString()); + return null; + } + } + + private void encryptTablesFile() { + try { + System.out.println("Encoding tables file..."); + RandomAccessFile inFilth = new RandomAccessFile("..\\tables.txt", "r"); + String inStr = new String(); + + while (inFilth.getFilePointer() < inFilth.length()) { + String in = inFilth.readLine(); + System.out.println(in); + inStr = inStr + in + "\r\n"; + } + + inFilth.close(); + byte[] encrypted = this.encrypt(inStr); + RandomAccessFile out = new RandomAccessFile(this.tableFile, "rw"); + RandomAccessFile out2 = new RandomAccessFile("..\\tables.dat", "rw"); + out.writeInt(encrypted.length); + out2.writeInt(encrypted.length); + out.write(encrypted); + out2.write(encrypted); + out.close(); + out2.close(); + System.out.println("Tables file " + this.tableFile + " successfully written."); + } catch (Exception var6) { + System.out.println("Error encoding tables file: " + var6.toString()); + } + } +} diff --git a/NET/worlds/core/Sort.java b/NET/worlds/core/Sort.java new file mode 100644 index 0000000..9030d94 --- /dev/null +++ b/NET/worlds/core/Sort.java @@ -0,0 +1,91 @@ +package NET.worlds.core; + +import java.awt.Choice; +import java.awt.List; +import java.util.Enumeration; +import java.util.Vector; + +public class Sort { + public static void sort(String[] list) { + quicksort(list, 0, list.length - 1); + } + + public static String[] sort(Enumeration<String> e, int count) { + String[] list = new String[count]; + + for (int i = 0; i < count; i++) { + list[i] = e.nextElement().toString(); + } + + quicksort(list, 0, count - 1); + return list; + } + + public static String[] sort(Vector<String> v) { + return sort(v.elements(), v.size()); + } + + public static String[] sortKeys(java.util.Hashtable<String, ?> h) { + return sort(h.keys(), h.size()); + } + + public static void sortInto(List list, java.util.Hashtable<String, ?> h) { + String[] content = sortKeys(h); + + for (int i = 0; i < content.length; i++) { + list.add(content[i]); + } + } + + public static void sortInto(List list, Vector<String> v) { + String[] content = sort(v); + + for (int i = 0; i < content.length; i++) { + list.add(content[i]); + } + } + + public static void sortInto(Choice list, java.util.Hashtable<String, ?> h) { + String[] content = sortKeys(h); + + for (int i = 0; i < content.length; i++) { + list.add(content[i]); + } + } + + public static void sortInto(Choice list, Vector<String> v) { + String[] content = sort(v); + + for (int i = 0; i < content.length; i++) { + list.add(content[i]); + } + } + + private static void quicksort(String[] objectList, int l, int r) { + if (r > l) { + String v = objectList[r]; + int i = l - 1; + int j = r; + + String tstr; + do { + while (objectList[++i].compareTo(v) < 0) { + } + + do { + j--; + } while (j > l && objectList[j].compareTo(v) > 0); + + tstr = objectList[i]; + objectList[i] = objectList[j]; + objectList[j] = tstr; + } while (j > i); + + objectList[j] = objectList[i]; + objectList[i] = objectList[r]; + objectList[r] = tstr; + quicksort(objectList, l, i - 1); + quicksort(objectList, i + 1, r); + } + } +} diff --git a/NET/worlds/core/Std.java b/NET/worlds/core/Std.java new file mode 100644 index 0000000..7ee2b6f --- /dev/null +++ b/NET/worlds/core/Std.java @@ -0,0 +1,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(); +} diff --git a/NET/worlds/core/Std_A.java b/NET/worlds/core/Std_A.java new file mode 100644 index 0000000..26ad8da --- /dev/null +++ b/NET/worlds/core/Std_A.java @@ -0,0 +1,4 @@ +package NET.worlds.core; + +class Std_A implements Std_IA { +} diff --git a/NET/worlds/core/Std_B.java b/NET/worlds/core/Std_B.java new file mode 100644 index 0000000..de80c7c --- /dev/null +++ b/NET/worlds/core/Std_B.java @@ -0,0 +1,4 @@ +package NET.worlds.core; + +class Std_B extends Std_A implements Std_IB { +} diff --git a/NET/worlds/core/Std_IA.java b/NET/worlds/core/Std_IA.java new file mode 100644 index 0000000..fe225b2 --- /dev/null +++ b/NET/worlds/core/Std_IA.java @@ -0,0 +1,4 @@ +package NET.worlds.core; + +interface Std_IA { +} diff --git a/NET/worlds/core/Std_IB.java b/NET/worlds/core/Std_IB.java new file mode 100644 index 0000000..fc4e6e7 --- /dev/null +++ b/NET/worlds/core/Std_IB.java @@ -0,0 +1,4 @@ +package NET.worlds.core; + +interface Std_IB extends Std_IA { +} diff --git a/NET/worlds/core/SystemInfo.java b/NET/worlds/core/SystemInfo.java new file mode 100644 index 0000000..ceb2a7f --- /dev/null +++ b/NET/worlds/core/SystemInfo.java @@ -0,0 +1,114 @@ +package NET.worlds.core; + +import NET.worlds.console.Main; +import NET.worlds.console.MainCallback; +import NET.worlds.console.MainTerminalCallback; +import java.io.PrintStream; + +public class SystemInfo implements MainCallback, MainTerminalCallback { + private static SystemInfo instance = new SystemInfo(); + private long _lastFrame = 0L; + private long _lastReport = 0L; + private long _min; + private long _max; + private long _avg; + private long _avgCount = 0L; + + private SystemInfo() { + Main.register(this); + } + + @Override + public void mainCallback() { + long curTime = Std.getFastTime(); + long frameTime = curTime - this._lastFrame; + if (frameTime < this._min) { + this._min = frameTime; + } + + if (frameTime > this._max) { + this._max = frameTime; + } + + this._avg += frameTime; + this._avgCount++; + if (curTime - this._lastReport > 300000L) { + if (this._lastFrame != 0L) { + System.out.println(logTime() + "Frame rate report:" + this._min + "/" + this._avg / this._avgCount + "/" + this._max); + } + + this._min = 10000L; + this._max = 0L; + this._avg = 0L; + this._avgCount = 0L; + this._lastReport = curTime; + } + + this._lastFrame = curTime; + } + + @Override + public void terminalCallback() { + Main.unregister(this); + if (this._avgCount != 0L) { + System.out.println(logTime() + "Frame rate report:" + this._min + "/" + this._avg / this._avgCount + "/" + this._max); + } + } + + public static void Record(PrintStream out) { + out.println("DISK REPORT:"); + recordPath(out, "Windows SYSTEM path", GetSystemDirectory()); + recordPath(out, "Current Working Directory", GetCurrentDirectory()); + out.println(""); + out.println("JAVA MEMORY:"); + out.println(logTime() + "\t Free memory: " + Runtime.getRuntime().freeMemory()); + out.println(logTime() + "\tTotal memory: " + Runtime.getRuntime().totalMemory()); + out.println(""); + out.println("WINDOWS MEMORY:"); + out.println(logTime() + "\tTotal Physical Memory: " + GetTotalPhysicalMemory()); + out.println(logTime() + "\tAvail Physical Memory: " + GetAvailPhysicalMemory()); + out.println(logTime() + "\t Total Paged Memory: " + GetTotalPagedMemory()); + out.println(logTime() + "\t Avail Paged Memory: " + GetAvailPagedMemory()); + out.println(""); + out.println(logTime() + "Java Properties: " + System.getProperties()); + out.println(logTime() + "Number of CPUs: " + GetNumberOfProcessors()); + out.println(logTime() + "Processor Type: " + GetProcessorType()); + out.println(logTime() + "Platform Type: " + GetPlatformID()); + } + + private static void recordPath(PrintStream out, String comment, String path) { + out.println(logTime() + comment + ": " + path); + if (path != null) { + String drive = path.substring(0, 2); + out.println(logTime() + "\tFree disk space (" + drive + "): " + GetDiskFreeSpace(drive + "\\") + " KB"); + } + } + + public static String logTime() { + return "[" + Std.getRealTime() + "] "; + } + + public static native int GetDiskFreeSpace(String var0); + + public static int GetDiskFreeSpace() { + return GetDiskFreeSpace(null); + } + + public static native String GetSystemDirectory(); + + public static native String GetCurrentDirectory(); + + public static native int GetTotalPhysicalMemory(); + + public static native int GetAvailPhysicalMemory(); + + public static native int GetTotalPagedMemory(); + + public static native int GetAvailPagedMemory(); + + public static native String GetPlatformID(); + + public static native int GetNumberOfProcessors(); + + public static native String GetProcessorType(); +} diff --git a/NET/worlds/core/TestInstanceOf.java b/NET/worlds/core/TestInstanceOf.java new file mode 100644 index 0000000..d62f34c --- /dev/null +++ b/NET/worlds/core/TestInstanceOf.java @@ -0,0 +1,45 @@ +package NET.worlds.core; + +public class TestInstanceOf { + public TestInstanceOf() { + System.out.println("Testing instanceOf"); + Std_A a = new Std_A(); + Std_B b = new Std_B(); + Std_A[] aa = new Std_A[1]; + Std_B[] bb = new Std_B[1]; + + try { + assert Std.instanceOf(a, a.getClass()); + + assert Std.instanceOf(b, b.getClass()); + + assert Std.instanceOf(b, a.getClass()); + + assert !Std.instanceOf(a, b.getClass()); + + assert Std.instanceOf(a, Class.forName(cName("Std_IA"))); + + assert !Std.instanceOf(a, Class.forName(cName("Std_IB"))); + + assert Std.instanceOf(b, Class.forName(cName("Std_IA"))); + + assert Std.instanceOf(b, Class.forName(cName("Std_IB"))); + + assert Std.instanceOf(aa, aa.getClass()); + + assert Std.instanceOf(bb, bb.getClass()); + + assert Std.instanceOf(bb, aa.getClass()); + + assert !Std.instanceOf(aa, bb.getClass()); + + System.out.println("Passed all tests"); + } catch (ClassNotFoundException var6) { + System.out.println("Failed"); + } + } + + private static String cName(String className) { + return "NET.worlds.core." + className; + } +} diff --git a/NET/worlds/core/Timer.java b/NET/worlds/core/Timer.java new file mode 100644 index 0000000..75053e8 --- /dev/null +++ b/NET/worlds/core/Timer.java @@ -0,0 +1,21 @@ +package NET.worlds.core; + +public class Timer extends Thread { + private float m_delay; + private TimerCallback m_callback; + + public Timer(float delay, TimerCallback callback) { + this.m_delay = delay; + this.m_callback = callback; + } + + @Override + public void run() { + try { + sleep((long)(this.m_delay * 1000.0F)); + } catch (InterruptedException var2) { + } + + this.m_callback.timerDone(); + } +} diff --git a/NET/worlds/core/TimerCallback.java b/NET/worlds/core/TimerCallback.java new file mode 100644 index 0000000..78f7069 --- /dev/null +++ b/NET/worlds/core/TimerCallback.java @@ -0,0 +1,5 @@ +package NET.worlds.core; + +public interface TimerCallback { + void timerDone(); +} |