Fix crucial channel settings bug
This commit is contained in:
parent
3dd5201750
commit
5d5c10d7a5
|
@ -15,6 +15,7 @@ import Crown from "./Crown";
|
||||||
import { ChannelList } from "./ChannelList";
|
import { ChannelList } from "./ChannelList";
|
||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
import { saveChatHistory, getChatHistory } from "../data/history";
|
import { saveChatHistory, getChatHistory } from "../data/history";
|
||||||
|
import { mixin } from "../util/helpers";
|
||||||
|
|
||||||
interface CachedKickban {
|
interface CachedKickban {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
@ -23,9 +24,10 @@ interface CachedKickban {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Channel extends EventEmitter {
|
export class Channel extends EventEmitter {
|
||||||
private settings: Partial<IChannelSettings> = config.defaultSettings;
|
private settings: Partial<IChannelSettings>;
|
||||||
private ppl = new Array<Participant>();
|
private ppl = new Array<Participant>();
|
||||||
public chatHistory = new Array<ClientEvents["a"]>();
|
public chatHistory = new Array<ClientEvents["a"]>();
|
||||||
|
|
||||||
private async loadChatHistory() {
|
private async loadChatHistory() {
|
||||||
this.chatHistory = await getChatHistory(this.getID());
|
this.chatHistory = await getChatHistory(this.getID());
|
||||||
}
|
}
|
||||||
|
@ -44,6 +46,8 @@ export class Channel extends EventEmitter {
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.settings = {};
|
||||||
|
mixin(this.settings, config.defaultSettings);
|
||||||
this.logger = new Logger("Channel - " + _id);
|
this.logger = new Logger("Channel - " + _id);
|
||||||
|
|
||||||
// Validate settings in set
|
// Validate settings in set
|
||||||
|
@ -51,7 +55,9 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
if (!this.isLobby()) {
|
if (!this.isLobby()) {
|
||||||
if (set) {
|
if (set) {
|
||||||
|
this.logger.debug("Passed settings:", set);
|
||||||
const validatedSet = validateChannelSettings(set);
|
const validatedSet = validateChannelSettings(set);
|
||||||
|
this.logger.debug("Validated settings:", validatedSet);
|
||||||
|
|
||||||
for (const key of Object.keys(set)) {
|
for (const key of Object.keys(set)) {
|
||||||
if ((validatedSet as any)[key] === false) continue;
|
if ((validatedSet as any)[key] === false) continue;
|
||||||
|
@ -67,9 +73,7 @@ export class Channel extends EventEmitter {
|
||||||
if (part) this.giveCrown(part);
|
if (part) this.giveCrown(part);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (this.isLobby()) {
|
|
||||||
this.settings = config.lobbySettings;
|
this.settings = config.lobbySettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +216,9 @@ export class Channel extends EventEmitter {
|
||||||
parseInt(set.color.substring(5, 7), 16) - 0x40
|
parseInt(set.color.substring(5, 7), 16) - 0x40
|
||||||
);
|
);
|
||||||
|
|
||||||
set.color2 = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
set.color2 = `#${r.toString(16).padStart(2, "0")}${g
|
||||||
|
.toString(16)
|
||||||
|
.padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isLobby() && !admin) return;
|
if (this.isLobby() && !admin) return;
|
||||||
|
@ -305,12 +311,12 @@ export class Channel extends EventEmitter {
|
||||||
|
|
||||||
// Send our state data back
|
// Send our state data back
|
||||||
socket.sendArray([
|
socket.sendArray([
|
||||||
{
|
// {
|
||||||
m: "ch",
|
// m: "ch",
|
||||||
ch: this.getInfo(),
|
// ch: this.getInfo(),
|
||||||
p: part.id,
|
// p: part.id,
|
||||||
ppl: this.getParticipantList()
|
// ppl: this.getParticipantList()
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
m: "c",
|
m: "c",
|
||||||
c: this.chatHistory.slice(-50)
|
c: this.chatHistory.slice(-50)
|
||||||
|
@ -324,20 +330,25 @@ export class Channel extends EventEmitter {
|
||||||
} = socket.getCursorPos();
|
} = socket.getCursorPos();
|
||||||
|
|
||||||
// Broadcast a participant update for them
|
// Broadcast a participant update for them
|
||||||
this.sendArray([
|
this.sendArray(
|
||||||
{
|
[
|
||||||
m: "p",
|
{
|
||||||
_id: part._id,
|
m: "p",
|
||||||
name: part.name,
|
_id: part._id,
|
||||||
color: part.color,
|
name: part.name,
|
||||||
id: part.id,
|
color: part.color,
|
||||||
x: cursorPos.x,
|
id: part.id,
|
||||||
y: cursorPos.y
|
x: cursorPos.x,
|
||||||
}
|
y: cursorPos.y
|
||||||
]);
|
}
|
||||||
|
],
|
||||||
|
part.id
|
||||||
|
);
|
||||||
|
|
||||||
// Broadcast a channel update so everyone subscribed to the channel list can see us
|
// Broadcast a channel update so everyone subscribed to the channel list can see us
|
||||||
this.emit("update", this);
|
this.emit("update", this);
|
||||||
|
|
||||||
|
this.logger.debug("Settings:", this.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -442,11 +453,16 @@ export class Channel extends EventEmitter {
|
||||||
* @param arr List of events to send to clients
|
* @param arr List of events to send to clients
|
||||||
*/
|
*/
|
||||||
public sendArray<EventID extends keyof ClientEvents>(
|
public sendArray<EventID extends keyof ClientEvents>(
|
||||||
arr: ClientEvents[EventID][]
|
arr: ClientEvents[EventID][],
|
||||||
|
blockPartID?: string
|
||||||
) {
|
) {
|
||||||
let sentSocketIDs = new Array<string>();
|
let sentSocketIDs = new Array<string>();
|
||||||
|
|
||||||
for (const p of this.ppl) {
|
for (const p of this.ppl) {
|
||||||
|
if (blockPartID) {
|
||||||
|
if (p.id == blockPartID) continue;
|
||||||
|
}
|
||||||
|
|
||||||
socketLoop: for (const socket of socketsBySocketID.values()) {
|
socketLoop: for (const socket of socketsBySocketID.values()) {
|
||||||
if (socket.isDestroyed()) continue socketLoop;
|
if (socket.isDestroyed()) continue socketLoop;
|
||||||
if (socket.getParticipantID() != p.id) continue socketLoop;
|
if (socket.getParticipantID() != p.id) continue socketLoop;
|
||||||
|
|
|
@ -57,3 +57,9 @@ export function spoop_text(message: string) {
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function mixin(obj1: any, obj2: any) {
|
||||||
|
for (const key of Object.keys(obj2)) {
|
||||||
|
obj1[key] = obj2[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -29,11 +29,11 @@ Command.addCommand(
|
||||||
Command.addCommand(
|
Command.addCommand(
|
||||||
new Command(["memory", "mem"], "memory", msg => {
|
new Command(["memory", "mem"], "memory", msg => {
|
||||||
const mem = process.memoryUsage();
|
const mem = process.memoryUsage();
|
||||||
return `Memory: ${(mem.heapUsed / 1000 / 1000).toFixed(2)} MB used / ${(
|
return `Memory: ${(mem.heapUsed / 1000 / 1000).toFixed(2)} MB / ${(
|
||||||
mem.heapTotal /
|
mem.heapTotal /
|
||||||
1000 /
|
1000 /
|
||||||
1000
|
1000
|
||||||
).toFixed(2)} MB total`;
|
).toFixed(2)} MB / ${(mem.rss / 1000 / 1000).toFixed(2)} MB`;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -51,24 +51,22 @@ Command.addCommand(
|
||||||
|
|
||||||
Command.addCommand(
|
Command.addCommand(
|
||||||
new Command(["list", "ls"], "list <channels, users>", async msg => {
|
new Command(["list", "ls"], "list <channels, users>", async msg => {
|
||||||
if(msg.args.length > 1) {
|
if (msg.args.length > 1) {
|
||||||
if(msg.args[1] == "channels") {
|
if (msg.args[1] == "channels") {
|
||||||
return (
|
return (
|
||||||
"Channels:\n- " +
|
"Channels:\n- " +
|
||||||
ChannelList.getList()
|
ChannelList.getList()
|
||||||
.map(ch => ch.getID())
|
.map(ch => ch.getID())
|
||||||
.join("\n- ")
|
.join("\n- ")
|
||||||
);
|
);
|
||||||
} else if (msg.args[1] == "users") {
|
} else if (msg.args[1] == "users") {
|
||||||
var user = getUsers();
|
var user = getUsers();
|
||||||
var users = "";
|
var users = "";
|
||||||
((await user).users).forEach(u => {
|
(await user).users.forEach(u => {
|
||||||
users += `\n- [${u.id}]: ${u.name}`
|
users += `\n- [${u.id}]: ${u.name}`;
|
||||||
})
|
});
|
||||||
|
|
||||||
return (
|
return "Users: " + (await (await user).count) + users;
|
||||||
"Users: "+await (await user).count + users
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return "list <channels, users>";
|
return "list <channels, users>";
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ export class Socket extends EventEmitter {
|
||||||
_id: facadeID,
|
_id: facadeID,
|
||||||
name: this.user.name,
|
name: this.user.name,
|
||||||
color: this.user.color,
|
color: this.user.color,
|
||||||
id: this.id
|
id: this.getParticipantID()
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue