Made a seperate server for 508. Updated a few other things.

This is a test for a second line, just wanted to see what it
would do.
This commit is contained in:
Travis Burtrum 2009-09-12 22:24:11 -04:00
parent 9e4cc66d2b
commit d42efa478c
6 changed files with 158 additions and 13 deletions

View File

@ -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()) {

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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

View File

@ -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

View File

@ -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();
}
// }
}
}
}