emscripten networking!

This commit is contained in:
Mister Hat 2021-07-19 14:02:07 -05:00
parent 5583ddff51
commit 4b8bcc19d5
6 changed files with 671 additions and 140 deletions

View File

@ -1,12 +1,13 @@
java -jar ./JCGO/jcgo.jar mudclient -src ./mudclient204-threadless \
@JCGO/stdpaths.in
patch -p0 -i sdl.diff
patch -p0 -i emscripten-sdl.diff
emcc -O2 -I ./JCGO/include -I ./JCGO/native -I \
-fno-strict-aliasing \
-DJCGO_NOGC -DJCGO_FPFAST -DJCGO_FASTMATH -DJCGO_INET \
-DJCGO_NOGC -DJCGO_FPFAST -DJCGO_FASTMATH \
-DJCGO_INTFIT -DJCGO_UNIX -D_FPU_CONTROL_H -D_IEEEFP_H -DJCGO_UNIFSYS \
-o mudclient.html jcgo_Out/Main.c -lm -lSDL2 \
-s ALLOW_MEMORY_GROWTH=1 -s USE_SDL=2 -s ASYNCIFY \
-s 'ASYNCIFY_IMPORTS=["js_clientStream_new","js_clientStream_readStream","js_clientStream_availableStream","js_clientStream_readStreamBytes"]' \
--preload-file ./data204

View File

@ -0,0 +1,606 @@
diff -uarN jcgo_Out/ClntStrm.c jcgo_Out_Patched/ClntStrm.c
--- jcgo_Out/ClntStrm.c 2021-07-19 13:56:54.496508856 -0500
+++ jcgo_Out_Patched/ClntStrm.c 2021-07-19 13:58:22.185577736 -0500
@@ -12,6 +12,36 @@
#include "jcgobchk.h"
#endif
+EM_JS(void, js_clientStream_new, (), {
+ const socket = new window.MUDCLIENT_Socket('localhost', 43595);
+ Asyncify.handleAsync(async () => {
+ await socket.connect();
+ window.MUDCLIENT_socket = socket;
+ });
+});
+
+EM_JS(void, js_clientStream_writeStreamBytes, (char* buff, int len), {
+ window.MUDCLIENT_socket.write(window.HEAP8.slice(buff, buff + len));
+});
+
+EM_JS(int, js_clientStream_readStream, (), {
+ return Asyncify.handleAsync(async () => {
+ return await window.MUDCLIENT_socket.read();
+ });
+});
+
+EM_JS(int, js_clientStream_availableStream, (), {
+ return Asyncify.handleAsync(async () => {
+ return await window.MUDCLIENT_socket.available();
+ });
+});
+
+EM_JS(void, js_clientStream_readStreamBytes, (char* buff, int len), {
+ Asyncify.handleAsync(async () => {
+ await window.MUDCLIENT_socket.readBytes(window.HEAP8, buff, len);
+ });
+});
+
JCGO_NOSEP_INLINE package_ClientStream CFASTCALL
package_ClientStream__this__L7rjha( package_ClientStream This, package_GameShell
applet )
@@ -28,6 +58,7 @@
package_ClientStream__new__L7rjha( package_GameShell applet )
{
JCGO_CLINIT_TRIG(package_ClientStream__class);
+ js_clientStream_new();
return package_ClientStream__this__L7rjha(
(package_ClientStream)jcgo_newObject((jvtable)&package_ClientStream_methods),
applet);
@@ -53,7 +84,7 @@
{
return 0;
}
- return (jint)12345678L;
+ return (jint) js_clientStream_readStream();
}
}
@@ -66,7 +97,7 @@
{
return 0;
}
- return (jint)12345678L;
+ return (jint) js_clientStream_availableStream();
}
}
@@ -79,11 +110,16 @@
{
return;
}
- (java_io_PrintStream__println__Ls(
+ char bytes[len];
+ js_clientStream_readStreamBytes(bytes, len);
+ for (int i = 0; i < len; i++) {
+ JCGO_ARRAY_BACCESS(buff, i + off) = (jbyte) bytes[i];
+ }
+ /*(java_io_PrintStream__println__Ls(
JCGO_CLINIT_VARACC(java_lang_System__class, java_lang_System__out),
JCGO_STRREF_OF(jcgo_string2_ClntStrm)));
JCGO_THROW_EXC((java_io_IOException__new__Ls(
- JCGO_STRREF_OF(jcgo_string3_ClntStrm))));
+ JCGO_STRREF_OF(jcgo_string3_ClntStrm))));*/
}
}
@@ -101,11 +137,16 @@
JCGO_FIELD_NZACCESS(This, buffer)= (jbyteArr)jcgo_newArray(JCGO_CORECLASS_FOR(OBJT_jbyte),
0, (jint)5000);
}
- (java_io_PrintStream__println__Ls(
+ char bytes[len];
+ for (int i = 0; i < len; i++) {
+ bytes[i] = JCGO_ARRAY_BACCESS(buff, off + i);
+ }
+ js_clientStream_writeStreamBytes(bytes, len);
+ /*(java_io_PrintStream__println__Ls(
JCGO_CLINIT_VARACC(java_lang_System__class, java_lang_System__out),
JCGO_STRREF_OF(jcgo_string4_ClntStrm)));
JCGO_THROW_EXC((java_io_IOException__new__Ls(
- JCGO_STRREF_OF(jcgo_string5_ClntStrm))));
+ JCGO_STRREF_OF(jcgo_string5_ClntStrm))));*/
}
}
diff -uarN jcgo_Out/GameShll.c jcgo_Out_Patched/GameShll.c
--- jcgo_Out/GameShll.c 2021-07-19 13:56:54.400507684 -0500
+++ jcgo_Out_Patched/GameShll.c 2021-07-19 13:57:19.720816667 -0500
@@ -12,6 +12,126 @@
#include "jcgobchk.h"
#endif
+void get_keycodes(jchar* charCode, jint* code) {
+ switch (event.key.keysym.scancode) {
+ case SDL_SCANCODE_LEFT:
+ *code = 37;
+ *charCode = 65535;
+ break;
+ case SDL_SCANCODE_RIGHT:
+ *code = 39;
+ *charCode = 65535;
+ break;
+ case SDL_SCANCODE_UP:
+ *code = 38;
+ *charCode = 65535;
+ break;
+ case SDL_SCANCODE_DOWN:
+ *code = 40;
+ *charCode = 65535;
+ break;
+ default:
+ *charCode = event.key.keysym.sym;
+ const char* keyName = SDL_GetKeyName(event.key.keysym.sym);
+
+ if (strlen(keyName) == 1) {
+ *code = keyName[0];
+ } else {
+ *code = *charCode;
+ }
+
+ // absolutely dumb hack but i don't want to use SDL's textinput
+ if (event.key.keysym.mod & KMOD_SHIFT) {
+ if (*charCode >= 'a' && *charCode <= 'z') {
+ *charCode -= 32;
+ } else {
+ switch (*charCode) {
+ case ';':
+ *charCode = ':';
+ break;
+ case '`':
+ *charCode = '~';
+ break;
+ case '1':
+ *charCode = '!';
+ break;
+ case '2':
+ *charCode = '@';
+ break;
+ case '3':
+ *charCode = '#';
+ break;
+ case '4':
+ *charCode = '$';
+ break;
+ case '5':
+ *charCode = '%';
+ break;
+ case '6':
+ *charCode = '^';
+ break;
+ case '7':
+ *charCode = '&';
+ break;
+ case '8':
+ *charCode = '*';
+ break;
+ case '9':
+ *charCode = '(';
+ break;
+ case '0':
+ *charCode = ')';
+ break;
+ case '-':
+ *charCode = '_';
+ break;
+ case '=':
+ *charCode = '+';
+ break;
+ }
+ }
+ }
+ break;
+ }
+}
+
+void handle_sdl_events(package_GameShell This) {
+ while (SDL_PollEvent(&event)) {
+ switch (event.type) {
+ case SDL_QUIT:
+ exit(0);
+ break;
+ case SDL_KEYDOWN: {
+ jchar charCode;
+ jint code;
+ get_keycodes(&charCode, &code);
+ (package_GameShell__keyPressed__CI(This, code, charCode));
+ break;
+ }
+ case SDL_KEYUP: {
+ jchar charCode;
+ jint code;
+ get_keycodes(&charCode, &code);
+ (package_GameShell__keyReleased__I(This, code));
+ break;
+ }
+ case SDL_MOUSEMOTION:
+ (package_GameShell__mouseMoved__II(This, event.motion.x, event.motion.y));
+ break;
+ case SDL_MOUSEBUTTONDOWN: {
+ jint button = event.button.button == 3 ? 2 : 1;
+ (package_GameShell__mousePressed__III(This, event.button.x, event.button.y,
+ button));
+ break;
+ }
+ case SDL_MOUSEBUTTONUP:
+ (package_GameShell__mouseReleased__II(This, event.button.x,
+ event.button.y));
+ break;
+ }
+ }
+}
+
JCGO_NOSEP_INLINE void CFASTCALL
package_GameShell__keyPressed__CI( package_GameShell This, jint code,
jchar chr )
@@ -287,6 +407,34 @@
package_GameShell__run__( package_GameShell This )
{
{
+ jint width = JCGO_FIELD_NZACCESS(This, appletWidth);
+ jint height = JCGO_FIELD_NZACCESS(This, appletHeight) + 2;
+
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
+ fprintf(stderr, "SDL_Init(): %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ wanted_audio.freq = 8000;
+ wanted_audio.format = AUDIO_S16;
+ wanted_audio.channels = 1;
+ wanted_audio.silence = 0;
+ wanted_audio.samples = 1024;
+ wanted_audio.callback = NULL;
+
+ if (SDL_OpenAudio(&wanted_audio, NULL) < 0) {
+ fprintf(stderr, "SDL_OpenAudio(): %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ SDL_PauseAudio(0);
+
+ window = SDL_CreateWindow("Runescape by Andrew Gower", SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
+ screen = SDL_GetWindowSurface(window);
+ pixel_surface = SDL_CreateRGBSurface(0, width, height, 32, 0xff0000, 0x00ff00,
+ 0x0000ff, 0);
+
jint i;
jint j;
jint sleep;
@@ -370,8 +518,7 @@
sleep= JCGO_FIELD_NZACCESS(This, threadSleep);
}
}
- (java_io_PrintStream__println__I(
- java_lang_System__out, sleep + (jint)51339L));
+ emscripten_sleep(sleep);
JCGO_ARRAY_JACCESS(JCGO_FIELD_NZACCESS(This, timings), i)= time;
i= (i + (jint)1) % (jint)10;
if (sleep > (jint)1)
@@ -394,6 +541,7 @@
while (i1 < (jint)256)
{
jint jcgo_rcvrI1;
+ handle_sdl_events(This);
(JCGO_CALL_NZVFUNC(This)->handleInputs__(
This));
i1+= j;
@@ -633,8 +781,7 @@
JCGO_STRREF_OF(jcgo_string19_GameShll)));
(JCGO_CALL_NZVFUNC(This)->onClosing__(
This));
- (java_io_PrintStream__println__I(
- java_lang_System__out, (jint)51339L + (jint)1000));
+ emscripten_sleep(1000);
(java_lang_System__exit__I(
0));
}
diff -uarN jcgo_Out/GmCnnctn.c jcgo_Out_Patched/GmCnnctn.c
--- jcgo_Out/GmCnnctn.c 2021-07-19 13:56:54.404507733 -0500
+++ jcgo_Out_Patched/GmCnnctn.c 2021-07-19 13:57:19.720816667 -0500
@@ -348,9 +348,7 @@
{
(JCGO_CALL_NZVFUNC(This)->showLoginScreenStatus__LsLs(
This, JCGO_STRREF_OF(jcgo_string11_GmCnnctn), JCGO_STRREF_OF(jcgo_string12_GmCnnctn)));
- (java_io_PrintStream__println__I(
- JCGO_CLINIT_VARACC(java_lang_System__class, java_lang_System__out),
- (jint)51339L + (jint)2000));
+ emscripten_sleep(2000);
(JCGO_CALL_NZVFUNC(This)->showLoginScreenStatus__LsLs(
This, JCGO_STRREF_OF(jcgo_string13_GmCnnctn), JCGO_STRREF_OF(jcgo_string14_GmCnnctn)));
return;
@@ -742,9 +740,7 @@
}
if (JCGO_FIELD_NZACCESS(This, autoLoginTimeout) > 0)
{
- (java_io_PrintStream__println__I(
- JCGO_CLINIT_VARACC(java_lang_System__class, java_lang_System__out),
- (jint)51339L + (jint)5000));
+ emscripten_sleep(5000);
JCGO_FIELD_NZACCESS(This, autoLoginTimeout)--;
(package_GameConnection__login__LsLsZ(
This, JCGO_FIELD_NZACCESS(This, username), JCGO_FIELD_NZACCESS(This,
diff -uarN jcgo_Out/KeyEvent.h jcgo_Out_Patched/KeyEvent.h
--- jcgo_Out/KeyEvent.h 2021-07-19 13:56:54.448508270 -0500
+++ jcgo_Out_Patched/KeyEvent.h 2021-07-19 13:57:19.732816813 -0500
@@ -2,21 +2,21 @@
#ifdef JCGO_116
-#define package_KeyEvent__VK_LEFT (-(jint)12345678L)
+#define package_KeyEvent__VK_LEFT (37)
-#define package_KeyEvent__VK_RIGHT (-(jint)12345678L)
+#define package_KeyEvent__VK_RIGHT (39)
-#define package_KeyEvent__VK_UP (-(jint)12345678L)
+#define package_KeyEvent__VK_UP (38)
-#define package_KeyEvent__VK_DOWN (-(jint)12345678L)
+#define package_KeyEvent__VK_DOWN (40)
-#define package_KeyEvent__VK_SPACE (-(jint)12345678L)
+#define package_KeyEvent__VK_SPACE (SDLK_SPACE)
-#define package_KeyEvent__VK_F1 (-(jint)12345678L)
+#define package_KeyEvent__VK_F1 (SDL_SCANCODE_F1)
-#define package_KeyEvent__VK_BACK_SPACE (-(jint)12345678L)
+#define package_KeyEvent__VK_BACK_SPACE (SDLK_BACKSPACE)
-#define package_KeyEvent__VK_ENTER (-(jint)12345678L)
+#define package_KeyEvent__VK_ENTER (SDLK_RETURN)
JCGO_NOSEP_STATIC package_KeyEvent CFASTCALL
package_KeyEvent__this__( package_KeyEvent This );
diff -uarN jcgo_Out/Main.c jcgo_Out_Patched/Main.c
--- jcgo_Out/Main.c 2021-07-19 13:56:54.552509540 -0500
+++ jcgo_Out_Patched/Main.c 2021-07-19 13:57:19.748817008 -0500
@@ -1120,6 +1120,204 @@
MAINENTRY
( int argc, JCGO_MAIN_TCHAR **targv )
{
+ EM_ASM(
+ const CLOSE_TIMEOUT = 5000;
+
+ class Socket {
+ constructor(host, port) {
+ this.host = host;
+ this.port = port;
+
+ this.client = null;
+ this.connected = false;
+
+ // amount of bytes are left to read since last read call (in total)
+ this.bytesAvailable = 0;
+
+ // the message buffers that arrive from the websocket
+ this.buffers = [];
+
+ // the current buffer we're reading
+ this.currentBuffer = null;
+
+ // amount of bytes we read in current buffer
+ this.offset = 0;
+
+ // amount of bytes left in current buffer
+ this.bytesLeft = 0;
+ }
+
+ connect() {
+ return new Promise((resolve, reject) => {
+ this.client = new WebSocket(
+ 'ws://' + this.host + ':' + this.port,
+ 'binary'
+ );
+
+ const closeTimeout = setTimeout(() => {
+ if (!this.connected) {
+ this.client.close();
+ reject(new Error('websocket connect timeout'));
+ }
+ }, CLOSE_TIMEOUT);
+
+ this.client.binaryType = 'arraybuffer';
+
+ const onError = (err) => {
+ if (this.onError) {
+ this.onError(err);
+ this.onError = undefined;
+ }
+
+ reject(err);
+ };
+
+ this.client.addEventListener('error', onError);
+
+ this.client.addEventListener('close', () => {
+ if (this.onClose) {
+ this.onClose(-1);
+ this.onClose = undefined;
+ }
+
+ this.connected = false;
+ this.clear();
+ });
+
+ this.client.addEventListener('message', (msg) => {
+ this.buffers.push(new Int8Array(msg.data));
+ this.bytesAvailable += msg.data.byteLength;
+ this.refreshCurrentBuffer();
+
+ if (this.onNextMessage) {
+ this.onNextMessage(msg.data.byteLength);
+ this.onNextMessage = undefined;
+ }
+ });
+
+ this.client.addEventListener('open', () => {
+ this.connected = true;
+ clearTimeout(closeTimeout);
+ resolve();
+ });
+ });
+ }
+
+ write(bytes, offset = 0, length = -1) {
+ if (!this.connected) {
+ throw new Error('attempting to write to closed socket');
+ }
+
+ length = length === -1 ? bytes.length : length;
+
+ this.client.send(bytes.slice(offset, offset + length));
+ }
+
+ refreshCurrentBuffer() {
+ if (this.bytesLeft === 0 && this.bytesAvailable > 0) {
+ this.currentBuffer = this.buffers.shift();
+ this.offset = 0;
+
+ if (this.currentBuffer && this.currentBuffer.length) {
+ this.bytesLeft = this.currentBuffer.length;
+ } else {
+ this.bytesLeft = 0;
+ }
+ }
+ }
+
+ // read the first byte available in the buffer, or wait for one to be sent
+ // if none are available.
+ async read() {
+ if (!this.connected) {
+ return -1;
+ }
+
+ if (this.bytesLeft > 0) {
+ this.bytesLeft--;
+ this.bytesAvailable--;
+
+ return this.currentBuffer[this.offset++] & 0xff;
+ }
+
+ const bytesRead = await new Promise((resolve, reject) => {
+ this.onClose = resolve;
+ this.onError = reject;
+ this.onNextMessage = resolve;
+ });
+
+ if (bytesRead === -1) {
+ return -1;
+ }
+
+ return await this.read();
+ }
+
+ // read multiple bytes (specified by `length`) and put them into the
+ // `destination` array at specified `offset` (0 by default).
+ async readBytes(destination, offset = 0, length = -1) {
+ if (!this.connected) {
+ return -1;
+ }
+
+ length = length === -1 ? destination.length : length;
+
+ if (this.bytesAvailable >= length) {
+ while (length > 0) {
+ destination[offset++] =
+ this.currentBuffer[this.offset++] & 0xff;
+
+ this.bytesLeft -= 1;
+ this.bytesAvailable -= 1;
+ length -= 1;
+
+ if (this.bytesLeft === 0) {
+ this.refreshCurrentBuffer();
+ }
+ }
+
+ return;
+ }
+
+ const bytesRead = await new Promise((resolve, reject) => {
+ this.onClose = resolve;
+ this.onError = reject;
+ this.onNextMessage = resolve;
+ });
+
+ if (bytesRead === -1) {
+ return -1;
+ }
+
+ return await this.readBytes(destination, offset, length);
+ }
+
+ close() {
+ if (!this.connected) {
+ return;
+ }
+
+ this.client.close();
+ }
+
+ available() {
+ return this.bytesAvailable;
+ }
+
+ clear() {
+ if (this.connected) {
+ this.client.close();
+ }
+
+ this.currentBuffer = null;
+ this.buffers.length = 0;
+ this.bytesLeft = 0;
+ }
+ }
+
+ window.MUDCLIENT_Socket = Socket;
+ );
+
JCGO_MAIN_LAUNCH(argc, targv);
return 0;
}
diff -uarN jcgo_Out/Main.h jcgo_Out_Patched/Main.h
--- jcgo_Out/Main.h 2021-07-19 13:56:54.508509003 -0500
+++ jcgo_Out_Patched/Main.h 2021-07-19 13:57:19.748817008 -0500
@@ -1376,4 +1376,15 @@
JCGO_SEP_EXTERN CONST struct java_lang_Object_methods_s jObjectArr15_methods;
JCGO_SEP_EXTERN CONST struct java_lang_Object_methods_s jObjectArr16_methods;
+#include <SDL2/SDL.h>
+#include <emscripten.h>
+
+SDL_Window *window;
+SDL_Surface *screen;
+SDL_Surface *pixel_surface;
+SDL_Event event;
+SDL_AudioSpec wanted_audio;
+
+short pcm_out[1024 * 1024];
+
#endif
diff -uarN jcgo_Out/Surface.c jcgo_Out_Patched/Surface.c
--- jcgo_Out/Surface.c 2021-07-19 13:56:54.448508270 -0500
+++ jcgo_Out_Patched/Surface.c 2021-07-19 13:57:19.732816813 -0500
@@ -786,9 +786,17 @@
{
(package_Surface__setcomplete__(
This));
- (java_io_PrintStream__println__Ls(
- JCGO_CLINIT_VARACC(java_lang_System__class, java_lang_System__out),
- JCGO_STRREF_OF(jcgo_string5_Surface)));
+
+ if (!window) {
+ return;
+ }
+
+ jint* pixel_bytes = (jint*) JCGO_FIELD_NZACCESS(This, pixels);
+ jint area = JCGO_FIELD_NZACCESS(This, width2) * JCGO_FIELD_NZACCESS(This,
+ height2);
+ memcpy(pixel_surface->pixels, pixel_bytes + 5, area * sizeof(jint));
+ SDL_BlitSurface(pixel_surface, NULL, screen, NULL);
+ SDL_UpdateWindowSurface(window);
}
}

View File

@ -1,130 +1,80 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class ClientStream extends Packet {
private InputStream instream;
private OutputStream outstream;
private Socket socket;
private boolean closing;
private byte buffer[];
private int endoffset;
private int offset;
private boolean closed;
public ClientStream(Socket socket, GameShell applet) throws IOException {
public ClientStream(GameShell applet) throws IOException {
closing = false;
closed = true;
this.socket = socket;
instream = socket.getInputStream();
outstream = socket.getOutputStream();
closed = false;
//applet.startThread(this);
//closed = false;
}
public void closeStream() {
super.closeStream();
closing = true;
try {
if (instream != null)
instream.close();
if (outstream != null)
outstream.close();
if (socket != null)
socket.close();
} catch (IOException Ex) {
System.out.println("Error closing stream");
}
closed = true;
//synchronized (this) {
notify();
//}
buffer = null;
}
public int readStream()
throws IOException {
if (closing)
public int readStream() throws IOException {
if (closing) {
return 0;
else
return instream.read();
}
return 12345678;
//return instream.read();
}
public int availableStream()
throws IOException {
if (closing)
public int availableStream() throws IOException {
if (closing) {
return 0;
else
return instream.available();
}
return 12345678;
}
public void readStreamBytes(int len, int off, byte buff[])
throws IOException {
if (closing)
public void readStreamBytes(int len, int off, byte buff[]) throws IOException {
if (closing) {
return;
}
/*
int k = 0;
boolean flag = false;
int l;
for (; k < len; k += l)
if ((l = instream.read(buff, k + off, len - k)) <= 0)
throw new IOException("EOF");
*/
System.out.println("readStreamBytes");
throw new IOException("EOF");
}
public void writeStreamBytes(byte buff[], int off, int len)
throws IOException {
if (closing)
public void writeStreamBytes(byte buff[], int off, int len) throws IOException {
if (closing) {
return;
if (buffer == null)
buffer = new byte[5000];
//synchronized (this) {
for (int l = 0; l < len; l++) {
buffer[offset] = buff[l + off];
offset = (offset + 1) % 5000;
if (offset == (endoffset + 4900) % 5000)
throw new IOException("buffer overflow");
}
notify();
//}
}
public void run() {
while (!closed) {
int len;
int off;
//synchronized (this) {
if (offset == endoffset)
try {
wait();
} catch (InterruptedException Ex) {
}
if (closed)
return;
off = endoffset;
if (offset >= endoffset)
len = offset - endoffset;
else
len = 5000 - endoffset;
//}
if (len > 0) {
try {
outstream.write(buffer, off, len);
} catch (IOException ioexception) {
super.socketException = true;
super.socketExceptionMessage = "Twriter:" + ioexception;
}
endoffset = (endoffset + len) % 5000;
try {
if (offset == endoffset)
outstream.flush();
} catch (IOException ioexception1) {
super.socketException = true;
super.socketExceptionMessage = "Twriter:" + ioexception1;
}
}
}
if (buffer == null) {
buffer = new byte[5000];
}
System.out.println("writeStreamBytes");
throw new IOException("buffer overflow");
/*
for (int l = 0; l < len; l++) {
buffer[offset] = buff[l + off];
offset = (offset + 1) % 5000;
if (offset == (endoffset + 4900) % 5000) {
throw new IOException("buffer overflow");
}
}*/
}
}

View File

@ -47,10 +47,12 @@ public class GameConnection extends GameShell {
protected void login(String u, String p, boolean reconnecting) {
if (worldFullTimeout > 0) {
showLoginScreenStatus("Please wait...", "Connecting to server");
System.out.println(51339 + 2000);
/*
try {
Thread.sleep(2000L);
} catch (Exception Ex) {
}
}*/
showLoginScreenStatus("Sorry! The server is currently full.", "Please try again later");
return;
}
@ -67,7 +69,7 @@ public class GameConnection extends GameShell {
drawTextBox("Connection lost! Please wait...", "Attempting to re-establish");
else
showLoginScreenStatus("Please wait...", "Connecting to server");
clientStream = new ClientStream(createSocket(server, port), this);
clientStream = new ClientStream(/*createSocket(server, port),*/this);
clientStream.maxReadTries = maxReadTries;
long l = Utility.username2hash(u);
clientStream.newPacket((Command.CL_SESSION));
@ -241,14 +243,18 @@ public class GameConnection extends GameShell {
} catch (Exception exception) {
System.out.println(String.valueOf(exception));
}
if (autoLoginTimeout > 0) {
/*
try {
Thread.sleep(5000L);
} catch (Exception Ex) {
}
}*/
System.out.println(51339 + 5000);
autoLoginTimeout--;
login(username, password, reconnecting);
}
if (reconnecting) {
username = "";
password = "";

View File

@ -252,10 +252,14 @@ public class GameShell {
public void destroy() {
stopTimeout = -1;
/*
try {
Thread.sleep(5000L);
} catch (Exception ignored) {
}
}*/
System.out.println(51339 + 5000);
if (stopTimeout == -1) {
System.out.println("5 seconds expired, forcing kill");
@ -268,10 +272,13 @@ public class GameShell {
System.out.println("Closing program");
onClosing();
System.out.println(51339 + 1000);
/*
try {
Thread.sleep(1000L);
} catch (Exception ignored) {
}
}*/
System.exit(0);
}
@ -322,10 +329,12 @@ public class GameShell {
if (sleep < threadSleep)
sleep = threadSleep;
}
/*
try {
Thread.sleep(sleep);
} catch (InterruptedException ignored) {
}
}*/
System.out.println(51339 + sleep);
timings[i] = time;
i = (i + 1) % 10;
if (sleep > 1) {

View File

@ -2,31 +2,12 @@ import java.io.IOException;
public class Packet {
//static char charMap[];
public static int anIntArray537[] = new int[256];
public static int anIntArray541[] = new int[256];
public int readTries;
public int maxReadTries;
public int packetStart;
public byte packetData[];
/*private static int anIntArray521[] = {
0, 1, 3, 7, 15, 31, 63, 127, 255, 511,
1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff,
0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff,
0x3fffffff, 0x7fffffff, -1
};
int anInt522 = 61;
int anInt523 = 59;
int anInt524 = 42;
int anInt525 = 43;
int anInt526 = 44; // index list for charMap
int anInt527 = 45;
int anInt528 = 46;
int anInt529 = 47;
int anInt530 = 92;
int anInt531 = 32;
int anInt532 = 124;
int anInt533 = 34; */
public ISAAC isaacIncoming;
public ISAAC isaacOutgoing;
protected int length;
@ -98,8 +79,7 @@ public class Packet {
return 0;
}
public void readStreamBytes(int i, int j, byte abyte0[])
throws IOException {
public void readStreamBytes(int i, int j, byte abyte0[]) throws IOException {
}
public boolean hasPacket() {
@ -242,25 +222,4 @@ public class Packet {
sendPacket();
writePacket(0);
}
// public static int anInt543;
/*static
{
charMap = new char[256];
for(int i = 0; i < 256; i++)
charMap[i] = (char)i;
charMap[61] = '=';
charMap[59] = ';';
charMap[42] = '*';
charMap[43] = '+';
charMap[44] = ',';
charMap[45] = '-';
charMap[46] = '.';
charMap[47] = '/';
charMap[92] = '\\';
charMap[124] = '|';
charMap[33] = '!';
charMap[34] = '"';
} */
}