Treat Lobby As A Normal Room
This commit is contained in:
parent
3c4f0dacb3
commit
8eb344a655
@ -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")]
|
[HubMethodName("UpdateStatus")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task UpdateStatusAsync(User user, int status)
|
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}");
|
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<User>()); }
|
|
||||||
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")]
|
[HubMethodName("JoinRoom")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task JoinRoomAsync(User user, Room room)
|
public async Task JoinRoomAsync(User user, Room room)
|
||||||
@ -168,6 +125,20 @@ namespace qtc_api.Hubs
|
|||||||
Log($"User {user.Username} Has Joined {room.Name}");
|
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")]
|
[HubMethodName("LeaveRoom")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task LeaveRoomAsync(User user, Room room)
|
public async Task LeaveRoomAsync(User user, Room room)
|
||||||
@ -184,10 +155,9 @@ namespace qtc_api.Hubs
|
|||||||
|
|
||||||
[HubMethodName("SendMessage")]
|
[HubMethodName("SendMessage")]
|
||||||
[Authorize]
|
[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")]
|
[HubMethodName("SendDirectMessage")]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user