Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing flat file store loading issues #3

Open
wants to merge 5 commits into
base: feature/dev-store
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/server-config.example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"updateServerHost": "0.0.0.0",
"updateServerPort": 43592,
"storeDir": "../store",
"clientVersion": 435
"storePath": "../store",
"gameVersion": 435
}
3,545 changes: 330 additions & 3,215 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "lib/index.d.ts",
"scripts": {
"build": "rimraf lib && tsc",
"start": "ts-node-dev --max-old-space-size=1024 --respawn src/main.ts",
"start": "ts-node-dev --max-old-space-size=2048 --respawn src/main.ts",
"lint": "eslint --ext .ts src",
"lint:fix": "eslint --ext .ts src --fix",
"package": "rimraf lib && npm i && npm run build && npm publish --dry-run"
Expand All @@ -22,22 +22,22 @@
"author": "Tynarus",
"license": "GPL-3.0",
"dependencies": {
"@runejs/common": "2.0.0-rc.1",
"@runejs/filestore": "file:../filestore",
"crc-32": "^1.2.0",
"@runejs/common": "2.0.0-rc.9",
"@runejs/filestore": "file:../filestore/lib",
"graceful-fs": "^4.2.8",
"source-map-support": "^0.5.19",
"tslib": "^2.2.0"
"tslib": "^2.3.1"
},
"devDependencies": {
"@runejs/eslint-config": "^1.0.0",
"@types/node": "^14.14.37",
"@types/node": "^16.10.5",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"eslint": "^7.32.0",
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"ts-node": "^10.3.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.2.4"
"typescript": "^4.4.4"
},
"eslintConfig": {
"extends": [
Expand Down
9 changes: 2 additions & 7 deletions src/config/update-server-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { ServerConfigOptions } from '@runejs/common/net';
export interface UpdateServerConfig extends ServerConfigOptions {
updateServerHost: string;
updateServerPort: number;
storeDir: string;
clientVersion: number;
storePath: string;
gameVersion: number;
}

export const defaultConfig: Partial<UpdateServerConfig> = {
storeDir: '../store',
clientVersion: 435
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './update-server';
export * from './net/update-server-connection';
export * from './net/file-request';
export { UpdateServerConfig } from './config/update-server-config';
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { logger } from '@runejs/common';
import UpdateServer from './update-server';
import 'source-map-support/register';

import { logger } from '@runejs/common';
import { UpdateServer } from './update-server';


UpdateServer.launch()
.then(() => logger.info(`Ready to accept connections.`))
Expand Down
1 change: 1 addition & 0 deletions src/net/file-request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface FileRequest {
archiveName: string;
archiveIndex: number;
fileIndex: number;
}
28 changes: 16 additions & 12 deletions src/net/update-server-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Socket } from 'net';
import { logger } from '@runejs/common';
import { SocketServer } from '@runejs/common/net';
import { ByteBuffer } from '@runejs/common/buffer';
import UpdateServer from '../update-server';
import { UpdateServer } from '../update-server';
import { FileRequest } from './file-request';


Expand All @@ -22,8 +22,9 @@ export class UpdateServerConnection extends SocketServer {
}

public initialHandshake(buffer: ByteBuffer): boolean {
logger.info(`initialHandshake, readable = ${buffer.readable}`);
const clientVersion: number = buffer.get('int');
const supportedVersion: number = this.updateServer.serverConfig.clientVersion;
const supportedVersion: number = this.updateServer.serverConfig.gameVersion;

const responseCode: number = clientVersion === supportedVersion ? CONNECTION_ACCEPTED : UNSUPPORTED_CLIENT_VERSION;
const success: boolean = responseCode === CONNECTION_ACCEPTED;
Expand All @@ -37,8 +38,8 @@ export class UpdateServerConnection extends SocketServer {
public decodeMessage(buffer: ByteBuffer): void {
while(buffer.readable >= 4) {
const requestMethod = buffer.get('byte', 'u'); // 0, 1, 2, 3, or 4
const indexId = buffer.get('byte', 'u');
const fileId = buffer.get('short', 'u');
const archiveIndex = buffer.get('byte', 'u');
const fileIndex = buffer.get('short', 'u');

if(requestMethod >= 4) {
// error
Expand All @@ -51,7 +52,9 @@ export class UpdateServerConnection extends SocketServer {
break;
}

const fileRequest: FileRequest = { archiveIndex: indexId, fileIndex: fileId };
const fileRequest: FileRequest = {
archiveIndex, fileIndex,
archiveName: this.updateServer.fileStore.getArchive(String(archiveIndex)).name };

if(requestMethod === 1) {
try {
Expand Down Expand Up @@ -95,13 +98,14 @@ export class UpdateServerConnection extends SocketServer {

const requestedFile = this.updateServer.handleFileRequest(fileRequest);

if(requestedFile) {
this.socket.write(requestedFile);
} else {
throw new Error(`File ${fileRequest.fileIndex} in index ${fileRequest.archiveIndex} is missing.`);
// ^^^ this should have already been logged up the chain, no need to do it again here
// ^^^ just leaving for reference while testing
// this.socket.write(this.generateEmptyFile(indexId, fileId));
if(this.socket && !this.socket.destroyed && this.socket.writable) {
if(requestedFile) {
this.socket.write(requestedFile);
} else {
logger.error(`Unable to find file ${fileRequest.fileIndex} in archive ${fileRequest.archiveName}.`);
// this.socket.write(this.generateEmptyFile(fileRequest,
// StoreConfig.archives.get(String(fileRequest.archiveIndex)).versioned ? 0 : undefined));
}
}
}

Expand Down
Loading