forked from ppfun/pixelplanet
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();
|
||||
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();
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user