forked from Hri7566/mpp-server-dev2
Fix channel settings
This commit is contained in:
parent
c835d4611a
commit
28d9127059
|
@ -6,9 +6,9 @@ lobbySettings:
|
||||||
lobby: true
|
lobby: true
|
||||||
chat: true
|
chat: true
|
||||||
crownsolo: false
|
crownsolo: false
|
||||||
|
visible: true
|
||||||
color: "#eeeeee"
|
color: "#eeeeee"
|
||||||
color2: "#888888"
|
color2: "#888888"
|
||||||
visible: true
|
|
||||||
|
|
||||||
defaultSettings:
|
defaultSettings:
|
||||||
chat: true
|
chat: true
|
||||||
|
|
|
@ -49,19 +49,26 @@ export class Channel {
|
||||||
|
|
||||||
// TODO Add the crown
|
// TODO Add the crown
|
||||||
|
|
||||||
constructor(
|
constructor(private _id: string, set?: Partial<ChannelSettings>) {
|
||||||
private _id: string,
|
|
||||||
set: Partial<ChannelSettings> = config.defaultSettings
|
|
||||||
) {
|
|
||||||
this.logger = new Logger("Channel - " + _id);
|
this.logger = new Logger("Channel - " + _id);
|
||||||
// Verify default settings just in case
|
|
||||||
this.changeSettings(this.settings, true);
|
|
||||||
|
|
||||||
if (this.isLobby()) {
|
// Validate settings in set
|
||||||
set = config.lobbySettings;
|
// Set the verified settings
|
||||||
|
|
||||||
|
if (set && !this.isLobby()) {
|
||||||
|
const validatedSet = validateChannelSettings(set);
|
||||||
|
|
||||||
|
for (const key in Object.keys(validatedSet)) {
|
||||||
|
if (!(validatedSet as any)[key]) continue;
|
||||||
|
|
||||||
|
(this.settings as any)[key] = (set as any)[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.changeSettings(set);
|
if (this.isLobby()) {
|
||||||
|
this.logger.debug(config.lobbySettings);
|
||||||
|
this.settings = config.lobbySettings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getID() {
|
public getID() {
|
||||||
|
@ -89,6 +96,8 @@ export class Channel {
|
||||||
if (set.owner_id) set.owner_id = undefined;
|
if (set.owner_id) set.owner_id = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isLobby() && !admin) return;
|
||||||
|
|
||||||
// Verify settings
|
// Verify settings
|
||||||
const validSettings = validateChannelSettings(set);
|
const validSettings = validateChannelSettings(set);
|
||||||
|
|
||||||
|
@ -164,6 +173,7 @@ export class Channel {
|
||||||
if (this.hasUser(part._id)) {
|
if (this.hasUser(part._id)) {
|
||||||
this.ppl.splice(this.ppl.indexOf(part), 1);
|
this.ppl.splice(this.ppl.indexOf(part), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Broadcast channel update
|
// TODO Broadcast channel update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,9 @@ export function loadConfig<T>(filepath: string, def: T) {
|
||||||
const data = readFileSync(filepath).toString();
|
const data = readFileSync(filepath).toString();
|
||||||
const parsed = YAML.parse(data);
|
const parsed = YAML.parse(data);
|
||||||
|
|
||||||
return parsed as T || def;
|
return parsed as T;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Unable to load config:", err);
|
console.error("Unable to load config:", err);
|
||||||
} finally {
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,14 @@ declare type ChannelSettings = {
|
||||||
crownsolo: boolean;
|
crownsolo: boolean;
|
||||||
chat: boolean;
|
chat: boolean;
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
limit: number;
|
|
||||||
} & Partial<{
|
} & Partial<{
|
||||||
color2: string;
|
color2: string;
|
||||||
lobby: boolean;
|
lobby: boolean;
|
||||||
owner_id: string;
|
owner_id: string;
|
||||||
"lyrical notes": boolean;
|
"lyrical notes": boolean;
|
||||||
"no cussing": boolean;
|
"no cussing": boolean;
|
||||||
|
|
||||||
|
limit: number;
|
||||||
noindex: boolean;
|
noindex: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue