mirror of
https://github.com/Kaveinator/NetickProForUnity.git
synced 2025-10-27 02:09:06 -07:00
auto
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace LiteNetLib.Utils
|
||||
{
|
||||
internal sealed class NtpRequest
|
||||
{
|
||||
private const int ResendTimer = 1000;
|
||||
private const int KillTimer = 10000;
|
||||
public const int DefaultPort = 123;
|
||||
private readonly IPEndPoint _ntpEndPoint;
|
||||
private int _resendTime = ResendTimer;
|
||||
private int _killTime = 0;
|
||||
|
||||
public NtpRequest(IPEndPoint endPoint)
|
||||
{
|
||||
_ntpEndPoint = endPoint;
|
||||
}
|
||||
|
||||
public bool NeedToKill => _killTime >= KillTimer;
|
||||
|
||||
public bool Send(Socket socket, int time)
|
||||
{
|
||||
_resendTime += time;
|
||||
_killTime += time;
|
||||
if (_resendTime < ResendTimer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var packet = new NtpPacket();
|
||||
try
|
||||
{
|
||||
int sendCount = socket.SendTo(packet.Bytes, 0, packet.Bytes.Length, SocketFlags.None, _ntpEndPoint);
|
||||
return sendCount == packet.Bytes.Length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user