quantum-space-buddies/QSB/Events/ServerTimeEvent.cs

28 lines
804 B
C#
Raw Normal View History

2020-08-09 19:33:36 +01:00
using QSB.Messaging;
2020-08-09 20:46:02 +01:00
using QSB.TimeSync;
2020-08-09 19:33:36 +01:00
namespace QSB.Events
{
2020-08-10 18:17:54 +02:00
public class ServerTimeEvent : QSBEvent<ServerTimeMessage>
2020-08-09 19:33:36 +01:00
{
2020-08-10 11:45:24 +01:00
public override MessageType Type => MessageType.ServerTime;
2020-08-09 19:33:36 +01:00
public override void SetupListener()
{
2020-08-10 18:17:54 +02:00
GlobalMessenger<float, int>.AddListener("QSBServerTime", (time, count) => SendEvent(CreateMessage(time, count)));
2020-08-09 19:33:36 +01:00
}
2020-08-09 20:46:02 +01:00
2020-08-10 18:17:54 +02:00
private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
ServerTime = time,
LoopCount = count
};
2020-08-10 14:40:06 +01:00
public override void OnReceiveRemote(ServerTimeMessage message)
2020-08-09 20:46:02 +01:00
{
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
}
2020-08-09 19:33:36 +01:00
}
}