mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Cache server CRCs
This commit is contained in:
@@ -7,6 +7,7 @@ import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -24,6 +25,11 @@ public final class IndexedFileSystem implements Closeable {
|
||||
*/
|
||||
private ByteBuffer crcTable;
|
||||
|
||||
/**
|
||||
* The {@link #crcTable} represented as an {@code int} array.
|
||||
*/
|
||||
private int[] crcs;
|
||||
|
||||
/**
|
||||
* The data file.
|
||||
*/
|
||||
@@ -143,6 +149,22 @@ public final class IndexedFileSystem implements Closeable {
|
||||
throw new IllegalStateException("Cannot get CRC table from a writable file system.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CRC table as an {@code int} array.
|
||||
*
|
||||
* @return The CRC table as an {@code int} array.
|
||||
* @throws IOException If there is an error accessing files to create the table.
|
||||
*/
|
||||
public int[] getCrcs() throws IOException {
|
||||
if (crcs != null) {
|
||||
return crcs;
|
||||
}
|
||||
|
||||
ByteBuffer buffer = getCrcTable();
|
||||
Arrays.setAll(crcs, crc -> buffer.getInt());
|
||||
return crcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a file.
|
||||
*
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.apollo.login;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -120,12 +119,8 @@ public final class LoginService extends Service {
|
||||
return true;
|
||||
}
|
||||
|
||||
ByteBuffer buffer = getContext().getFileSystem().getCrcTable();
|
||||
|
||||
int[] clientCrcs = request.getArchiveCrcs();
|
||||
int[] serverCrcs = new int[clientCrcs.length];
|
||||
|
||||
Arrays.setAll(serverCrcs, crc -> buffer.getInt());
|
||||
int[] serverCrcs = getContext().getFileSystem().getCrcs();
|
||||
|
||||
if (Arrays.equals(clientCrcs, serverCrcs)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user