From cf9d977d0882b880dcfd403be956a8c1af3b15b0 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 6 Nov 2018 22:07:09 +0100 Subject: [PATCH] structural changes HConnection & outgoingHandler --- .../java/gearth/protocol/HConnection.java | 47 +++++++++---------- .../main/java/gearth/protocol/HPacket.java | 12 +---- .../packethandler/OutgoingHandler.java | 16 +++++++ 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java index a3c9763..091ed15 100644 --- a/G-Earth/src/main/java/gearth/protocol/HConnection.java +++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java @@ -111,6 +111,7 @@ public class HConnection { private volatile boolean autoDetectHost = false; private volatile String clientHostAndPort = ""; + private volatile String hotelVersion = ""; public State getState() { @@ -249,33 +250,33 @@ public class HConnection { if (DEBUG) System.out.println(habbo_server.getLocalAddress().getHostAddress() + ": " + habbo_server.getLocalPort()); final boolean[] aborted = new boolean[1]; - Rc4Obtainer rc4Obtainer = new Rc4Obtainer(this); + OutgoingHandler outgoingHandler = new OutgoingHandler(habbo_server_out, trafficListeners); + rc4Obtainer.setOutgoingHandler(outgoingHandler); + + IncomingHandler incomingHandler = new IncomingHandler(client_out, trafficListeners); + rc4Obtainer.setIncomingHandler(incomingHandler); + + outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> { + this.hotelVersion = hotelVersion; + incomingHandler.setAsDataStream(); + clientHostAndPort = client.getLocalAddress().getHostAddress() + ":" + client.getPort(); + if (DEBUG) System.out.println(clientHostAndPort); + setState(State.CONNECTED); + onConnect(); + outHandler = outgoingHandler; + inHandler = incomingHandler; + }); + // wachten op data van client new Thread(() -> { try { - OutgoingHandler handler = new OutgoingHandler(habbo_server_out, trafficListeners); - rc4Obtainer.setOutgoingHandler(handler); - while (!client.isClosed() && (state == State.WAITING_FOR_CLIENT || state == State.CONNECTED)) { byte[] buffer; while (client_in.available() > 0) { client_in.read(buffer = new byte[client_in.available()]); - - handler.act(buffer); - if (!datastream[0] && handler.isDataStream()) { - clientHostAndPort = client.getLocalAddress().getHostAddress() + ":" + client.getPort(); - if (DEBUG) System.out.println(clientHostAndPort); - datastream[0] = true; - setState(State.CONNECTED); - onConnect(); - - outHandler = handler; - //client_outputStream = client_out; - //server_outputStream = habbo_server_out; - } - + outgoingHandler.act(buffer); } Thread.sleep(1); @@ -307,18 +308,11 @@ public class HConnection { // wachten op data van server new Thread(() -> { try { - IncomingHandler handler = new IncomingHandler(client_out, trafficListeners); - rc4Obtainer.setIncomingHandler(handler); - while (!habbo_server.isClosed() && (state == State.CONNECTED || state == State.WAITING_FOR_CLIENT)) { byte[] buffer; while (habbo_server_in.available() > 0) { habbo_server_in.read(buffer = new byte[habbo_server_in.available()]); - if (!handler.isDataStream() && datastream[0]) { - handler.setAsDataStream(); - inHandler = handler; - } - handler.act(buffer); + incomingHandler.act(buffer); } Thread.sleep(1); } @@ -434,6 +428,7 @@ public class HConnection { if (state != this.state) { if (state != State.CONNECTED) { clientHostAndPort = ""; + hotelVersion = ""; } State buffer = this.state; diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index 1b87aac..f7a8ed7 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -494,6 +494,7 @@ public class HPacket implements StringifyAble { while (i >= 6) { if (canReadString(i)) { String s = readString(i); + System.out.println(s.contains(oldS)); if (s.contains(oldS) && i + 2 + s.length() <= max) { String replacement = s.replaceAll(oldS, newS); @@ -912,17 +913,6 @@ public class HPacket implements StringifyAble { } public static void main(String[] args) { -// HPacket packet = new HPacket("{l}{u:1442}{i:5}{i:4}{i:80015}{s:goiazdq}{s:samen spelen is tof}{b:false}{i:4}{s:spelletjes spelen}"); -// -// System.out.println(packet.replaceAllSubstrings("spelen", "ownen").replaceAllIntegers(4, 45664868).toExpression()); - - HPacket packet2 = new HPacket("[0][0][10]([14]1[0][0][0][1][0][0][0][155][0][0][0][0][0][0][0][20][0][3]j¸[0][27]Sibyl System - Company News[0][0][0]8b09104s23014s04104s250148dc581e8240be4d7ceaaf11eacdd9bc0[0][0][16]f[0][0][0]ÿ[0][1][91]æ[0][0][0][17][0][1][91]æ[0]ΧO[0][6]Zhepyr[0][0][10]à[0][3]Õ¹[0][12]Bedrijfsblad[0][0][0]8b12114t48234s04234s2511416196f44746ef4f19213efb77da53d95[0][0][1][18][0][0][0]¾[0][0][11]c[0][0][0][12][0][0][11]c[1].D[11][0][10]AlphaRosea[0][2][143]b[0][3][138],[0][18]Imperial Newsflash[0][0][0]>b25114s41044s21044s25044s171109dcddee64fc01679e8792223ff4d9aaa[0][0][2]q[0][0][0]«[0][0]&7[0][0][0]&[0][0]&7[1]*[125]¸[0][6]Xorasy[0][0]&w[0][3]o[139][0][17][91]s[93] Ruilkamer [91]s[93][0][0][0]2b21054t14064s440376457dc68b5359c1d21b3bf6bec2a1b89[0][0]@[21][0][0][0][154][0][0]§Î[0][0][2][7][0][0]§Î[1]-Û¢[0][6]Furnix[0][0][2][31][0][2][141]«[0][28]Defensie Voorlichtingsdienst[0][0][0]>b01064s12117s43114t40014s55111c4408dc36ad72edd8798afd29b00f523[0][0][1][148][0][0][0]l[0][0][7][150][0][0][0][11][0][0][7][150][1]%t[132][0][7]jkaddai[0][0]¿[15][0][3]à^[0][25][91]PA[93] Recruitment Helpdesk[0][0][0]>b08134s02014s19114s95066s850685f0d5a0fa9d247da3b52f707434abee7[0][0][0][7][0][0][0]^[0][0][0]k[0][0][0]k[0][0][0]k[1][22]\u00ADä[0][12]supermooieik[0][0]`Î[0][3]µ[125][0][25][91]A&R[93] Afk / Weggeef [91]A&R[93][0][0][0]8b01114s21014s16174s3604791309a5ddb6265ba42f806c14577e7e4[0][0][0][5][0][0][0]H[0][0][0]&[0][0][0]&[0][0][0]&[0]î[6]Õ[0][5]Ziemy[0][0][30]¡[0][3]#k[0][16]Give-Away - Fans[0][0][0]8b09044s34021s34044s340175320e7b023fe1cf24ac5d63221d1cffd[0][0][0][158][0][0][0];[0][0][14]¿[0][0][0][145][0][0][14]¿[1][24]%[2][0][7]-Rhedyn[0][2][143]#[0][3]á;[0][26]USA: Friends & Supporters.[0][0][0]>b10044s36044s44044t28104s39011005466e044e3ee85d5d3f19b487a471e[0][0][0][4][0][0][0]3[0][0][0][17][0][0][0][17][0][0][0][17][1].[138]·[0][12]Pingponglord[0][5]§[152][0][3]áé[0][16]United Newspaper[0][0][0]>b25114s11174s27014s18114t39114542b32ec5cf1b7b46c1492a842c8db84[0][0][0][6][0][0][0],[0][0][0][8][0][0][0][2][0][0][0][8][1][19]w[18][0][11]horselady54[0][9]®P[0][2]ߨ[0][27]Â¥Maanâ[128][153]s WEGGEEF SPEL! Â¥[0][0][0]>b25114s19094t22130t22112s90098c7264b555fc9e31ebe09245d6dfd55bf[0][0][0]![0][0][0]%[0][0][3]6[0][0][3]6[0][0][3]6[0]x¯U[0][10]!MaAntJah![0][2][144]l[0][3]µ\\[0][24]Vief's AFK Game FastPass[0][0][0]>b17064s03134s01010s26104s990641aae3ad5e5b42ed0f4834f5e81286a6e[0][0][0][8][0][0][0]#[0][0][0]a[0][0][0]G[0][0][0]a[1][28]~ý[0][11]Zinzi.Jewel[0][0]ES[0][2]y¥[0][23]Ministerie van Defensie[0][0][0]>b01064s12117s33114s55111t121146e65aff06b414dcdd0cb1ee875196b06[0][0][0][18][0][0][0]#[0][0][0]9[0][0][0]9[0][0][0]9[1]$á[27][0][11]rienie3011.[4]ø\"e[0][3]â_[0][17]µ AFK GAME µ FP[0][0][0]>b21124s23114s24104s93058s83050d2d4b464249d608190ef2ea72f185ecf[0][0][0][2][0][0][0]\"[0][0][0][31][0][0][0][31][0][0][0][31][1]*[154]_[0][9]:Knoppers[0][4]W¥[0][3]×þ[0][7][91]ST[93] FP[0][0][0]>b01024t57136t57138t57132t571306d625674d548ca13deafce5494690ee7[0][0][0][9][0][0][0][30][0][0][0]L[0][0][0]L[0][0][0]L[1]-[31]ì[0][5]Sam_6[0][3][24]ü[0][3]Y[10][0][31]Â¥Super rare weggeef spelÂ¥ fan[0][0][0]8b22134t47134s44134s161148f04a326436a7effa87df4ae0b9347d1[0][0][0][10][0][0][0][30][0][0][0]X[0][0][0][8][0][0][0]X[1]*g[132][0][11]Magnificant[0][4]F[8][0][3]á[20][0][22]Â¥ FP - AFK Weggeef Â¥[0][0][0]8b27134s29091s44114s110170838dbeadf0710910d9ecb526fb4ce63[0][0][0][6][0][0][0][28][0][0][0]%[0][0][0]%[0][0][0]%[0][6]æ[8][0][5]ricks[0][3]Ý©[0][3]Á[158][0][17]Â¥Bingo WeggeefÂ¥[0][0][0]>b01114s23114s24014s11097s13094a7b12ac9ec084a539a94c876400d01c5[0][0][0][9][0][0][0][26][0][0][1][0][0][0][1][0][0][0][1][0][1][16]Ág[0][11]Marianella-[0][2]æS[0][3][157]¥[0][27]Sollicitatie - Storage Wars[0][0][0]>b05164s23114s21164s43114s2411492ea1401b86bf2876d1d27963e96ba39[0][0][0]Ø[0][0][0][26][0][0][6]P[0][0][6]P[0][0][6]P[1][16]Ág[0][11]Marianella-[0][2]Åò[0][2]ÀY[0][16]--Googlen's fans[0][0][0]8b05134s03083s12097s591142b94aa70f93fb872022c01de7cf33f5e[0][0][0]'[0][0][0][20][0][0][0]Ò[0][0][0]Ò[0][0][0]Ò[1][0]µI[0][9]--Googlen[0][1][128]É"); - - System.out.println(packet2.isCorrupted()); - - packet2.replaceAllSubstrings("Sibyl", "Habbo Inside"); - System.out.println(packet2); - System.out.println(packet2.isCorrupted()); } } \ No newline at end of file diff --git a/G-Earth/src/main/java/gearth/protocol/packethandler/OutgoingHandler.java b/G-Earth/src/main/java/gearth/protocol/packethandler/OutgoingHandler.java index e98d314..ff65bcc 100644 --- a/G-Earth/src/main/java/gearth/protocol/packethandler/OutgoingHandler.java +++ b/G-Earth/src/main/java/gearth/protocol/packethandler/OutgoingHandler.java @@ -5,6 +5,8 @@ import gearth.protocol.HPacket; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; public class OutgoingHandler extends Handler { @@ -12,10 +14,24 @@ public class OutgoingHandler extends Handler { super(outputStream, listeners); } + private List onDatastreamConfirmedListeners = new ArrayList<>(); + public void addOnDatastreamConfirmedListener(OnDatastreamConfirmedListener listener) { + onDatastreamConfirmedListeners.add(listener); + } + public interface OnDatastreamConfirmedListener { + void confirm(String hotelVersion); + } + private void dataStreamCheck(byte[] buffer) { if (!isDataStream) { HPacket hpacket = new HPacket(buffer); isDataStream = (hpacket.getBytesLength() > 6 && hpacket.length() < 100); + if (isDataStream) { + String version = hpacket.readString(); + for (OnDatastreamConfirmedListener listener : onDatastreamConfirmedListeners) { + listener.confirm(version); + } + } } }