From 620c6d39faf286e4c4d13690bccda7d2ec1b1aa5 Mon Sep 17 00:00:00 2001 From: YDL <1368269699@QQ.COM> Date: Thu, 22 Sep 2022 09:33:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=88=BF=E9=97=B4=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AX.WebDrillServer/Hubs/FireDeductionHub.cs | 43 ++++++++++++------- .../FireDeductionHub/RoomCreateDto.cs | 4 +- .../Services/FireDeductionHub/RoomManager.cs | 1 - 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/AX.WebDrillServer/Hubs/FireDeductionHub.cs b/AX.WebDrillServer/Hubs/FireDeductionHub.cs index 79a04cc..797c227 100644 --- a/AX.WebDrillServer/Hubs/FireDeductionHub.cs +++ b/AX.WebDrillServer/Hubs/FireDeductionHub.cs @@ -43,14 +43,19 @@ namespace AX.WebDrillServer.Hubs { return roomManager.GetUserByConnectionId(connectionId); } - + /// + /// 创建房间 + /// + /// + /// + /// public async Task CallServer_CreateRoom(RoomCreateDto createInfo) { try { RoomCreateResultData resultData = new RoomCreateResultData(); var user = roomManager.GetUser(createInfo.UserId); - if (user == null) + if (user == null)//如果查询不到创建房间的用户 { resultData.RoomCreateResult = RoomCreateResult.用户不存在; return resultData; @@ -58,8 +63,8 @@ namespace AX.WebDrillServer.Hubs FireDeductionRoom room = new FireDeductionRoom(); room.Owner = createInfo.UserId; room.RoomId = Guid.NewGuid().ToString(); - room.RoomName = createInfo.RoomName; - room.Password = createInfo.RoomPassword; + room.RoomName = createInfo.Name == null ? "未命名房间" : createInfo.Name; + room.Password = createInfo.Password; roomManager.AddRoom(room); user.RoomId = room.RoomId; @@ -77,28 +82,36 @@ namespace AX.WebDrillServer.Hubs throw new Exception(ex.Message); } } - public async Task EnterRoom(string roomId, FireDeductionUser user, string? password = null) + public bool CallServer_EnterRoom(string roomId, FireDeductionUser user, string? password = null) { bool result = false; - - var room = roomManager.GetRoom(roomId); - if (room != null && room.Password == password) + try { - if (!room.Users.Contains(user)) + var room = roomManager.GetRoom(roomId); + if (room != null && room.Password == password) { - result = true; + if (!room.Users.Contains(user)) + { + + result = true; + room.Users.Add(user); + user.RoomId = room.RoomId; + } + else + { + throw new NotImplementedException("房间中已经存在该用户!"); + } } else { - throw new NotImplementedException("房间中已经存在该用户!"); + throw new NotImplementedException("房间信息有误!"); } } - else + catch (Exception) { - throw new NotImplementedException("房间信息有误!"); - } - + throw; + } return result; } diff --git a/AX.WebDrillServer/Services/FireDeductionHub/RoomCreateDto.cs b/AX.WebDrillServer/Services/FireDeductionHub/RoomCreateDto.cs index 301ff45..c358547 100644 --- a/AX.WebDrillServer/Services/FireDeductionHub/RoomCreateDto.cs +++ b/AX.WebDrillServer/Services/FireDeductionHub/RoomCreateDto.cs @@ -3,7 +3,7 @@ public class RoomCreateDto { public string UserId { get; set; } = null!; - public string? RoomPassword { get; set; } - public string RoomName { get; set; } = null!; + public string? Password { get; set; } + public string Name { get; set; } = null!; } } diff --git a/AX.WebDrillServer/Services/FireDeductionHub/RoomManager.cs b/AX.WebDrillServer/Services/FireDeductionHub/RoomManager.cs index 1ebf7c0..3b25998 100644 --- a/AX.WebDrillServer/Services/FireDeductionHub/RoomManager.cs +++ b/AX.WebDrillServer/Services/FireDeductionHub/RoomManager.cs @@ -2,7 +2,6 @@ { public class RoomManager { - private List fireDeductionRooms = new List(); private List fireDeductionUsers = new List();