2021-12-25 22:53:36 -08:00
|
|
|
|
using OWML.Common;
|
2021-08-08 20:04:15 +01:00
|
|
|
|
using QSB.ClientServerStateSync;
|
2021-12-24 22:33:29 -08:00
|
|
|
|
using QSB.ClientServerStateSync.Messages;
|
2021-12-23 16:26:31 -08:00
|
|
|
|
using QSB.ConversationSync.Messages;
|
2021-12-24 21:28:41 -08:00
|
|
|
|
using QSB.LogSync.Messages;
|
2020-12-14 16:28:03 +00:00
|
|
|
|
using QSB.Messaging;
|
2020-08-22 20:21:13 +01:00
|
|
|
|
using QSB.Utility;
|
2020-12-11 22:42:21 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2021-12-23 13:49:47 -08:00
|
|
|
|
namespace QSB.Player.Messages
|
2020-08-10 14:40:06 +01:00
|
|
|
|
{
|
2021-12-24 21:42:14 -08:00
|
|
|
|
// Can be sent by any client (including host) to signal they want latest worldobject, player, and server information
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public class RequestStateResyncMessage : QSBMessage
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-12-22 18:20:53 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set to true when we send this, and false when we receive a player info message back. <br/>
|
|
|
|
|
/// this prevents message spam a bit.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static bool _waitingForEvent;
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2021-12-24 21:42:53 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// used instead of QSBMessageManager.Send to do the extra check
|
|
|
|
|
/// </summary>
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public void Send()
|
2021-12-11 11:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (_waitingForEvent)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_waitingForEvent = true;
|
2021-12-22 18:20:53 -08:00
|
|
|
|
QSBMessageManager.Send(this);
|
2021-12-11 11:47:21 +00:00
|
|
|
|
}
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public override void OnReceiveLocal()
|
2021-12-11 11:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
QSBCore.UnityEvents.FireInNUpdates(() =>
|
|
|
|
|
{
|
|
|
|
|
if (_waitingForEvent)
|
|
|
|
|
{
|
2022-01-21 22:29:13 -08:00
|
|
|
|
if (QSBPlayerManager.PlayerList.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Did not receive PlayerInformationEvent in time. Setting _waitingForEvent to false.", MessageType.Info);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-11 11:47:21 +00:00
|
|
|
|
_waitingForEvent = false;
|
|
|
|
|
}
|
|
|
|
|
}, 60);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public override void OnReceiveRemote()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-12-24 22:15:31 -08:00
|
|
|
|
// if host, send worldobject and server states
|
|
|
|
|
if (QSBCore.IsHost)
|
2020-12-19 10:56:25 +00:00
|
|
|
|
{
|
2021-12-24 22:33:29 -08:00
|
|
|
|
new ServerStateMessage(ServerStateManager.Instance.GetServerState()) { To = From }.Send();
|
|
|
|
|
new PlayerInformationMessage { To = From }.Send();
|
2021-12-13 22:16:32 -08:00
|
|
|
|
|
2022-01-18 00:27:32 -08:00
|
|
|
|
if (QSBWorldSync.AllObjectsReady)
|
2021-12-13 22:16:32 -08:00
|
|
|
|
{
|
2022-01-21 15:13:16 -08:00
|
|
|
|
QSBWorldSync.DialogueConditions.ForEach(condition
|
|
|
|
|
=> new DialogueConditionMessage(condition.Key, condition.Value) { To = From }.Send());
|
|
|
|
|
|
|
|
|
|
QSBWorldSync.ShipLogFacts.ForEach(fact
|
|
|
|
|
=> new RevealFactMessage(fact.Id, fact.SaveGame, false) { To = From }.Send());
|
2021-12-13 22:16:32 -08:00
|
|
|
|
}
|
2020-12-19 10:56:25 +00:00
|
|
|
|
}
|
2021-12-24 22:15:31 -08:00
|
|
|
|
// if client, send player and client states
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-26 04:33:20 -08:00
|
|
|
|
new PlayerInformationMessage { To = From }.Send();
|
2021-12-24 22:15:31 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 00:27:32 -08:00
|
|
|
|
if (QSBWorldSync.AllObjectsReady)
|
2021-12-06 00:02:51 -08:00
|
|
|
|
{
|
2022-01-21 14:56:45 -08:00
|
|
|
|
foreach (var worldObject in QSBWorldSync.GetWorldObjects())
|
|
|
|
|
{
|
2022-01-21 15:13:16 -08:00
|
|
|
|
worldObject.SendResyncInfo(From);
|
2022-01-21 14:56:45 -08:00
|
|
|
|
}
|
2020-12-19 10:56:25 +00:00
|
|
|
|
}
|
2021-08-08 20:04:15 +01:00
|
|
|
|
}
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-12-26 04:33:20 -08:00
|
|
|
|
}
|