fix:修复房间已经结束了但是房间内的人物信息被清空的问题

This commit is contained in:
lishuo 2023-07-27 18:07:42 +08:00
parent 02aef8382e
commit 65c19a5071

View File

@ -438,10 +438,10 @@ namespace OnlineUserPool.ViewModels
//先移除当前用户在其他房间的信息(考虑服务器重启的时候没有响应客户端退出命令) //先移除当前用户在其他房间的信息(考虑服务器重启的时候没有响应客户端退出命令)
private void RemoveOtherRoomInfo(int userId, int roomId) private void RemoveOtherRoomInfo(int userId, int roomId)
{ {
var preRoom = RoomList.ToList().Where(c => c.Status == 0 && c.List.Where(c => c.UserId == userId).Any() && c.RoomId != roomId).FirstOrDefault(); var preRoom = RoomList.ToList().FirstOrDefault(c => c.Status == 0 && c.List.Any(a => a.UserId == userId) && c.RoomId != roomId);
if (preRoom != null) if (preRoom != null)
{ {
var needRemove = preRoom.List.Where(c => c.UserId == userId).FirstOrDefault(); var needRemove = preRoom.List.FirstOrDefault(c => c.UserId == userId && c.Saved == false);
preRoom.List.Remove(needRemove); preRoom.List.Remove(needRemove);
if (preRoom.List.Count == 0) if (preRoom.List.Count == 0)
{ {
@ -794,7 +794,7 @@ namespace OnlineUserPool.ViewModels
SendDataSize = $"\t单客户端数据包V1{ data1.GetBytes().Length / 1000D }KB一共占用带宽{ data1.GetBytes().Length / 1000D * clients1.Count }KB压缩以后{ data1.GetBytes(true).Length / 1000D * clients1.Count }KB"; SendDataSize = $"\t单客户端数据包V1{ data1.GetBytes().Length / 1000D }KB一共占用带宽{ data1.GetBytes().Length / 1000D * clients1.Count }KB压缩以后{ data1.GetBytes(true).Length / 1000D * clients1.Count }KB";
#region udp发送数 #region
foreach (var item in clients1) foreach (var item in clients1)
{ {
try try
@ -846,14 +846,6 @@ namespace OnlineUserPool.ViewModels
} }
} }
#endregion #endregion
//#region tcp发送数据
//var tcpClient = clients1.Where(c => c.Service is TcpService1).FirstOrDefault();
//if(tcpClient != null)
//{
// tcpClient.Service.Send(dataV1, dataV1.Length, null);
//}
//#endregion
} }
private void GameRoomDisConnectHandler(HostModel client) private void GameRoomDisConnectHandler(HostModel client)
@ -865,7 +857,7 @@ namespace OnlineUserPool.ViewModels
RoomList.ToList().ForEach(o => { RoomList.ToList().ForEach(o => {
if (o.List != null && o.Status != 2) if (o.List != null && o.Status != 2)
{ {
var needRemove = o.List.Where(c => c.UserId == client.MemberId).FirstOrDefault(); var needRemove = o.List.FirstOrDefault(c => c.UserId == client.MemberId && c.Saved == false);
o.List.Remove(needRemove); o.List.Remove(needRemove);
} }
}); });
@ -932,7 +924,7 @@ namespace OnlineUserPool.ViewModels
var room = RoomList.ToList().FirstOrDefault(c => c.RoomId == client.RoomId); var room = RoomList.ToList().FirstOrDefault(c => c.RoomId == client.RoomId);
if(room == null)return; if(room == null)return;
var needRemove = room.List.FirstOrDefault(c => c.UserId == client.MemberId); var needRemove = room.List.FirstOrDefault(c => c.UserId == client.MemberId && c.Saved == false);
if(needRemove == null)return; if(needRemove == null)return;
//从房间中移除,并考虑是否需要删除房间和移交房主 //从房间中移除,并考虑是否需要删除房间和移交房主