|
|
@ -33,7 +33,11 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
_logger = logger; |
|
|
|
_logger = logger; |
|
|
|
this.roomManager = roomManager; |
|
|
|
this.roomManager = roomManager; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 获取当前房间列表 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="userId"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
public List<RoomShowInfo> CallServer_GetRoomList(string userId) |
|
|
|
public List<RoomShowInfo> CallServer_GetRoomList(string userId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return roomManager.GetAllRooms(); |
|
|
|
return roomManager.GetAllRooms(); |
|
|
@ -57,7 +61,7 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
RoomCreateResultData resultData = new RoomCreateResultData(); |
|
|
|
RoomCreateResultData resultData = new RoomCreateResultData()!; |
|
|
|
var user = roomManager.GetUser(createInfo.UserId); |
|
|
|
var user = roomManager.GetUser(createInfo.UserId); |
|
|
|
if (user == null)//查询不到创建房间的用户 |
|
|
|
if (user == null)//查询不到创建房间的用户 |
|
|
|
{ |
|
|
|
{ |
|
|
@ -74,12 +78,14 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
resultData.RoomCreateResult = RoomCreateResult.RoomReName; |
|
|
|
resultData.RoomCreateResult = RoomCreateResult.RoomReName; |
|
|
|
return resultData; |
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
FireDeductionRoom room = new FireDeductionRoom(); |
|
|
|
FireDeductionRoom room = new() |
|
|
|
room.Owner = createInfo.UserId; |
|
|
|
{ |
|
|
|
room.OwnerName = user.UserName; |
|
|
|
Owner = createInfo.UserId, |
|
|
|
room.RoomId = Guid.NewGuid().ToString(); |
|
|
|
OwnerName = user.UserName, |
|
|
|
room.RoomName = createInfo.Name = createInfo.Name; |
|
|
|
RoomId = Guid.NewGuid().ToString(), |
|
|
|
room.Password = createInfo.Password; |
|
|
|
RoomName = createInfo.Name, |
|
|
|
|
|
|
|
Password = createInfo.Password |
|
|
|
|
|
|
|
}; |
|
|
|
roomManager.AddRoom(room); |
|
|
|
roomManager.AddRoom(room); |
|
|
|
|
|
|
|
|
|
|
|
user.RoomId = room.RoomId; |
|
|
|
user.RoomId = room.RoomId; |
|
|
@ -97,29 +103,40 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
throw new Exception(ex.Message); |
|
|
|
throw new Exception(ex.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public bool CallServer_EnterRoom(string roomId, FireDeductionUser user, string? password = null) |
|
|
|
|
|
|
|
|
|
|
|
public async Task<RoomEnterResult> CallServer_EnterRoom(RoomEnterData enterInfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool result = false; |
|
|
|
|
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
var room = roomManager.GetRoom(roomId); |
|
|
|
var room = roomManager.GetRoom(enterInfo.RoomId); |
|
|
|
if (room != null && room.Password == password) |
|
|
|
if (room == null)//根据id查不到房间 |
|
|
|
{ |
|
|
|
|
|
|
|
if (!room.Users.Contains(user)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
return RoomEnterResult.RoomError; |
|
|
|
result = true; |
|
|
|
|
|
|
|
room.Users.Add(user); |
|
|
|
|
|
|
|
user.RoomId = room.RoomId; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
var user = roomManager.GetUser(enterInfo.UserId); |
|
|
|
|
|
|
|
if (user == null)//根据id查不到用户 |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException("房间中已经存在该用户!"); |
|
|
|
return RoomEnterResult.NoUserExist; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var roomHas = roomManager.GetRoom(enterInfo.RoomId, enterInfo.Password); |
|
|
|
|
|
|
|
if (roomHas != null)//获取到要进入的房间跟用户信息 |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
roomManager.AddUser(user); |
|
|
|
|
|
|
|
user.RoomId = roomHas.RoomId; |
|
|
|
|
|
|
|
RoommateChangeData data = new() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ChangeType = RoommateChangeType.Add, |
|
|
|
|
|
|
|
FireDeductionUser = user, |
|
|
|
|
|
|
|
FireDeductionUsers = roomHas.Users |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
//通知web端刷新房间用户列表 |
|
|
|
|
|
|
|
await Clients.Group(roomHas.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return RoomEnterResult.Success; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException("房间信息有误!"); |
|
|
|
return RoomEnterResult.RoomError; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
catch (Exception) |
|
|
@ -127,38 +144,41 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
|
|
|
|
|
|
|
|
throw; |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> LeaveRoom(string roomId, string userId) |
|
|
|
public async Task<RoomEnterResult> CallServer_LeaveRoom(RoomLeaveData leaveInfo) |
|
|
|
{ |
|
|
|
|
|
|
|
bool result = false; |
|
|
|
|
|
|
|
await Task.Run(() => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var room = roomManager.GetRoom(roomId); |
|
|
|
|
|
|
|
if (room != null) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
var user = room.Users.FirstOrDefault(u => u.UserId == userId); |
|
|
|
try |
|
|
|
if (user != null) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
room.Users.Remove(user); |
|
|
|
var room = roomManager.GetRoom(leaveInfo.RoomId); |
|
|
|
if (room.Users.Count == 0) |
|
|
|
if (room == null)//根据id查不到房间 |
|
|
|
{ |
|
|
|
{ |
|
|
|
//TODO:保持空房间xx分钟 |
|
|
|
return RoomEnterResult.RoomError; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
var user = roomManager.GetUser(leaveInfo.UserId); |
|
|
|
|
|
|
|
if (user == null)//根据id查不到用户 |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException("用户信息有误!"); |
|
|
|
return RoomEnterResult.NoUserExist; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
roomManager.RemoveUser(leaveInfo.UserId); |
|
|
|
|
|
|
|
user.RoomId = ""; |
|
|
|
|
|
|
|
RoommateChangeData data = new() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ChangeType = RoommateChangeType.Remove, |
|
|
|
|
|
|
|
FireDeductionUser = user, |
|
|
|
|
|
|
|
FireDeductionUsers = room.Users |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
//通知web端刷新房间用户列表 |
|
|
|
|
|
|
|
await Clients.Group(room.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return RoomEnterResult.Success; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException("房间信息有误!"); |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public async Task RoomSendMessage(string RoomId, string Message) |
|
|
|
public async Task RoomSendMessage(string RoomId, string Message) |
|
|
|
{ |
|
|
|
{ |
|
|
|