초기커밋
This commit is contained in:
40
ServerCore/Sync/TimeSyncHelper.cs
Normal file
40
ServerCore/Sync/TimeSyncHelper.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
//=============================================================================================
|
||||
// 서버로 부터 수신한 시간을 기준 시간으로 설정시켜
|
||||
// 서버 시간을 기준으로 동기화되어 관리될 수 있는 기능을 지원하는 클래스 이다.
|
||||
//
|
||||
// author : kangms
|
||||
//
|
||||
//=============================================================================================
|
||||
public class TimeSyncHelper
|
||||
{
|
||||
private readonly string m_server_type = string.Empty;
|
||||
private DateTime m_server_time = ConstDateTimeValue.MinTime;
|
||||
private System.Diagnostics.Stopwatch m_stop_watch = new System.Diagnostics.Stopwatch();
|
||||
public TimeSyncHelper(string serverType)
|
||||
{
|
||||
m_server_type = serverType;
|
||||
}
|
||||
public void setupFromTimeServer(DateTime serverTime, TimeSpan ping)
|
||||
{
|
||||
m_server_time = serverTime.toUtcTime().AddMilliseconds(ping.TotalMilliseconds / 2);
|
||||
m_stop_watch = m_stop_watch ?? new System.Diagnostics.Stopwatch();
|
||||
m_stop_watch.Reset();
|
||||
m_stop_watch.Start();
|
||||
}
|
||||
|
||||
public DateTime getCurrentByTimeServer()
|
||||
{
|
||||
return m_server_time + m_stop_watch.Elapsed;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user