|
|
@ -88,8 +88,9 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
}; |
|
|
|
}; |
|
|
|
roomManager.AddRoom(room); |
|
|
|
roomManager.AddRoom(room); |
|
|
|
|
|
|
|
|
|
|
|
user.RoomId = room.RoomId; |
|
|
|
//移除逻辑:创建房间直接进入房间的处理逻辑由web端主动发起进入房间 |
|
|
|
room.Users.Add(user); |
|
|
|
//user.RoomId = room.RoomId; |
|
|
|
|
|
|
|
//room.Users.Add(user); |
|
|
|
|
|
|
|
|
|
|
|
await Groups.AddToGroupAsync(user.ConnectionId, room.RoomId); |
|
|
|
await Groups.AddToGroupAsync(user.ConnectionId, room.RoomId); |
|
|
|
await Clients.All.SendAsync("callWeb_refreshRoomList", roomManager.GetAllRooms()); |
|
|
|
await Clients.All.SendAsync("callWeb_refreshRoomList", roomManager.GetAllRooms()); |
|
|
@ -108,19 +109,22 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="enterInfo"></param> |
|
|
|
/// <param name="enterInfo"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<RoomEnterResult> CallServer_EnterRoom(RoomEnterData enterInfo) |
|
|
|
public async Task<RoomEnterResultData> CallServer_EnterRoom(RoomEnterData enterInfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
RoomEnterResultData resultData = new(); |
|
|
|
var room = roomManager.GetRoom(enterInfo.RoomId); |
|
|
|
var room = roomManager.GetRoom(enterInfo.RoomId); |
|
|
|
if (room == null)//根据id查不到房间 |
|
|
|
if (room == null)//根据id查不到房间 |
|
|
|
{ |
|
|
|
{ |
|
|
|
return RoomEnterResult.RoomError; |
|
|
|
resultData.enterResult = RoomEnterResult.RoomError; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
var user = roomManager.GetUser(enterInfo.UserId); |
|
|
|
var user = roomManager.GetUser(enterInfo.UserId); |
|
|
|
if (user == null)//根据id查不到用户 |
|
|
|
if (user == null)//根据id查不到用户 |
|
|
|
{ |
|
|
|
{ |
|
|
|
return RoomEnterResult.NoUserExist; |
|
|
|
resultData.enterResult = RoomEnterResult.NoUserExist; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
var roomHas = roomManager.GetRoom(enterInfo.RoomId, enterInfo.Password); |
|
|
|
var roomHas = roomManager.GetRoom(enterInfo.RoomId, enterInfo.Password); |
|
|
|
if (roomHas != null)//获取到要进入的房间跟用户信息 |
|
|
|
if (roomHas != null)//获取到要进入的房间跟用户信息 |
|
|
@ -136,11 +140,14 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
//通知web端刷新房间用户列表 |
|
|
|
//通知web端刷新房间用户列表 |
|
|
|
await Clients.Group(roomHas.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
await Clients.Group(roomHas.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
|
|
|
|
|
|
|
|
return RoomEnterResult.Success; |
|
|
|
resultData.RoomId = roomHas.RoomId; |
|
|
|
|
|
|
|
resultData.enterResult = RoomEnterResult.Success; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
return RoomEnterResult.RoomError; |
|
|
|
resultData.enterResult = RoomEnterResult.RoomError; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
catch (Exception) |
|
|
@ -155,19 +162,22 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="leaveInfo"></param> |
|
|
|
/// <param name="leaveInfo"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<RoomEnterResult> CallServer_LeaveRoom(RoomLeaveData leaveInfo) |
|
|
|
public async Task<RoomLeaveResultData> CallServer_LeaveRoom(RoomLeaveData leaveInfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
RoomLeaveResultData resultData = new(); |
|
|
|
var room = roomManager.GetRoom(leaveInfo.RoomId); |
|
|
|
var room = roomManager.GetRoom(leaveInfo.RoomId); |
|
|
|
if (room == null)//根据id查不到房间 |
|
|
|
if (room == null)//根据id查不到房间 |
|
|
|
{ |
|
|
|
{ |
|
|
|
return RoomEnterResult.RoomError; |
|
|
|
resultData.leaveResult = RoomLeaveResult.RoomError; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
var user = roomManager.GetUser(leaveInfo.UserId); |
|
|
|
var user = roomManager.GetUser(leaveInfo.UserId); |
|
|
|
if (user == null)//根据id查不到用户 |
|
|
|
if (user == null)//根据id查不到用户 |
|
|
|
{ |
|
|
|
{ |
|
|
|
return RoomEnterResult.NoUserExist; |
|
|
|
resultData.leaveResult = RoomLeaveResult.NoUserExist; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
roomManager.RemoveUser(leaveInfo.UserId); |
|
|
|
roomManager.RemoveUser(leaveInfo.UserId); |
|
|
@ -181,7 +191,9 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
//通知web端刷新房间用户列表 |
|
|
|
//通知web端刷新房间用户列表 |
|
|
|
await Clients.Group(room.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
await Clients.Group(room.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
|
|
|
|
|
|
|
|
return RoomEnterResult.Success; |
|
|
|
resultData.RoomId = room.RoomId; |
|
|
|
|
|
|
|
resultData.leaveResult = RoomLeaveResult.Success; |
|
|
|
|
|
|
|
return resultData; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
{ |
|
|
|