Skip to content

Commit

Permalink
Fixing all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlackParade committed Oct 18, 2020
1 parent 3a6d578 commit 5668e69
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 14 deletions.
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"name": "rune.js",
"version": "0.5.0",
Expand All @@ -8,7 +7,7 @@
"start": "npm run start:dev",
"start:dev": "rimraf dist && npm run build && concurrently \"npm run build:watch\" \"node --max-old-space-size=4096 dist/main.js\"",
"start:game-server": "rimraf dist && npm run build && node --max-old-space-size=4096 dist/main.js",
"start:login-server": "rimraf dist && npm run build && node --max-old-space-size=2048 dist/login-server.js",
"start:login-server": "concurrently \"mongod --dbpath=/data/sessions\" \"rimraf dist && npm run build && node --max-old-space-size=2048 dist/login-server.js\"",
"start:update-server": "rimraf dist && npm run build && node --max-old-space-size=2048 dist/update-server.js",
"lint": "tslint --project tsconfig.json",
"fake-players": "concurrently \"npm run build:watch\" \"node --max-old-space-size=4096 dist/main.js -fakePlayers\"",
Expand Down Expand Up @@ -38,6 +37,8 @@
"express": "^4.17.1",
"js-yaml": "^3.13.1",
"lodash": "^4.17.15",
"mongodb": "^3.6.2",
"mongodb-server": "^1.0.0",
"quadtree-lib": "^1.0.9",
"rxjs": "^6.5.4",
"source-map-support": "^0.5.16",
Expand Down
14 changes: 10 additions & 4 deletions src/net/server/login-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class LoginServerConnection implements SocketConnectionHandler {

const credentialsResponseCode = this.checkCredentials(username, password);
if(credentialsResponseCode === -1) {
this.sendLoginResponse(LoginResponseCode.SUCCESS);
this.sendLogin([ clientKey1, clientKey2 ], gameClientId, username, password, isLowDetail);
} else {
logger.info(`${username} attempted to login but received error code ${ credentialsResponseCode }.`);
Expand Down Expand Up @@ -203,11 +202,11 @@ class LoginServerConnection implements SocketConnectionHandler {
private handleLoginHandshake(buffer: ByteBuffer): void {
buffer.get('BYTE', 'UNSIGNED'); // Name hash

const serverKey = BigInt(Math.floor(Math.random() * 999999));
this.serverKey = BigInt(Math.floor(Math.random() * 999999));

const outputBuffer = new ByteBuffer(9);
outputBuffer.put(0, 'BYTE'); // Initial server login response -> 0 for OK
outputBuffer.put(serverKey, 'LONG');
outputBuffer.put(this.serverKey, 'LONG');
this.gameServerSocket.write(outputBuffer);

this.connectionStage = ConnectionStage.ACTIVE;
Expand All @@ -228,7 +227,14 @@ export const registerSocket = (socket: Socket): void => {

const connection: LoginServerConnection = new LoginServerConnection(socket);

socket.on('data', data => connection.dataReceived(new ByteBuffer(data)));
socket.on('data', async data => {
try {
await connection.dataReceived(new ByteBuffer(data));
} catch(e) {
logger.error(e);
socket.destroy();
}
});

socket.on('close', () => {
// @TODO socket close event
Expand Down
5 changes: 4 additions & 1 deletion src/net/server/server-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ export class ServerGateway {
buffer.put(LoginResponseCode.ALREADY_LOGGED_IN);
} else {
this.createPlayer([ clientKey1, clientKey2 ], gameClientId, username, passwordHash, lowDetail ? 'low' : 'high');
this.serverType = 'game_server';
return;
}
} catch(e) {
logger.error(e);
this.gameServerConnection.closeSocket();
if(this.gameServerConnection) {
this.gameServerConnection.closeSocket();
}
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/net/server/update-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ class UpdateServerConnection implements SocketConnectionHandler {
const gameVersion = buffer.get('INT');
const outputBuffer = new ByteBuffer(1);

console.log(gameVersion);

if(gameVersion === 435) {
outputBuffer.put(6);
outputBuffer.put(0); // good to go!
this.connectionStage = ConnectionStage.ACTIVE;
this.gameServerSocket.write(outputBuffer);
} else {
outputBuffer.put(0);
outputBuffer.put(6); // out of date
this.gameServerSocket.write(outputBuffer);
this.gameServerSocket.destroy();
}
break;
default:
case ConnectionStage.ACTIVE:
while(buffer.readable >= 4) {
const type = buffer.get('BYTE', 'UNSIGNED');
const index = buffer.get('BYTE', 'UNSIGNED');
Expand All @@ -85,6 +82,8 @@ class UpdateServerConnection implements SocketConnectionHandler {
}
}
break;
default:
break;
}

return Promise.resolve(undefined);
Expand Down Expand Up @@ -145,7 +144,14 @@ const registerSocket = (socket: Socket): void => {

logger.info(`Updateserver connection established.`);

socket.on('data', data => connection.dataReceived(new ByteBuffer(data)));
socket.on('data', async data => {
try {
await connection.dataReceived(new ByteBuffer(data));
} catch(e) {
logger.error(e);
socket.destroy();
}
});

socket.on('close', () => {
// @TODO socket close event
Expand Down

0 comments on commit 5668e69

Please sign in to comment.