Markus_Persson
JGO Kernel      Posts: 2092 Medals: 10
Mojang Specifications
|
 |
«
Reply #120 on:
2009-12-18 05:08:00 » |
|
Clever! =D *thumbs up*
|
|
|
|
Eli Delventhal
« League of Dukes » JGO Kernel      Posts: 3478 Medals: 38
Game Engineer
|
 |
«
Reply #121 on:
2009-12-18 10:12:47 » |
|
My graphics are animations of 8 frames each which consists of a global palette of 6 colours which of which sequential frames are simply XORed with the previous frame. Very cheap to decode and give sufficient compression (when gzipped) due to the similarities between frames. I have all my resources in a single separate file which is added to a jar with my class file and then i let Riven's tool at it  Hrm. I don't have the knowhow to do that. I suppose I can just upload a JAR at this point.
|
See my work:OTC Software<br /> Currently Working On:Secret project... I edit JGO in production, because I simply don't waste time writing bugs
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #122 on:
2009-12-18 16:26:54 » |
|
Not sure if it is just me but i am no longer able to upload a jar to Riven's tool... i get the following message after what seems to be a time out: 1 2
| null Connection: close |
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #123 on:
2009-12-18 16:36:52 » |
|
It works here. What are you uploading? Sourcecode or a JAR? How big?
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #124 on:
2009-12-18 17:01:32 » |
|
a jar file of 7k
I have attached it to this post.
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #125 on:
2009-12-18 17:18:32 » |
|
Fixed. The latest update 'featuring' that Proguard hint b0rked it. Seems like you still have room to spare x.progrd.kz.pack.gz => 3443 bytes
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #126 on:
2009-12-18 17:27:22 » |
|
Fixed. The latest update 'featuring' that Proguard hint b0rked it. Seems like you still have room to spare x.progrd.kz.pack.gz => 3443 bytesgroovy! yeah, I have not yet finished the game logic yet, nor have optimised the code for space yet.  I do have my graphics and the 20 levels done. Just not merged into one resource file yet. So I am hoping i will be able to get some sound in.
|
|
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #127 on:
2009-12-19 17:24:06 » |
|
lol... not to be a spoil sport and all but now the option to upload a JAR seems to have gone... I tried both IE 5 and firefox 3.5.6
Wierd! it came back... i guess Riven was doing something in the background at the time.
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #128 on:
2009-12-19 17:32:58 » |
|
I haven't touched it 
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #129 on:
2009-12-19 17:58:08 » |
|
i have reached my monthly download quota and so my internet connection has been shaped to 64KiBs perhaps that has something to do with it.
Ah well it seems to be working for me now.
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #130 on:
2009-12-19 18:05:19 » |
|
 Damn. That option is only available when the service could identify you as a JGO member, as a silly way to prevent untraceable people from uploading massive JARs. You were probably accessing it from another IP, and it only was able to identify you after you made the post on JGO  Funny how innocent features tend to backfire 
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #131 on:
2009-12-19 18:13:05 » |
|
well it was effective in stopping unknown ips 
|
|
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #132 on:
2010-01-02 03:08:46 » |
|
lol it seems i am good at finding features with your tool Riven  I have created an experiment to see whether embedding data into the class would give a smaller result as compared to a seperate resource file. The embedded data class file comes to 53k, the source file is 72k. I was expecting the java compiler to fail as i thought there was a 32k limit on the size of strings but it seems to compile and run fine locally in an applet viewer. The source is attached to this post. Your tool outputs the following and does not progress to the download section: 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
| entered work queue sourcecode OK javac
Note: /home/indiespot/http-files/4k/run.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.
OK jar OK proguard OK pack200 OK:47682 7z OK kzip OK Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143 bjwflate Exit value: 143 pack200 OK:45700 7z OK kzip Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143Exit value: 143 |
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #133 on:
2010-01-02 09:56:27 » |
|
kZip was unable to zip it, due to a 2sec timeout, after which I kill the process, and hence there is no pack.gz file to copy to the download location, resulting in a NullPointerException. Fixed now by bumping the timeout to 10sec, as every kzip on your massive input took 3sec.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #134 on:
2010-01-02 10:02:43 » |
|
I don't think I like it taking so long... I put the timeout back there, as it takes a few minutes, at 100% CPU. This was the output: 1 2 3 4 5 6 7 8 9 10 11 12
| run.java => 73101 bytes run.class => 50709 bytes run.normal.jar => 7110 bytes run.progrd.jar => 5700 bytes run.normal.pack => 47682 bytes run.progrd.pack => 45700 bytes run.normal.7z.pack.gz => 6001 bytes run.progrd.7z.pack.gz => 4944 bytes run.normal.kz.pack.gz => 5142 bytes run.progrd.kz.pack.gz => 4283 bytes run.normal.bj.pack.gz => 5309 bytes run.progrd.bj.pack.gz => 4463 bytes |
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #135 on:
2010-01-02 10:14:42 » |
|
The following code will not compile, but will get you started running kZip and BJWflate bruteforce. It mainly shows how not to properly code in Java  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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
| private static int bruteforceKzip(PrintStream html, File packFile, File packGzFile, int splitOffset, int splitStep, int steps, int reruns) throws IOException { File min = packGzFile; File[] dst = new File[steps]; int minSplit = -1; for (int i = 0; i < dst.length; i++) { dst[i] = new File(packGzFile.getParentFile(), i + "_" + packGzFile.getName()); int split = splitOffset + i * splitStep;
for (int k = 0; k < reruns; k++) { if (kzip_deflopt_gz(html, packFile, dst[i], split, k != 0)) { if (dst[i].length() != 0 && ((min == null || min.length() == 0) || dst[i].length() < min.length())) { min = dst[i]; minSplit = split; } } } }
if (minSplit != -1) FileUtil.copyFile(min, packGzFile);
for (int i = 0; i < dst.length; i++) dst[i].delete(); return minSplit; }
private static int bruteforceBjwflate(PrintStream html, File packFile, File packGzFile, int maxSplit) throws IOException { File min = packGzFile; int minSplit = -1;
List<File> dsts = new ArrayList<File>();
for (int splitSize = 4, i = 0; splitSize <= maxSplit; splitSize += (splitSize <= 12 ? 4 : (splitSize <= 32 ? 8 : (splitSize <= 128 ? 16 : 32))), i++) { File dst = new File(packGzFile.getParentFile(), splitSize + "_" + packGzFile.getName());
if (bjwflate_deflopt_gz(html, packFile, dst, splitSize, false)) { if (dst.length() != 0 && ((min == null || min.length() == 0) || dst.length() < min.length())) { min = dst; minSplit = splitSize; } } }
if (minSplit != -1) FileUtil.copyFile(min, packGzFile);
for (File dst : dsts) dst.delete(); return minSplit; }
public static boolean kzip_deflopt_gz(PrintStream html, File src, File dst, int splitSize, boolean rn) { System.out.println("kzip:" + splitSize + " @ " + System.currentTimeMillis());
File zip = new File(src.getParentFile(), src.getName() + ".zip"); File dir = new File(src.getParentFile(), "tmp_" + System.nanoTime()); dir.mkdir();
try { try { FileUtil.copyFile(src, new File(dir, src.getName()));
String[] cmds = new String[rn ? 5 : 4]; cmds[0] = "/root/kzipmix-static/kzip-static"; cmds[1] = "-y"; cmds[2] = "-b" + splitSize; if (rn) cmds[3] = "-rn"; cmds[rn ? 4 : 3] = zip.getAbsolutePath();
final Process proc = Runtime.getRuntime().exec(cmds, null, dir); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); Streams.asynchronousTransfer(proc.getInputStream(), stdout); Streams.asynchronousTransfer(proc.getErrorStream(), stderr);
final CountdownLatch latch = new CountdownLatch();
new Thread() { public void run() { if (!latch.waitFor(2 * 1000)) { proc.destroy(); } } }.start();
int exit = proc.waitFor(); latch.countdown();
if (splitSize == 0 && !rn) html.append("<h1>kzip</h1>");
if (stderr.size() != 0) { html.append("<pre>"); html.append("<font color=blue>" + Text.utf8(stdout.toByteArray()) + "</font>"); html.append("</pre>"); html.append("<pre>"); html.append("<font color=red>" + Text.utf8(stderr.toByteArray()) + "</font>"); html.append("</pre>"); } if (exit != 0) html.append("<font color=green>Exit value: " + exit + "</font>"); html.flush();
if (exit != 0) return false; } catch (Exception exc) { html.append("<pre>"); html.append("<font color=purple>EXCEPTION: " + exc.getClass().getName() + "</font>"); html.append("</pre>"); html.flush();
exc.printStackTrace(); return false; }
try { zip2gz(new FileInputStream(zip), new FileOutputStream(dst)); html.append("<font color=blue>OK </font>"); html.flush(); } catch (IOException exc) { html.append("<pre>"); html.append("<font color=purple>EXCEPTION: " + exc.getClass().getName() + "</font>"); html.append("</pre>"); html.flush();
exc.printStackTrace(); return false; }
return true; } finally { zip.delete(); FileUtil.deleteDirectory(dir, true); } }
public static boolean bjwflate_deflopt_gz(PrintStream html, File src, File dst, int splitSize, boolean noprep) { System.out.println("bjwflate:" + splitSize + " @ " + System.currentTimeMillis());
File zip = new File(src.getParentFile(), src.getName() + ".zip");
try { try { String[] cmds = new String[noprep ? 6 : 5]; cmds[0] = "/usr/bin/wine"; cmds[1] = "/root/BJWFlate.exe"; cmds[2] = "-y"; if (noprep) cmds[3] = "-n"; cmds[noprep ? 4 : 3] = zip.getAbsolutePath(); cmds[noprep ? 5 : 4] = src.getAbsolutePath();
final Process proc = Runtime.getRuntime().exec(cmds, null); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); Streams.asynchronousTransfer(proc.getInputStream(), stdout); Streams.asynchronousTransfer(proc.getErrorStream(), stderr);
final CountdownLatch latch = new CountdownLatch();
new Thread() { public void run() { if (!latch.waitFor(2 * 1000)) { proc.destroy(); } } }.start();
int exit = proc.waitFor(); latch.countdown();
if (splitSize == 4) html.append("<h1>bjwflate</h1>");
if (stderr.size() != 0) { html.append("<pre>"); html.append("<font color=blue>" + Text.utf8(stdout.toByteArray()) + "</font>"); html.append("</pre>"); html.append("<pre>"); html.append("<font color=red>" + Text.utf8(stderr.toByteArray()) + "</font>"); html.append("</pre>"); } if (exit != 0) html.append("<font color=green>Exit value: " + exit + "</font>"); html.flush();
if (exit != 0) return false; } catch (Exception exc) { html.append("<pre>"); html.append("<font color=purple>EXCEPTION: " + exc.getClass().getName() + "</font>"); html.append("</pre>"); html.flush();
exc.printStackTrace(); return false; }
{ }
try { zip2gz(new FileInputStream(zip), new FileOutputStream(dst)); html.append("<font color=blue>OK </font>"); html.flush(); } catch (IOException exc) { html.append("<pre>"); html.append("<font color=purple>EXCEPTION: " + exc.getClass().getName() + "</font>"); html.append("</pre>"); html.flush();
exc.printStackTrace(); return false; }
return true; } finally { zip.delete(); } } |
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #136 on:
2010-01-02 10:15:32 » |
|
Continuing this hideous code... 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
| public static boolean gz_7z(PrintStream html, File src, File dst) { System.out.println("7z");
try { String[] cmds = new String[4]; cmds[0] = "/root/p7zip_9.04/bin/7z"; cmds[1] = "a"; cmds[2] = dst.getAbsolutePath(); cmds[3] = src.getAbsolutePath();
Process proc = Runtime.getRuntime().exec(cmds); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); Streams.asynchronousTransfer(proc.getInputStream(), stdout); Streams.asynchronousTransfer(proc.getErrorStream(), stderr); int exit = proc.waitFor();
html.append("<h1>7z</h1>"); if (stderr.size() != 0) { html.append("<pre>"); html.append("<font color=blue>" + Text.utf8(stdout.toByteArray()) + "</font>"); html.append("</pre>"); html.append("<pre>"); html.append("<font color=red>" + Text.utf8(stderr.toByteArray()) + "</font>"); html.append("</pre>"); } if (exit != 0) html.append("<font color=green>Exit value: " + exit + "</font>"); else html.append("<font color=blue>OK</font>"); html.flush();
if (exit != 0) return false; return true; } catch (Exception exc) { html.append("<pre>"); html.append("<font color=purple>EXCEPTION: " + exc.getClass().getName() + "</font>"); html.append("</pre>"); html.flush();
exc.printStackTrace(); return false; } }
public static void zip2gz(InputStream in, OutputStream out) throws IOException { in = new BufferedInputStream(in); out = new BufferedOutputStream(out);
out.write(0x1f); out.write(0x8b); out.write(0x08); out.write(0x00); out.write(0x00); out.write(0x00); out.write(0x00); out.write(0x00); out.write(0x00); out.write(0xff);
for (int i = 0; i < 14; i++) in.read(); int crc1 = in.read(); int crc2 = in.read(); int crc3 = in.read(); int crc4 = in.read(); int cmpSz = (in.read() & 0xff) + ((in.read() & 0xff) << 8) + ((in.read() & 0xff) << 16) + ((in.read() & 0xff) << 24); int ucmpSz1 = in.read(); int ucmpSz2 = in.read(); int ucmpSz3 = in.read(); int ucmpSz4 = in.read(); int nameLen = (in.read() & 0xff) + ((in.read() & 0xff) << 8); int xfLen = (in.read() & 0xff) + ((in.read() & 0xff) << 8); for (int i = 0; i < nameLen; i++) in.read(); for (int i = 0; i < xfLen; i++) in.read();
byte[] buf = new byte[4096]; while (cmpSz > 0) { int desired = cmpSz > buf.length ? buf.length : cmpSz; int len = in.read(buf, 0, desired); if (len == 0) throw new EOFException(); out.write(buf, 0, len); cmpSz -= len; }
out.write(crc1); out.write(crc2); out.write(crc3); out.write(crc4); out.write(ucmpSz1); out.write(ucmpSz2); out.write(ucmpSz3); out.write(ucmpSz4);
out.close(); in.close(); } |
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
moogie
JGO Strike Force    Posts: 773 Medals: 4
Java games rock!
|
 |
«
Reply #137 on:
2010-01-02 17:06:39 » |
|
I thought it might be some thing like that  Thanks for the code, i did something similar for my obsolete 4KJO tool. This was just an experiment... which judging by the results you have listed was a failure  My non-embedded version is currently sitting at 4073 bytes so i will stick with that and will just have to cannibalize some features of the game inorder to complete my entry. Cheers
|
|
|
|
|
pjt33
JGO Strike Force    Posts: 890 Medals: 17
|
 |
«
Reply #138 on:
2010-01-25 12:43:51 » |
|
For people who don't have a properly configured web server with which to test. This is a bit paranoid, so it shouldn't let your box get rooted. 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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
| package com.akshor.pjt33.server;
import java.io.*; import java.net.*; import java.util.*;
public class HTTPD implements Runnable { private static File rootDir;
private final Socket sock;
private String request;
private Object resource;
private int responseCode;
private Map<String, String> requestHeaders = new HashMap<String, String>();
private Map<String, String> responseHeaders = new HashMap<String, String>();
private HTTPD(Socket sock) { this.sock = sock; }
public static void main(String[] args) throws IOException { if (args.length < 1 || args.length > 2) usage(); rootDir = new File(args[0]); if (!rootDir.isDirectory()) usage(); int port = 8080; if (args.length == 2) { try { port = Integer.parseInt(args[1]); } catch (NumberFormatException nfe) { usage(); } }
ServerSocket serverSock = new ServerSocket(port); while (true) { Socket sock = serverSock.accept(); if (!sock.getInetAddress().isLoopbackAddress()) { System.out.println("Denying request from non-local IP "+sock.getInetAddress()); sock.close(); continue; }
new Thread(new HTTPD(sock)).start(); } }
private static void usage() { System.err.println("Usage: java HTTPD <root-dir> [port]"); System.err.println("Default port is 8080"); System.exit(-1); }
public void run() { try { final String utf8 = "UTF-8"; BufferedOutputStream outbin = new BufferedOutputStream(sock.getOutputStream()); PrintWriter out = new PrintWriter(new OutputStreamWriter(outbin, utf8)); BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream(), utf8));
InetAddress addr = sock.getInetAddress(); String line; while ((line = in.readLine()) != null) { if (request == null) { String[] bits = line.split(" "); if (bits.length == 3) { if ("GET".equals(bits[0])) { request = bits[1]; } else { responseCode = 501; resource = "Not supported"; } } else { responseCode = 400; resource = "Bad request"; break; } } else if (line.length() == 0) { break; } else { String[] bits = line.split(":"); if (bits.length == 2) { requestHeaders.put(bits[0].trim().toLowerCase(), bits[1].trim().toLowerCase()); } } }
if (responseCode == 0) { handleRequest(); }
int responseSize = 0; if (responseCode == 0 || resource == null) { responseCode = 501; resource = "Internal error"; } if (resource instanceof String) { resource = resource.toString().getBytes(utf8); responseHeaders.put("Content-Encoding", utf8); responseHeaders.put("Content-Type", "text/plain; charset=UTF-8"); } if (resource instanceof byte[]) responseSize = ((byte[])resource).length; else if (resource instanceof File) responseSize = (int)((File)resource).length(); responseHeaders.put("Content-Length", Integer.toString(responseSize));
out.println("HTTP/1.1 "+responseCode); for (Map.Entry<String, String> e : responseHeaders.entrySet()) { out.println(e.getKey()+": "+e.getValue()); } out.println(); out.flush(); if (resource instanceof byte[]) { outbin.write((byte[])resource); } else if (resource instanceof File) { FileInputStream fis = new FileInputStream((File)resource); byte[] buf = new byte[4096]; int len; while ((len = fis.read(buf)) != -1) { outbin.write(buf, 0, len); } fis.close(); }
System.out.println(new Date()+" ["+addr+"] "+responseCode+" ("+responseSize+" bytes) for "+request);
outbin.close(); in.close(); } catch (IOException ioe) { ioe.printStackTrace(); } }
private void handleRequest() { try { request = URLDecoder.decode(request, "UTF-8"); } catch (UnsupportedEncodingException ufe) { InternalError err = new InternalError(); err.initCause(ufe); throw err; }
if (request.indexOf("..") >= 0) { responseCode = 401; resource = "Unauthorized"; return; }
if (!request.startsWith("/")) { request = "/" + request; } File file = new File(rootDir, request); if (!file.isFile()) { responseCode = 404; resource = "Not found"; } else { responseCode = 200; resource = file; String contentType = getContentType(request); if (contentType != null) { responseHeaders.put("Content-Type", contentType); } else { responseHeaders.put("Content-Type", "application/x-unknown"); } }
if (request.endsWith(".jar") && requestHeaders.get("accept-encoding") != null && requestHeaders.get("accept-encoding").contains("pack200-gzip")) { File _jar_pack_gz = new File(rootDir, request+".pack.gz"); File _pack_gz = new File(rootDir, request.replace("jar$", "pack.gz")); if (_jar_pack_gz.isFile() || _pack_gz.isFile()) { responseCode = 200; resource = _jar_pack_gz.isFile() ? _jar_pack_gz : _pack_gz; responseHeaders.put("Content-Type", "application/x-java-archive"); responseHeaders.put("Content-Encoding", "pack200-gzip"); } } }
private String getContentType(String request) { if (request.endsWith(".html")) return "text/html"; if (request.endsWith(".jar")) return "application/x-java-archive"; return null; } } |
|
|
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #139 on:
2010-01-30 15:44:20 » |
|
Sorry if this was already answered elsewhere but using Riven's compression tool ( http://www.indiespot.net/app/java-four-kay), I always get a ClassNotFoundException exception. Also, does the tool sign the class? Here is the html page I use for local deployment testing, using the deployment toolkit: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="http://java.com/js/deployJava.js"></script> <script> var attributes = { codebase:'.', code:'G', archive:'bf9fa6fd1c80baa50a581f690bd67bb2.6.pack.gz', width:'800', height:'600' }; var parameters = { separate_jvm:'true', java_arguments:'-Djnlp.packEnabled=true', }; deployJava.runApplet(attributes, parameters, '1.5'); </script> </head> <body> </body> </html> |
Here is the stack trace: 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
| Java Plug-in 1.6.0_18 Using JRE version 1.6.0_18-b07 Java HotSpot(TM) Client VM User home directory = C:\Users\admin ---------------------------------------------------- c: clear console window f: finalize objects on finalization queue g: garbage collect h: display this help message l: dump classloader list m: print memory usage o: trigger logging q: hide console r: reload policy configuration s: dump system and deployment properties t: dump thread list v: dump thread stack x: clear classloader cache 0-5: set trace level to <n> ----------------------------------------------------
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.definition value null security: property package.definition new value com.sun.javaws security: property package.definition value com.sun.javaws security: property package.definition new value com.sun.javaws,com.sun.deploy security: property package.definition value com.sun.javaws,com.sun.deploy security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss security: property package.definition value com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@1de3f2d basic: load: class G not found. load: class G not found. java.lang.ClassNotFoundException: G at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source) at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Exception: java.lang.ClassNotFoundException: G security: Accessing keys and certificate in Mozilla user profile: null |
Any idea what's happening here? Thanks
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #140 on:
2010-01-30 15:49:56 » |
|
The service does not sign the jar.
Does the non-proguard .pack.gz version work?
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #142 on:
2010-01-30 16:33:08 » |
|
Very surprising! I'll try on my website then.
Riven, I'll try later the other outputs from your service. I'm a baby-sitter for now :-)
|
|
|
|
SimonH
JGO Strike Force    Posts: 882 Medals: 13
|
 |
«
Reply #143 on:
2010-01-31 09:50:04 » |
|
For people who don't have a properly configured web server with which to test. This is a bit paranoid, so it shouldn't let your box get rooted. Works great - thanks!
|
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #144 on:
2010-02-01 21:13:38 » |
|
I tried the non-proguard version of my game but now I have a different error: 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
| basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@1de3f2d network: Cache entry not found [url: http:network: Connecting http:network: Connecting http:network: Cache entry not found [url: http:network: Connecting http:network: Downloading resource: http: Content-Length: 1,896 Content-Encoding: gzip java.io.IOException: Invalid jar file at com.sun.deploy.net.HttpDownloadHelper.download(Unknown Source) at com.sun.deploy.cache.Cache$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.deploy.cache.Cache.downloadResourceToCache(Unknown Source) at com.sun.deploy.cache.DeployFileOutputStream.close(Unknown Source) at java.io.FilterOutputStream.close(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(Unknown Source) at java.io.BufferedInputStream.close(Unknown Source) at sun.plugin.PluginURLJarFileCallBack.downloadJAR(Unknown Source) at sun.plugin.PluginURLJarFileCallBack.access$000(Unknown Source) at sun.plugin.PluginURLJarFileCallBack$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source) at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source) at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source) at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source) at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFileInternal(Unknown Source) at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFile(Unknown Source) at sun.misc.URLClassPath$JarLoader.getJarFile(Unknown Source) at sun.misc.URLClassPath$JarLoader.access$600(Unknown Source) at sun.misc.URLClassPath$JarLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.misc.URLClassPath$JarLoader.ensureOpen(Unknown Source) at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source) at sun.misc.URLClassPath$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.misc.URLClassPath.getLoader(Unknown Source) at sun.misc.URLClassPath.getLoader(Unknown Source) at sun.misc.URLClassPath.getResource(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source) at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) network: Cache entry not found [url: http:network: CleanupThread used 49381 us network: Connecting http:network: CleanupThread used 4 us network: Downloading resource: http: Content-Length: 1,896 Content-Encoding: x-gzip basic: load: class G not found. load: class G not found. java.lang.ClassNotFoundException: G at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source) at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Exception: java.lang.ClassNotFoundException: G security: Accessing keys and certificate in Mozilla user profile: null |
The jar is detected as invalid: 1
| java.io.IOException: Invalid jar file |
|
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #145 on:
2010-02-01 21:35:45 » |
|
Just to narrow the cause, I'm able to run my game in an applet in a normal jar on my local machine. I really think there's something broken or missing with pack or other formats. Or the optimizations applied brake something. I'll try the service by uploading my jar.
|
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #146 on:
2010-02-01 21:44:08 » |
|
The jar way doesn't work neither.
|
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #147 on:
2010-02-01 22:13:05 » |
|
Hmm, it was successful with the first generate pack.gz from copy pasted code BUT only one time. I tried all the other produced pack.gz and they didn't work. I tried again the first pack.gz and it no longer works! I also selected "keep class members" option. And after each try I always deleted the IE cache and java plug-in cache. I'm very confused now. BTW, what does "compile and self destruct" do? That sounds scary! 
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5495 Medals: 202
Hand over your head.
|
 |
«
Reply #148 on:
2010-02-02 03:41:40 » |
|
My tool isn't doing anything fancy. It does: javac, jar, (proguard, )pack200, {bjwflate|kzip|7z} The only part that can corrupt it is proguard, which is why I made it optional. Hmm, it was successful with the first generate pack.gz from copy pasted code BUT only one time. I tried all the other produced pack.gz and they didn't work. I tried again the first pack.gz and it no longer works! I also selected "keep class members" option. And after each try I always deleted the IE cache and java plug-in cache. I'm very confused now.
1 2 3
| network: Downloading resource: http: Content-Length: 1,896 Content-Encoding: x-gzip |
That's actually quite weird... there shouldn't be a Content-Encoding: x-gzip header, as it will cause the browser to ungz it, which will probably screwup any attempt the plugin makes at loading the pack.gz file (it will try to ungz the ungz-ed stream) What kind of webserver are you running? Ah... Apache/1.3.39. BTW, what does "compile and self destruct" do? That sounds scary!  It will install a cute trojan on the server 
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
TheAnalogKid
« League of Dukes » JGO Wizard      Posts: 1307 Medals: 2
|
 |
«
Reply #149 on:
2010-02-02 12:21:51 » |
|
There's something with the service: 1 2 3 4 5
| entered work queue sourcecode OK
EXCEPTION: java.io.IOException |
It will install a cute trojan on the server What does it do, seriously? I'd like to know.
|
|
|
|
|