Connection & GameFrame

This commit is contained in:
thedaneeffect committed 2021-04-26 16:38:40 -04:00
1 parent 52ffdc89c9
commit cc9ff929b2
4 files changed
+720 -808

No files matched your search

+142 -142
View File
@@ -9,155 +9,155 @@ import java.net.Socket;
public class Connection implements Runnable {
public final Socket aSocket421;
public final GameShell anShell_423;
public InputStream anInputStream419;
public OutputStream anOutputStream420;
public boolean closed = false;
public byte[] aByteArray424;
public int anInt425;
public int anInt426;
public boolean aBoolean427 = false;
public boolean aBoolean428 = false;
public final Socket socket;
public final GameShell shell;
public InputStream in;
public OutputStream out;
public boolean closed = false;
public byte[] buf;
public int tcycl;
public int tnum;
public boolean writer = false;
public boolean ioerror = false;
public Connection(GameShell shell, Socket socket) throws IOException {
anShell_423 = shell;
aSocket421 = socket;
aSocket421.setSoTimeout(30000);
aSocket421.setTcpNoDelay(true);
anInputStream419 = aSocket421.getInputStream();
anOutputStream420 = aSocket421.getOutputStream();
}
public Connection(GameShell shell, Socket socket) throws IOException {
this.shell = shell;
this.socket = socket;
this.socket.setSoTimeout(30000);
this.socket.setTcpNoDelay(true);
in = this.socket.getInputStream();
out = this.socket.getOutputStream();
}
public void method267() {
closed = true;
try {
if (anInputStream419 != null) {
anInputStream419.close();
}
if (anOutputStream420 != null) {
anOutputStream420.close();
}
if (aSocket421 != null) {
aSocket421.close();
}
} catch (IOException _ex) {
System.out.println("Error closing stream");
}
aBoolean427 = false;
synchronized (this) {
notify();
}
aByteArray424 = null;
}
public void close() {
closed = true;
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
if (socket != null) {
socket.close();
}
} catch (IOException _ex) {
System.out.println("Error closing stream");
}
writer = false;
synchronized (this) {
notify();
}
buf = null;
}
public int method268() throws IOException {
if (closed) {
return 0;
} else {
return anInputStream419.read();
}
}
public int read() throws IOException {
if (closed) {
return 0;
} else {
return in.read();
}
}
public int available() throws IOException {
if (closed) {
return 0;
} else {
return anInputStream419.available();
}
}
public int available() throws IOException {
if (closed) {
return 0;
} else {
return in.available();
}
}
public void method270(byte[] abyte0, int i, int j) throws IOException {
if (closed) {
return;
}
int k;
for (; j > 0; j -= k) {
k = anInputStream419.read(abyte0, i, j);
if (k <= 0) {
throw new IOException("EOF");
}
i += k;
}
}
public void read(byte[] dst, int off, int len) throws IOException {
if (closed) {
return;
}
int k;
for (; len > 0; len -= k) {
k = in.read(dst, off, len);
if (k <= 0) {
throw new IOException("EOF");
}
off += k;
}
}
public void method271(int i, byte[] abyte0, int k) throws IOException {
if (closed) {
return;
}
if (aBoolean428) {
aBoolean428 = false;
throw new IOException("Error in writer thread");
}
if (aByteArray424 == null) {
aByteArray424 = new byte[5000];
}
synchronized (this) {
for (int l = 0; l < i; l++) {
aByteArray424[anInt426] = abyte0[l + k];
anInt426 = (anInt426 + 1) % 5000;
if (anInt426 == ((anInt425 + 4900) % 5000)) {
throw new IOException("buffer overflow");
}
}
if (!aBoolean427) {
aBoolean427 = true;
anShell_423.startThread(this, 3);
}
notify();
}
}
public void write(byte[] src, int off, int len) throws IOException {
if (closed) {
return;
}
if (ioerror) {
ioerror = false;
throw new IOException("Error in writer thread");
}
if (buf == null) {
buf = new byte[5000];
}
synchronized (this) {
for (int i = 0; i < len; i++) {
buf[tnum] = src[i + off];
tnum = (tnum + 1) % 5000;
if (tnum == ((tcycl + 4900) % 5000)) {
throw new IOException("buffer overflow");
}
}
if (!writer) {
writer = true;
shell.startThread(this, 3);
}
notify();
}
}
@Override
public void run() {
while (aBoolean427) {
int i;
int j;
synchronized (this) {
if (anInt426 == anInt425) {
try {
wait();
} catch (InterruptedException ignored) {
}
}
if (!aBoolean427) {
return;
}
j = anInt425;
if (anInt426 >= anInt425) {
i = anInt426 - anInt425;
} else {
i = 5000 - anInt425;
}
}
if (i > 0) {
try {
anOutputStream420.write(aByteArray424, j, i);
} catch (IOException _ex) {
aBoolean428 = true;
}
anInt425 = (anInt425 + i) % 5000;
try {
if (anInt426 == anInt425) {
anOutputStream420.flush();
}
} catch (IOException _ex) {
aBoolean428 = true;
}
}
}
}
@Override
public void run() {
while (writer) {
int i;
int j;
synchronized (this) {
if (tnum == tcycl) {
try {
wait();
} catch (InterruptedException ignored) {
}
}
if (!writer) {
return;
}
j = tcycl;
if (tnum >= tcycl) {
i = tnum - tcycl;
} else {
i = 5000 - tcycl;
}
}
if (i > 0) {
try {
out.write(buf, j, i);
} catch (IOException _ex) {
ioerror = true;
}
tcycl = (tcycl + i) % 5000;
try {
if (tnum == tcycl) {
out.flush();
}
} catch (IOException _ex) {
ioerror = true;
}
}
}
}
public void method272() {
System.out.println("closed:" + closed);
System.out.println("tcycl:" + anInt425);
System.out.println("tnum:" + anInt426);
System.out.println("writer:" + aBoolean427);
System.out.println("ioerror:" + aBoolean428);
try {
System.out.println("available:" + available());
} catch (IOException ignored) {
}
}
public void debug() {
System.out.println("closed:" + closed);
System.out.println("tcycl:" + tcycl);
System.out.println("tnum:" + tnum);
System.out.println("writer:" + writer);
System.out.println("ioerror:" + ioerror);
try {
System.out.println("available:" + available());
} catch (IOException ignored) {
}
}
}
+58 -107
View File
@@ -4,7 +4,6 @@
import org.apache.commons.math3.random.ISAACRandom;
import java.applet.AppletContext;
import java.awt.*;
import java.io.DataInputStream;
import java.io.EOFException;
@@ -576,21 +575,6 @@ public class Game extends GameShell {
public Game() {
}
@Override
public void init() {
nodeId = Integer.parseInt(getParameter("nodeid"));
portOffset = Integer.parseInt(getParameter("portoff"));
String s = getParameter("lowmem");
if ((s != null) && s.equals("1")) {
setLowmem();
} else {
setHighmem();
}
String s1 = getParameter("free");
members = (s1 == null) || !s1.equals("1");
initApplet(765, 503);
}
@Override
public void run() {
if (aBoolean880) {
@@ -600,25 +584,16 @@ public class Game extends GameShell {
}
}
@Override
public AppletContext getAppletContext() {
return super.getAppletContext();
}
@Override
public URL getCodeBase() {
try {
if (super.frame != null) {
return new URL("http://127.0.0.1:" + (80 + portOffset));
}
return new URL("http://lucas.xenorune.com:" + (80 + portOffset));
} catch (Exception ignored) {
}
return super.getCodeBase();
return null;
}
@Override
public String getParameter(String s) {
return super.getParameter(s);
throw new UnsupportedOperationException();
}
@Override
@@ -921,31 +896,31 @@ public class Game extends GameShell {
aImageArray1219[l4] = new Image8(archiveMedia, "mod_icons", l4);
}
Image24 image = new Image24(archiveMedia, "backleft1", 0);
aArea_903 = new DrawArea(image.width, image.height, getComponent());
aArea_903 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backleft2", 0);
aArea_904 = new DrawArea(image.width, image.height, getComponent());
aArea_904 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backright1", 0);
aArea_905 = new DrawArea(image.width, image.height, getComponent());
aArea_905 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backright2", 0);
aArea_906 = new DrawArea(image.width, image.height, getComponent());
aArea_906 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backtop1", 0);
aArea_907 = new DrawArea(image.width, image.height, getComponent());
aArea_907 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backvmid1", 0);
aArea_908 = new DrawArea(image.width, image.height, getComponent());
aArea_908 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backvmid2", 0);
aArea_909 = new DrawArea(image.width, image.height, getComponent());
aArea_909 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backvmid3", 0);
aArea_910 = new DrawArea(image.width, image.height, getComponent());
aArea_910 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
image = new Image24(archiveMedia, "backhmid2", 0);
aArea_911 = new DrawArea(image.width, image.height, getComponent());
aArea_911 = new DrawArea(image.width, image.height, this);
image.blitOpaque(0, 0);
int i5 = (int) (Math.random() * 21D) - 10;
int j5 = (int) (Math.random() * 21D) - 10;
@@ -1068,7 +1043,7 @@ public class Game extends GameShell {
Signlink.reporterror = false;
try {
if (connection != null) {
connection.method267();
connection.close();
}
} catch (Exception ignored) {
}
@@ -1217,18 +1192,6 @@ public class Game extends GameShell {
aBoolean1255 = true;
}
@Override
public java.awt.Component getComponent() {
if (Signlink.mainapp != null) {
return Signlink.mainapp;
}
if (super.frame != null) {
return super.frame;
} else {
return this;
}
}
@Override
public void startThread(Runnable runnable, int priority) {
if (priority > 10) {
@@ -1948,18 +1911,6 @@ public class Game extends GameShell {
public void method28(String s) {
System.out.println(s);
try {
getAppletContext().showDocument(new URL(getCodeBase(), "loaderror_" + s + ".html"));
} catch (Exception exception) {
exception.printStackTrace();
}
//noinspection InfiniteLoopStatement
while (true) {
try {
Thread.sleep(1000L);
} catch (Exception ignored) {
}
}
}
public void handleParentComponentInput(int x, Component parent, int mouseX, int y, int mouseY, int scrollY) {
@@ -2874,7 +2825,7 @@ public class Game extends GameShell {
public void method44() {
try {
if (connection != null) {
connection.method267();
connection.close();
}
} catch (Exception ignored) {
}
@@ -3946,7 +3897,7 @@ public class Game extends GameShell {
}
try {
if ((connection != null) && (aBuffer_1192.position > 0)) {
connection.method271(aBuffer_1192.position, aBuffer_1192.data, 0);
connection.write(aBuffer_1192.data, 0, aBuffer_1192.position);
aBuffer_1192.position = 0;
anInt1010 = 0;
}
@@ -3980,23 +3931,23 @@ public class Game extends GameShell {
aArea_1123 = null;
aArea_1124 = null;
aArea_1125 = null;
imageTitle0 = new DrawArea(128, 265, getComponent());
imageTitle0 = new DrawArea(128, 265, this);
Draw2D.clear();
imageTitle1 = new DrawArea(128, 265, getComponent());
imageTitle1 = new DrawArea(128, 265, this);
Draw2D.clear();
imageTitle2 = new DrawArea(509, 171, getComponent());
imageTitle2 = new DrawArea(509, 171, this);
Draw2D.clear();
imageTitle3 = new DrawArea(360, 132, getComponent());
imageTitle3 = new DrawArea(360, 132, this);
Draw2D.clear();
imageTitle4 = new DrawArea(360, 200, getComponent());
imageTitle4 = new DrawArea(360, 200, this);
Draw2D.clear();
imageTitle5 = new DrawArea(202, 238, getComponent());
imageTitle5 = new DrawArea(202, 238, this);
Draw2D.clear();
imageTitle6 = new DrawArea(203, 238, getComponent());
imageTitle6 = new DrawArea(203, 238, this);
Draw2D.clear();
imageTitle7 = new DrawArea(74, 94, getComponent());
imageTitle7 = new DrawArea(74, 94, this);
Draw2D.clear();
imageTitle8 = new DrawArea(75, 94, getComponent());
imageTitle8 = new DrawArea(75, 94, this);
Draw2D.clear();
if (archiveTitle != null) {
createTitleBackground();
@@ -4208,12 +4159,12 @@ public class Game extends GameShell {
Connection connection = this.connection;
ingame = false;
anInt1038 = 0;
method84(aString1173, aString1174, true);
login(aString1173, aString1174, true);
if (!ingame) {
method44();
}
try {
connection.method267();
connection.close();
} catch (Exception ignored) {
}
}
@@ -5202,7 +5153,7 @@ public class Game extends GameShell {
System.out.println("scene-state:" + sceneState);
System.out.println("draw-state:" + method54());
if (connection != null) {
connection.method272();
connection.debug();
}
super.debug = true;
}
@@ -5962,16 +5913,16 @@ public class Game extends GameShell {
imageTitle6 = null;
imageTitle7 = null;
imageTitle8 = null;
areaChatback = new DrawArea(479, 96, getComponent());
aArea_1164 = new DrawArea(172, 156, getComponent());
areaChatback = new DrawArea(479, 96, this);
aArea_1164 = new DrawArea(172, 156, this);
Draw2D.clear();
imageMapback.blit(0, 0);
areaInvback = new DrawArea(190, 261, getComponent());
areaViewport = new DrawArea(512, 334, getComponent());
areaInvback = new DrawArea(190, 261, this);
areaViewport = new DrawArea(512, 334, this);
Draw2D.clear();
aArea_1123 = new DrawArea(496, 50, getComponent());
aArea_1124 = new DrawArea(269, 37, getComponent());
aArea_1125 = new DrawArea(249, 45, getComponent());
aArea_1123 = new DrawArea(496, 50, this);
aArea_1124 = new DrawArea(269, 37, this);
aArea_1125 = new DrawArea(249, 45, this);
aBoolean1255 = true;
}
@@ -6068,27 +6019,27 @@ public class Game extends GameShell {
return (((((src & 0xff00ff) * invAlpha) + ((dst & 0xff00ff) * alpha)) & 0xff00ff00) + ((((src & 0xff00) * invAlpha) + ((dst & 0xff00) * alpha)) & 0xff0000)) >> 8;
}
public void method84(String s, String s1, boolean flag) {
public void login(String username, String password, boolean reconnect) {
try {
if (!flag) {
if (!reconnect) {
aString1266 = "";
aString1267 = "Connecting to server...";
method135(true);
}
connection = new Connection(this, openSocket(43594 + portOffset));
long l = StringUtil.toBase37(s);
long l = StringUtil.toBase37(username);
int i = (int) ((l >> 16) & 31L);
aBuffer_1192.position = 0;
aBuffer_1192.put1(14);
aBuffer_1192.put1(i);
connection.method271(2, aBuffer_1192.data, 0);
connection.write(aBuffer_1192.data, 0, 2);
for (int j = 0; j < 8; j++) {
connection.method268();
connection.read();
}
int k = connection.method268();
int k = connection.read();
int i1 = k;
if (k == 0) {
connection.method270(in.data, 0, 8);
connection.read(in.data, 0, 8);
in.position = 0;
aLong1215 = in.get8();
@@ -6106,11 +6057,11 @@ public class Game extends GameShell {
aBuffer_1192.put4(seed[2]);
aBuffer_1192.put4(seed[3]);
aBuffer_1192.put4(Signlink.uid);
aBuffer_1192.put(s);
aBuffer_1192.put(s1);
aBuffer_1192.put(username);
aBuffer_1192.put(password);
aBuffer_1192.encrypt(RSA_PUBLIC_KEY, RSA_MODULUS);
aBuffer_847.position = 0;
if (flag) {
if (reconnect) {
aBuffer_847.put1(18);
} else {
aBuffer_847.put1(16);
@@ -6128,20 +6079,20 @@ public class Game extends GameShell {
seed[j2] += 50;
}
randomIn = new ISAACRandom(seed);
connection.method271(aBuffer_847.position, aBuffer_847.data, 0);
k = connection.method268();
connection.write(aBuffer_847.data, 0, aBuffer_847.position);
k = connection.read();
}
if (k == 1) {
try {
Thread.sleep(2000L);
} catch (Exception ignored) {
}
method84(s, s1, flag);
login(username, password, reconnect);
return;
}
if (k == 2) {
rights = connection.method268();
aBoolean1205 = connection.method268() == 1;
rights = connection.read();
aBoolean1205 = connection.read() == 1;
aLong1220 = 0L;
anInt1022 = 0;
aMouseRecorder_879.anInt810 = 0;
@@ -6318,7 +6269,7 @@ public class Game extends GameShell {
return;
}
if (k == 21) {
for (int k1 = connection.method268(); k1 >= 0; k1--) {
for (int k1 = connection.read(); k1 >= 0; k1--) {
aString1266 = "You have only just left another world";
aString1267 = "Your profile will be transferred in: " + k1 + " seconds";
method135(true);
@@ -6327,7 +6278,7 @@ public class Game extends GameShell {
} catch (Exception ignored) {
}
}
method84(s, s1, flag);
login(username, password, reconnect);
return;
}
if (k == -1) {
@@ -6338,7 +6289,7 @@ public class Game extends GameShell {
} catch (Exception ignored) {
}
anInt1038++;
method84(s, s1, flag);
login(username, password, reconnect);
} else {
aString1266 = "No response from loginserver";
aString1267 = "Please wait 1 minute and try again.";
@@ -6967,7 +6918,7 @@ public class Game extends GameShell {
}
public void method94() {
Graphics g = getComponent().getGraphics();
Graphics g = this.getGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, 765, 503);
setFrameRate(1);
@@ -9715,7 +9666,7 @@ public class Game extends GameShell {
k1 += 20;
if ((super.mousePressButton == 1) && (super.mousePressX >= (i1 - 75)) && (super.mousePressX <= (i1 + 75)) && (super.mousePressY >= (k1 - 20)) && (super.mousePressY <= (k1 + 20))) {
anInt1038 = 0;
method84(aString1173, aString1174, false);
login(aString1173, aString1174, false);
if (ingame) {
return;
}
@@ -9925,7 +9876,7 @@ public class Game extends GameShell {
}
if (ptype == -1) {
connection.method270(in.data, 0, 1);
connection.read(in.data, 0, 1);
ptype = in.data[0] & 0xff;
if (randomIn != null) {
ptype = (ptype - randomIn.nextInt()) & 0xff;
@@ -9936,7 +9887,7 @@ public class Game extends GameShell {
if (psize == -1) {
if (available > 0) {
connection.method270(in.data, 0, 1);
connection.read(in.data, 0, 1);
psize = in.data[0] & 0xff;
available--;
} else {
@@ -9946,7 +9897,7 @@ public class Game extends GameShell {
if (psize == -2) {
if (available > 1) {
connection.method270(in.data, 0, 2);
connection.read(in.data, 0, 2);
in.position = 0;
psize = in.get2U();
available -= 2;
@@ -9960,7 +9911,7 @@ public class Game extends GameShell {
}
in.position = 0;
connection.method270(in.data, 0, psize);
connection.read(in.data, 0, psize);
anInt1009 = 0;
anInt843 = anInt842;
anInt842 = anInt841;
+9 -22
View File
@@ -2,36 +2,23 @@
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
import javax.swing.*;
import java.awt.*;
public class GameFrame extends Frame {
public class GameFrame extends JFrame {
public final GameShell shell;
public GameFrame(GameShell shell, int width, int height) {
public GameFrame(GameShell shell) {
this.shell = shell;
setTitle("Jagex");
setResizable(false);
show();
toFront();
resize(width + 8, height + 28);
}
@Override
public Graphics getGraphics() {
Graphics g = super.getGraphics();
g.translate(4, 24);
return g;
}
@Override
public void update(Graphics g) {
shell.update(g);
}
@Override
public void paint(Graphics g) {
shell.paint(g);
setLayout(new BorderLayout());
add(shell,BorderLayout.CENTER);
pack();
setLocationRelativeTo(null);
setVisible(true);
transferFocus();
}
}
File diff suppressed because it is too large. Load diff