Skip to content

Commit b16aec4

Browse files
authored
Merge pull request #200 from runejs/refactor/update-server
refactor: refactoring around update server
2 parents 208dc65 + 24b62e1 commit b16aec4

File tree

13 files changed

+311
-211
lines changed

13 files changed

+311
-211
lines changed

src/main/java/org/runejs/client/Class60.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.runejs.client.language.Native;
1313
import org.runejs.client.media.Rasterizer;
1414
import org.runejs.client.media.VertexNormal;
15-
import org.runejs.client.net.UpdateServer;
1615
import org.runejs.client.sound.MusicSystem;
1716
import org.runejs.Configuration;
1817
import org.runejs.client.util.BitUtils;
@@ -542,7 +541,7 @@ public static void renderLoginScreen(Component arg0, CacheArchive huffmanCacheAr
542541
MusicSystem.method412(false, CacheArchive.musicCacheArchive, 0, Native.titleSong, 10, "", MusicSystem.musicVolume);
543542
else
544543
MusicSystem.method405(10);
545-
UpdateServer.resetUpdateServerRequests(false);
544+
Game.updateServer.resetRequests(false);
546545
MovedStatics.clearScreen = true;
547546
MovedStatics.aBoolean512 = true;
548547
}

src/main/java/org/runejs/client/ClientScriptRunner.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static void parseClientScriptPacket(Signlink signlink, Buffer buffer) {
146146
}
147147
clientScriptRunner.opcodes[i] = opcode;
148148
clientScriptRunner.values[i] = val;
149-
clientScriptRunner.valueNodes[i] = signlink.createType10Node(stringToType(typeString), valName);
149+
clientScriptRunner.valueNodes[i] = signlink.putFieldNode(stringToType(typeString), valName);
150150
} else if(opcode == 3 || opcode == 4) {
151151
String typeString = new String(buffer.getRSString().method80());
152152
String functionName = new String(buffer.getRSString().method80());
@@ -169,7 +169,7 @@ public static void parseClientScriptPacket(Signlink signlink, Buffer buffer) {
169169
argTypes[j] = stringToType(argNames[j]);
170170
}
171171

172-
clientScriptRunner.functionNodes[i] = signlink.method386(argTypes, functionName, stringToType(typeString));
172+
clientScriptRunner.functionNodes[i] = signlink.putMethodNode(argTypes, functionName, stringToType(typeString));
173173
clientScriptRunner.argumentValues[i] = argValueData;
174174
}
175175
} catch(ClassNotFoundException classnotfoundexception) {
@@ -199,15 +199,15 @@ public static void createClientScriptCheckPacket(int packetId, PacketBuffer buff
199199

200200
for(int i = 0; clientScriptRunner.scriptCount > i; i++) {
201201
if(clientScriptRunner.valueNodes[i] != null) {
202-
if(clientScriptRunner.valueNodes[i].status == 2)
202+
if(clientScriptRunner.valueNodes[i].status == SignlinkNode.Status.ERRORED)
203203
clientScriptRunner.errorCodes[i] = -5;
204-
if(clientScriptRunner.valueNodes[i].status == 0)
204+
if(clientScriptRunner.valueNodes[i].status == SignlinkNode.Status.NOT_INITIALIZED)
205205
bool = true;
206206
}
207207
if(clientScriptRunner.functionNodes[i] != null) {
208-
if(clientScriptRunner.functionNodes[i].status == 2)
208+
if(clientScriptRunner.functionNodes[i].status == SignlinkNode.Status.ERRORED)
209209
clientScriptRunner.errorCodes[i] = -6;
210-
if(clientScriptRunner.functionNodes[i].status == 0)
210+
if(clientScriptRunner.functionNodes[i].status == SignlinkNode.Status.NOT_INITIALIZED)
211211
bool = true;
212212
}
213213
}

src/main/java/org/runejs/client/Game.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public class Game {
7676
*/
7777
public static final CutsceneCamera cutsceneCamera = new CutsceneCamera();
7878

79+
/**
80+
* TODO use interface
81+
*/
82+
public static final UpdateServer updateServer = new UpdateServer();
83+
7984
public static FriendList friendList;
8085

8186
public static final SocialList ignoreList = new SocialList(100);
@@ -90,7 +95,7 @@ public class Game {
9095
public static int modewhere = 0;
9196
public static long lastClickTime = 0L;
9297
public static int mouseInvInterfaceIndex = 0;
93-
public static int anInt509 = 0;
98+
public static int updateServerConnectAttemptCounter = 0;
9499
public static boolean aBoolean519 = true;
95100
public static MouseCapturer mouseCapturer;
96101
public static int anInt2591 = 0;
@@ -110,7 +115,7 @@ public class Game {
110115
public static int connectionStage = 0;
111116
public static int anInt292 = 0;
112117
public static boolean accountFlagged = false;
113-
public static long aLong1841;
118+
public static long updateServerHandshakeSentAtMs;
114119
public static int clientVersion;
115120
public static int playerRights = 0;
116121
public static Timer gameTimer;
@@ -871,7 +876,7 @@ public static void method353() {
871876
}
872877

873878

874-
if(aBoolean519 && UpdateServer.getActiveCount(false, true) == 0) {
879+
if(aBoolean519 && updateServer.getActiveTaskCount(false, true) == 0) {
875880
aBoolean519 = false;
876881
}
877882
if(aBoolean519) {
@@ -1596,12 +1601,12 @@ public static void handleLoginScreenActions() {
15961601
}
15971602
if (loginStatus == 1) { // Create connection to server, and wait for it to become available
15981603
if (MovedStatics.gameServerSignlinkNode == null) {
1599-
MovedStatics.gameServerSignlinkNode = signlink.createSocketNode(currentPort);
1604+
MovedStatics.gameServerSignlinkNode = signlink.putSocketNode(currentPort);
16001605
}
1601-
if (MovedStatics.gameServerSignlinkNode.status == 2) {
1606+
if (MovedStatics.gameServerSignlinkNode.status == SignlinkNode.Status.ERRORED) {
16021607
throw new IOException();
16031608
}
1604-
if (MovedStatics.gameServerSignlinkNode.status == 1) {
1609+
if (MovedStatics.gameServerSignlinkNode.status == SignlinkNode.Status.INITIALIZED) {
16051610
MovedStatics.gameServerSocket = new GameSocket((Socket) MovedStatics.gameServerSignlinkNode.value, signlink);
16061611
loginStatus = 2;
16071612
MovedStatics.gameServerSignlinkNode = null;
@@ -2137,16 +2142,16 @@ public void method35(int arg1) {
21372142
if (anInt292 >= 4) {
21382143
if (gameStatusCode <= 5) {
21392144
this.openErrorPage("js5connect");
2140-
anInt509 = 3000;
2145+
updateServerConnectAttemptCounter = 3000;
21412146
} else
2142-
anInt509 = 3000;
2147+
updateServerConnectAttemptCounter = 3000;
21432148
}
21442149
} else {
21452150
this.openErrorPage("js5connect_outofdate");
21462151
gameStatusCode = 1000;
21472152
}
21482153
} else if (gameStatusCode > 5)
2149-
anInt509 = 3000;
2154+
updateServerConnectAttemptCounter = 3000;
21502155
else {
21512156
this.openErrorPage("js5connect_full");
21522157
gameStatusCode = 1000;
@@ -2189,7 +2194,7 @@ public void processGameLoop() {
21892194

21902195
public void handleUpdateServer() {
21912196
if (gameStatusCode != 1000) {
2192-
boolean bool = UpdateServer.processUpdateServerResponse();
2197+
boolean bool = updateServer.poll();
21932198
if (!bool)
21942199
connectUpdateServer();
21952200
}
@@ -2238,33 +2243,33 @@ else if (gameStatusCode == 5) {
22382243
}
22392244

22402245
public void connectUpdateServer() {
2241-
if (UpdateServer.crcMismatches >= 4) {
2246+
if (updateServer.crcMismatchesCount >= 4) {
22422247
this.openErrorPage("js5crc");
22432248
gameStatusCode = 1000;
22442249
} else {
2245-
if (UpdateServer.ioExceptions >= 4) {
2250+
if (updateServer.ioExceptionsCount >= 4) {
22462251
if (gameStatusCode > 5) {
2247-
UpdateServer.ioExceptions = 3;
2248-
anInt509 = 3000;
2252+
updateServer.ioExceptionsCount = 3;
2253+
updateServerConnectAttemptCounter = 3000;
22492254
} else {
22502255
this.openErrorPage("js5io");
22512256
gameStatusCode = 1000;
22522257
return;
22532258
}
22542259
}
2255-
if (anInt509-- <= 0) {
2260+
if (updateServerConnectAttemptCounter-- <= 0) {
22562261
do {
22572262
try {
22582263
if (connectionStage == 0) {
2259-
updateServerSignlinkNode = signlink.createSocketNode(currentPort);
2264+
updateServerSignlinkNode = signlink.putSocketNode(currentPort);
22602265
connectionStage++;
22612266
}
22622267
if (connectionStage == 1) {
2263-
if (updateServerSignlinkNode.status == 2) {
2268+
if (updateServerSignlinkNode.status == SignlinkNode.Status.ERRORED) {
22642269
method35(-1);
22652270
break;
22662271
}
2267-
if (updateServerSignlinkNode.status == 1)
2272+
if (updateServerSignlinkNode.status == SignlinkNode.Status.INITIALIZED)
22682273
connectionStage++;
22692274
}
22702275
if (connectionStage == 2) {
@@ -2274,11 +2279,11 @@ public void connectUpdateServer() {
22742279
buffer.putIntBE(435); // Cache revision
22752280
updateServerSocket.sendDataFromBuffer(5, 0, buffer.buffer);
22762281
connectionStage++;
2277-
aLong1841 = System.currentTimeMillis();
2282+
updateServerHandshakeSentAtMs = System.currentTimeMillis();
22782283
}
22792284
if (connectionStage == 3) {
22802285
if (gameStatusCode > 5 && updateServerSocket.inputStreamAvailable() <= 0) {
2281-
if (System.currentTimeMillis() + -aLong1841 > 30000L) {
2286+
if (System.currentTimeMillis() - updateServerHandshakeSentAtMs > 30000L) {
22822287
method35(-2);
22832288
break;
22842289
}
@@ -2294,7 +2299,7 @@ public void connectUpdateServer() {
22942299
if (connectionStage != 4)
22952300
break;
22962301

2297-
UpdateServer.handleUpdateServerConnection(updateServerSocket, gameStatusCode > 20);
2302+
updateServer.receiveConnection(updateServerSocket, gameStatusCode > 20);
22982303

22992304
updateServerSignlinkNode = null;
23002305
connectionStage = 0;
@@ -2335,7 +2340,7 @@ public void close() {
23352340
method249();
23362341
MusicSystem.syncedStop(false);
23372342
SoundSystem.stop();
2338-
UpdateServer.killUpdateServerSocket();
2343+
updateServer.close();
23392344
method947(-1);
23402345
do {
23412346
try {

src/main/java/org/runejs/client/GameShell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void openClientApplet(String cacheFolder, int cacheIndexes, int fileStore
251251
Insets insets = clientFrame.getInsets();
252252
clientFrame.setSize(insets.right + width + insets.left, insets.bottom + insets.top + height);
253253
MovedStatics.signlink = Game.signlink = new Signlink(true, null, inetAddress, fileStoreId, cacheFolder, cacheIndexes);
254-
Game.signlink.createThreadNode(1, this);
254+
Game.signlink.putThreadNode(1, this);
255255
} catch (Exception exception) {
256256
MovedStatics.printException(null, exception);
257257
}

src/main/java/org/runejs/client/GameSocket.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public void kill() {
5454
}
5555

5656
if (signLinkNode != null) {
57-
while (signLinkNode.status == 0) {
57+
while (signLinkNode.status == SignlinkNode.Status.NOT_INITIALIZED) {
5858
MovedStatics.threadSleep(1L);
5959
}
6060

61-
if (signLinkNode.status == 1) {
61+
if (signLinkNode.status == SignlinkNode.Status.INITIALIZED) {
6262
try {
6363
// Kill the signLinkNode
6464
((Thread) signLinkNode.value).join();
@@ -89,7 +89,7 @@ public void sendDataFromBuffer(int size, int startPos, byte[] data) throws IOExc
8989
throw new IOException();
9090
}
9191
if (signLinkNode == null)
92-
signLinkNode = signLink.createThreadNode(3, this);
92+
signLinkNode = signLink.putThreadNode(3, this);
9393
this.notifyAll();
9494
}
9595
}

src/main/java/org/runejs/client/MovedStatics.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public static void method440() {
387387
Class60.aProducingGraphicsBuffer_463 = null;
388388
Class60.anIntArray1013 = null;
389389
MusicSystem.method405(10);
390-
UpdateServer.resetUpdateServerRequests(true);
390+
Game.updateServer.resetRequests(true);
391391
aBoolean512 = false;
392392
}
393393
}
@@ -492,7 +492,7 @@ public static IndexedImage method538() {
492492
public static void method332(int arg0) {
493493
synchronized (anObject162) {
494494
if (anInt1987 == 0)
495-
Game.signlink.createThreadNode(5, new Class44());
495+
Game.signlink.putThreadNode(5, new Class44());
496496
anInt1987 = arg0;
497497
}
498498
}
@@ -545,10 +545,10 @@ public static void printException(String arg0, Throwable exception) {
545545
string = string.replace('@', '_');
546546
string = string.replace('&', '_');
547547
string = string.replace('#', '_');
548-
SignlinkNode signlinkNode = signlink.addType4Node(new URL(signlink.gameShell.getCodeBase(), "clienterror.ws?c=" + Game.clientVersion + "&u=" + aLong853 + "&v1=" + Signlink.javaVendor + "&v2=" + Signlink.javaVersion + "&e=" + string));
549-
while (signlinkNode.status == 0)
548+
SignlinkNode signlinkNode = signlink.putDataInputStreamNode(new URL(signlink.gameShell.getCodeBase(), "clienterror.ws?c=" + Game.clientVersion + "&u=" + aLong853 + "&v1=" + Signlink.javaVendor + "&v2=" + Signlink.javaVersion + "&e=" + string));
549+
while (signlinkNode.status == SignlinkNode.Status.NOT_INITIALIZED)
550550
threadSleep(1L);
551-
if (signlinkNode.status != 1)
551+
if (signlinkNode.status != SignlinkNode.Status.INITIALIZED)
552552
return;
553553
DataInputStream datainputstream = (DataInputStream) signlinkNode.value;
554554
datainputstream.read();
@@ -3559,7 +3559,7 @@ public static void startup() {
35593559
}
35603560
} else if (loadingPercent == 110) {
35613561
Game.mouseCapturer = new MouseCapturer();
3562-
Game.signlink.createThreadNode(10, Game.mouseCapturer);
3562+
Game.signlink.putThreadNode(10, Game.mouseCapturer);
35633563
Native.currentLoadingText = English.loadedInputHandler;
35643564
loadingPercent = 120;
35653565
anInt1607 = 94;

src/main/java/org/runejs/client/cache/CacheArchive.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.runejs.client.*;
44
import org.runejs.client.cache.bzip.BZip;
55
import org.runejs.client.io.Buffer;
6-
import org.runejs.client.net.UpdateServer;
76
import org.runejs.client.node.Class40_Sub6;
87

98
import java.io.ByteArrayInputStream;
@@ -60,7 +59,7 @@ public CacheArchive(CacheIndex dataIndex, CacheIndex metaIndex, int cacheIndexId
6059
aBoolean1811 = arg5;
6160
this.metaIndex = metaIndex;
6261
this.cacheIndexId = cacheIndexId;
63-
UpdateServer.getArchiveChecksum(this, this.cacheIndexId);
62+
Game.updateServer.requestArchiveChecksum(this, this.cacheIndexId);
6463
}
6564

6665
public static CacheArchive loadArchive(int cacheIndexId, boolean arg1, boolean arg2, boolean arg4) {
@@ -164,7 +163,7 @@ public int getPercentLoaded() {
164163
return 100;
165164
if(aByteArrayArray212 != null)
166165
return 99;
167-
int i = UpdateServer.calculateDataLoaded(255, cacheIndexId);
166+
int i = Game.updateServer.getLoadedPercentage(255, cacheIndexId);
168167
if(i >= 100)
169168
i = 99;
170169
return i;
@@ -176,15 +175,15 @@ public void method198(boolean arg1, byte[] arg2, int arg3, CacheIndex arg4) {
176175
if(aBoolean1800)
177176
throw new RuntimeException();
178177
if(arg2 == null) {
179-
UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0,
178+
Game.updateServer.enqueueFileRequest(true, this, 255, cacheIndexId, (byte) 0,
180179
archiveCrcValue);
181180
return;
182181
}
183182
crc32.reset();
184183
crc32.update(arg2, 0, arg2.length);
185184
int i = (int) crc32.getValue();
186185
if(i != archiveCrcValue) {
187-
UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0,
186+
Game.updateServer.enqueueFileRequest(true, this, 255, cacheIndexId, (byte) 0,
188187
archiveCrcValue);
189188
return;
190189
}
@@ -197,7 +196,7 @@ public void method198(boolean arg1, byte[] arg2, int arg3, CacheIndex arg4) {
197196
if(arg2 == null || arg2.length <= 2) {
198197
aBooleanArray1796[arg3] = false;
199198
if(aBoolean1811 || arg1)
200-
UpdateServer.method327(arg1, this, cacheIndexId, arg3, (byte) 2, anIntArray252[arg3]);
199+
Game.updateServer.enqueueFileRequest(arg1, this, cacheIndexId, arg3, (byte) 2, anIntArray252[arg3]);
201200
return;
202201
}
203202
crc32.reset();
@@ -207,7 +206,7 @@ public void method198(boolean arg1, byte[] arg2, int arg3, CacheIndex arg4) {
207206
if(i != anIntArray252[arg3] || i_0_ != anIntArray224[arg3]) {
208207
aBooleanArray1796[arg3] = false;
209208
if(aBoolean1811 || arg1)
210-
UpdateServer.method327(arg1, this, cacheIndexId, arg3, (byte) 2, anIntArray252[arg3]);
209+
Game.updateServer.enqueueFileRequest(arg1, this, cacheIndexId, arg3, (byte) 2, anIntArray252[arg3]);
211210
return;
212211
}
213212
aBooleanArray1796[arg3] = true;
@@ -220,11 +219,11 @@ public void method177(int arg1) {
220219
if(dataIndex != null && aBooleanArray1796 != null && aBooleanArray1796[arg1])
221220
method602(this, arg1, dataIndex);
222221
else
223-
UpdateServer.method327(true, this, cacheIndexId, arg1, (byte) 2, anIntArray252[arg1]);
222+
Game.updateServer.enqueueFileRequest(true, this, cacheIndexId, arg1, (byte) 2, anIntArray252[arg1]);
224223
}
225224

226225
public void method174(int arg0) {
227-
UpdateServer.method399(cacheIndexId, arg0);
226+
Game.updateServer.moveRequestToPendingQueue(cacheIndexId, arg0);
228227
}
229228

230229
public void method199() {
@@ -249,7 +248,7 @@ public void method199() {
249248
public void requestLatestVersion(int crcValue) {
250249
archiveCrcValue = crcValue;
251250
if(metaIndex == null)
252-
UpdateServer.method327(true, this, 255, cacheIndexId, (byte) 0, archiveCrcValue);
251+
Game.updateServer.enqueueFileRequest(true, this, 255, cacheIndexId, (byte) 0, archiveCrcValue);
253252
else
254253
method602(this, cacheIndexId, metaIndex);
255254
}
@@ -259,7 +258,7 @@ public int method201(int arg0) {
259258
return 100;
260259
if(aBooleanArray1796[arg0])
261260
return 100;
262-
return UpdateServer.calculateDataLoaded(cacheIndexId, arg0);
261+
return Game.updateServer.getLoadedPercentage(cacheIndexId, arg0);
263262
}
264263

265264
public int method202() {

0 commit comments

Comments
 (0)