mpp-server-dev2/src/Server.js

41 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-06-06 19:22:43 +02:00
const Client = require("./Client.js")
class Server extends EventEmitter {
constructor(config) {
super();
EventEmitter.call(this);
this.wss = new WebSocket.Server({
port: config.port,
backlog: 100,
verifyClient: function (info, done) {
done(true)
}
});
this.connectionid = 0;
this.connections = new Map();
2019-06-11 23:01:44 +02:00
this.roomlisteners = new Map();
2019-06-06 19:22:43 +02:00
this.rooms = new Map();
this.wss.on('connection', (ws, req) => {
this.connections.set(++this.connectionid, new Client(ws, req, this));
});
2019-06-14 19:57:09 +02:00
this.legit_m = ["a", "bye", "hi", "ch", "+ls", "-ls", "m", "n", "devices", "t", "chset", "userset", "chown", "kickban", "admin message", "color"]
2019-06-06 19:22:43 +02:00
this.welcome_motd = config.motd || "You agree to read this message.";
this._id_Private_Key = config._id_PrivateKey || "boppity";
this.defaultUsername = config.defaultUsername || "Anonymous";
this.defaultRoomColor = config.defaultRoomColor || "#3b5054";
this.defaultLobbyColor = config.defaultLobbyColor || "#19b4b9";
this.defaultLobbyColor2 = config.defaultLobbyColor2 || "#801014";
2019-06-14 19:57:09 +02:00
this.adminpass = config.adminpass || "Bop It";
2019-06-06 19:22:43 +02:00
};
2019-06-11 23:01:44 +02:00
updateRoom(data) {
2019-07-06 01:25:13 +02:00
if (!data.ch.settings.visible) return;
2019-06-11 23:01:44 +02:00
for (let cl of Array.from(this.roomlisteners.values())) {
cl.sendArray([{
"m": "ls",
"c": false,
"u": [data.ch]
}])
}
}
2019-06-06 19:22:43 +02:00
}
module.exports = Server;