From 8eb344a655691b70bd964cda6779a08ddb71d879 Mon Sep 17 00:00:00 2001 From: Moonbase Date: Fri, 14 Nov 2025 18:35:12 -0800 Subject: [PATCH] Treat Lobby As A Normal Room --- qtc-net-server/Hubs/ChatHub.cs | 62 +++++++++------------------------- 1 file changed, 16 insertions(+), 46 deletions(-) diff --git a/qtc-net-server/Hubs/ChatHub.cs b/qtc-net-server/Hubs/ChatHub.cs index 72ad6a5..eb0ea8e 100644 --- a/qtc-net-server/Hubs/ChatHub.cs +++ b/qtc-net-server/Hubs/ChatHub.cs @@ -91,20 +91,6 @@ namespace qtc_api.Hubs } } - [HubMethodName("JoinRoomGuest")] - public async Task JoinRoomGuestAsync(string roomId, string username) - { - // here we can just add the client to the room group and call it a day since the user isn't authenticated - var room = await _roomService.GetRoom(roomId); - - if(room != null && room.Success && room.Data != null) - { - await Groups.AddToGroupAsync(Context.ConnectionId, room.Data.Id); - - await Clients.Group(room.Data.Id).SendAsync("GuestJoin", username); - } - } - [HubMethodName("UpdateStatus")] [Authorize] public async Task UpdateStatusAsync(User user, int status) @@ -124,35 +110,6 @@ namespace qtc_api.Hubs Log($"Something Went Wrong Setting The Status On User {user.Username}"); } - [HubMethodName("JoinLobby")] - [Authorize] - public async Task JoinLobbyAsync(User user) - { - await Groups.AddToGroupAsync(Context.ConnectionId, "LOBBY"); - - await Clients.Group("LOBBY").SendAsync("RoomMessage", $"[SERVER] User {user.Username} Has Joined The Lobby"); - - if (!GroupUsers.TryGetValue("LOBBY", out _)) { GroupUsers.Add("LOBBY", new List()); } - GroupUsers["LOBBY"].Add(user); - - await Clients.Groups("LOBBY").SendAsync("RoomUserList", GroupUsers["LOBBY"]); - Log($"User {user.Username} Has Joined The Lobby"); - } - - [HubMethodName("LeaveLobby")] - [Authorize] - public async Task LeaveLobbyAsync(User user) - { - await Groups.RemoveFromGroupAsync(Context.ConnectionId, "LOBBY"); - - await Clients.Group("LOBBY").SendAsync("RoomMessage", $"[SERVER] User {user.Username} Has Left The Lobby"); - - if (GroupUsers.TryGetValue("LOBBY", out _)) GroupUsers["LOBBY"].Remove(GroupUsers["LOBBY"].FirstOrDefault(e => e.Id == user.Id)!); - - await Clients.Client("LOBBY").SendAsync("RoomUserList", GroupUsers["LOBBY"]); - Log($"User {user.Username} Has Left The Lobby"); - } - [HubMethodName("JoinRoom")] [Authorize] public async Task JoinRoomAsync(User user, Room room) @@ -168,6 +125,20 @@ namespace qtc_api.Hubs Log($"User {user.Username} Has Joined {room.Name}"); } + [HubMethodName("JoinRoomGuest")] + public async Task JoinRoomGuestAsync(string roomId, string username) + { + // here we can just add the client to the room group and call it a day since the user isn't authenticated + var room = await _roomService.GetRoom(roomId); + + if (room != null && room.Success && room.Data != null) + { + await Groups.AddToGroupAsync(Context.ConnectionId, room.Data.Id); + + await Clients.Group(room.Data.Id).SendAsync("GuestJoin", username); + } + } + [HubMethodName("LeaveRoom")] [Authorize] public async Task LeaveRoomAsync(User user, Room room) @@ -184,10 +155,9 @@ namespace qtc_api.Hubs [HubMethodName("SendMessage")] [Authorize] - public async Task SendMessageAsync(User user, Message message, bool IsLobbyMsg, Room room = null!) + public async Task SendMessageAsync(User user, Message message, Room room) { - if(IsLobbyMsg == true) { await Clients.Group("LOBBY").SendAsync("RoomMessage", $"[{user.Username}] {message.Content}"); return; } - await Clients.Group(room.Id).SendAsync("RoomMessage", $"[{user.Username}] {message.Content}"); + await Clients.Group(room.Id).SendAsync("RoomMessage", $"{user.Username}: {message.Content}"); } [HubMethodName("SendDirectMessage")]