forked from Hri7566/mpp-server-dev2
idk
This commit is contained in:
parent
f45f77a9ed
commit
0eae040cbb
|
@ -26,12 +26,20 @@ const LOGGER_PARTICIPANT = {
|
||||||
id: "logger"
|
id: "logger"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const SERVER_PARTICIPANT = {
|
||||||
|
name: "mpp",
|
||||||
|
color: "#ffffff",
|
||||||
|
_id: "0",
|
||||||
|
id: "0"
|
||||||
|
};
|
||||||
|
|
||||||
const LOGGING_CHANNEL = "lolwutsecretloggingchannel";
|
const LOGGING_CHANNEL = "lolwutsecretloggingchannel";
|
||||||
const BAN_CHANNEL = "test/awkward";
|
const BAN_CHANNEL = "test/awkward";
|
||||||
|
|
||||||
class Channel extends EventEmitter {
|
class Channel extends EventEmitter {
|
||||||
static loggingChannel = LOGGING_CHANNEL;
|
static loggingChannel = LOGGING_CHANNEL;
|
||||||
static loggerParticipant = LOGGER_PARTICIPANT;
|
static loggerParticipant = LOGGER_PARTICIPANT;
|
||||||
|
static serverParticipant = SERVER_PARTICIPANT;
|
||||||
static banChannel = BAN_CHANNEL;
|
static banChannel = BAN_CHANNEL;
|
||||||
|
|
||||||
constructor(server, _id, settings, cl) {
|
constructor(server, _id, settings, cl) {
|
||||||
|
@ -125,7 +133,7 @@ class Channel extends EventEmitter {
|
||||||
if (this.isLobby(this._id)) {
|
if (this.isLobby(this._id)) {
|
||||||
this.colorInterval = setInterval(() => {
|
this.colorInterval = setInterval(() => {
|
||||||
this.setDefaultLobbyColorBasedOnDate();
|
this.setDefaultLobbyColorBasedOnDate();
|
||||||
}, 500);
|
}, 5000);
|
||||||
this.setDefaultLobbyColorBasedOnDate();
|
this.setDefaultLobbyColorBasedOnDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ const level = require("level");
|
||||||
const { db } = require("./UserModel");
|
const { db } = require("./UserModel");
|
||||||
const Logger = require("./Logger");
|
const Logger = require("./Logger");
|
||||||
|
|
||||||
var logger = new Logger("Database");
|
const logger = new Logger("Database");
|
||||||
|
|
||||||
mongoose.connect(
|
mongoose.connect(
|
||||||
process.env.MONGO_URL,
|
process.env.MONGO_URL,
|
||||||
|
@ -23,10 +23,11 @@ mongoose.connect(
|
||||||
logger.error("Unable to connect to database service");
|
logger.error("Unable to connect to database service");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
logger.log("Connected");
|
logger.log("Connected to Mongo");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO implement this with an if statement instead
|
||||||
fs.mkdirSync("db/", {
|
fs.mkdirSync("db/", {
|
||||||
recursive: true
|
recursive: true
|
||||||
});
|
});
|
||||||
|
@ -35,11 +36,15 @@ class Database {
|
||||||
static userdb;
|
static userdb;
|
||||||
static roomdb;
|
static roomdb;
|
||||||
static bandb;
|
static bandb;
|
||||||
|
static utildb;
|
||||||
|
|
||||||
static async load() {
|
static async load() {
|
||||||
|
logger.log("Initializing level stores...");
|
||||||
this.userdb = mongoose.connection;
|
this.userdb = mongoose.connection;
|
||||||
this.roomdb = level("db/rooms.db");
|
this.roomdb = level("db/rooms.db");
|
||||||
this.bandb = level("db/ban.db");
|
this.bandb = level("db/ban.db");
|
||||||
|
this.utildb = level("db/util.db");
|
||||||
|
logger.log("Level stores initialized");
|
||||||
|
|
||||||
// const writeFile = promisify(fs.writeFile);
|
// const writeFile = promisify(fs.writeFile);
|
||||||
// const readdir = promisify(fs.readdir);
|
// const readdir = promisify(fs.readdir);
|
||||||
|
@ -155,18 +160,27 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
static deleteRoomSettings(_id) {
|
static deleteRoomSettings(_id) {
|
||||||
|
if (!this.bandb) return this.load();
|
||||||
this.roomdb.del("room~" + _id);
|
this.roomdb.del("room~" + _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static addIPBan(ip) {
|
static addIPBan(ip) {
|
||||||
|
if (!this.bandb) return this.load();
|
||||||
this.bandb.put("ipban~" + ip, true);
|
this.bandb.put("ipban~" + ip, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static removeIPBan(ip) {
|
static removeIPBan(ip) {
|
||||||
|
if (!this.bandb) return this.load();
|
||||||
this.bandb.del("ipban~" + ip);
|
this.bandb.del("ipban~" + ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static isIPBanned(ip, cb) {
|
static isIPBanned(ip, cb) {
|
||||||
|
if (!this.bandb) {
|
||||||
|
// FIXME this was causing a crash :/ maybe it should be async instead of return false?
|
||||||
|
this.load();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.roomdb.get("ipban~" + ip, (err, value) => {
|
this.roomdb.get("ipban~" + ip, (err, value) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -177,6 +191,18 @@ class Database {
|
||||||
if (value == true) return true;
|
if (value == true) return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static utilSet(key, value) {
|
||||||
|
return this.utildb.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static utilGet(key) {
|
||||||
|
return this.utildb.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
static utilDel(key) {
|
||||||
|
return this.utildb.del(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoomDataModel {
|
class RoomDataModel {
|
||||||
|
|
|
@ -107,10 +107,7 @@ Command.addCommand(
|
||||||
if (!msg.args[2]) {
|
if (!msg.args[2]) {
|
||||||
cl.emit(
|
cl.emit(
|
||||||
"color",
|
"color",
|
||||||
{
|
{ color: c.toHexa(), _id: cl.user._id },
|
||||||
color: c.toHexa(),
|
|
||||||
_id: cl.user._id
|
|
||||||
},
|
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
ch.adminChat(
|
ch.adminChat(
|
||||||
|
@ -125,10 +122,7 @@ Command.addCommand(
|
||||||
if (winner) {
|
if (winner) {
|
||||||
cl.emit(
|
cl.emit(
|
||||||
"color",
|
"color",
|
||||||
{
|
{ color: c.toHexa(), _id: winner.user._id },
|
||||||
color: c.toHexa(),
|
|
||||||
_id: winner.user._id
|
|
||||||
},
|
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
ch.adminChat(
|
ch.adminChat(
|
||||||
|
@ -231,6 +225,63 @@ Command.addCommand(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = {
|
/*
|
||||||
Command
|
Command.addCommand(
|
||||||
};
|
new Command(
|
||||||
|
"ip",
|
||||||
|
["ip"],
|
||||||
|
undefined,
|
||||||
|
"%Pip",
|
||||||
|
0,
|
||||||
|
(cl, ch, msg) => {
|
||||||
|
if (msg.args[1]) {
|
||||||
|
const winner = new Array(cl.server.connections.values()).find(
|
||||||
|
cl => {
|
||||||
|
if (!cl.user) return false;
|
||||||
|
console.log(cl.user._id);
|
||||||
|
return cl.user ? cl.user._id == msg.args[1] : false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (winner) {
|
||||||
|
cl.sendArray([
|
||||||
|
{
|
||||||
|
m: "a",
|
||||||
|
a: "IP: " + winner.ip,
|
||||||
|
p: {
|
||||||
|
name: "mpp",
|
||||||
|
color: "#ffffff",
|
||||||
|
_id: "0",
|
||||||
|
id: "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
cl.sendArray([
|
||||||
|
{
|
||||||
|
m: "a",
|
||||||
|
a: "No IP found.",
|
||||||
|
p: {
|
||||||
|
name: "mpp",
|
||||||
|
color: "#ffffff",
|
||||||
|
_id: "0",
|
||||||
|
id: "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cl.sendArray([
|
||||||
|
{
|
||||||
|
m: "a",
|
||||||
|
a: "ip: " + cl.ip,
|
||||||
|
p: { name: "mpp", color: "#ffffff", _id: "0", id: "0" }
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"admin"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = { Command };
|
||||||
|
|
|
@ -1,57 +1,65 @@
|
||||||
const config = require ('../config');
|
const config = require("../config");
|
||||||
|
|
||||||
class RoomSettings {
|
class RoomSettings {
|
||||||
static allowedProperties = {
|
static allowedProperties = {
|
||||||
color: {
|
color: {
|
||||||
type: 'color',
|
type: "color",
|
||||||
default: config.defaultRoomSettings.color,
|
default: config.defaultRoomSettings.color,
|
||||||
allowedChange: true,
|
allowedChange: true,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
color2: {
|
color2: {
|
||||||
type: 'color2',
|
type: "color2",
|
||||||
default: config.defaultRoomSettings.color2,
|
default: config.defaultRoomSettings.color2,
|
||||||
allowedChange: true,
|
allowedChange: true,
|
||||||
required: false
|
required: false
|
||||||
},
|
},
|
||||||
lobby: {
|
lobby: {
|
||||||
type: 'boolean',
|
type: "boolean",
|
||||||
allowedChange: false,
|
allowedChange: false,
|
||||||
required: false
|
required: false
|
||||||
},
|
},
|
||||||
visible: {
|
visible: {
|
||||||
type: 'boolean',
|
type: "boolean",
|
||||||
default: true,
|
default: true,
|
||||||
allowedChange: true,
|
allowedChange: true,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
chat: {
|
chat: {
|
||||||
type: 'boolean',
|
type: "boolean",
|
||||||
default: true,
|
default: true,
|
||||||
allowedChange: true,
|
allowedChange: true,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
owner_id: {
|
owner_id: {
|
||||||
type: 'string',
|
type: "string",
|
||||||
allowedChange: false,
|
allowedChange: false,
|
||||||
required: false
|
required: false
|
||||||
},
|
},
|
||||||
crownsolo: {
|
crownsolo: {
|
||||||
type: 'boolean',
|
type: "boolean",
|
||||||
default: false,
|
default: false,
|
||||||
allowedChange: true,
|
allowedChange: true,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
"no cussing": {
|
"no cussing": {
|
||||||
type: 'boolean',
|
type: "boolean",
|
||||||
allowedChange: true,
|
allowedChange: true,
|
||||||
required: false
|
required: false
|
||||||
|
},
|
||||||
|
"lyrical notes": {
|
||||||
|
type: "boolean",
|
||||||
|
allowedChange: false,
|
||||||
|
required: false
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
constructor(set, context) {
|
constructor(set, context) {
|
||||||
Object.keys(RoomSettings.allowedProperties).forEach(key => {
|
Object.keys(RoomSettings.allowedProperties).forEach(key => {
|
||||||
if (typeof(RoomSettings.allowedProperties[key].default) !== 'undefined') {
|
if (
|
||||||
|
typeof RoomSettings.allowedProperties[key].default !==
|
||||||
|
"undefined"
|
||||||
|
) {
|
||||||
if (this[key] !== RoomSettings.allowedProperties[key].default) {
|
if (this[key] !== RoomSettings.allowedProperties[key].default) {
|
||||||
this[key] = RoomSettings.allowedProperties[key].default;
|
this[key] = RoomSettings.allowedProperties[key].default;
|
||||||
}
|
}
|
||||||
|
@ -60,22 +68,36 @@ class RoomSettings {
|
||||||
|
|
||||||
Object.keys(RoomSettings.allowedProperties).forEach(key => {
|
Object.keys(RoomSettings.allowedProperties).forEach(key => {
|
||||||
if (RoomSettings.allowedProperties[key].required == true) {
|
if (RoomSettings.allowedProperties[key].required == true) {
|
||||||
if (typeof(this[key]) == 'undefined') {
|
if (typeof this[key] == "undefined") {
|
||||||
this[key] = RoomSettings.allowedProperties[key].default;
|
this[key] = RoomSettings.allowedProperties[key].default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof(set) !== 'undefined') {
|
if (typeof set !== "undefined") {
|
||||||
Object.keys(set).forEach(key => {
|
Object.keys(set).forEach(key => {
|
||||||
if (typeof(set[key]) == 'undefined') return;
|
if (typeof set[key] == "undefined") return;
|
||||||
if (Object.keys(RoomSettings.allowedProperties).indexOf(key) !== -1) {
|
if (
|
||||||
if (typeof(context) == 'undefined') {
|
Object.keys(RoomSettings.allowedProperties).indexOf(key) !==
|
||||||
this[key] = this.verifyPropertyType(key, set[key], RoomSettings.allowedProperties[key].type);
|
-1
|
||||||
|
) {
|
||||||
|
if (typeof context == "undefined") {
|
||||||
|
this[key] = this.verifyPropertyType(
|
||||||
|
key,
|
||||||
|
set[key],
|
||||||
|
RoomSettings.allowedProperties[key].type
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (context == 'user') {
|
if (context == "user") {
|
||||||
if (RoomSettings.allowedProperties[key].allowedChange) {
|
if (
|
||||||
this[key] = this.verifyPropertyType(key, set[key], RoomSettings.allowedProperties[key].type);
|
RoomSettings.allowedProperties[key]
|
||||||
|
.allowedChange
|
||||||
|
) {
|
||||||
|
this[key] = this.verifyPropertyType(
|
||||||
|
key,
|
||||||
|
set[key],
|
||||||
|
RoomSettings.allowedProperties[key].type
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,17 +109,17 @@ class RoomSettings {
|
||||||
verifyPropertyType(key, pr, type) {
|
verifyPropertyType(key, pr, type) {
|
||||||
let ret;
|
let ret;
|
||||||
|
|
||||||
if (typeof(RoomSettings.allowedProperties[key]) !== 'object') return;
|
if (typeof RoomSettings.allowedProperties[key] !== "object") return;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'color':
|
case "color":
|
||||||
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
||||||
ret = pr;
|
ret = pr;
|
||||||
} else {
|
} else {
|
||||||
ret = RoomSettings.allowedProperties[key].default;
|
ret = RoomSettings.allowedProperties[key].default;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'color2':
|
case "color2":
|
||||||
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
||||||
ret = pr;
|
ret = pr;
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,9 +127,12 @@ class RoomSettings {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (typeof(pr) == type) {
|
if (typeof pr == type) {
|
||||||
ret = pr;
|
ret = pr;
|
||||||
} else if (typeof(RoomSettings.allowedProperties[key].default) !== 'undefined') {
|
} else if (
|
||||||
|
typeof RoomSettings.allowedProperties[key].default !==
|
||||||
|
"undefined"
|
||||||
|
) {
|
||||||
ret = RoomSettings.allowedProperties[key].default;
|
ret = RoomSettings.allowedProperties[key].default;
|
||||||
} else {
|
} else {
|
||||||
ret = undefined;
|
ret = undefined;
|
||||||
|
@ -121,15 +146,26 @@ class RoomSettings {
|
||||||
changeSettings(set) {
|
changeSettings(set) {
|
||||||
Object.keys(set).forEach(key => {
|
Object.keys(set).forEach(key => {
|
||||||
if (RoomSettings.allowedProperties[key].allowedChange) {
|
if (RoomSettings.allowedProperties[key].allowedChange) {
|
||||||
this[key] = this.verifyPropertyType(key, set[key], RoomSettings.allowedProperties[key].type);
|
this[key] = this.verifyPropertyType(
|
||||||
|
key,
|
||||||
|
set[key],
|
||||||
|
RoomSettings.allowedProperties[key].type
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static changeSettings(set, admin) {
|
static changeSettings(set, admin) {
|
||||||
Object.keys(set).forEach(key => {
|
Object.keys(set).forEach(key => {
|
||||||
if (RoomSettings.allowedProperties[key].allowedChange || admin == true) {
|
if (
|
||||||
set[key] = RoomSettings.verifyPropertyType(key, set[key], RoomSettings.allowedProperties[key].type);
|
RoomSettings.allowedProperties[key].allowedChange ||
|
||||||
|
admin == true
|
||||||
|
) {
|
||||||
|
set[key] = RoomSettings.verifyPropertyType(
|
||||||
|
key,
|
||||||
|
set[key],
|
||||||
|
RoomSettings.allowedProperties[key].type
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return set;
|
return set;
|
||||||
|
@ -138,17 +174,17 @@ class RoomSettings {
|
||||||
static verifyPropertyType(key, pr, type) {
|
static verifyPropertyType(key, pr, type) {
|
||||||
let ret;
|
let ret;
|
||||||
|
|
||||||
if (typeof(RoomSettings.allowedProperties[key]) !== 'object') return;
|
if (typeof RoomSettings.allowedProperties[key] !== "object") return;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'color':
|
case "color":
|
||||||
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
||||||
ret = pr;
|
ret = pr;
|
||||||
} else {
|
} else {
|
||||||
ret = RoomSettings.allowedProperties[key].default;
|
ret = RoomSettings.allowedProperties[key].default;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'color2':
|
case "color2":
|
||||||
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
if (/^#[0-9a-f]{6}$/i.test(pr)) {
|
||||||
ret = pr;
|
ret = pr;
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,9 +192,12 @@ class RoomSettings {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (typeof(pr) == type) {
|
if (typeof pr == type) {
|
||||||
ret = pr;
|
ret = pr;
|
||||||
} else if (typeof(RoomSettings.allowedProperties[key].default) !== 'undefined') {
|
} else if (
|
||||||
|
typeof RoomSettings.allowedProperties[key].default !==
|
||||||
|
"undefined"
|
||||||
|
) {
|
||||||
ret = RoomSettings.allowedProperties[key].default;
|
ret = RoomSettings.allowedProperties[key].default;
|
||||||
} else {
|
} else {
|
||||||
ret = undefined;
|
ret = undefined;
|
||||||
|
|
Loading…
Reference in New Issue