forked from powerfun/udpservice
内存优化
This commit is contained in:
parent
8f0845faaa
commit
b07be239fd
@ -1,14 +1,10 @@
|
|||||||
using OnlineUserPool.Api;
|
using OnlineUserPool.Api;
|
||||||
using OnlineUserPool.Model;
|
using OnlineUserPool.Model;
|
||||||
using OnlineUserPool.Unility;
|
using OnlineUserPool.Unility;
|
||||||
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Timers;
|
|
||||||
|
|
||||||
namespace OnlineUserPool.Hander
|
namespace OnlineUserPool.Hander
|
||||||
{
|
{
|
||||||
@ -16,13 +12,19 @@ namespace OnlineUserPool.Hander
|
|||||||
{
|
{
|
||||||
private static List<MapRecordRanking> mapRecordRankings = new List<MapRecordRanking>();
|
private static List<MapRecordRanking> mapRecordRankings = new List<MapRecordRanking>();
|
||||||
private static object locker = new object();//防止服务端响应慢,多次加载
|
private static object locker = new object();//防止服务端响应慢,多次加载
|
||||||
//private int top = ConfigHelp.Top;
|
private const int START = 120;
|
||||||
|
private const int SMALL = 100;
|
||||||
|
private const int MEDIUM = 150;
|
||||||
|
private const int LARGE = 180;
|
||||||
|
private const int OFFSET = 15;
|
||||||
|
const int offset = 1;
|
||||||
|
const int timeInterval = 15;
|
||||||
|
List<MsgModel> msgModels = new List<MsgModel>();
|
||||||
|
private DateTime UpdateVirtualTime { get; set; }
|
||||||
|
|
||||||
public MapRecordRankingHander()
|
public MapRecordRankingHander()
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
//var timer = new Timer();
|
|
||||||
//timer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
@ -32,26 +34,13 @@ namespace OnlineUserPool.Hander
|
|||||||
var records = WebService.GetMapRouteRandomRecord(START, null);
|
var records = WebService.GetMapRouteRandomRecord(START, null);
|
||||||
mapRecordRankings.AddRange(WebService.GetRecordFileFromServer(records.Select(n => n.Id).ToList()));
|
mapRecordRankings.AddRange(WebService.GetRecordFileFromServer(records.Select(n => n.Id).ToList()));
|
||||||
UpdateVirtualTime = DateTime.Now;
|
UpdateVirtualTime = DateTime.Now;
|
||||||
//var pageSize = 10;
|
|
||||||
//var pageCount = (int)Math.Ceiling(records.Count / (double)pageSize);
|
|
||||||
//for (int i = 0; i < pageCount; i++)
|
|
||||||
//{
|
|
||||||
// mapRecordRankings.AddRange(WebService.GetRecordFileFromServer(records.Skip(i * pageSize).Take(pageSize).Select(n => n.Id).ToList()));
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const int START = 120;
|
|
||||||
private const int SMALL = 100;
|
|
||||||
private const int MEDIUM = 150;
|
|
||||||
private const int LARGE = 180;
|
|
||||||
private const int OFFSET = 15;
|
|
||||||
|
|
||||||
//根据当前时段计算虚拟总人数
|
//根据当前时段计算虚拟总人数
|
||||||
private int ComputeTop()
|
private int ComputeTop()
|
||||||
{
|
{
|
||||||
var rand = new Random();
|
var rand = new Random();
|
||||||
|
|
||||||
var hour = DateTime.Now.Hour;//当前点数
|
var hour = DateTime.Now.Hour;//当前点数
|
||||||
int offset = 1;//少:1 中:3 多:10
|
int offset = 1;//少:1 中:3 多:10
|
||||||
if (hour <= 6)
|
if (hour <= 6)
|
||||||
@ -79,11 +68,13 @@ namespace OnlineUserPool.Hander
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<MsgModel> GetVirtualUserData()
|
public List<MsgModel> GetVirtualUserData()
|
||||||
{
|
{
|
||||||
List<MsgModel> msgModels = new List<MsgModel>();
|
msgModels.Clear();
|
||||||
if(ConfigHelp.ShowVirtualUser == false)
|
|
||||||
|
if (ConfigHelp.ShowVirtualUser == false)
|
||||||
{
|
{
|
||||||
return msgModels;
|
return msgModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapRecordRankings != null)
|
if (mapRecordRankings != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mapRecordRankings.Count; i++)
|
for (int i = 0; i < mapRecordRankings.Count; i++)
|
||||||
@ -93,12 +84,7 @@ namespace OnlineUserPool.Hander
|
|||||||
var item = mapRecordRankings[i];
|
var item = mapRecordRankings[i];
|
||||||
item.CurrentIndex++;
|
item.CurrentIndex++;
|
||||||
TargetData targetData = item.GetCurrentTargetData();
|
TargetData targetData = item.GetCurrentTargetData();
|
||||||
//List<string> prop = new List<string>()
|
|
||||||
//{
|
|
||||||
// Math.Round(targetData._Speed, 2).ToString(),
|
|
||||||
// targetData._Power.ToString(),
|
|
||||||
// targetData._Cadence.ToString()
|
|
||||||
//};
|
|
||||||
var weightKg = 0.0D;
|
var weightKg = 0.0D;
|
||||||
if (targetData._Power >= 0)
|
if (targetData._Power >= 0)
|
||||||
{
|
{
|
||||||
@ -110,9 +96,9 @@ namespace OnlineUserPool.Hander
|
|||||||
//机器人上线
|
//机器人上线
|
||||||
var loginInfo = new MsgModel()
|
var loginInfo = new MsgModel()
|
||||||
{
|
{
|
||||||
exit = item.End,
|
Exit = item.End,
|
||||||
IsCompleted = item.End,
|
IsCompleted = item.End,
|
||||||
MemberId = item.UserId,//虚拟的人Id变为负数
|
MemberId = item.UserId, //虚拟的人Id变为负数
|
||||||
Point = new double[] { -1d, -1d },
|
Point = new double[] { -1d, -1d },
|
||||||
//Prop = string.Join(',', prop),
|
//Prop = string.Join(',', prop),
|
||||||
RouteId = item.RouteId,
|
RouteId = item.RouteId,
|
||||||
@ -126,11 +112,12 @@ namespace OnlineUserPool.Hander
|
|||||||
};
|
};
|
||||||
msgModels.Add(loginInfo);
|
msgModels.Add(loginInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
var info = new MsgModel()
|
var info = new MsgModel()
|
||||||
{
|
{
|
||||||
exit = item.End,
|
Exit = item.End,
|
||||||
IsCompleted = item.End,
|
IsCompleted = item.End,
|
||||||
MemberId = item.UserId,//虚拟的人Id变为负数
|
MemberId = item.UserId, //虚拟的人Id变为负数
|
||||||
Point = new double[] { Math.Round(targetData._Lat, 6), Math.Round(targetData._Lon, 6) },
|
Point = new double[] { Math.Round(targetData._Lat, 6), Math.Round(targetData._Lon, 6) },
|
||||||
//Prop = string.Join(',', prop),
|
//Prop = string.Join(',', prop),
|
||||||
RouteId = item.RouteId,
|
RouteId = item.RouteId,
|
||||||
@ -148,13 +135,12 @@ namespace OnlineUserPool.Hander
|
|||||||
{
|
{
|
||||||
Log.Error("加载虚拟人物错误:" + e.Message + "\r\n" + e.StackTrace);
|
Log.Error("加载虚拟人物错误:" + e.Message + "\r\n" + e.StackTrace);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return msgModels;
|
return msgModels;
|
||||||
}
|
}
|
||||||
const int offset = 1;
|
|
||||||
const int timeInterval = 15;
|
|
||||||
private DateTime UpdateVirtualTime { get; set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除已经骑行完的人,添加新的人物进去
|
/// 删除已经骑行完的人,添加新的人物进去
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -162,11 +148,9 @@ namespace OnlineUserPool.Hander
|
|||||||
{
|
{
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
//var offlineCount = mapRecordRankings.Where(c => c.End).Count();//下线人数
|
|
||||||
var top = ComputeTop();//理论上当前时间段虚拟用户的总数
|
var top = ComputeTop();//理论上当前时间段虚拟用户的总数
|
||||||
mapRecordRankings.RemoveAll(n => n.End);//移除骑行结束的人
|
mapRecordRankings.RemoveAll(n => n.End);//移除骑行结束的人
|
||||||
var routeIds = mapRecordRankings.Select(n => n.RouteId).Distinct().ToList();
|
var routeIds = mapRecordRankings.Select(n => n.RouteId).Distinct().ToList();
|
||||||
|
|
||||||
var currentVirtualCount = mapRecordRankings.Count(d => d.UserId < 0);//实际虚拟用户数
|
var currentVirtualCount = mapRecordRankings.Count(d => d.UserId < 0);//实际虚拟用户数
|
||||||
if (top - currentVirtualCount > 0)
|
if (top - currentVirtualCount > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -68,7 +68,7 @@ namespace OnlineUserPool.Hander
|
|||||||
var point = _turfHelper.Along(item.Distance * _index);
|
var point = _turfHelper.Along(item.Distance * _index);
|
||||||
var info = new MsgModel()
|
var info = new MsgModel()
|
||||||
{
|
{
|
||||||
exit = false,
|
Exit = false,
|
||||||
IsCompleted = false,
|
IsCompleted = false,
|
||||||
MemberId = item.Id,//虚拟的人Id变为负数
|
MemberId = item.Id,//虚拟的人Id变为负数
|
||||||
Point = new double[] { Math.Round(point.Latitude, 6), Math.Round(point.Longitude, 6) },
|
Point = new double[] { Math.Round(point.Latitude, 6), Math.Round(point.Longitude, 6) },
|
||||||
@ -81,7 +81,7 @@ namespace OnlineUserPool.Hander
|
|||||||
Speed = item.Speed,
|
Speed = item.Speed,
|
||||||
WeightKg = 0,
|
WeightKg = 0,
|
||||||
PreDistance = preDistance,
|
PreDistance = preDistance,
|
||||||
Competitionid = _competitionid
|
CompetitionId = _competitionid
|
||||||
};
|
};
|
||||||
msgModels.Add(info);
|
msgModels.Add(info);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,31 +1,85 @@
|
|||||||
using Newtonsoft.Json;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OnlineUserPool.Model
|
namespace OnlineUserPool.Model
|
||||||
{
|
{
|
||||||
public class MsgModel : ReceiveModel
|
public class MsgModel : ReceiveModel
|
||||||
{
|
{
|
||||||
public int RouteId { get; set; }
|
private int _RouteId = 0;
|
||||||
public int MemberId { get; set; }
|
public int RouteId {
|
||||||
public double[] Point { get; set; }
|
get {
|
||||||
public bool IsCompleted { get; set; }
|
return _RouteId;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
SetProperty(ref _RouteId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool exit = false;
|
private int _MemberId = 0;
|
||||||
public double Speed { get; set; }
|
public int MemberId {
|
||||||
public double HeartRate { get; set; }
|
get => _MemberId;
|
||||||
public double Power { get; set; }
|
set => SetProperty(ref _MemberId, value);
|
||||||
public double Cadence { get; set; }
|
}
|
||||||
public int TotalTicks { get; set; }
|
|
||||||
|
public double[] Point { get; set; }
|
||||||
|
|
||||||
|
private bool _IsCompleted;
|
||||||
|
public bool IsCompleted {
|
||||||
|
get => _IsCompleted;
|
||||||
|
set => SetProperty(ref _IsCompleted, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _exit;
|
||||||
|
public bool Exit {
|
||||||
|
get => _exit;
|
||||||
|
set => SetProperty(ref _exit, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double _Speed = 0;
|
||||||
|
public double Speed {
|
||||||
|
get => _Speed;
|
||||||
|
set => SetProperty(ref _Speed, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double _HeartRate = 0;
|
||||||
|
public double HeartRate {
|
||||||
|
get => _HeartRate;
|
||||||
|
set => SetProperty(ref _HeartRate, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double _Power = 0;
|
||||||
|
public double Power {
|
||||||
|
get => _Power;
|
||||||
|
set => SetProperty(ref _Power, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double _Cadence = 0;
|
||||||
|
public double Cadence {
|
||||||
|
get => _Cadence;
|
||||||
|
set => SetProperty(ref _Cadence, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _TotalTicks = 0;
|
||||||
|
public int TotalTicks {
|
||||||
|
get => _TotalTicks;
|
||||||
|
set => SetProperty(ref _TotalTicks, value);
|
||||||
|
}
|
||||||
|
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// 需要展示的属性
|
///// 需要展示的属性
|
||||||
///// </summary>
|
///// </summary>
|
||||||
//public string Prop { get; set; }
|
//public string Prop { get; set; }
|
||||||
|
|
||||||
public double PreDistance { get; set; }
|
private double _PreDistance = 0;
|
||||||
|
public double PreDistance {
|
||||||
|
get => _PreDistance;
|
||||||
|
set => SetProperty(ref _PreDistance, value);
|
||||||
|
}
|
||||||
|
|
||||||
public double EndDistance { get; set; }
|
private double _EndDistance = 0;
|
||||||
|
public double EndDistance {
|
||||||
|
get => _EndDistance;
|
||||||
|
set => SetProperty(ref _EndDistance, value);
|
||||||
|
}
|
||||||
|
|
||||||
//public bool IsVirtual { get; set; }
|
//public bool IsVirtual { get; set; }
|
||||||
|
|
||||||
@ -34,30 +88,84 @@ namespace OnlineUserPool.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 功率体重比
|
/// 功率体重比
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double WeightKg { get; set; }
|
private double _WeightKg = 0;
|
||||||
|
public double WeightKg {
|
||||||
|
get => _WeightKg;
|
||||||
|
set => SetProperty(ref _WeightKg, value);
|
||||||
|
}
|
||||||
|
|
||||||
public int Competitionid { get; set; }
|
private int _CompetitionId = 0;
|
||||||
|
public int CompetitionId {
|
||||||
|
get => _CompetitionId;
|
||||||
|
set => SetProperty(ref _CompetitionId, value);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Saved { get; set; }
|
private bool _Saved ;
|
||||||
|
public bool Saved {
|
||||||
|
get => _Saved;
|
||||||
|
set => SetProperty(ref _Saved, value);
|
||||||
|
}
|
||||||
|
|
||||||
//public bool ShowVirtual { get; set; }
|
//public bool ShowVirtual { get; set; }
|
||||||
|
|
||||||
public int FrameRate { get; set; }
|
private int _FrameRate = 0;
|
||||||
public int RoomId { get; set; }
|
public int FrameRate {
|
||||||
|
get => _FrameRate;
|
||||||
|
set => SetProperty(ref _FrameRate, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _RoomId = 0;
|
||||||
|
public int RoomId {
|
||||||
|
get => _RoomId;
|
||||||
|
set => SetProperty(ref _RoomId, value);
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime? StartTime { get; set; }
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
public string Request { get; set; }
|
private string _Request;
|
||||||
|
public string Request {
|
||||||
|
get => _Request;
|
||||||
|
set => SetProperty(ref _Request, value);
|
||||||
|
}
|
||||||
|
|
||||||
public string Model { get; set; }
|
private string _Model;
|
||||||
|
public string Model {
|
||||||
|
get => _Model;
|
||||||
|
set => SetProperty(ref _Model, value);
|
||||||
|
}
|
||||||
|
|
||||||
public string ToString(int v)
|
public string ToString(int v)
|
||||||
{
|
{
|
||||||
if (v == 2)
|
if (v == 2)
|
||||||
{
|
{
|
||||||
return $"{ RouteId },{ MemberId },{ string.Join(":", Point) },{ Convert.ToInt32(IsCompleted) },{ Speed },{ PreDistance },{ EndDistance },{ WeightKg },{ Competitionid },{ Convert.ToInt32(Saved)},{ Power} ,{ HeartRate},{ Cadence},{ TotalTicks},{ FrameRate},{RoomId},{StartTime}";
|
return $"{ RouteId },{ MemberId },{ string.Join(":", Point) },{ Convert.ToInt32(IsCompleted) },{ Speed },{ PreDistance },{ EndDistance },{ WeightKg },{ CompetitionId },{ Convert.ToInt32(Saved)},{ Power} ,{ HeartRate},{ Cadence},{ TotalTicks},{ FrameRate},{RoomId},{StartTime}";
|
||||||
}
|
}
|
||||||
return $"{ RouteId },{ MemberId },{ string.Join(":", Point) },{ Convert.ToInt32(IsCompleted) },{ Speed },{ PreDistance },{ EndDistance },{ WeightKg },{ Competitionid },{ Convert.ToInt32(Saved)}";
|
return $"{ RouteId },{ MemberId },{ string.Join(":", Point) },{ Convert.ToInt32(IsCompleted) },{ Speed },{ PreDistance },{ EndDistance },{ WeightKg },{ CompetitionId },{ Convert.ToInt32(Saved)}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(MsgModel model)
|
||||||
|
{
|
||||||
|
this.CompetitionId = model.CompetitionId;
|
||||||
|
this.EndDistance = model.EndDistance;
|
||||||
|
this.HeartRate = model.HeartRate;
|
||||||
|
this.IsCompleted = model.IsCompleted;
|
||||||
|
this.MemberId = model.MemberId;
|
||||||
|
this.Point = model.Point;
|
||||||
|
this.PreDistance = model.PreDistance;
|
||||||
|
this.RouteId = model.RouteId;
|
||||||
|
this.Speed = model.Speed;
|
||||||
|
this.WeightKg = model.WeightKg;
|
||||||
|
this.Saved = model.Saved;
|
||||||
|
this.HeartRate = model.HeartRate;
|
||||||
|
this.Cadence = model.Cadence;
|
||||||
|
this.TotalTicks = model.TotalTicks;
|
||||||
|
this.FrameRate = model.FrameRate;
|
||||||
|
this.RoomId = model.RoomId;
|
||||||
|
this.StartTime = model.StartTime;
|
||||||
|
this.Request = model.Request;
|
||||||
|
this.Power = model.Power;
|
||||||
|
this.Exit = model.Exit;
|
||||||
|
this.Model = model.Model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Prism.Mvvm;
|
||||||
|
|
||||||
namespace OnlineUserPool.Model
|
namespace OnlineUserPool.Model
|
||||||
{
|
{
|
||||||
public class ReceiveModel
|
public class ReceiveModel : BindableBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 命令类型,0ping命令,1消息, 2设置客户端信息, 3观察者模式
|
/// 命令类型,0ping命令,1消息, 2设置客户端信息, 3观察者模式
|
||||||
|
|||||||
@ -44,31 +44,32 @@ namespace OnlineUserPool.Model
|
|||||||
return string.Format($"{Ticks},{_Power},{_Speed},{_Distance},{_Cadence},{_HeartRate},{_Lat},{_Lon},{_Bearing}");
|
return string.Format($"{Ticks},{_Power},{_Speed},{_Distance},{_Cadence},{_HeartRate},{_Lat},{_Lon},{_Bearing}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TargetData _target = new TargetData();
|
||||||
public static TargetData Read(string data)
|
public static TargetData Read(string data)
|
||||||
{
|
{
|
||||||
string[] split = data.Split(',');
|
string[] split = data.Split(',');
|
||||||
var target = new TargetData();
|
_target.Ticks = int.Parse(split[0]);
|
||||||
target.Ticks = int.Parse(split[0]);
|
_target._Power = double.Parse(split[1]);
|
||||||
target._Power = double.Parse(split[1]);
|
_target._Speed = double.Parse(split[2]);
|
||||||
target._Speed = double.Parse(split[2]);
|
_target._Distance = double.Parse(split[3]);
|
||||||
target._Distance = double.Parse(split[3]);
|
_target._Cadence = double.Parse(split[4]);
|
||||||
target._Cadence = double.Parse(split[4]);
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(split[5]) && split[5] != "null")
|
if (!string.IsNullOrWhiteSpace(split[5]) && split[5] != "null")
|
||||||
{
|
{
|
||||||
target._HeartRate = int.Parse(split[5]);
|
_target._HeartRate = int.Parse(split[5]);
|
||||||
}
|
}
|
||||||
if (split.Length > 6)
|
if (split.Length > 6)
|
||||||
{
|
{
|
||||||
target._Lat = double.Parse(split[6]);
|
_target._Lat = double.Parse(split[6]);
|
||||||
target._Lon = double.Parse(split[7]);
|
_target._Lon = double.Parse(split[7]);
|
||||||
|
|
||||||
if (split.Length >= 9)
|
if (split.Length >= 9)
|
||||||
{
|
{
|
||||||
target._Bearing = double.Parse(split[8]);
|
_target._Bearing = double.Parse(split[8]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return target;
|
|
||||||
|
return _target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,11 +29,8 @@ namespace OnlineUserPool.ViewModels
|
|||||||
private static object locker = new object();
|
private static object locker = new object();
|
||||||
public static System.Timers.Timer timer;
|
public static System.Timers.Timer timer;
|
||||||
private static IHandle mapRecordRankingHander;
|
private static IHandle mapRecordRankingHander;
|
||||||
|
|
||||||
private Dispatcher dispatcher;
|
private Dispatcher dispatcher;
|
||||||
public ObservableCollection<MsgModel> Customers { get; private set; } =
|
public ObservableCollection<MsgModel> Customers { get; private set; } = new ObservableCollection<MsgModel>();
|
||||||
new ObservableCollection<MsgModel>();
|
|
||||||
|
|
||||||
private string _Title = "";
|
private string _Title = "";
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
@ -72,7 +69,9 @@ namespace OnlineUserPool.ViewModels
|
|||||||
SetProperty(ref _closeVirtualUser, value);
|
SetProperty(ref _closeVirtualUser, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const int ROOM_TIME_OUT = 60;
|
||||||
|
private const int TOTAL_PROCESS = 100;
|
||||||
//private IService _udpService;
|
//private IService _udpService;
|
||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel()
|
||||||
@ -87,15 +86,13 @@ namespace OnlineUserPool.ViewModels
|
|||||||
//初测程序关闭事件
|
//初测程序关闭事件
|
||||||
Application.Current.MainWindow.Closing += MainWindow_Closing;
|
Application.Current.MainWindow.Closing += MainWindow_Closing;
|
||||||
Title = $"{ IPAddress.Any }:{ ConfigHelp.UdpPort }";
|
Title = $"{ IPAddress.Any }:{ ConfigHelp.UdpPort }";
|
||||||
|
|
||||||
dispatcher = Dispatcher.CurrentDispatcher;
|
dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
|
||||||
WriteLine(DateTime.Now.ToShortDateString());
|
WriteLine(DateTime.Now.ToShortDateString());
|
||||||
LogHelper.Init();
|
LogHelper.Init();
|
||||||
mapRecordRankingHander = new MapRecordRankingHander();//
|
mapRecordRankingHander = new MapRecordRankingHander();//
|
||||||
//mapRecordRankingHander = new MultiUserHandle();
|
//mapRecordRankingHander = new MultiUserHandle();
|
||||||
Log.Information($"初始化连接,当前地址:{ IPAddress.Any }:{ConfigHelp.UdpPort}");
|
Log.Information($"初始化连接,当前地址:{ IPAddress.Any }:{ConfigHelp.UdpPort}");
|
||||||
new TcpService().RunServer(ReceivedData, CientDisconnected);
|
new TcpService().RunServer(ReceivedData, ClientDisconnected);
|
||||||
var _udpService = new UdpService();
|
var _udpService = new UdpService();
|
||||||
_udpService.RunServer(ReceivedData);
|
_udpService.RunServer(ReceivedData);
|
||||||
|
|
||||||
@ -105,6 +102,18 @@ namespace OnlineUserPool.ViewModels
|
|||||||
timer.AutoReset = true;
|
timer.AutoReset = true;
|
||||||
timer.Start();
|
timer.Start();
|
||||||
Log.Information("等待连接");
|
Log.Information("等待连接");
|
||||||
|
ReleaseMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReleaseMemory()
|
||||||
|
{
|
||||||
|
var timers = new System.Timers.Timer(3333);
|
||||||
|
timers.Elapsed += (s, e) =>
|
||||||
|
{
|
||||||
|
GC.Collect();
|
||||||
|
};
|
||||||
|
timers.AutoReset = true;
|
||||||
|
timers.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
@ -151,16 +160,19 @@ namespace OnlineUserPool.ViewModels
|
|||||||
{
|
{
|
||||||
var client = Clients.FirstOrDefault(n => n.Equals(remoteIpEndPoint));
|
var client = Clients.FirstOrDefault(n => n.Equals(remoteIpEndPoint));
|
||||||
var msg1 = (msg as MsgModel);
|
var msg1 = (msg as MsgModel);
|
||||||
client.Competitionid = msg1.Competitionid;
|
client.Competitionid = msg1.CompetitionId;
|
||||||
client.Model = msg1.Model;
|
client.Model = msg1.Model;
|
||||||
|
|
||||||
if (client.Model == "")
|
if (client.Model == "")
|
||||||
{
|
{
|
||||||
client.RoomId = msg1.RoomId;
|
client.RoomId = msg1.RoomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg1.V > 0)
|
if (msg1.V > 0)
|
||||||
{
|
{
|
||||||
client.V = msg1.V;
|
client.V = msg1.V;
|
||||||
}
|
}
|
||||||
|
|
||||||
receiveMes.Add(msg1);
|
receiveMes.Add(msg1);
|
||||||
HandleGameRoomSaved(msg1);
|
HandleGameRoomSaved(msg1);
|
||||||
}
|
}
|
||||||
@ -184,15 +196,6 @@ namespace OnlineUserPool.ViewModels
|
|||||||
HandleGameRoom(msg);
|
HandleGameRoom(msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (msg.CommandType == 0)
|
|
||||||
{
|
|
||||||
//client.ShowVirtual = msg.ShowVirtual;
|
|
||||||
}
|
|
||||||
else if (msg.CommandType == 1)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -208,6 +211,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
GameRoomHelper.Set(RoomList.ToList());
|
GameRoomHelper.Set(RoomList.ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleGameRoomSaved(MsgModel msg1)
|
private void HandleGameRoomSaved(MsgModel msg1)
|
||||||
{
|
{
|
||||||
//对战房间内的人保存处理
|
//对战房间内的人保存处理
|
||||||
@ -336,7 +340,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
Point = new double[] { 0d, 0d },
|
Point = new double[] { 0d, 0d },
|
||||||
});
|
});
|
||||||
|
|
||||||
var temp = string.Join("|", list.Where(m => m.Competitionid == needSend.Competitionid).Select(m => m.ToString(2))) + "|";
|
var temp = string.Join("|", list.Where(m => m.CompetitionId == needSend.Competitionid).Select(m => m.ToString(2))) + "|";
|
||||||
List<RoomModel> rooms;
|
List<RoomModel> rooms;
|
||||||
if (!string.IsNullOrEmpty(query.Name))
|
if (!string.IsNullOrEmpty(query.Name))
|
||||||
{
|
{
|
||||||
@ -547,8 +551,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
SendGameRoomMessage(room);
|
SendGameRoomMessage(room);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private const int ROOM_TIME_OUT = 60;
|
|
||||||
private const int TOTAL_PROCESS = 100;
|
|
||||||
//处理房间内人loading进度
|
//处理房间内人loading进度
|
||||||
private void HandleGameRoomProcess(ReceiveModel msg)
|
private void HandleGameRoomProcess(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -635,10 +638,6 @@ namespace OnlineUserPool.ViewModels
|
|||||||
{
|
{
|
||||||
dispatcher.Invoke(() =>
|
dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
//Customers.Clear();
|
|
||||||
|
|
||||||
//删除已经发送的数据
|
|
||||||
//receiveMes.Clear();
|
|
||||||
//移除5钟内连接不上的客户端
|
//移除5钟内连接不上的客户端
|
||||||
Clients.ToList().ForEach(item =>
|
Clients.ToList().ForEach(item =>
|
||||||
{
|
{
|
||||||
@ -650,67 +649,32 @@ namespace OnlineUserPool.ViewModels
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
var msgs = CloneJson(receiveMes).ToList();
|
|
||||||
receiveMes.Clear();
|
|
||||||
|
|
||||||
if (!CloseVirtualUser)
|
|
||||||
{
|
|
||||||
//加入虚拟人物消息
|
|
||||||
var virtualData = mapRecordRankingHander.GetVirtualUserData();
|
|
||||||
VirtualData = $"{virtualData.Count}";
|
|
||||||
WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-当前在线人数:" + Clients.Count + "-当前虚拟人数:" + virtualData.Count);
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
WriteLine($"在线人:{Newtonsoft.Json.JsonConvert.SerializeObject(msgs)}");
|
|
||||||
//\r\n虚拟人:{Newtonsoft.Json.JsonConvert.SerializeObject(virtualData)}
|
|
||||||
#endif
|
|
||||||
msgs.AddRange(virtualData);
|
|
||||||
}
|
|
||||||
//屏蔽房间模式的用户
|
|
||||||
var c = Clients.Where(c => string.IsNullOrEmpty(c.Model)).ToList();
|
|
||||||
SendMessage(c, msgs);
|
|
||||||
|
|
||||||
dispatcher.Invoke(() =>
|
dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
Customers.Clear();
|
var msgs = receiveMes.ToList();
|
||||||
foreach (var item in msgs)
|
//加入虚拟人物消息
|
||||||
|
if (!CloseVirtualUser)
|
||||||
{
|
{
|
||||||
if (Customers.Any(c => c.MemberId == item.MemberId))
|
var virtualData = mapRecordRankingHander.GetVirtualUserData();
|
||||||
{
|
VirtualData = $"{virtualData.Count}";
|
||||||
continue;
|
msgs.AddRange(virtualData);
|
||||||
}
|
|
||||||
Customers.Add(item);
|
|
||||||
}
|
}
|
||||||
|
//屏蔽房间模式的用户
|
||||||
//移除下线的客户端
|
var c = Clients.Where(c => string.IsNullOrEmpty(c.Model)).ToList();
|
||||||
for (int i = 0; i < msgs.Count; i++)
|
SendMessage(c, msgs);
|
||||||
{
|
RemoveClientAdvanced(msgs);
|
||||||
if (msgs[i].exit && msgs[i].MemberId > 0)//客户端退出,并且不是虚拟的人物
|
AddCustomers(msgs);
|
||||||
{
|
receiveMes.Clear();
|
||||||
//这个地方有严重的逻辑错误(虚拟的人物不能和真实的人用同一个名字)
|
msgs.Clear();
|
||||||
var info = Clients.FirstOrDefault(n => n.MemberId == msgs[i].MemberId);
|
msgs = null;
|
||||||
if (info != null)
|
|
||||||
{
|
|
||||||
RemoveClient(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//删除已经发送的数据
|
|
||||||
//receiveMes.Clear();
|
|
||||||
//移除5钟内连接不上的客户端
|
|
||||||
Clients.ToList().ForEach(item =>
|
|
||||||
{
|
|
||||||
if (item.Expire)
|
|
||||||
{
|
|
||||||
RemoveClient(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//更新虚拟人物信息
|
||||||
|
mapRecordRankingHander.RemoveEndAndAddNewVirtualUser(Clients.Count);
|
||||||
}
|
}
|
||||||
//更新虚拟人物信息
|
|
||||||
mapRecordRankingHander.RemoveEndAndAddNewVirtualUser(Customers.Count);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -718,52 +682,70 @@ namespace OnlineUserPool.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendMessage(IList<HostModel> clients, List<MsgModel> msgModels)
|
private void RemoveClientAdvanced(List<MsgModel> msgs)
|
||||||
{
|
{
|
||||||
if (!clients.Any() || !msgModels.Any())
|
//移除下线的客户端
|
||||||
|
for (int i = 0; i < msgs.Count; i++)
|
||||||
|
{
|
||||||
|
if (msgs[i].Exit && msgs[i].MemberId > 0)//客户端退出,并且不是虚拟的人物
|
||||||
|
{
|
||||||
|
//这个地方有严重的逻辑错误(虚拟的人物不能和真实的人用同一个名字)
|
||||||
|
var info = Clients.FirstOrDefault(n => n.MemberId == msgs[i].MemberId);
|
||||||
|
if (info != null)
|
||||||
|
{
|
||||||
|
RemoveClient(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除5钟内连接不上的客户端
|
||||||
|
Clients.ToList().ForEach(item =>
|
||||||
|
{
|
||||||
|
if (item.Expire)
|
||||||
|
{
|
||||||
|
RemoveClient(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddCustomers(List<MsgModel> msgs)
|
||||||
|
{
|
||||||
|
foreach (var item in msgs)
|
||||||
|
{
|
||||||
|
var client = Clients.FirstOrDefault(c => c.MemberId == item.MemberId);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
Customers.Remove(item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var customer = Customers.FirstOrDefault(c => c.MemberId == item.MemberId);
|
||||||
|
if (customer != null)
|
||||||
|
{
|
||||||
|
customer.Update(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Customers.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringBuilder sb = new StringBuilder();
|
||||||
|
private void SendMessage(IList<HostModel> clients, List<MsgModel> list)
|
||||||
|
{
|
||||||
|
if (!clients.Any() || !list.Any())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var clients1 = clients.ToList();
|
var clients1 = clients.ToList();
|
||||||
|
|
||||||
var list = CloneJson<List<MsgModel>>(msgModels);
|
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
{
|
{
|
||||||
item.PreDistance = Math.Round(item.PreDistance, 5);
|
item.PreDistance = Math.Round(item.PreDistance, 5);
|
||||||
item.EndDistance = Math.Round(item.EndDistance, 5);
|
item.EndDistance = Math.Round(item.EndDistance, 5);
|
||||||
item.WeightKg = Math.Round(item.WeightKg, 2);
|
item.WeightKg = Math.Round(item.WeightKg, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(list.Select(m => new {
|
|
||||||
m.RouteId,
|
|
||||||
m.MemberId,
|
|
||||||
m.Point,
|
|
||||||
m.IsCompleted,
|
|
||||||
m.exit,
|
|
||||||
m.Speed,
|
|
||||||
m.PreDistance,
|
|
||||||
m.EndDistance,
|
|
||||||
//m.IsVirtual,//后面要把这个字段过滤掉
|
|
||||||
m.WeightKg,
|
|
||||||
m.Competitionid,
|
|
||||||
m.Saved,
|
|
||||||
m.FrameRate,
|
|
||||||
}));
|
|
||||||
var data = Encoding.ASCII.GetBytes(jsonString);
|
|
||||||
|
|
||||||
var strV1 = string.Join("|", list.Select(m => m.ToString(1)));
|
|
||||||
if (!string.IsNullOrWhiteSpace(strV1))
|
|
||||||
{
|
|
||||||
strV1 += "|";
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteLine(strV1);
|
|
||||||
WriteLine(strV1.Length.ToString());
|
|
||||||
|
|
||||||
var data1 = new NetworkData(strV1);
|
|
||||||
var data1ForUdp = new NetworkData(strV1.Last() == '|' ? strV1.Substring(0, strV1.Length - 1) : strV1);
|
|
||||||
|
|
||||||
SendDataSize = $"\t单客户端数据包V1:{ data1.GetBytes().Length / 1000D }KB,一共占用带宽:{ data1.GetBytes().Length / 1000D * clients1.Count }KB,压缩以后{ data1.GetBytes(true).Length / 1000D * clients1.Count }KB";
|
|
||||||
|
|
||||||
#region 发送数据
|
#region 发送数据
|
||||||
foreach (var item in clients1)
|
foreach (var item in clients1)
|
||||||
@ -771,39 +753,73 @@ namespace OnlineUserPool.ViewModels
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (item == null) continue;
|
if (item == null) continue;
|
||||||
|
|
||||||
if (item.V != 1 && item.V != 2)
|
if (item.V != 1 && item.V != 2)
|
||||||
{
|
{
|
||||||
|
var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(list.Select(m => new {
|
||||||
|
m.RouteId,
|
||||||
|
m.MemberId,
|
||||||
|
m.Point,
|
||||||
|
m.IsCompleted,
|
||||||
|
exit = m.Exit,
|
||||||
|
m.Speed,
|
||||||
|
m.PreDistance,
|
||||||
|
m.EndDistance,
|
||||||
|
//m.IsVirtual,//后面要把这个字段过滤掉
|
||||||
|
m.WeightKg,
|
||||||
|
Competitionid = m.CompetitionId,
|
||||||
|
m.Saved,
|
||||||
|
m.FrameRate,
|
||||||
|
}));
|
||||||
|
var data = Encoding.ASCII.GetBytes(jsonString);
|
||||||
item.Service.Send(data, data.Length, item.IPEndPoint);
|
item.Service.Send(data, data.Length, item.IPEndPoint);
|
||||||
|
data = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.V == 1 && item.Service is UdpService)
|
if (item.V == 1 && item.Service is UdpService)
|
||||||
{
|
{
|
||||||
|
sb.Clear();
|
||||||
|
|
||||||
|
foreach (var obj in list)
|
||||||
|
{
|
||||||
|
sb.Append(obj.ToString(1));
|
||||||
|
sb.Append("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
var strV1 = sb.ToString();
|
||||||
|
var data1ForUdp = new NetworkData(strV1.Last() == '|' ? strV1.Substring(0, strV1.Length - 1) : strV1);
|
||||||
item.Service.Send(data1ForUdp.GetBytes(), data1ForUdp.GetBytes().Length, item.IPEndPoint);
|
item.Service.Send(data1ForUdp.GetBytes(), data1ForUdp.GetBytes().Length, item.IPEndPoint);
|
||||||
|
data1ForUdp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item.Service is TcpService)
|
if(item.Service is TcpService)
|
||||||
{
|
{
|
||||||
NetworkData ddd = null;
|
NetworkData networkData = null;
|
||||||
if (item.V == 1)
|
if (item.V == 1)
|
||||||
{
|
{
|
||||||
ddd = data1;
|
sb.Clear();
|
||||||
|
foreach (var obj in list)
|
||||||
|
{
|
||||||
|
sb.Append(obj.ToString(1));
|
||||||
|
sb.Append("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
var strV1 = sb.ToString();
|
||||||
|
var data1 = new NetworkData(strV1);
|
||||||
|
networkData = data1;
|
||||||
}
|
}
|
||||||
else if (item.V == 2)
|
else if (item.V == 2)
|
||||||
{
|
{
|
||||||
var temp = string.Join("|", list.Where(m => m.Competitionid == item.Competitionid).Select(m => m.ToString(2))) + "|";
|
networkData = HandleGzipNetworkData(list,item);
|
||||||
var watchList1 = string.Join('|', clients1.Where(c => c.IsWatch && c.Competitionid == item.Competitionid).Select(c => c.MemberId));
|
|
||||||
var e = string.Join("|", list.Where(c => c.RoomId > 0 || c.FrameRate > 0).Select(c => $"{c.MemberId},{c.RoomId},{c.FrameRate},{c.TotalTicks}"));
|
|
||||||
var strV21 = $"*l{{{ temp }}};w{{{ watchList1 }}};e{{{ e }}};#";
|
|
||||||
ddd = new NetworkData(strV21);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isZip = item.Encoding == "gzip";
|
bool isZip = item.Encoding == "gzip";
|
||||||
item.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, item.IPEndPoint);
|
item.Service.Send(networkData.GetBytes(isZip), networkData.GetBytes(isZip).Length, item.IPEndPoint);
|
||||||
|
networkData = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -812,9 +828,63 @@ namespace OnlineUserPool.ViewModels
|
|||||||
Log.Error($"{ item.IPEndPoint.ToString() }:{ e.Message }\r\n{ e.StackTrace }");
|
Log.Error($"{ item.IPEndPoint.ToString() }:{ e.Message }\r\n{ e.StackTrace }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clients1 = null;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NetworkData HandleGzipNetworkData(List<MsgModel> list, HostModel item)
|
||||||
|
{
|
||||||
|
sb.Clear();
|
||||||
|
foreach (var obj in list.Where(m => m.CompetitionId == item.Competitionid).Select(m => m.ToString(2)))
|
||||||
|
{
|
||||||
|
sb.Append(obj);
|
||||||
|
sb.Append("|");
|
||||||
|
}
|
||||||
|
sb.Remove(sb.Length - 1, 1);
|
||||||
|
var temp = sb.ToString();
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
foreach (var obj in Clients.Where(c => c.IsWatch && c.Competitionid == item.Competitionid).Select(c => c.MemberId))
|
||||||
|
{
|
||||||
|
sb.Append(obj);
|
||||||
|
sb.Append("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
sb.Remove(sb.Length - 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var watchList1 = sb.ToString();
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
foreach (var c in list.Where(c => c.RoomId > 0 || c.FrameRate > 0))
|
||||||
|
{
|
||||||
|
sb.Append($"{c.MemberId},{c.RoomId},{c.FrameRate},{c.TotalTicks}");
|
||||||
|
sb.Append("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
sb.Remove(sb.Length - 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var e = sb.ToString();
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append("*l{");
|
||||||
|
sb.Append(temp);
|
||||||
|
sb.Append("};w{");
|
||||||
|
sb.Append(watchList1);
|
||||||
|
sb.Append("};e{");
|
||||||
|
sb.Append(e);
|
||||||
|
sb.Append("};#");
|
||||||
|
var strV2 = sb.ToString();
|
||||||
|
var data2 = new NetworkData(strV2);
|
||||||
|
return data2;
|
||||||
|
}
|
||||||
|
|
||||||
private void GameRoomDisConnectHandler(HostModel client)
|
private void GameRoomDisConnectHandler(HostModel client)
|
||||||
{
|
{
|
||||||
////如果是在对战房间或者对战列表掉线执行,骑行阶段断开连接不移除房间信息
|
////如果是在对战房间或者对战列表掉线执行,骑行阶段断开连接不移除房间信息
|
||||||
@ -828,15 +898,16 @@ namespace OnlineUserPool.ViewModels
|
|||||||
o.List.Remove(needRemove);
|
o.List.Remove(needRemove);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var needRemoveList = RoomList.ToList().Where(c => c.List.Count == 0 && c.Status != 2).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);
|
||||||
}
|
}
|
||||||
|
|
||||||
BroadCastGameRoomList();
|
BroadCastGameRoomList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WriteLine(string str)
|
void WriteLine(string str)
|
||||||
{
|
{
|
||||||
//Debug.WriteLine(str);
|
//Debug.WriteLine(str);
|
||||||
@ -859,7 +930,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source), deserializeSettings);
|
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source), deserializeSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CientDisconnected(EndPoint point)
|
private void ClientDisconnected(EndPoint point)
|
||||||
{
|
{
|
||||||
dispatcher.Invoke(() =>
|
dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
@ -874,7 +945,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
Log.Information("在CientDisconnected触发以后,删除client时报错了,"+ ex.Message +", " + ex.StackTrace);
|
Log.Information("在ClientDisconnected触发以后,删除client时报错了,"+ ex.Message +", " + ex.StackTrace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -883,6 +954,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
{
|
{
|
||||||
BeforeRemoved(client);
|
BeforeRemoved(client);
|
||||||
Clients.Remove(client);
|
Clients.Remove(client);
|
||||||
|
Customers.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BeforeRemoved(HostModel client)
|
private void BeforeRemoved(HostModel client)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user