|
|
|
@ -43,14 +43,19 @@ namespace AX.WebDrillServer.Hubs
|
|
|
|
|
{ |
|
|
|
|
return roomManager.GetUserByConnectionId(connectionId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 创建房间 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="createInfo"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
/// <exception cref="Exception"></exception> |
|
|
|
|
public async Task<RoomCreateResultData> 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<bool> 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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|