mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-20 15:41:01 +00:00
auth queue message
This commit is contained in:
parent
bce5fd395a
commit
f5d6339862
@ -1,34 +0,0 @@
|
||||
using QSB.Events;
|
||||
using QuantumUNET.Components;
|
||||
|
||||
namespace QSB.AuthoritySync
|
||||
{
|
||||
public class AuthQueueEvent : QSBEvent<AuthQueueMessage>
|
||||
{
|
||||
public override bool RequireWorldObjectsReady => true;
|
||||
|
||||
public override void SetupListener() =>
|
||||
GlobalMessenger<QNetworkIdentity, AuthQueueAction>.AddListener(EventNames.QSBAuthQueue, Handler);
|
||||
|
||||
public override void CloseListener() =>
|
||||
GlobalMessenger<QNetworkIdentity, AuthQueueAction>.RemoveListener(EventNames.QSBAuthQueue, Handler);
|
||||
|
||||
private void Handler(QNetworkIdentity identity, AuthQueueAction action) => SendEvent(CreateMessage(identity, action));
|
||||
|
||||
private AuthQueueMessage CreateMessage(QNetworkIdentity identity, AuthQueueAction action) => new()
|
||||
{
|
||||
OnlySendToHost = true,
|
||||
Identity = identity,
|
||||
EnumValue = action
|
||||
};
|
||||
|
||||
|
||||
public override void OnReceiveLocal(bool isHost, AuthQueueMessage message) => OnReceive(message);
|
||||
public override void OnReceiveRemote(bool isHost, AuthQueueMessage message) => OnReceive(message);
|
||||
|
||||
private static void OnReceive(AuthQueueMessage message)
|
||||
{
|
||||
message.Identity.UpdateAuthQueue(message.FromId, message.EnumValue);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +1,31 @@
|
||||
using QSB.Messaging;
|
||||
using QuantumUNET.Components;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET;
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QSB.AuthoritySync
|
||||
{
|
||||
public class AuthQueueMessage : EnumMessage<AuthQueueAction>
|
||||
public class AuthQueueMessage : QSBEnumMessage<AuthQueueAction>
|
||||
{
|
||||
public QNetworkIdentity Identity;
|
||||
public QNetworkInstanceId NetId;
|
||||
|
||||
public AuthQueueMessage() => To = 0;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Identity = reader.ReadNetworkIdentity();
|
||||
NetId = reader.ReadNetworkId();
|
||||
}
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(Identity);
|
||||
writer.Write(NetId);
|
||||
}
|
||||
|
||||
public override bool ShouldReceive => WorldObjectManager.AllObjectsReady;
|
||||
public override void OnReceiveLocal() => QNetworkServer.objects[NetId].UpdateAuthQueue(From, Value);
|
||||
public override void OnReceiveRemote() => QNetworkServer.objects[NetId].UpdateAuthQueue(From, Value);
|
||||
}
|
||||
|
||||
public enum AuthQueueAction
|
||||
|
@ -1,4 +1,4 @@
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET;
|
||||
using QuantumUNET.Components;
|
||||
@ -89,7 +89,11 @@ namespace QSB.AuthoritySync
|
||||
#region any client
|
||||
|
||||
public static void FireAuthQueue(this QNetworkIdentity identity, AuthQueueAction action) =>
|
||||
QSBEventManager.FireEvent(EventNames.QSBAuthQueue, identity, action);
|
||||
new AuthQueueMessage
|
||||
{
|
||||
NetId = identity.NetId,
|
||||
Value = action
|
||||
}.Send();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
@ -100,7 +100,6 @@
|
||||
public const string QSBLearnLaunchCodes = nameof(QSBLearnLaunchCodes);
|
||||
public const string QSBSatelliteRepairTick = nameof(QSBSatelliteRepairTick);
|
||||
public const string QSBSatelliteRepaired = nameof(QSBSatelliteRepairTick);
|
||||
public const string QSBAuthQueue = nameof(QSBAuthQueue);
|
||||
public const string QSBJellyfishRising = nameof(QSBJellyfishRising);
|
||||
public const string QSBTornadoFormState = nameof(QSBTornadoFormState);
|
||||
public const string QSBRequestGameDetails = nameof(QSBRequestGameDetails);
|
||||
|
@ -10,7 +10,7 @@ namespace QSB.Messaging
|
||||
/// set automatically when sending a message
|
||||
public uint From;
|
||||
/// <summary>
|
||||
/// uint.MaxValue = send to everyone <br/>
|
||||
/// (default) uint.MaxValue = send to everyone <br/>
|
||||
/// 0 = send to host
|
||||
/// </summary>
|
||||
public uint To = uint.MaxValue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user