quantum-space-buddies/QSB/Player/Messages/PlayerReadyMessage.cs

44 lines
1.0 KiB
C#
Raw Normal View History

2021-12-22 16:44:03 -08:00
using OWML.Common;
using QSB.Messaging;
using QSB.Utility;
namespace QSB.Player.Messages
2021-12-22 16:44:03 -08:00
{
public class PlayerReadyMessage : QSBMessage<bool>
{
public PlayerReadyMessage(bool ready) => Value = ready;
public override void OnReceiveRemote()
2021-12-22 16:44:03 -08:00
{
if (QSBCore.IsHost)
{
HandleServer();
}
else
{
HandleClient();
}
2021-12-22 16:44:03 -08:00
}
private void HandleServer()
2021-12-22 16:44:03 -08:00
{
DebugLog.DebugWrite($"[SERVER] Get ready event from {From} (ready = {Value})", MessageType.Success);
QSBPlayerManager.GetPlayer(From).IsReady = Value;
new PlayerInformationMessage().Send();
2021-12-22 16:44:03 -08:00
}
private void HandleClient()
{
DebugLog.DebugWrite($"[CLIENT] Get ready event from {From} (ready = {Value})", MessageType.Success);
if (!QSBPlayerManager.PlayerExists(From))
{
DebugLog.ToConsole(
"Error - Got ready event for non-existent player! Did we not send a PlayerStatesRequestEvent? Or was it not handled?",
MessageType.Error);
return;
}
QSBPlayerManager.GetPlayer(From).IsReady = Value;
}
2021-12-22 16:44:03 -08:00
}
}