From 8644f3787e8963b105c9c9fce0201136dab14bbb Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Sun, 28 Jan 2024 10:51:10 -0500 Subject: [PATCH] Add chset --- src/channel/Channel.ts | 37 ++++++++++++++++++++++++++-- src/ws/events/user/handlers/chset.ts | 12 +++++++++ src/ws/events/user/index.ts | 2 ++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/ws/events/user/handlers/chset.ts diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index b48c440..a70c044 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -173,6 +173,37 @@ export class Channel extends EventEmitter { if (set.owner_id) set.owner_id = undefined; } + this.logger.debug( + "Dreaded color2 conditions:", + typeof set.color == "string", + "and", + typeof set.color2 == "undefined" + ); + + if ( + typeof set.color == "string" && + (typeof set.color2 == "undefined" || + set.color2 === this.settings.color2) + ) { + this.logger.debug("Setting color 2 from first color:", set.color); + this.logger.debug("Red:", parseInt(set.color.substring(1, 2), 16)); + const r = Math.max( + 0, + parseInt(set.color.substring(1, 3), 16) - 0x40 + ); + const g = Math.max( + 0, + parseInt(set.color.substring(3, 5), 16) - 0x40 + ); + const b = Math.max( + 0, + 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")}`; + this.logger.debug("Color 2 is now:", set.color2); + } + if (this.isLobby() && !admin) return; // Verify settings @@ -187,6 +218,8 @@ export class Channel extends EventEmitter { )[key]; } } + + this.emit("update", this); } /** @@ -289,7 +322,7 @@ export class Channel extends EventEmitter { * @param socket Socket that is leaving */ public leave(socket: Socket) { - this.logger.debug("Leave called"); + // this.logger.debug("Leave called"); const part = socket.getParticipant() as Participant; let dupeCount = 0; @@ -301,7 +334,7 @@ export class Channel extends EventEmitter { } } - this.logger.debug("Dupes:", dupeCount); + // this.logger.debug("Dupes:", dupeCount); if (dupeCount == 1) { const p = this.ppl.find(p => p.id == socket.getParticipantID()); diff --git a/src/ws/events/user/handlers/chset.ts b/src/ws/events/user/handlers/chset.ts new file mode 100644 index 0000000..cf38125 --- /dev/null +++ b/src/ws/events/user/handlers/chset.ts @@ -0,0 +1,12 @@ +import { ServerEventListener } from "../../../../util/types"; + +export const chset: ServerEventListener<"chset"> = { + id: "chset", + callback: (msg, socket) => { + // Change channel settings + if (typeof msg.set == "undefined") return; + const ch = socket.getCurrentChannel(); + if (!ch) return; + ch.changeSettings(msg.set, false); + } +}; diff --git a/src/ws/events/user/index.ts b/src/ws/events/user/index.ts index 38fb80f..d6e3bc1 100644 --- a/src/ws/events/user/index.ts +++ b/src/ws/events/user/index.ts @@ -12,6 +12,7 @@ import { n } from "./handlers/n"; import { plus_ls } from "./handlers/+ls"; import { minus_ls } from "./handlers/-ls"; import { admin_message } from "./handlers/admin_message"; +import { chset } from "./handlers/chset"; EVENTGROUP_USER.add(hi); EVENTGROUP_USER.add(devices); @@ -23,5 +24,6 @@ EVENTGROUP_USER.add(n); EVENTGROUP_USER.add(plus_ls); EVENTGROUP_USER.add(minus_ls); EVENTGROUP_USER.add(admin_message); +EVENTGROUP_USER.add(chset); eventGroups.push(EVENTGROUP_USER);