|
|
|
@ -7,7 +7,10 @@ using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
|
using Microsoft.VisualBasic; |
|
|
|
|
using NPOI.SS.Util; |
|
|
|
|
using System.Collections.Concurrent; |
|
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
using System.Security.Claims; |
|
|
|
|
|
|
|
|
|
namespace AX.WebDrillServer.Hubs |
|
|
|
@ -30,16 +33,48 @@ namespace AX.WebDrillServer.Hubs
|
|
|
|
|
_logger = logger; |
|
|
|
|
this.roomManager = roomManager; |
|
|
|
|
} |
|
|
|
|
public async Task<FireDeductionRoom> CreateRoom(RoomCreateDto createInfo, FireDeductionUser user) |
|
|
|
|
|
|
|
|
|
public List<FireDeductionRoom> CallServer_GetRoomList(string userId) |
|
|
|
|
{ |
|
|
|
|
FireDeductionRoom room = new FireDeductionRoom(); |
|
|
|
|
room.Owner = createInfo.UserId; |
|
|
|
|
room.RoomId = Guid.NewGuid().ToString(); |
|
|
|
|
room.RoomName = createInfo.RoomName; |
|
|
|
|
room.Password = createInfo.RoomPassword; |
|
|
|
|
room.Users.Add(user); |
|
|
|
|
await Groups.AddToGroupAsync(user.ConnectionId, room.RoomId); |
|
|
|
|
return room; |
|
|
|
|
return roomManager.GetAllRooms(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public FireDeductionUser? CallServer_GetUser(string connectionId) |
|
|
|
|
{ |
|
|
|
|
return roomManager.GetUserByConnectionId(connectionId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<RoomCreateResultData> CallServer_CreateRoom(RoomCreateDto createInfo) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
RoomCreateResultData resultData = new RoomCreateResultData(); |
|
|
|
|
var user = roomManager.GetUser(createInfo.UserId); |
|
|
|
|
if (user == null) |
|
|
|
|
{ |
|
|
|
|
resultData.RoomCreateResult = RoomCreateResult.用户不存在; |
|
|
|
|
return resultData; |
|
|
|
|
} |
|
|
|
|
FireDeductionRoom room = new FireDeductionRoom(); |
|
|
|
|
room.Owner = createInfo.UserId; |
|
|
|
|
room.RoomId = Guid.NewGuid().ToString(); |
|
|
|
|
room.RoomName = createInfo.RoomName; |
|
|
|
|
room.Password = createInfo.RoomPassword; |
|
|
|
|
roomManager.AddRoom(room); |
|
|
|
|
|
|
|
|
|
user.RoomId = room.RoomId; |
|
|
|
|
room.Users.Add(user); |
|
|
|
|
|
|
|
|
|
await Groups.AddToGroupAsync(user.ConnectionId, room.RoomId); |
|
|
|
|
await Clients.All.SendAsync("callWeb_refreshRoomList", roomManager.GetAllRooms()); |
|
|
|
|
|
|
|
|
|
resultData.RoomCreateResult = RoomCreateResult.成功; |
|
|
|
|
return resultData; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw new Exception(ex.Message); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public async Task<bool> EnterRoom(string roomId, FireDeductionUser user, string? password = null) |
|
|
|
|
{ |
|
|
|
@ -106,6 +141,7 @@ namespace AX.WebDrillServer.Hubs
|
|
|
|
|
{ |
|
|
|
|
await Clients.All.SendAsync(Message); |
|
|
|
|
//TODO:保存数据 |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task OnConnectedAsync() |
|
|
|
@ -119,6 +155,8 @@ namespace AX.WebDrillServer.Hubs
|
|
|
|
|
if (user != null) |
|
|
|
|
{ |
|
|
|
|
user.Online = true; |
|
|
|
|
if (user.ConnectionId != Context.ConnectionId) |
|
|
|
|
user.ConnectionId = Context.ConnectionId; |
|
|
|
|
var room = roomManager.GetRoomByUserId(user.UserId); |
|
|
|
|
if (room != null) |
|
|
|
|
{ |
|
|
|
@ -131,6 +169,8 @@ namespace AX.WebDrillServer.Hubs
|
|
|
|
|
user.ConnectionId = Context.ConnectionId; |
|
|
|
|
user.UserId = userId!; |
|
|
|
|
user.UserName = userName!; |
|
|
|
|
|
|
|
|
|
roomManager.AddUser(user); |
|
|
|
|
} |
|
|
|
|
_logger.LogInformation("[{userId}][{name}] connected", userId, userName); |
|
|
|
|
|
|
|
|
|