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

43 lines
989 B
C#
Raw Normal View History

2021-12-23 00:44:03 +00:00
using OWML.Common;
using QSB.Messaging;
using QSB.Utility;
2022-03-03 03:46:33 +00:00
namespace QSB.Player.Messages;
public class PlayerReadyMessage : QSBMessage<bool>
2021-12-23 00:44:03 +00:00
{
2022-03-11 01:57:50 +00:00
public PlayerReadyMessage(bool ready) : base(ready) { }
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote()
{
if (QSBCore.IsHost)
2021-12-23 00:44:03 +00:00
{
2022-03-03 03:46:33 +00:00
HandleServer();
2021-12-23 00:44:03 +00:00
}
2022-03-03 03:46:33 +00:00
else
2021-12-23 00:44:03 +00:00
{
2022-03-03 03:46:33 +00:00
HandleClient();
2021-12-23 00:44:03 +00:00
}
2022-03-03 03:46:33 +00:00
}
2021-12-23 00:44:03 +00:00
2022-03-03 03:46:33 +00:00
private void HandleServer()
{
DebugLog.DebugWrite($"[SERVER] Get ready event from {From} (ready = {Data})", MessageType.Success);
QSBPlayerManager.GetPlayer(From).IsReady = Data;
new PlayerInformationMessage().Send();
}
2022-03-03 03:46:33 +00:00
private void HandleClient()
{
DebugLog.DebugWrite($"[CLIENT] Get ready event from {From} (ready = {Data})", 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;
}
2022-03-03 03:46:33 +00:00
QSBPlayerManager.GetPlayer(From).IsReady = Data;
2021-12-23 00:44:03 +00:00
}
}