parse canvasId more stricly to number on websocket
This commit is contained in:
parent
4e74912655
commit
a9fcd04eef
|
@ -22,7 +22,7 @@ class SocketClient extends EventEmitter {
|
||||||
super();
|
super();
|
||||||
console.log('Creating WebSocketClient');
|
console.log('Creating WebSocketClient');
|
||||||
this.ws = null;
|
this.ws = null;
|
||||||
this.canvasId = '0';
|
this.canvasId = 0;
|
||||||
this.channelId = 0;
|
this.channelId = 0;
|
||||||
/*
|
/*
|
||||||
* properties set in connect and open:
|
* properties set in connect and open:
|
||||||
|
@ -105,12 +105,10 @@ class SocketClient extends EventEmitter {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
this.timeLastPing = now;
|
this.timeLastPing = now;
|
||||||
this.timeLastSent = now;
|
this.timeLastSent = now;
|
||||||
this.readyState = WebSocket.OPEN;
|
|
||||||
|
|
||||||
this.emit('open', {});
|
this.emit('open', {});
|
||||||
if (this.canvasId !== null) {
|
this.readyState = WebSocket.OPEN;
|
||||||
this.send(RegisterCanvas.dehydrate(this.canvasId));
|
this.send(RegisterCanvas.dehydrate(this.canvasId));
|
||||||
}
|
|
||||||
console.log(`Register ${chunks.length} chunks`);
|
console.log(`Register ${chunks.length} chunks`);
|
||||||
this.send(RegisterMultipleChunks.dehydrate(chunks));
|
this.send(RegisterMultipleChunks.dehydrate(chunks));
|
||||||
this.processMsgQueue();
|
this.processMsgQueue();
|
||||||
|
|
|
@ -468,9 +468,6 @@ class SocketServer {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case PixelUpdate.OP_CODE: {
|
case PixelUpdate.OP_CODE: {
|
||||||
const { canvasId, user } = ws;
|
const { canvasId, user } = ws;
|
||||||
if (canvasId === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { ip } = user;
|
const { ip } = user;
|
||||||
|
|
||||||
const limiter = rateLimit.get(ip);
|
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;
|
let failureRet = null;
|
||||||
// check if captcha needed
|
// check if captcha needed
|
||||||
if (await needCaptcha(ip)) {
|
if (await needCaptcha(ip)) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default {
|
||||||
const buffer = new ArrayBuffer(1 + 1);
|
const buffer = new ArrayBuffer(1 + 1);
|
||||||
const view = new DataView(buffer);
|
const view = new DataView(buffer);
|
||||||
view.setInt8(0, OP_CODE);
|
view.setInt8(0, OP_CODE);
|
||||||
view.setInt8(1, canvasId);
|
view.setInt8(1, Number(canvasId));
|
||||||
return buffer;
|
return buffer;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user