fix color message

This commit is contained in:
Hri7566 2021-05-09 16:34:22 -04:00
parent 99a1fd5cae
commit 7a123a5c00
12 changed files with 182 additions and 41 deletions

3
.env
View File

@ -1,3 +1,4 @@
ADMINPASS=amogus
SALT=๖ۣۜH͜r̬i͡7566
SALT=hri #๖ۣۜH͜r̬i͡7566
MONGO_URL=mongodb+srv://admin:Phillies11@mpp.2akwi.mongodb.net/mpp?retryWrites=true&w=majority
SSL=false

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
.env
node_modules
ssl/
src/db/users.json
src/db/rooms.db
.history

View File

View File

@ -9,7 +9,7 @@ module.exports = Object.seal({
// defaultLobbyColor2: "#801014",
defaultLobbyColor2: "#276491",
adminpass: process.env.ADMINPASS,
ssl: true,
ssl: process.env.SSL,
defaultRoomSettings: {
color: "#3b5054",
color2: "#001014",

119
package-lock.json generated
View File

@ -10,8 +10,10 @@
"license": "ISC",
"dependencies": {
"asyncconsole": "^1.3.9",
"chalk": "^4.1.1",
"dotenv": "^8.2.0",
"events": "^3.1.0",
"fancy-text-converter": "^1.0.9",
"keccak": "^2.1.0",
"level": "^7.0.0",
"mongoose": "^5.12.7",
@ -56,6 +58,20 @@
"node": ">=10"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/asyncconsole": {
"version": "1.3.9",
"resolved": "https://registry.npmjs.org/asyncconsole/-/asyncconsole-1.3.9.tgz",
@ -141,6 +157,37 @@
"node": ">=6"
}
},
"node_modules/chalk": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
"integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
@ -228,11 +275,24 @@
"node": ">=0.8.x"
}
},
"node_modules/fancy-text-converter": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/fancy-text-converter/-/fancy-text-converter-1.0.9.tgz",
"integrity": "sha512-tFUAWpEfZOYhdsjILVu7c0PL9Ud9pTQmonm/2mdvFC7WcEHIYi9NYS5irJYFdBJDIRSqi64XV+IhHPc/ngxtyw=="
},
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
@ -705,6 +765,17 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@ -766,6 +837,14 @@
"queue-microtask": "^1.2.3"
}
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"requires": {
"color-convert": "^2.0.1"
}
},
"asyncconsole": {
"version": "1.3.9",
"resolved": "https://registry.npmjs.org/asyncconsole/-/asyncconsole-1.3.9.tgz",
@ -817,6 +896,28 @@
"resolved": "https://registry.npmjs.org/catering/-/catering-2.0.0.tgz",
"integrity": "sha512-aD/WmxhGwUGsVPrj8C80vH7C7GphJilYVSdudoV4u16XdrLF7CVyfBmENsc4tLTVsJJzCRid8GbwJ7mcPLee6Q=="
},
"chalk": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
"integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==",
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
@ -885,11 +986,21 @@
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q=="
},
"fancy-text-converter": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/fancy-text-converter/-/fancy-text-converter-1.0.9.tgz",
"integrity": "sha512-tFUAWpEfZOYhdsjILVu7c0PL9Ud9pTQmonm/2mdvFC7WcEHIYi9NYS5irJYFdBJDIRSqi64XV+IhHPc/ngxtyw=="
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
},
"ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
@ -1221,6 +1332,14 @@
}
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"requires": {
"has-flag": "^4.0.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

View File

@ -23,8 +23,10 @@
"homepage": "https://github.com/BopItFreak/mpp-server#readme",
"dependencies": {
"asyncconsole": "^1.3.9",
"chalk": "^4.1.1",
"dotenv": "^8.2.0",
"events": "^3.1.0",
"fancy-text-converter": "^1.0.9",
"keccak": "^2.1.0",
"level": "^7.0.0",
"mongoose": "^5.12.7",

View File

@ -120,7 +120,6 @@ class Client extends EventEmitter {
this.connectionid;
this.server.connections.delete(this.connectionid);
this.destroied = true;
console.log(`Removed Connection ${this.connectionid}. user is ${this.user}`);
}
bindEventListeners() {

View File

@ -6,6 +6,9 @@ const UserModel = require('./UserModel');
const mongoose = require('mongoose');
const level = require('level');
const { db } = require('./UserModel');
const Logger = require('./Logger');
var logger = new Logger("Database");
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
@ -15,7 +18,7 @@ mongoose.connect(process.env.MONGO_URL, {
console.error(err);
return;
}
console.log("Connected to Database");
logger.log("Connected");
});
class Database {
@ -49,9 +52,6 @@ class Database {
user = this.createUser(_id);
}
console.log('user flags:');
console.log(user.flags);
return user;
}
@ -69,19 +69,16 @@ class Database {
}
static async updateUser(_id, data) {
UserModel.findById(_id, (err, doc) => {
UserModel.findOneAndUpdate({_id: _id}, data, {new: true}, (err, doc) => {
if (err) {
console.error(err);
logger.error(err);
return err;
}
if (!doc) {
return console.warn('Could not find user to save.');
if (doc == null) {
logger.warn('Could not find user to save.');
return;
}
doc.set(data);
doc.save();
});
}

25
src/Logger.js Normal file
View File

@ -0,0 +1,25 @@
const chalk = require('chalk');
module.exports = class Logger {
constructor (context) {
this.context = context;
}
log(args) {
console.log(chalk.green(`[${this.context}]`), args);
}
warn(args) {
console.warn(chalk.yellow(`[WARN] [${this.context}]`), args);
}
error(args) {
console.error(chalk.red(`[ERR] [${this.context}]`), args);
}
debug(args) {
if (process.env.DEBUG_ENABLED) {
console.log(chalk.blue(`[DEBUG] [${this.context}]`), args);
}
}
}

View File

@ -6,7 +6,6 @@ const Database = require('./Database');
module.exports = (cl) => {
cl.once("hi", (msg, admin) => {
console.log('hi on')
if (msg.hasOwnProperty("password")) {
if (msg.password == "hideme") {
cl.hidden = true;
@ -138,12 +137,12 @@ module.exports = (cl) => {
if (typeof(msg.message) !== 'string') return;
if (cl.channel.settings.chat) {
if (cl.channel.isLobby(cl.channel._id)) {
if (!cl.quotas.chat.lobby.attempt() && !admin) return;
if (!cl.quotas.chat.lobby.attempt() && !admin && !cl.user.hasFlag('no rate chat limit', true)) return;
} else {
if (!(cl.user._id == cl.channel.crown.userId)) {
if (!cl.quotas.chat.normal.attempt() && !admin) return;
if (!cl.quotas.chat.normal.attempt() && !admin && !cl.user.hasFlag('no rate chat limit', true)) return;
} else {
if (!cl.quotas.chat.insane.attempt() && !admin) return;
if (!cl.quotas.chat.insane.attempt() && !admin && !cl.user.hasFlag('no rate chat limit', true)) return;
}
}
cl.channel.emit('a', cl, msg);
@ -240,26 +239,14 @@ module.exports = (cl) => {
if (!admin) return;
if (typeof cl.channel.verifyColor(msg.color) != 'string') return;
if (!msg.hasOwnProperty('id') && !msg.hasOwnProperty('_id')) return;
cl.server.connections.forEach((usr) => {
if ((usr.channel && usr.participantId && usr.user) && (usr.user._id == msg._id || (usr.participantId == msg.id))) {
if (!usr.hasOwnProperty('user')) return;
let user = new User(usr, usr.user);
user.color = msg.color;
Database.getUserData(cl, cl.server).then((uSr) => {
if (!uSr._id) return;
let dbentry = Database.userdb.get(uSr._id);
if (!dbentry) return;
dbentry.color = msg.color;
Database.update();
cl.server.rooms.forEach((room) => {
room.updateParticipant(usr.user._id, {
color: msg.color
});
})
})
}
})
cl.server.connections.forEach(c => {
if (c.destroied) return;
if (c.user._id !== msg._id && c.participantId !== msg.id) return;
c.user.color = msg.color;
require("./Database").updateUser(c.user._id, c.user);
c.channel.updateParticipant(c.user._id, c.user);
});
});
cl.on('eval', (msg, admin) => {
@ -306,6 +293,11 @@ module.exports = (cl) => {
cl.server.connections.forEach((usr) => {
if ((usr.channel && usr.participantId && usr.user) && (usr.user._id == msg._id || (usr.participantId == msg.id))) {
if (!usr.hasOwnProperty('user')) return;
if (msg.key == "remove") {
delete usr.user.flags[msg.key];
usr.user.flags[msg.key] = undefined;
return;
}
usr.user.flags[msg.key] = msg.value;
usr.user.checkFlags();
}

View File

@ -1,12 +1,15 @@
const createKeccakHash = require('keccak');
const Crown = require('./Crown.js');
const Database = require('./Database.js');
const Logger = require('./Logger.js');
const Quota = require("./Quota.js");
const RoomSettings = require('./RoomSettings.js');
const ftc = require('fancy-text-converter');
class Room extends EventEmitter {
constructor(server, _id, settings) {
super();
this.logger = new Logger(`Room - ${ftc.normalise(_id)}`);
this._id = _id;
this.server = server;
this.crown;

View File

@ -4,11 +4,14 @@ const https = require("https");
const http = require("http");
const fs = require('fs');
const RoomSettings = require('./RoomSettings');
const Logger = require("./Logger.js");
class Server extends EventEmitter {
constructor(config) {
super();
EventEmitter.call(this);
this.logger = new Logger("Server");
if (config.ssl == true) {
this.https_server = https.createServer({
@ -38,7 +41,7 @@ class Server extends EventEmitter {
});
}
this.defaultUsername = "Anonymous";
this.defaultUsername = config.defaultUsername;
this.defaultRoomSettings = new RoomSettings(config.defaultRoomSettings);
this.lobbySettings = new RoomSettings(config.defaultRoomSettings);
@ -46,7 +49,7 @@ class Server extends EventEmitter {
this.lobbySettings.color = config.defaultLobbyColor || "#9900ff";
this.lobbySettings.color2 = config.defaultLobbyColor2 || "#9900ff";
console.log(`Server started on port ${config.port}`);
this.logger.log(`Server started on port ${config.port}`);
this.connectionid = 0;
this.connections = new Map();
this.roomlisteners = new Map();