Skip to content

Commit

Permalink
add crc checks and remove original cache
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleyrs committed Jul 17, 2024
1 parent 675a2ef commit 5b29523
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 33 deletions.
12 changes: 4 additions & 8 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,8 @@ export abstract class Client extends GameShell {
protected loadArchive = async (filename: string, displayName: string, crc: number, progress: number): Promise<Jagfile> => {
let retry: number = 5;
let data: Int8Array | undefined = await this.db?.cacheload(filename);
if (GameShell.getParameter('world') !== '999') {
if (data && Packet.crc32(data) !== crc) {
data = undefined;
}
if (data && Packet.crc32(data) !== crc) {
data = undefined;
}

if (data) {
Expand Down Expand Up @@ -744,10 +742,8 @@ export abstract class Client extends GameShell {

protected setMidi = async (name: string, crc: number, length: number): Promise<void> => {
let data: Int8Array | undefined = await this.db?.cacheload(name + '.mid');
if (GameShell.getParameter('world') !== '999') {
if (data && crc !== 12345678 && Packet.crc32(data) !== crc) {
data = undefined;
}
if (data && crc !== 12345678 && Packet.crc32(data) !== crc) {
data = undefined;
}

if (!data) {
Expand Down
35 changes: 10 additions & 25 deletions src/js/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,14 @@ class Game extends Client {
await Bzip.load(await (await fetch('bz2.wasm')).arrayBuffer());
this.db = new Database(await Database.openDatabase());

let checksums: Packet;
if (Game.getParameter('world') !== '999') {
const checksums: Packet = new Packet(new Uint8Array(await downloadUrl(`${Client.httpAddress}/crc`)));
for (let i: number = 0; i < 9; i++) {
this.archiveChecksums[i] = checksums.g4;
}
checksums = new Packet(new Uint8Array(await downloadUrl(`${Client.httpAddress}/crc`)));
} else {
const archives: string[] = ['config', 'crc', 'interface', 'media', 'models', 'sounds', 'textures', 'title', 'wordenc'];
try {
const responses: Response[] = await Promise.all(archives.map((url: string): Promise<Response> => fetch(`${Client.clientversion}/archives/${url}`, {cache: 'no-cache'})));
if (responses.some((response: Response): boolean => response.ok === false)) {
throw new Error();
}
const data: ArrayBuffer[] = await Promise.all(responses.map((response: Response): Promise<ArrayBuffer> => response.arrayBuffer()));
for (let i: number = 0; i < data.length; i++) {
await this.db?.cachesave(archives[i], new Int8Array(data[i]));
}
} catch (e) {
console.error(e);
}
checksums = new Packet(new Uint8Array(await downloadUrl('data/pack/client/crc')));
}
for (let i: number = 0; i < 9; i++) {
this.archiveChecksums[i] = checksums.g4;
}

if (!Client.lowMemory) {
Expand Down Expand Up @@ -5055,10 +5044,8 @@ class Game extends Client {
let data: Int8Array | undefined;
if (landCrc !== 0) {
data = await this.db?.cacheload(`m${mapsquareX}_${mapsquareZ}`);
if (Game.getParameter('world') !== '999') {
if (data && Packet.crc32(data) !== landCrc) {
data = undefined;
}
if (data && Packet.crc32(data) !== landCrc) {
data = undefined;
}
if (!data) {
this.sceneState = 0;
Expand All @@ -5072,10 +5059,8 @@ class Game extends Client {
}
if (locCrc !== 0) {
data = await this.db?.cacheload(`l${mapsquareX}_${mapsquareZ}`);
if (Game.getParameter('world') !== '999') {
if (data && Packet.crc32(data) !== locCrc) {
data = undefined;
}
if (data && Packet.crc32(data) !== locCrc) {
data = undefined;
}
if (!data) {
this.sceneState = 0;
Expand Down
Empty file.
Binary file removed src/public/225/archives/config
Binary file not shown.
Binary file removed src/public/225/archives/crc
Binary file not shown.
Binary file removed src/public/225/archives/interface
Binary file not shown.
Binary file removed src/public/225/archives/media
Binary file not shown.
Binary file removed src/public/225/archives/models
Binary file not shown.
Binary file removed src/public/225/archives/sounds
Binary file not shown.
Binary file removed src/public/225/archives/textures
Binary file not shown.
Binary file removed src/public/225/archives/title
Binary file not shown.
Binary file removed src/public/225/archives/wordenc
Binary file not shown.
Binary file removed src/public/225/runescape.jar
Binary file not shown.

0 comments on commit 5b29523

Please sign in to comment.