From ed14c30f9e55ea5cd20cb83468ccb5c919187119 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 6 Dec 2021 00:15:47 -0800 Subject: [PATCH] with request resync, server should only send requesting client the info, rather than sending it to everyone --- QSB/Messaging/PlayerMessage.cs | 6 +++++- QSB/Player/Events/RequestStateResyncEvent.cs | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/QSB/Messaging/PlayerMessage.cs b/QSB/Messaging/PlayerMessage.cs index b14eb553..1be3da98 100644 --- a/QSB/Messaging/PlayerMessage.cs +++ b/QSB/Messaging/PlayerMessage.cs @@ -28,6 +28,10 @@ namespace QSB.Messaging /// public uint ForId { get; set; } = uint.MaxValue; + /// used to force set ForId. + /// primarily used for state resyncing, when the server needs to send a specific client a bunch of events + public static uint ForIdOverride = uint.MaxValue; + public override void Deserialize(QNetworkReader reader) { FromId = reader.ReadUInt32(); @@ -46,7 +50,7 @@ namespace QSB.Messaging writer.Write(OnlySendToHost); if (!OnlySendToHost) { - writer.Write(ForId); + writer.Write(ForIdOverride != uint.MaxValue ? ForIdOverride : ForId); } } } diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index 3d8cd289..57d0a231 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -30,15 +30,19 @@ namespace QSB.Player.Events public override void OnReceiveRemote(bool isHost, PlayerMessage message) { - // if host, send worldobject and server states + // if host, send worldobject and server states TO THE REQUESTING CLIENT if (isHost) { + PlayerMessage.ForIdOverride = message.FromId; + QSBEventManager.FireEvent(EventNames.QSBServerState, ServerStateManager.Instance.GetServerState()); QSBEventManager.FireEvent(EventNames.QSBPlayerInformation); SendWorldObjectInfo(); + + PlayerMessage.ForIdOverride = uint.MaxValue; } - // if client, send player and client states + // if client, send player and client states TO EVERYONE else { QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);