Skip to content

Commit 24b62e1

Browse files
committed
refactor: changes from @Promises #201
1 parent 1e008a4 commit 24b62e1

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ public static void method353() {
876876
}
877877

878878

879-
if(aBoolean519 && updateServer.getActiveCount(false, true) == 0) {
879+
if(aBoolean519 && updateServer.getActiveTaskCount(false, true) == 0) {
880880
aBoolean519 = false;
881881
}
882882
if(aBoolean519) {
@@ -2243,13 +2243,13 @@ else if (gameStatusCode == 5) {
22432243
}
22442244

22452245
public void connectUpdateServer() {
2246-
if (updateServer.crcMismatches >= 4) {
2246+
if (updateServer.crcMismatchesCount >= 4) {
22472247
this.openErrorPage("js5crc");
22482248
gameStatusCode = 1000;
22492249
} else {
2250-
if (updateServer.ioExceptions >= 4) {
2250+
if (updateServer.ioExceptionsCount >= 4) {
22512251
if (gameStatusCode > 5) {
2252-
updateServer.ioExceptions = 3;
2252+
updateServer.ioExceptionsCount = 3;
22532253
updateServerConnectAttemptCounter = 3000;
22542254
} else {
22552255
this.openErrorPage("js5io");

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-
Game.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 = Game.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-
Game.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-
Game.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-
Game.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-
Game.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-
Game.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-
Game.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-
Game.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 Game.updateServer.calculateDataLoaded(cacheIndexId, arg0);
261+
return Game.updateServer.getLoadedPercentage(cacheIndexId, arg0);
263262
}
264263

265264
public int method202() {

src/main/java/org/runejs/client/net/IUpdateServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface IUpdateServer {
1414

1515
void close();
1616

17-
int calculateDataLoaded(int volume, int file);
17+
int getLoadedPercentage(int volume, int file);
1818

19-
int getActiveCount(boolean pending, boolean immediate);
19+
int getActiveTaskCount(boolean pending, boolean immediate);
2020
}

src/main/java/org/runejs/client/net/UpdateServer.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import java.util.zip.CRC32;
1111

1212
public class UpdateServer implements IUpdateServer {
13-
public int ioExceptions = 0;
14-
public int crcMismatches = 0;
13+
public int ioExceptionsCount = 0;
14+
public int crcMismatchesCount = 0;
1515

1616
private GameSocket updateServerSocket;
1717
private Buffer fileDataBuffer = new Buffer(8);
@@ -112,7 +112,7 @@ public void receiveConnection(GameSocket socket, boolean isLoggedIn) {
112112
/* empty */
113113
}
114114
updateServerSocket = null;
115-
ioExceptions++;
115+
ioExceptionsCount++;
116116
}
117117
}
118118
msSinceLastUpdate = 0;
@@ -226,12 +226,12 @@ public boolean poll() {
226226
}
227227
encryption = (byte) (int) (Math.random() * 255.0 + 1.0);
228228
updateServerSocket = null;
229-
crcMismatches++;
229+
crcMismatchesCount++;
230230
return false;
231231
}
232232

233-
ioExceptions = 0;
234-
crcMismatches = 0;
233+
ioExceptionsCount = 0;
234+
crcMismatchesCount = 0;
235235
currentResponse.cacheArchive.method196((currentResponse.key & 0xff0000L) == 16711680L, (int) (currentResponse.key & 0xffffL), highPriorityRequest, inboundFile.buffer);
236236
}
237237

@@ -318,14 +318,14 @@ public boolean poll() {
318318
exception.printStackTrace();
319319
}
320320

321-
ioExceptions++;
321+
ioExceptionsCount++;
322322
updateServerSocket = null;
323323

324324
return false;
325325
}
326326
}
327327

328-
public void method327(boolean isPriority, CacheArchive archive, int archiveIndexId, int fileId, byte arg4, int expectedCrc) {
328+
public void enqueueFileRequest(boolean isPriority, CacheArchive archive, int archiveIndexId, int fileId, byte arg4, int expectedCrc) {
329329
long fileKey = fileId + ((long) archiveIndexId << 16);
330330
UpdateServerNode updateServerNode = (UpdateServerNode) highPriorityWriteQueue.getNode(fileKey);
331331

@@ -361,17 +361,20 @@ public void method327(boolean isPriority, CacheArchive archive, int archiveIndex
361361
}
362362
}
363363

364-
public void method399(int arg0, int arg2) {
364+
/**
365+
* TODO suspicious name
366+
*/
367+
public void moveRequestToPendingQueue(int arg0, int arg2) {
365368
long l = (arg0 << 16) + arg2;
366369
UpdateServerNode updateServerNode = (UpdateServerNode) standardPriorityWriteQueue.getNode(l);
367370
if (updateServerNode != null) {
368371
pendingWriteQueue.unshift(updateServerNode);
369372
}
370373
}
371374

372-
public void getArchiveChecksum(CacheArchive cacheArchive, int cacheIndexId) {
375+
public void requestArchiveChecksum(CacheArchive cacheArchive, int cacheIndexId) {
373376
if (crcTableBuffer == null) {
374-
method327(true, null, 255, 255, (byte) 0, 0);
377+
enqueueFileRequest(true, null, 255, 255, (byte) 0, 0);
375378
cacheArchiveLoaders[cacheIndexId] = cacheArchive;
376379
} else {
377380
crcTableBuffer.currentPosition = 5 + cacheIndexId * 4;
@@ -402,7 +405,7 @@ public void resetRequests(boolean loggedIn) {
402405
/* empty */
403406
}
404407
updateServerSocket = null;
405-
ioExceptions++;
408+
ioExceptionsCount++;
406409
}
407410
}
408411

@@ -416,15 +419,15 @@ public void close() {
416419
}
417420

418421
@Override
419-
public int calculateDataLoaded(int volume, int file) {
422+
public int getLoadedPercentage(int volume, int file) {
420423
long l = (long) ((volume << 16) + file);
421424
if (currentResponse == null || currentResponse.key != l)
422425
return 0;
423426
return 1 + inboundFile.currentPosition * 99 / (inboundFile.buffer.length + -currentResponse.padding);
424427
}
425428

426429
@Override
427-
public int getActiveCount(boolean includeStandardPriority, boolean includeHighPriority) {
430+
public int getActiveTaskCount(boolean includeStandardPriority, boolean includeHighPriority) {
428431
int total = 0;
429432
if (includeHighPriority) {
430433
total += highPriorityResponseCount + highPriorityWriteCount;

0 commit comments

Comments
 (0)