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

33 lines
1017 B
C#
Raw Normal View History

2020-08-13 21:46:16 +02:00
using QSB.Events;
using QSB.Messaging;
2020-08-09 19:33:36 +01:00
2020-08-13 21:46:16 +02:00
namespace QSB.TimeSync
2020-08-09 19:33:36 +01:00
{
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 19:24:28 +02:00
GlobalMessenger<float, int>.AddListener(EventNames.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-15 20:32:58 +01:00
public override void CloseListener()
{
GlobalMessenger<float, int>.RemoveListener(EventNames.QSBServerTime, (time, count) => SendEvent(CreateMessage(time, count)));
}
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
}
}