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