From 1c64c7e6332f7806f0a1d9adf19681ae45c9c7bc Mon Sep 17 00:00:00 2001 From: YDL <1368269699@QQ.COM> Date: Fri, 30 Sep 2022 15:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=A3=E6=95=A3=E6=88=BF?= =?UTF-8?q?=E9=97=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DateTimeExtensions.cs | 13 +++++ AX.WebDrillServer/Hubs/FireDeductionHub.cs | 53 +++++++++++++++++++ .../FireDeductionRoomEnums.cs | 6 ++- AX.WebDrillServer/appsettings.json | 4 +- 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/AX.WebDrillServer/Extensions/DateTimeExtensions.cs b/AX.WebDrillServer/Extensions/DateTimeExtensions.cs index b844e91..de6ba8e 100644 --- a/AX.WebDrillServer/Extensions/DateTimeExtensions.cs +++ b/AX.WebDrillServer/Extensions/DateTimeExtensions.cs @@ -59,5 +59,18 @@ { return (long)TimeSpan.FromTicks(time.Ticks - DateTime.UnixEpoch.Ticks).TotalMilliseconds - TimeZoneInfo.Local.GetUtcOffset(time).Hours * 60 * 60 * 1000; } + + /// + /// 将Unix时间戳转换为时间 + /// + /// + /// + public static DateTime GetDateTimeFromUnix(long timeStamp) + { + DateTime startDt = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Local); + long lTime = timeStamp * 10000; + TimeSpan toNow = new TimeSpan(lTime); + return startDt.Add(toNow); + } } } \ No newline at end of file diff --git a/AX.WebDrillServer/Hubs/FireDeductionHub.cs b/AX.WebDrillServer/Hubs/FireDeductionHub.cs index 61d6ac5..adb1894 100644 --- a/AX.WebDrillServer/Hubs/FireDeductionHub.cs +++ b/AX.WebDrillServer/Hubs/FireDeductionHub.cs @@ -221,6 +221,58 @@ namespace AX.WebDrillServer.Hubs throw; } } + /// + /// 解散房间 + /// + /// + /// + public async Task CallServer_DisposeRoom() + { + RoomDisposeResultData resultData = new(); + var userId = Context.UserIdentifier; + try + { + var room = roomManager.GetRoomByUserId(userId!); + + if (room == null) + { + resultData.Result = RoomDisposeResult.Failed; + resultData.RoomId = ""; + return resultData; + } + else + { + if (room.Owner == userId) + { + resultData.Result = RoomDisposeResult.Success; + resultData.RoomId = room.RoomId; + + await Clients.Group(room.RoomId).SendAsync("CallWeb_disposeRoom", resultData); + //房间中用户的房间信息重置 + foreach (var item in room.Users) + { + item.RoomId = ""; + } + //房间缓存移除该房间 + roomManager.RemoveRoom(room.RoomId); + //通知web端刷新房间列表 + await Clients.All.SendAsync("callWeb_refreshRoomList", roomManager.GetAllRooms()); + + return resultData; + } + else + { + resultData.Result = RoomDisposeResult.Failed; + resultData.RoomId = room.RoomId; + return resultData; + } + } + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } #endregion #region 推演API @@ -427,6 +479,7 @@ namespace AX.WebDrillServer.Hubs } #endregion + #region 上线下线处理 /// /// 上线处理 diff --git a/AX.WebDrillServer/Services/FireDeductionHub/FireDeductionRoomEnums.cs b/AX.WebDrillServer/Services/FireDeductionHub/FireDeductionRoomEnums.cs index 5e4a6f1..339d83a 100644 --- a/AX.WebDrillServer/Services/FireDeductionHub/FireDeductionRoomEnums.cs +++ b/AX.WebDrillServer/Services/FireDeductionHub/FireDeductionRoomEnums.cs @@ -32,7 +32,11 @@ OnLine,//上线 OffLine,//下线 } - + public enum RoomDisposeResult + { + Success,//成功 + Failed,//失败 + } public enum DrillResult { Success,//成功 diff --git a/AX.WebDrillServer/appsettings.json b/AX.WebDrillServer/appsettings.json index 5e08848..f0c010c 100644 --- a/AX.WebDrillServer/appsettings.json +++ b/AX.WebDrillServer/appsettings.json @@ -21,10 +21,10 @@ "Kestrel": { "Endpoints": { "Https": { - "Url": "https://*:7011" + "Url": "https://*:7013" }, "Http": { - "Url": "http://*:5011" + "Url": "http://*:5013" } } }