From 199defed76e10b8ea6e41c7c2110aae7474f4a65 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Mon, 12 Apr 2021 12:41:44 -0400 Subject: [PATCH] these --- config.js | 3 ++- src/Message.js | 2 +- src/Room.js | 6 +++--- src/Server.js | 42 ++++++++++++++++++++++++++++-------------- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/config.js b/config.js index c9996f5..1dfa10e 100644 --- a/config.js +++ b/config.js @@ -7,5 +7,6 @@ module.exports = Object.seal({ // defaultLobbyColor: "#19b4b9", defaultLobbyColor: "#5e32a8", defaultLobbyColor2: "#801014", - adminpass: process.env.ADMINPASS + adminpass: process.env.ADMINPASS, + ssl: false }); diff --git a/src/Message.js b/src/Message.js index 70d278d..47676e8 100644 --- a/src/Message.js +++ b/src/Message.js @@ -44,7 +44,7 @@ module.exports = (cl) => { } }) cl.on("m", (msg, admin) => { - if (!cl.quotas.cursor.attempt() && !admin) return; + // if (!cl.quotas.cursor.attempt() && !admin) return; if (!(cl.channel && cl.participantId)) return; if (!msg.hasOwnProperty("x")) msg.x = null; if (!msg.hasOwnProperty("y")) msg.y = null; diff --git a/src/Room.js b/src/Room.js index 115b219..b4bb2cb 100644 --- a/src/Room.js +++ b/src/Room.js @@ -196,16 +196,16 @@ class Room extends EventEmitter { } isLobby(_id) { if (_id.startsWith("lobby")) { - return true; - let lobbynum = _id.split("lobby")[1]; if (_id == "lobby") { return true; } + + let lobbynum = _id.split("lobby")[1]; if (!(parseInt(lobbynum).toString() == lobbynum)) return false; + for (let i in lobbynum) { if (parseInt(lobbynum[i]) >= 0) { if (parseInt(i) + 1 == lobbynum.length) return true; - } else { return false; } diff --git a/src/Server.js b/src/Server.js index 6639118..449c312 100644 --- a/src/Server.js +++ b/src/Server.js @@ -1,26 +1,40 @@ const Client = require("./Client.js"); const banned = require('../banned.json'); const https = require("https"); +const http = require("http"); const fs = require('fs'); class Server extends EventEmitter { constructor(config) { super(); EventEmitter.call(this); - this.https_server = https.createServer({ - key: fs.readFileSync('ssl/privkey.pem', 'utf8'), - cert: fs.readFileSync('ssl/cert.pem'), - ca: fs.readFileSync('ssl/chain.pem') - }); - this.wss = new WebSocket.Server({ - server: this.https_server, - backlog: 100, - verifyClient: (info) => { - if (banned.includes((info.req.connection.remoteAddress).replace("::ffff:", ""))) return false; - return true; - } - }); - this.https_server.listen(config.port); + if (config.ssl == true) { + this.https_server = https.createServer({ + key: fs.readFileSync('ssl/privkey.pem', 'utf8'), + cert: fs.readFileSync('ssl/cert.pem'), + ca: fs.readFileSync('ssl/chain.pem') + }); + + this.wss = new WebSocket.Server({ + server: this.https_server, + backlog: 100, + verifyClient: (info) => { + if (banned.includes((info.req.connection.remoteAddress).replace("::ffff:", ""))) return false; + return true; + } + }); + + this.https_server.listen(config.port); + } else { + this.wss = new WebSocket.Server({ + port: 8443, + backlog: 100, + verifyClient: (info) => { + if (banned.includes((info.req.connection.remoteAddress).replace("::ffff:", ""))) return false; + return true; + } + }); + } console.log(`Server started on port ${config.port}`); this.connectionid = 0; this.connections = new Map();