feature:3.0.0

This commit is contained in:
lishuo committed 2023-08-01 11:02:04 +08:00
1 parent 65c19a5071
commit 9e1e0707dc
4 files changed
+180 -309

No files matched your search

+17 -34
View File
@@ -104,7 +104,7 @@ namespace OnlineUserPool.ViewModels
//mapRecordRankingHander = new MultiUserHandle();
Log.Information($"初始化连接,当前地址:{ IPAddress.Any }:{ConfigHelp.UdpPort}");
new TcpService1().RunServer(ReceivedData, CientDisconnected);
new TcpService().RunServer(ReceivedData, CientDisconnected);
//var tet = new System.Collections.Concurrent.ConcurrentBag<object>();
var _udpService = new UdpService();
@@ -302,7 +302,7 @@ namespace OnlineUserPool.ViewModels
var G = $"{total}l[{gameRoom},detail{{{ss}}}]";
var temp = string.Join("|", list.Select(m => m.ToString(2))) + "|";
var strV21 = $"*l{{{ temp }}};g{{{ G}}};#";
var ddd = new Data1(strV21);
var ddd = new NetworkData(strV21);
var needList = Clients.Where(c => c.RoomId == gameRoom.RoomId).ToList();
foreach (var client in needList)
@@ -329,7 +329,7 @@ namespace OnlineUserPool.ViewModels
{
var G = GameRoomMessageHandler(item);
var strV21 = $"*l{{{ temp }}};g{{{G}}};#";
var ddd = new Data1(strV21);
var ddd = new NetworkData(strV21);
bool isZip = item.Encoding == "gzip";
item.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, item.IPEndPoint);
}
@@ -382,7 +382,7 @@ namespace OnlineUserPool.ViewModels
}
var strV21 = $"*l{{{ temp }}};g{{{roomInfo}}};#";
var ddd = new Data1(strV21);
var ddd = new NetworkData(strV21);
bool isZip = needSend.Encoding == "gzip";
needSend.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, needSend.IPEndPoint);
}
@@ -749,7 +749,8 @@ namespace OnlineUserPool.ViewModels
item.EndDistance = Math.Round(item.EndDistance, 5);
item.WeightKg = Math.Round(item.WeightKg, 2);
}
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(list.Select(m => new {
var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(list.Select(m => new {
m.RouteId,
m.MemberId,
m.Point,
@@ -765,7 +766,6 @@ namespace OnlineUserPool.ViewModels
m.FrameRate,
}));
var data = Encoding.ASCII.GetBytes(jsonString);
//SendDataSize = (data.Length/1000D).ToString() +"KB";
var strV1 = string.Join("|", list.Select(m => m.ToString(1)));
if (!string.IsNullOrWhiteSpace(strV1))
@@ -773,24 +773,11 @@ namespace OnlineUserPool.ViewModels
strV1 += "|";
}
//strV1 = "abcdefghijklmnopqrstuvwxyz";
//System.IO.File.AppendAllText(System.Environment.CurrentDirectory + "要发送的数据.txt", strV1.Trim().Replace("\0", "") + "\r\n", Encoding.UTF8);
WriteLine(strV1);
WriteLine(strV1.Length.ToString());
//var dataV1 = Encoding.UTF8.GetBytes(strV1);
//var dataV1ForUdp = strV1.Last() == '|' ? Encoding.ASCII.GetBytes(strV1.Substring(0, strV1.Length - 1)) : dataV1;
//var dataCompressV1 = Encoding.UTF8.GetBytes($"*{ Convert.ToBase64String(CommonHelper.Compress(strV1)) }#");
var data1 = new Data1(strV1);
var data1ForUdp = new Data1(strV1.Last() == '|' ? strV1.Substring(0, strV1.Length - 1) : strV1);
//var watchList = string.Join('|', clients1.Where(c => c.IsWatch).Select(c => c.MemberId));
//var strV2 = $"*l{{{ strV1 }}};w{{{ watchList }}}#";
////var dataCompressV2 = Encoding.UTF8.GetBytes($"{ Convert.ToBase64String(CommonHelper.Compress(strV2)) }");
//var data2 = new Data1(strV2);
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";
@@ -799,26 +786,22 @@ namespace OnlineUserPool.ViewModels
{
try
{
if (item == null)
{
continue;
}
//if((item.Service is UdpService) ==false)
//{
// continue;
//}
if (item == null) continue;
if (item.V != 1 && item.V != 2)
{
item.Service.Send(data, data.Length, item.IPEndPoint);
continue;
}
if (item.V == 1 && item.Service is UdpService)
{
item.Service.Send(data1ForUdp.GetBytes(), data1ForUdp.GetBytes().Length, item.IPEndPoint);
}
else
if(item.Service is TcpService)
{
Data1 ddd = null;// = item.V == 1 ? ;
NetworkData ddd = null;
if (item.V == 1)
{
ddd = data1;
@@ -829,7 +812,7 @@ namespace OnlineUserPool.ViewModels
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 Data1(strV21);
ddd = new NetworkData(strV21);
}
else
{
@@ -951,10 +934,10 @@ namespace OnlineUserPool.ViewModels
}
}
public class Data1
public class NetworkData
{
private string _txt = "";
public Data1(string txt)
public NetworkData(string txt)
{
this._txt = txt;
}