parse canvasId more stricly to number on websocket

This commit is contained in:
HF 2022-08-12 16:16:41 +02:00
parent 4e74912655
commit a9fcd04eef
3 changed files with 10 additions and 9 deletions

View File

@ -22,7 +22,7 @@ class SocketClient extends EventEmitter {
super();
console.log('Creating WebSocketClient');
this.ws = null;
this.canvasId = '0';
this.canvasId = 0;
this.channelId = 0;
/*
* properties set in connect and open:
@ -105,12 +105,10 @@ class SocketClient extends EventEmitter {
const now = Date.now();
this.timeLastPing = now;
this.timeLastSent = now;
this.readyState = WebSocket.OPEN;
this.emit('open', {});
if (this.canvasId !== null) {
this.send(RegisterCanvas.dehydrate(this.canvasId));
}
this.readyState = WebSocket.OPEN;
this.send(RegisterCanvas.dehydrate(this.canvasId));
console.log(`Register ${chunks.length} chunks`);
this.send(RegisterMultipleChunks.dehydrate(chunks));
this.processMsgQueue();

View File

@ -468,9 +468,6 @@ class SocketServer {
switch (opcode) {
case PixelUpdate.OP_CODE: {
const { canvasId, user } = ws;
if (canvasId === null) {
return;
}
const { ip } = user;
const limiter = rateLimit.get(ip);
@ -486,6 +483,12 @@ class SocketServer {
}
}
if (canvasId === null) {
logger.info(`Closing websocket without canvas from ${ip}`);
ws.close();
return;
}
let failureRet = null;
// check if captcha needed
if (await needCaptcha(ip)) {

View File

@ -12,7 +12,7 @@ export default {
const buffer = new ArrayBuffer(1 + 1);
const view = new DataView(buffer);
view.setInt8(0, OP_CODE);
view.setInt8(1, canvasId);
view.setInt8(1, Number(canvasId));
return buffer;
},
};