2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-08-09 18:33:36 +00:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.TimeSync.Events
|
2020-08-09 18:33:36 +00:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class ServerTimeEvent : QSBEvent<ServerTimeMessage>
|
|
|
|
|
{
|
2021-12-05 11:03:09 +00:00
|
|
|
|
public override bool RequireWorldObjectsReady => false;
|
2021-12-04 16:39:37 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<float, int>.AddListener(EventNames.QSBServerTime, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<float, int>.RemoveListener(EventNames.QSBServerTime, Handler);
|
2020-08-15 19:32:58 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler(float time, int count) => SendEvent(CreateMessage(time, count));
|
2020-08-15 19:52:43 +00:00
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private ServerTimeMessage CreateMessage(float time, int count) => new()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ServerTime = time,
|
|
|
|
|
LoopCount = count
|
|
|
|
|
};
|
2020-08-10 16:17:54 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, ServerTimeMessage message) =>
|
|
|
|
|
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|