From 75f400330934fa16a77616d9b7cd5cc1f6b7746a Mon Sep 17 00:00:00 2001 From: PoolloverNathan Date: Wed, 23 Oct 2024 03:00:37 +0000 Subject: [PATCH] feat(gateway): use user in question as join/leave author this allows clients to automatically determine who joined/left, allowing the message to be customized. the old message is left for backwards-compatibility. --- src/index.ts | 6 +++--- src/opcodes/accountInitialisation.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2deed7c..c4b5668 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,9 +40,9 @@ wss.on("connection", function connection(ws: ChatClient, req) { sendMessage({ type: MessageTypes.Leave, userInfo: { - username: "System", - roles: Role.System, - id: "1" + username: ws.username, + roles: Role.System | ws.roles, + id: ws.id, }, content: `${ws.username} has left the chat.\nCurrently ${wss.clients.size} user${ wss.clients.size === 1 ? " is" : "s are" diff --git a/src/opcodes/accountInitialisation.ts b/src/opcodes/accountInitialisation.ts index d6fa296..bd96bfb 100644 --- a/src/opcodes/accountInitialisation.ts +++ b/src/opcodes/accountInitialisation.ts @@ -54,11 +54,11 @@ export async function accountInitialisation(client: ChatClient, d: any) { ); sendMessage({ type: 1, - userInfo: { - username: "System", - roles: Role.System, - id: "1" - }, + userInfo: { + username: client.username!, + roles: Role.System | client.roles!, + id: client.id!, + }, content: `${client.username} *(guest)* has joined the chat. Say hi!\nCurrently ${ wss.clients.size } user${wss.clients.size === 1 ? " is" : "s are"} online.`, @@ -132,9 +132,9 @@ export async function accountInitialisation(client: ChatClient, d: any) { sendMessage({ type: MessageTypes.Join, userInfo: { - username: "System", - roles: Role.System, - id: "1" + username: client.username!, + roles: Role.System | client.roles!, + id: client.id!, }, content: `${client.username} has joined the chat. Say hi!\nCurrently ${ wss.clients.size