quantum-space-buddies/QSB/TimeSync/ServerTimeEvent.cs
AmazingAlek 78f89a342e
player id stuff (#181)
* player id stuff
2020-08-17 19:19:41 +02:00

35 lines
998 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, Handler);
}
public override void CloseListener()
{
GlobalMessenger<float, int>.RemoveListener(EventNames.QSBServerTime, Handler);
}
private void Handler(float time, int count) => SendEvent(CreateMessage(time, count));
private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage
{
AboutId = LocalPlayerId,
ServerTime = time,
LoopCount = count
};
public override void OnReceiveRemote(ServerTimeMessage message)
{
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
}
}
}