This commit is contained in:
Hri7566 2021-04-12 12:41:44 -04:00
parent 427377dfcc
commit d951d4e694
4 changed files with 34 additions and 19 deletions

View File

@ -7,5 +7,6 @@ module.exports = Object.seal({
// defaultLobbyColor: "#19b4b9", // defaultLobbyColor: "#19b4b9",
defaultLobbyColor: "#5e32a8", defaultLobbyColor: "#5e32a8",
defaultLobbyColor2: "#801014", defaultLobbyColor2: "#801014",
adminpass: process.env.ADMINPASS adminpass: process.env.ADMINPASS,
ssl: false
}); });

View File

@ -44,7 +44,7 @@ module.exports = (cl) => {
} }
}) })
cl.on("m", (msg, admin) => { 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 (!(cl.channel && cl.participantId)) return;
if (!msg.hasOwnProperty("x")) msg.x = null; if (!msg.hasOwnProperty("x")) msg.x = null;
if (!msg.hasOwnProperty("y")) msg.y = null; if (!msg.hasOwnProperty("y")) msg.y = null;

View File

@ -196,16 +196,16 @@ class Room extends EventEmitter {
} }
isLobby(_id) { isLobby(_id) {
if (_id.startsWith("lobby")) { if (_id.startsWith("lobby")) {
return true;
let lobbynum = _id.split("lobby")[1];
if (_id == "lobby") { if (_id == "lobby") {
return true; return true;
} }
let lobbynum = _id.split("lobby")[1];
if (!(parseInt(lobbynum).toString() == lobbynum)) return false; if (!(parseInt(lobbynum).toString() == lobbynum)) return false;
for (let i in lobbynum) { for (let i in lobbynum) {
if (parseInt(lobbynum[i]) >= 0) { if (parseInt(lobbynum[i]) >= 0) {
if (parseInt(i) + 1 == lobbynum.length) return true; if (parseInt(i) + 1 == lobbynum.length) return true;
} else { } else {
return false; return false;
} }

View File

@ -1,17 +1,20 @@
const Client = require("./Client.js"); const Client = require("./Client.js");
const banned = require('../banned.json'); const banned = require('../banned.json');
const https = require("https"); const https = require("https");
const http = require("http");
const fs = require('fs'); const fs = require('fs');
class Server extends EventEmitter { class Server extends EventEmitter {
constructor(config) { constructor(config) {
super(); super();
EventEmitter.call(this); EventEmitter.call(this);
if (config.ssl == true) {
this.https_server = https.createServer({ this.https_server = https.createServer({
key: fs.readFileSync('ssl/privkey.pem', 'utf8'), key: fs.readFileSync('ssl/privkey.pem', 'utf8'),
cert: fs.readFileSync('ssl/cert.pem'), cert: fs.readFileSync('ssl/cert.pem'),
ca: fs.readFileSync('ssl/chain.pem') ca: fs.readFileSync('ssl/chain.pem')
}); });
this.wss = new WebSocket.Server({ this.wss = new WebSocket.Server({
server: this.https_server, server: this.https_server,
backlog: 100, backlog: 100,
@ -20,7 +23,18 @@ class Server extends EventEmitter {
return true; return true;
} }
}); });
this.https_server.listen(config.port); 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}`); console.log(`Server started on port ${config.port}`);
this.connectionid = 0; this.connectionid = 0;
this.connections = new Map(); this.connections = new Map();