초기커밋
This commit is contained in:
90
GameServer/P2P/P2PDataAction.cs
Normal file
90
GameServer/P2P/P2PDataAction.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class P2PDataAction : EntityActionBase
|
||||
{
|
||||
//단순 p2p 데이터 기록을 위한 Action
|
||||
public ConcurrentDictionary<UInt32, P2PPacketSummery> m_data { get; set; } = new();
|
||||
public DateTime m_next_logging_time { get; set; } = DateTimeHelper.Current;
|
||||
public DateTime m_last_update_time { get; set; } = DateTimeHelper.Current;
|
||||
readonly Int32 m_logging_time_interval_sec;
|
||||
|
||||
public P2PDataAction(Player owner) : base(owner)
|
||||
{
|
||||
m_logging_time_interval_sec = 30;
|
||||
}
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> accumulateP2PData(UInt32 packetId, byte[] array)
|
||||
{
|
||||
if (false == m_data.TryGetValue(packetId, out var summery))
|
||||
{
|
||||
summery = new P2PPacketSummery(array.Length);
|
||||
}
|
||||
summery.accumulateData(array.Length);
|
||||
|
||||
m_data[packetId] = summery;
|
||||
|
||||
var now = DateTimeHelper.Current;
|
||||
m_last_update_time = now;
|
||||
if (m_next_logging_time <= now)
|
||||
{
|
||||
Log.getLogger().info($"P2P Packet Data received total : {JsonConvert.SerializeObject(m_data)}");
|
||||
m_next_logging_time = m_next_logging_time.AddSeconds(m_logging_time_interval_sec);
|
||||
}
|
||||
|
||||
if (P2PDataLogManager.It.logActive() == false)
|
||||
{
|
||||
await P2PDataLogManager.It.activeMonitoring();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var result = new Result();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class P2PPacketSummery
|
||||
{
|
||||
public long m_packet_count { get; set; } = 0;
|
||||
public long m_total_packet_size { get; set; } = 0;
|
||||
|
||||
public P2PPacketSummery(long packetSize)
|
||||
{
|
||||
m_packet_count = 1;
|
||||
m_total_packet_size = packetSize;
|
||||
}
|
||||
|
||||
public P2PPacketSummery(long packetCount, long packetSize)
|
||||
{
|
||||
m_packet_count = packetCount;
|
||||
m_total_packet_size = packetSize;
|
||||
}
|
||||
|
||||
public void accumulateData(long packetSize)
|
||||
{
|
||||
m_packet_count += 1;
|
||||
m_total_packet_size += packetSize;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user