|
1 | 1 | import { logger } from '@runejs/core';
|
2 | 2 | import { ByteBuffer } from '@runejs/core/buffer';
|
3 | 3 | import { openServer, SocketConnectionHandler, parseServerConfig } from '@runejs/core/net';
|
4 |
| -import { Filestore, readDataChunk, readIndexedDataChunk } from '@runejs/filestore'; |
| 4 | +import { Filestore, readIndexedDataChunk } from '@runejs/filestore'; |
5 | 5 | import { Socket } from 'net';
|
6 | 6 | import * as CRC32 from 'crc-32';
|
7 | 7 |
|
@@ -50,9 +50,9 @@ class UpdateServerConnection extends SocketConnectionHandler {
|
50 | 50 | break;
|
51 | 51 | case ConnectionStage.ACTIVE:
|
52 | 52 | while(buffer.readable >= 4) {
|
53 |
| - const type = buffer.get('BYTE', 'UNSIGNED'); |
54 |
| - const index = buffer.get('BYTE', 'UNSIGNED'); |
55 |
| - const file = buffer.get('SHORT', 'UNSIGNED'); |
| 53 | + const type = buffer.get('byte', 'u'); |
| 54 | + const index = buffer.get('byte', 'u'); |
| 55 | + const file = buffer.get('short', 'u'); |
56 | 56 |
|
57 | 57 | switch(type) {
|
58 | 58 | case 0: // queue
|
@@ -86,13 +86,17 @@ class UpdateServerConnection extends SocketConnectionHandler {
|
86 | 86 | }
|
87 | 87 |
|
88 | 88 | private generateFile(index: number, file: number): Buffer {
|
89 |
| - let cacheFile: ByteBuffer | any; // @todo remove any when cache parser is using @runejs/core |
90 |
| - |
91 |
| - if(index === 255 && file === 255) { |
92 |
| - cacheFile = new ByteBuffer(this.updateServer.crcTable.length); |
93 |
| - this.updateServer.crcTable.copy(cacheFile, 0, 0); |
94 |
| - } else { |
95 |
| - cacheFile = this.updateServer.filestore.getIndex(index)?.getFile(file)?.content; |
| 89 | + let cacheFile: ByteBuffer; |
| 90 | + |
| 91 | + try { |
| 92 | + if(index === 255 && file === 255) { |
| 93 | + cacheFile = new ByteBuffer(this.updateServer.crcTable.length); |
| 94 | + this.updateServer.crcTable.copy(cacheFile, 0, 0); |
| 95 | + } else { |
| 96 | + cacheFile = readIndexedDataChunk(file, index, this.updateServer.filestore.channels).dataFile; |
| 97 | + } |
| 98 | + } catch(error) { |
| 99 | + logger.warn(`Unable to load filestore file for update server request`, index, file); |
96 | 100 | }
|
97 | 101 |
|
98 | 102 | if(!cacheFile || cacheFile.length === 0) {
|
|
0 commit comments