quantum-space-buddies/QSB/TimeSync/ServerTimeEvent.cs
2020-08-13 21:46:16 +02:00

28 lines
813 B
C#

using QSB.Events;
using QSB.Messaging;
namespace QSB.TimeSync
{
public class ServerTimeEvent : QSBEvent<ServerTimeMessage>
{
public override MessageType Type => MessageType.ServerTime;
public override void SetupListener()
{
GlobalMessenger<float, int>.AddListener(EventNames.QSBServerTime, (time, count) => SendEvent(CreateMessage(time, count)));
}
private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
ServerTime = time,
LoopCount = count
};
public override void OnReceiveRemote(ServerTimeMessage message)
{
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
}
}
}