diff --git a/cachedump/src/org/moparscape/cacheutils/v317/Main.java b/cachedump/src/org/moparscape/cacheutils/v317/Main.java index 89b7f2b..9f010a8 100644 --- a/cachedump/src/org/moparscape/cacheutils/v317/Main.java +++ b/cachedump/src/org/moparscape/cacheutils/v317/Main.java @@ -5,8 +5,8 @@ import java.io.*; public class Main { public static final String folderName = "/home/mopar/htdocs/317/ondemand/"; - //public static final String cacheToDumpFolder = "./cachedump/complete317/"; - public static final String cacheToDumpFolder = "/home/mopar/.moparscape/cache317/"; + public static final String cacheToDumpFolder = "./cachedump/complete317/"; + //public static final String cacheToDumpFolder = "/home/mopar/.moparscape/cache317/"; public static PrintStream log; public Main() { @@ -41,11 +41,12 @@ public class Main { if (data == null) { println("no data for: " + index + "," + id); - continue; + //continue; + data = new byte[]{0}; + } else { + println("data for: " + index + "," + id); } - println("data for: " + index + "," + id); - long hash = (((cacheIndexes[index].indexID - 1) << 16) + id); File file = new File(folderName + hash); if (file.exists()) { diff --git a/client508/src/client.java b/client508/src/client.java index cf72f86..95f43f9 100644 --- a/client508/src/client.java +++ b/client508/src/client.java @@ -90,7 +90,7 @@ public class client extends Applet_Sub1 implements org.moparscape.ClientInterfac public org.moparscape.userver.Server[] getUpdateServers(String defaultLocation, String customLocation){ org.moparscape.userver.Server[] ret = new org.moparscape.userver.Server[2]; - ret[0] = new org.moparscape.userver.v508.OndemandServer(defaultLocation, customLocation); + ret[0] = new org.moparscape.userver.v508.OndemandServer443(defaultLocation, customLocation); ret[1] = new org.moparscape.userver.v508.OndemandServer(defaultLocation, customLocation); return ret; } diff --git a/src/org/moparscape/userver/Server.java b/src/org/moparscape/userver/Server.java index 10c1460..53282ed 100644 --- a/src/org/moparscape/userver/Server.java +++ b/src/org/moparscape/userver/Server.java @@ -48,7 +48,7 @@ public abstract class Server extends Thread { isRunning = true; } catch (IOException e) { System.out.println("Could not open Server on port " + port); - Server.handleException(e); + handleException(e); } super.start(); } @@ -63,7 +63,7 @@ public abstract class Server extends Thread { try { handleConnection(sSock.accept()); } catch (IOException e) { - Server.handleException(e); + handleException(e); } } @@ -73,7 +73,7 @@ public abstract class Server extends Thread { thisThread.interrupt(); sSock.close(); } catch (Exception e) { - Server.handleException(e); + handleException(e); } } @@ -81,6 +81,7 @@ public abstract class Server extends Thread { public HttpURLConnection getHttpURLConnection(String request) { HttpURLConnection ret; String urlStr = customLocation + request; + //System.out.println("getHttpURLConnection urlStr: "+urlStr); try { ret = (HttpURLConnection) new URL(urlStr).openConnection(); // if response code is not 200 @@ -110,8 +111,11 @@ public abstract class Server extends Thread { return ret; } - public static void handleException(Exception e) { + public void handleException(Exception e) { if (MainPanel.debug()) { + String myName = this.getClass().getName(); + if(!myName.equals("org.moparscape.userver.v508.OndemandServer443")) + return; System.err.print("Server error: "); e.printStackTrace(); } diff --git a/src/org/moparscape/userver/v317/OndemandServer.java b/src/org/moparscape/userver/v317/OndemandServer.java index 8b643a5..405b742 100644 --- a/src/org/moparscape/userver/v317/OndemandServer.java +++ b/src/org/moparscape/userver/v317/OndemandServer.java @@ -61,7 +61,7 @@ public class OndemandServer extends Server { if (status == 10) System.out.println("ods: status is 10!"); long hash = (long) ((dataType << 16) + id); - // System.out.println("request " + hash); + System.out.println(String.format("request: %d,%d hash:%d", dataType, id, hash)); URLConnection url = getHttpURLConnection(odsPath + hash); // if url is null, custom and default cannot be reached, continue diff --git a/src/org/moparscape/userver/v508/OndemandServer.java b/src/org/moparscape/userver/v508/OndemandServer.java index 01b0c55..d110069 100644 --- a/src/org/moparscape/userver/v508/OndemandServer.java +++ b/src/org/moparscape/userver/v508/OndemandServer.java @@ -16,7 +16,7 @@ import java.net.URLConnection; * Time: 2:22:11 PM */ public class OndemandServer extends Server { - // TODO: this must dump to folders, too many files in one folder + public static final String odsPath = "508/%d/%d"; public static final int clientVersion = 508; @@ -110,7 +110,7 @@ public class OndemandServer extends Server { //long hash = (long) ((index << 16) + id); //System.out.println("request " + hash); - System.out.println(String.format(odsPath, index, id)); + //System.out.println(String.format(odsPath, index, id)); URLConnection url = getHttpURLConnection(String.format(odsPath, index, id)); // if url is null, custom and default cannot be reached, continue diff --git a/src/org/moparscape/userver/v508/OndemandServer443.java b/src/org/moparscape/userver/v508/OndemandServer443.java new file mode 100644 index 0000000..c9824e8 --- /dev/null +++ b/src/org/moparscape/userver/v508/OndemandServer443.java @@ -0,0 +1,140 @@ +package org.moparscape.userver.v508; + +import org.moparscape.userver.Server; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; +import java.net.URLConnection; + +/** + * Class:OndemandServer + * User: Silabsoft + * Date: Jul 6, 2009 + * Time: 2:22:11 PM + */ +public class OndemandServer443 extends Server { + + public static final String odsPath = "508/%d/%d"; + public static final int clientVersion = 508; + + public byte[] buffer = new byte[1024]; + public int len; + + public OndemandServer443(String defaultLocation) { + this(defaultLocation, 0); + } + + public OndemandServer443(String defaultLocation, int port) { + super(defaultLocation, port); + } + + public OndemandServer443(String defaultLocation, String customLocation) { + this(defaultLocation, 0, customLocation); + } + + public OndemandServer443(String defaultLocation, int port, String customLocation) { + super(defaultLocation, port, customLocation); + } + + public void handleConnection(Socket s) throws IOException { + //System.out.println("ods: new connection to update server"); + + boolean identify = false; + DataOutputStream out = new DataOutputStream(s.getOutputStream()); + DataInputStream in = new DataInputStream(s.getInputStream()); + //s.setSoTimeout(0); + if (in == null) + return; + while (!s.isClosed()) { + //System.out.println("in loop"); + byte dataType = 15; + int version = clientVersion; +// if (!identify) { +// //s.setSoTimeout(100); +// //System.out.println("HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); +// dataType = in.readByte(); +// //System.out.println("ANDNOW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); +// //s.setSoTimeout(0); +// version = in.readInt(); +// //System.out.println("dataType:" + dataType + " version:" + version); +// } +// if (!identify && dataType == 15 && version == clientVersion) { +// System.out.println("new client connected to update server"); +// out.writeByte(0); +// identify = true; +// in.skip(4); +// } else { + byte[] fromserv = new byte[1024]; + out.writeByte(0); + int numread = in.read(fromserv); + System.out.println("numread:"+numread); + int type = in.read(); + System.out.println("type:" + type); + if (type != 0 && type != 1 && type != 3) + System.exit(-433); + //int hash = ((in.get()& 0xff) << 16) + ((in.get()& 0xff) << 8) + (in.get()& 0xff); + if (type == 0 || type == 1) { + int index = in.read() & 0xff; + int id = in.readShort(); + //System.out.println("index:" + index + " id:" + id); +// if (index == 255 && id == 255) { +// System.out.println("writing out update keys"); +// for (int i : UPDATE_KEYS) +// out.writeByte(i); +// out.flush(); +// continue; +// } + +// byte[] data = cache.read(index, id); +// out.writeByte(index); +// out.writeShort(id); +// +// if (data == null) { +// System.out.println("oh shit"); +// return; +// } +// int c = 3; +// for (int i = 0; i < data.length; i++) { +// +// if (c == 512) { +// out.writeByte(255); +// c = 1; +// } +// out.writeByte(data[i]); +// +// c++; +// } +// out.flush(); +// +// if(true) +// continue; + + //long hash = (long) ((index << 16) + id); + //System.out.println("request " + hash); + //System.out.println(String.format(odsPath, index, id)); + + URLConnection url = getHttpURLConnection(String.format(odsPath, index, id)); + // if url is null, custom and default cannot be reached, continue + if (url == null) + continue; + + //int size = url.getContentLength(); + // if size == -1 it doesn't exist + // however this cannot be counted on as a 404 will still send html + //System.out.println("size: " + size); + InputStream data1 = url.getInputStream(); + + // buffer and len are static + while ((len = data1.read(buffer)) >= 0) + out.write(buffer, 0, len); + out.flush(); + data1.close(); + } + +// } + } + } +} \ No newline at end of file