send server/client state messages directly, since it sets the state both locally and remotely

This commit is contained in:
JohnCorby 2022-02-05 02:50:13 -08:00
parent 2f52ab9cae
commit 4f3c359946
8 changed files with 30 additions and 32 deletions

View File

@ -27,12 +27,6 @@ namespace QSB.ClientServerStateSync
private void OnDestroy() =>
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
public void SendChangeClientStateMessage(ClientState newState)
{
ChangeClientState(newState);
new ClientStateMessage(newState).Send();
}
public void ChangeClientState(ClientState newState)
{
if (PlayerTransformSync.LocalInstance == null || QSBPlayerManager.LocalPlayer.State == newState)
@ -143,7 +137,7 @@ namespace QSB.ClientServerStateSync
}
}
SendChangeClientStateMessage(newState);
new ClientStateMessage(newState).Send();
}
public void OnDeath()
@ -151,7 +145,7 @@ namespace QSB.ClientServerStateSync
var currentScene = QSBSceneManager.CurrentScene;
if (currentScene == OWScene.SolarSystem)
{
SendChangeClientStateMessage(ClientState.DeadInSolarSystem);
new ClientStateMessage(ClientState.DeadInSolarSystem).Send();
}
else if (currentScene == OWScene.EyeOfTheUniverse)
{
@ -170,7 +164,7 @@ namespace QSB.ClientServerStateSync
if (currentScene == OWScene.SolarSystem)
{
DebugLog.DebugWrite($"RESPAWN!");
SendChangeClientStateMessage(ClientState.AliveInSolarSystem);
new ClientStateMessage(ClientState.AliveInSolarSystem).Send();
}
else
{

View File

@ -5,6 +5,9 @@ using QSB.Utility;
namespace QSB.ClientServerStateSync.Messages
{
/// <summary>
/// sets the state both locally and remotely
/// </summary>
internal class ClientStateMessage : QSBMessage<ClientState>
{
public ClientStateMessage(ClientState state) => Value = state;

View File

@ -2,6 +2,9 @@
namespace QSB.ClientServerStateSync.Messages
{
/// <summary>
/// sets the state both locally and remotely
/// </summary>
internal class ServerStateMessage : QSBMessage<ServerState>
{
public ServerStateMessage(ServerState state) => Value = state;

View File

@ -42,12 +42,6 @@ namespace QSB.ClientServerStateSync
GlobalMessenger.RemoveListener("TriggerSupernova", OnTriggerSupernova);
}
public void SendChangeServerStateMessage(ServerState newState)
{
ChangeServerState(newState);
new ServerStateMessage(newState).Send();
}
public void ChangeServerState(ServerState newState)
{
if (_currentState == newState)
@ -69,34 +63,34 @@ namespace QSB.ClientServerStateSync
case OWScene.Credits_Fast:
case OWScene.Credits_Final:
case OWScene.PostCreditsScene:
SendChangeServerStateMessage(ServerState.Credits);
new ServerStateMessage(ServerState.Credits).Send();
break;
case OWScene.TitleScreen:
SendChangeServerStateMessage(ServerState.NotLoaded);
new ServerStateMessage(ServerState.NotLoaded).Send();
break;
case OWScene.SolarSystem:
if (oldScene == OWScene.SolarSystem)
{
SendChangeServerStateMessage(ServerState.WaitingForAllPlayersToReady);
new ServerStateMessage(ServerState.WaitingForAllPlayersToReady).Send();
}
else
{
SendChangeServerStateMessage(ServerState.InSolarSystem);
new ServerStateMessage(ServerState.InSolarSystem).Send();
}
break;
case OWScene.EyeOfTheUniverse:
SendChangeServerStateMessage(ServerState.WaitingForAllPlayersToReady);
new ServerStateMessage(ServerState.WaitingForAllPlayersToReady).Send();
break;
case OWScene.None:
case OWScene.Undefined:
default:
DebugLog.ToConsole($"Warning - newScene is {newScene}!", OWML.Common.MessageType.Warning);
SendChangeServerStateMessage(ServerState.NotLoaded);
new ServerStateMessage(ServerState.NotLoaded).Send();
break;
}
}
@ -105,7 +99,7 @@ namespace QSB.ClientServerStateSync
{
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
{
SendChangeServerStateMessage(ServerState.WaitingForAllPlayersToDie);
new ServerStateMessage(ServerState.WaitingForAllPlayersToDie).Send();
}
}
@ -148,16 +142,16 @@ namespace QSB.ClientServerStateSync
new StartLoopMessage().Send();
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
{
SendChangeServerStateMessage(ServerState.InSolarSystem);
new ServerStateMessage(ServerState.InSolarSystem).Send();
}
else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse)
{
SendChangeServerStateMessage(ServerState.InEye);
new ServerStateMessage(ServerState.InEye).Send();
}
else
{
DebugLog.ToConsole($"Error - All players were ready in non-universe scene!?", OWML.Common.MessageType.Error);
SendChangeServerStateMessage(ServerState.NotLoaded);
new ServerStateMessage(ServerState.NotLoaded).Send();
}
_blockNextCheck = true;

View File

@ -1,4 +1,5 @@
using QSB.ClientServerStateSync;
using QSB.ClientServerStateSync.Messages;
using QSB.Messaging;
using QSB.Patches;
using QSB.Utility;
@ -23,7 +24,7 @@ namespace QSB.DeathSync.Messages
Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop);
if (QSBCore.IsHost)
{
ServerStateManager.Instance.SendChangeServerStateMessage(ServerState.WaitingForAllPlayersToDie);
new ServerStateMessage(ServerState.WaitingForAllPlayersToDie).Send();
}
}
}

View File

@ -1,5 +1,6 @@
using OWML.Common;
using QSB.ClientServerStateSync;
using QSB.ClientServerStateSync.Messages;
using QSB.Messaging;
using QSB.Utility;
@ -14,16 +15,16 @@ namespace QSB.DeathSync.Messages
DebugLog.DebugWrite($" ~~~ LOOP START ~~~");
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
{
ClientStateManager.Instance.SendChangeClientStateMessage(ClientState.AliveInSolarSystem);
new ClientStateMessage(ClientState.AliveInSolarSystem).Send();
}
else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse)
{
ClientStateManager.Instance.SendChangeClientStateMessage(ClientState.AliveInEye);
new ClientStateMessage(ClientState.AliveInEye).Send();
}
else
{
DebugLog.ToConsole($"Error - Got StartLoop event when not in universe!", MessageType.Error);
ClientStateManager.Instance.SendChangeClientStateMessage(ClientState.NotLoaded);
new ClientStateMessage(ClientState.NotLoaded).Send();
}
}
}

View File

@ -1,5 +1,6 @@
using Mirror;
using QSB.ClientServerStateSync;
using QSB.ClientServerStateSync.Messages;
using QSB.Messaging;
using QSB.WorldSync;
using UnityEngine;
@ -41,7 +42,7 @@ namespace QSB.StatueSync.Messages
{
if (QSBCore.IsHost)
{
ServerStateManager.Instance.SendChangeServerStateMessage(ServerState.InStatueCutscene);
new ServerStateMessage(ServerState.InStatueCutscene).Send();
}
}
@ -49,7 +50,7 @@ namespace QSB.StatueSync.Messages
{
if (QSBCore.IsHost)
{
ServerStateManager.Instance.SendChangeServerStateMessage(ServerState.InStatueCutscene);
new ServerStateMessage(ServerState.InStatueCutscene).Send();
}
StatueManager.Instance.BeginSequence(PlayerPosition, PlayerRotation, CameraDegrees);

View File

@ -1,6 +1,7 @@
using Mirror;
using OWML.Common;
using QSB.ClientServerStateSync;
using QSB.ClientServerStateSync.Messages;
using QSB.DeathSync;
using QSB.Inputs;
using QSB.Messaging;
@ -297,7 +298,7 @@ namespace QSB.TimeSync
{
//?
DebugLog.ToConsole($"Warning - Server waiting for players to die, but players waiting for ready signal! Assume players correct.", MessageType.Warning);
ServerStateManager.Instance.SendChangeServerStateMessage(ServerState.WaitingForAllPlayersToReady);
new ServerStateMessage(ServerState.WaitingForAllPlayersToReady).Send();
}
}