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

Update dependencies and migrate to biome #4

Closed
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
35 changes: 35 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"recommended": true,
"noForEach": "off"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
}
5,720 changes: 1,147 additions & 4,573 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 16 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "@runejs/update-server",
"version": "2.0.0-alpha.0",
"version": "2.0.0-alpha.1",
"description": "RuneJS Game Update Server",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "rimraf lib && tsc",
"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",
"lint": "biome lint",
"lint:fix": "biome lint --write",
"format": "biome format",
"format:fix": "biome format --write",
"fin": "npm run lint:fix && npm run format:fix",
"start": "ts-node src/main.ts",
"package": "rimraf lib && npm i && npm run build && npm publish --dry-run"
},
"repository": {
Expand All @@ -22,29 +25,16 @@
"author": "Tynarus",
"license": "GPL-3.0",
"dependencies": {
"@runejs/common": "2.0.0-rc.14",
"@runejs/store": "file:../filestore/lib",
"graceful-fs": "^4.2.8",
"source-map-support": "^0.5.19",
"tslib": "^2.3.1"
"@runejs/common": "2.0.2-beta.3",
"@runejs/store": "file:../rjs-store/lib",
"source-map-support": "^0.5.21",
"tslib": "^2.8.1"
},
"devDependencies": {
"@runejs/eslint-config": "^1.0.0",
"@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": "^10.3.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.4.4"
},
"eslintConfig": {
"extends": [
"@runejs/eslint-config"
],
"parserOptions": {
"project": "./tsconfig.json"
}
"@biomejs/biome": "1.9.4",
"@types/node": "^22.10.7",
"rimraf": "6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
}
}
3 changes: 1 addition & 2 deletions src/config/update-server-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ServerConfigOptions } from '@runejs/common/net';

import type { ServerConfigOptions } from '@runejs/common/net';

export interface UpdateServerConfig extends ServerConfigOptions {
updateServerHost: string;
Expand Down
5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'source-map-support/register';
import { logger } from '@runejs/common';
import { UpdateServer } from './update-server';


UpdateServer.launch()
.then(() => logger.info(`Ready to accept connections.`))
.catch(error => logger.error(`Error launching Update Server.`, error));
.then(() => logger.info('Ready to accept connections.'))
.catch((error) => logger.error('Error launching Update Server.', error));
61 changes: 32 additions & 29 deletions src/net/update-server-connection.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
import { Socket } from 'net';
import type { Socket } from 'node:net';
import { logger } from '@runejs/common';
import { SocketServer } from '@runejs/common/net';
import { ByteBuffer } from '@runejs/common/buffer';
import { UpdateServer } from '../update-server';
import { FileRequest } from './file-request';

import type { ByteBuffer } from '@runejs/common/buffer';
import type { UpdateServer } from '../update-server';
import type { FileRequest } from './file-request';

export const CONNECTION_ACCEPTED = 0;
export const UNSUPPORTED_CLIENT_VERSION = 6;


export class UpdateServerConnection extends SocketServer {

private readonly updateServer: UpdateServer;
private fileRequests: FileRequest[] = [];

public constructor(updateServer: UpdateServer,
gameServerSocket: Socket) {
public constructor(updateServer: UpdateServer, gameServerSocket: Socket) {
super(gameServerSocket);
this.updateServer = updateServer;
}

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

const responseCode: number = clientVersion === supportedVersion ? CONNECTION_ACCEPTED : UNSUPPORTED_CLIENT_VERSION;
const responseCode: number =
clientVersion === supportedVersion
? CONNECTION_ACCEPTED
: UNSUPPORTED_CLIENT_VERSION;
const success: boolean = responseCode === CONNECTION_ACCEPTED;

// send the handshake response to the client
// this.socket.write(Buffer.from([ responseCode ]));
this.socket.write(Buffer.from([ CONNECTION_ACCEPTED ]));
this.socket.write(Buffer.from([CONNECTION_ACCEPTED]));

// return success;
return true;
}

public decodeMessage(buffer: ByteBuffer): void {
while(buffer.readable >= 4) {
while (buffer.readable >= 4) {
const requestMethod = buffer.get('byte', 'u'); // 0, 1, 2, 3, or 4
const archiveIndex = buffer.get('byte', 'u');
const fileIndex = buffer.get('short', 'u');

if(requestMethod >= 4) {
if (requestMethod >= 4) {
// error
return;
}

if(requestMethod >= 2) {
if (requestMethod >= 2) {
// clear queue
this.fileRequests = [];
break;
}

const fileRequest: FileRequest = {
archiveIndex, fileIndex,
archiveName: this.updateServer.fileStore.get(archiveIndex).name };
archiveIndex,
fileIndex,
archiveName: this.updateServer.fileStore.get(archiveIndex).name,
};

if(requestMethod === 1) {
if (requestMethod === 1) {
try {
this.sendFile(fileRequest);
} catch(error) {
} catch (error) {
logger.error(error);
}
} else if(requestMethod === 0) {
} else if (requestMethod === 0) {
this.fileRequests.push(fileRequest);
}
}
Expand All @@ -77,38 +79,39 @@ export class UpdateServerConnection extends SocketServer {
}

protected sendQueuedFiles(): void {
if(!this.fileRequests.length) {
if (!this.fileRequests.length) {
return;
}

const fileRequests = [ ...this.fileRequests ];
const fileRequests = [...this.fileRequests];
this.fileRequests = [];

for(const fileRequest of fileRequests) {
for (const fileRequest of fileRequests) {
try {
this.sendFile(fileRequest);
} catch(error) {
} catch (error) {
logger.error(error);
}
}
}

protected sendFile(fileRequest: FileRequest): void {
if(!this.connectionAlive) {
if (!this.connectionAlive) {
return;
}

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

if(this.socket && !this.socket.destroyed && this.socket.writable) {
if(requestedFile) {
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}.`);
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));
}
}
}

}
Loading