Skip to content

Commit

Permalink
feat(nin0): use user in question as join/leave author
Browse files Browse the repository at this point in the history
this allows clients to automatically determine who joined/left, allowing the message to be customized. the old message is left for backwards-compatibility.
  • Loading branch information
PoolloverNathan committed Oct 23, 2024
1 parent 5a1c4a7 commit 13ca1c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions src/opcodes/accountInitialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13ca1c7

Please sign in to comment.