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

45 lines
1.0 KiB
C#
Raw Normal View History

2021-12-23 00:44:03 +00:00
using OWML.Common;
using QSB.Messaging;
using QSB.Utility;
2021-12-23 21:49:47 +00:00
namespace QSB.Player.Messages
2021-12-23 00:44:03 +00:00
{
public class PlayerReadyMessage : QSBBoolMessage
{
2021-12-23 01:13:54 +00:00
public PlayerReadyMessage(bool ready) => Value = ready;
2021-12-23 00:44:03 +00:00
public override void OnReceiveRemote()
{
if (QSBCore.IsHost)
{
HandleServer();
}
else
{
HandleClient();
}
}
private void HandleServer()
{
DebugLog.DebugWrite($"[SERVER] Get ready event from {From} (ready = {Value})", MessageType.Success);
QSBPlayerManager.GetPlayer(From).IsReady = Value;
2021-12-23 01:38:08 +00:00
new PlayerInformationMessage().Send();
2021-12-23 00:44:03 +00: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-23 01:13:54 +00:00
}