quantum-space-buddies/QSB/AuthoritySync/AuthorityQueueEvent.cs
Mister_Nebula 554c2bb2dd cleanup
2021-12-07 15:56:08 +00:00

35 lines
1.1 KiB
C#

using QSB.Events;
using QuantumUNET.Components;
namespace QSB.AuthoritySync
{
public class AuthorityQueueEvent : QSBEvent<AuthorityQueueMessage>
{
public override bool RequireWorldObjectsReady => true;
public override void SetupListener() =>
GlobalMessenger<QNetworkIdentity, bool>.AddListener(EventNames.QSBAuthorityQueue, Handler);
public override void CloseListener() =>
GlobalMessenger<QNetworkIdentity, bool>.RemoveListener(EventNames.QSBAuthorityQueue, Handler);
private void Handler(QNetworkIdentity identity, bool queue) => SendEvent(CreateMessage(identity, queue));
private AuthorityQueueMessage CreateMessage(QNetworkIdentity identity, bool queue) => new()
{
OnlySendToHost = true,
Identity = identity,
Queue = queue
};
public override void OnReceiveLocal(bool isHost, AuthorityQueueMessage message) => OnReceive(message);
public override void OnReceiveRemote(bool isHost, AuthorityQueueMessage message) => OnReceive(message);
private static void OnReceive(AuthorityQueueMessage message)
{
message.Identity.UpdateAuthQueue(message.FromId, message.Queue);
}
}
}