Browse Source

添加解散房间接口

develop
杨栋梁 2 years ago
parent
commit
1c64c7e633
  1. 13
      AX.WebDrillServer/Extensions/DateTimeExtensions.cs
  2. 53
      AX.WebDrillServer/Hubs/FireDeductionHub.cs
  3. 6
      AX.WebDrillServer/Services/FireDeductionHub/FireDeductionRoomEnums.cs
  4. 4
      AX.WebDrillServer/appsettings.json

13
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;
}
/// <summary>
/// 将Unix时间戳转换为时间
/// </summary>
/// <param name="timeStamp"></param>
/// <returns></returns>
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);
}
}
}

53
AX.WebDrillServer/Hubs/FireDeductionHub.cs

@ -221,6 +221,58 @@ namespace AX.WebDrillServer.Hubs
throw;
}
}
/// <summary>
/// 解散房间
/// </summary>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async Task<RoomDisposeResultData> 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 上线下线处理
/// <summary>
/// 上线处理

6
AX.WebDrillServer/Services/FireDeductionHub/FireDeductionRoomEnums.cs

@ -32,7 +32,11 @@
OnLine,//上线
OffLine,//下线
}
public enum RoomDisposeResult
{
Success,//成功
Failed,//失败
}
public enum DrillResult
{
Success,//成功

4
AX.WebDrillServer/appsettings.json

@ -21,10 +21,10 @@
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://*:7011"
"Url": "https://*:7013"
},
"Http": {
"Url": "http://*:5011"
"Url": "http://*:5013"
}
}
}

Loading…
Cancel
Save