memberId为0的问题

This commit is contained in:
lishuo 2024-01-08 10:44:46 +08:00
parent 3fc9ac8234
commit 8f0845faaa

View File

@ -9,23 +9,16 @@ using OnlineUserPool.Unility;
using Serilog;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Windows.Threading;
using System.Diagnostics;
using OnlineUserPool.Services;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using System.IO.Compression;
using System.IO;
using System.Windows;
using OnlineUserPool.Api;
using OnlineUserPool.Api.Model;
namespace OnlineUserPool.ViewModels
{
public class MainWindowViewModel : BindableBase
{
public ObservableCollection<HostModel> Clients { get; private set; } = new ObservableCollection<HostModel>();
@ -97,27 +90,21 @@ namespace OnlineUserPool.ViewModels
dispatcher = Dispatcher.CurrentDispatcher;
//Customers.Add("suntao");
WriteLine(DateTime.Now.ToShortDateString());
LogHelper.Init();
mapRecordRankingHander = new MapRecordRankingHander();//
//mapRecordRankingHander = new MultiUserHandle();
Log.Information($"初始化连接,当前地址:{ IPAddress.Any }:{ConfigHelp.UdpPort}");
new TcpService().RunServer(ReceivedData, CientDisconnected);
//var tet = new System.Collections.Concurrent.ConcurrentBag<object>();
var _udpService = new UdpService();
_udpService.RunServer(ReceivedData);
Log.Information("服务启动成功");
timer = new System.Timers.Timer(500);
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = true;
timer.Start();
Log.Information("等待连接");
//Console.ReadKey();
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
@ -132,17 +119,18 @@ namespace OnlineUserPool.ViewModels
{
if (!Clients.Any(c => c.Equals(remoteIpEndPoint)))
{
Clients.Add(new HostModel
if (msg is SetClientCommand client)
{
IPEndPoint = remoteIpEndPoint,
LastActiveTime = DateTime.Now,
//RouteId = msg.RouteId,
//MemberId = msg.MemberId,
//V = msg.V,
//Encoding = msg.Encoding,
//Client = msg.Client,
Service = service
});
Clients.Add(new HostModel
{
IPEndPoint = remoteIpEndPoint,
LastActiveTime = DateTime.Now,
Service = service,
MemberId = client.MemberId,
Encoding = client.Encoding,
V = client.V
});
}
}
switch (msg.CommandType)
@ -201,15 +189,11 @@ namespace OnlineUserPool.ViewModels
}
if (msg.CommandType == 0)
{
//client.ShowVirtual = msg.ShowVirtual;
}
else if (msg.CommandType == 1)
{
}
});
}
@ -229,16 +213,16 @@ namespace OnlineUserPool.ViewModels
//对战房间内的人保存处理
if (msg1.RoomId > 0 && msg1.Saved)
{
var current = RoomList.ToList().Where(c => c.RoomId == msg1.RoomId).FirstOrDefault();
var current = RoomList.ToList().FirstOrDefault(c => c.RoomId == msg1.RoomId);
if (current != null)
{
//更新房间内的人的保存状态
var currentPlayer = current.List.Where(c => c.UserId == msg1.MemberId).FirstOrDefault();
var currentPlayer = current.List.FirstOrDefault(c => c.UserId == msg1.MemberId);
if (currentPlayer != null)
{
currentPlayer.Saved = true;
}
var notAllSaved = current.List.Where(c => !c.Saved).Any();
var notAllSaved = current.List.Any(c => !c.Saved);
if (!notAllSaved && current.Status != 2)
{
current.Status = 2;
@ -246,7 +230,7 @@ namespace OnlineUserPool.ViewModels
}
if (!current.Saved)
{
notAllSaved = current.List.Where(c => !c.Saved).Any();
notAllSaved = current.List.Any(c => !c.Saved);
if (!notAllSaved && current.Status != 2)
{
current.Status = 2;
@ -426,7 +410,7 @@ namespace OnlineUserPool.ViewModels
IsLock = !string.IsNullOrEmpty(createMsg.Password),
List = list,
};
var mine = Clients.Where(c => c.MemberId == createMsg.UserId).FirstOrDefault();
var mine = Clients.FirstOrDefault(c => c.MemberId == createMsg.UserId);
if (mine != null)
{
mine.RoomId = room.RoomId;
@ -457,13 +441,13 @@ namespace OnlineUserPool.ViewModels
{
var msg1 = msg as JoinGameRoomCommand;
RemoveOtherRoomInfo(msg1.UserId,msg1.RoomId);
var room = RoomList.ToList().Where(c => c.RoomId == msg1.RoomId).FirstOrDefault();
var room = RoomList.ToList().FirstOrDefault(c => c.RoomId == msg1.RoomId);
var client = Clients.FirstOrDefault(n => n.MemberId.Equals(msg1.UserId));
//更新房间信息
if (room != null)
{
var list = room.List;
var member = list.Where(c => c.UserId == msg1.UserId).FirstOrDefault();
var member = list.FirstOrDefault(c => c.UserId == msg1.UserId);
if (member != null)
{
member.JoinAt = msg1.JoinAt;
@ -514,12 +498,12 @@ namespace OnlineUserPool.ViewModels
private void HandleGameRoomStart(ReceiveModel msg)
{
var msg1 = msg as GameRoomStartCommand;
var client = Clients.Where(c => c.MemberId == msg1.UserId).FirstOrDefault();
var client = Clients.FirstOrDefault(c => c.MemberId == msg1.UserId);
if (client != null)
{
client.RoomId = msg1.RoomId;
}
var room = RoomList.ToList().Where(c => c.RoomId == msg1.RoomId).FirstOrDefault();
var room = RoomList.ToList().FirstOrDefault(c => c.RoomId == msg1.RoomId);
if (room != null)
{
room.Status = 1;