房间状态为进行中,如果房间为空也要删除房间

This commit is contained in:
lishuo 2022-08-24 18:45:03 +08:00
parent 22e77b1d46
commit bc0499b9f4
2 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@ namespace OnlineUserPool.Model
public int RoomId { get; set; } public int RoomId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int UserId { get; set; }//房主 public int UserId { get; set; }//房主
public int Status { get; set; }//房间状态 0 :准备状态 1开始loading public int Status { get; set; }//房间状态 0 :准备状态 1开始loading 2结束
public DateTime StatusChangedTime { get; set; } public DateTime StatusChangedTime { get; set; }
public DateTime CreateTime { get; set; }//创建时间 public DateTime CreateTime { get; set; }//创建时间
public DateTime? StartTime { get; set; }//开始时间 public DateTime? StartTime { get; set; }//开始时间

View File

@ -528,7 +528,7 @@ namespace OnlineUserPool.ViewModels
if (needRemove != null) if (needRemove != null)
{ {
list.Remove(needRemove); list.Remove(needRemove);
//如果当前是房主退出房间,房主替换成其他人 //如果当前是房主退出房间,房主替换成其他人 房主客户端中断也算
if (needRemove.IsOwner && list.Count() > 0) if (needRemove.IsOwner && list.Count() > 0)
{ {
var newOwner = list.FirstOrDefault(); var newOwner = list.FirstOrDefault();
@ -537,7 +537,7 @@ namespace OnlineUserPool.ViewModels
} }
} }
//人数为0删除房间 //人数为0删除房间
if (list.Count() == 0 && room.Status == 0) if (list.Count() == 0)
{ {
RoomList.Remove(room); RoomList.Remove(room);
} }
@ -845,18 +845,18 @@ namespace OnlineUserPool.ViewModels
private void GameRoomDisConnectHandler(HostModel client) private void GameRoomDisConnectHandler(HostModel client)
{ {
//如果是在对战房间或者对战列表掉线执行,骑行阶段断开连接不移除房间信息 ////如果是在对战房间或者对战列表掉线执行,骑行阶段断开连接不移除房间信息
if (client.Model != null && !client.Model.Equals("GameRoom")) //if (client.Model != null && !client.Model.Equals("GameRoom"))
return; // return;
RoomList.ToList().ForEach(o => { RoomList.ToList().ForEach(o => {
if (o.List != null && o.Status == 0) if (o.List != null && o.Status != 2)
{ {
var needRemove = o.List.Where(c => c.UserId == client.MemberId).FirstOrDefault(); var needRemove = o.List.Where(c => c.UserId == client.MemberId).FirstOrDefault();
o.List.Remove(needRemove); o.List.Remove(needRemove);
} }
}); });
var needRemoveList = RoomList.ToList().Where(c => c.List.Count == 0 && c.Status == 0).ToList(); var needRemoveList = RoomList.ToList().Where(c => c.List.Count == 0 && c.Status != 2).ToList();
foreach (var item in needRemoveList) foreach (var item in needRemoveList)
{ {
RoomList.Remove(item); RoomList.Remove(item);