PlayerInformation

This commit is contained in:
JohnCorby 2021-12-22 17:38:08 -08:00
parent 6d7fc8ecbf
commit c4be4fa6be
9 changed files with 75 additions and 96 deletions

View File

@ -5,6 +5,7 @@ using QuantumUNET.Transport;
namespace QSB.AuthoritySync
{
// always sent to host
public class AuthQueueMessage : QSBEnumMessage<AuthQueueAction>
{
private QNetworkInstanceId NetId;

View File

@ -36,7 +36,6 @@
public const string QSBConversation = nameof(QSBConversation);
public const string QSBConversationStartEnd = nameof(QSBConversationStartEnd);
public const string QSBChangeAnimType = nameof(QSBChangeAnimType);
public const string QSBPlayerInformation = nameof(QSBPlayerInformation);
public const string QSBRevealFact = nameof(QSBRevealFact);
public const string QSBSocketStateChange = nameof(QSBSocketStateChange);
public const string QSBMultiStateChange = nameof(QSBMultiStateChange);

View File

@ -123,7 +123,8 @@ namespace QSB.Messaging
if (!player.IsReady
&& player.PlayerId != QSBPlayerManager.LocalPlayerId
&& player.State is ClientState.AliveInSolarSystem or ClientState.AliveInEye or ClientState.DeadInSolarSystem
&& msg is not QSBEventRelay { Event: PlayerInformationEvent or RequestStateResyncEvent or ServerStateEvent }
&& msg is not QSBEventRelay { Event: RequestStateResyncEvent or ServerStateEvent }
and not PlayerInformationMessage
and not PlayerReadyMessage)
{
DebugLog.ToConsole($"Warning - Got message {msg} from player {msg.From}, but they were not ready. Asking for state resync, just in case.", MessageType.Warning);

View File

@ -1,43 +0,0 @@
using OWML.Common;
using QSB.Events;
using QSB.Utility;
namespace QSB.Player.Events
{
public class PlayerInformationEvent : QSBEvent<PlayerInformationMessage>
{
public override bool RequireWorldObjectsReady => false;
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerInformation, Handler);
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerInformation, Handler);
private void Handler() => SendEvent(CreateMessage(QSBPlayerManager.LocalPlayer));
private PlayerInformationMessage CreateMessage(PlayerInfo player) => new()
{
AboutId = player.PlayerId,
PlayerName = player.Name,
IsReady = player.IsReady,
FlashlightActive = player.FlashlightActive,
SuitedUp = player.SuitedUp,
ProbeLauncherEquipped = player.ProbeLauncherEquipped,
SignalscopeEquipped = player.SignalscopeEquipped,
TranslatorEquipped = player.TranslatorEquipped,
ProbeActive = player.ProbeActive,
ClientState = player.State
};
public override void OnReceiveRemote(bool server, PlayerInformationMessage message)
{
RequestStateResyncEvent._waitingForEvent = false;
if (QSBPlayerManager.PlayerExists(message.AboutId))
{
QSBPlayerManager.HandleFullStateMessage(message);
}
else
{
DebugLog.ToConsole($"Warning - got player information message about player that doesnt exist!", MessageType.Warning);
}
}
}
}

View File

@ -1,33 +1,36 @@
using QSB.ClientServerStateSync;
using OWML.Common;
using QSB.ClientServerStateSync;
using QSB.Events;
using QSB.Messaging;
using QSB.Utility;
using QuantumUNET.Transport;
namespace QSB.Player.Events
{
public class PlayerInformationMessage : PlayerMessage
public class PlayerInformationMessage : QSBMessage
{
public string PlayerName { get; set; }
public bool IsReady { get; set; }
public bool FlashlightActive { get; set; }
public bool SuitedUp { get; set; }
public bool ProbeLauncherEquipped { get; set; }
public bool SignalscopeEquipped { get; set; }
public bool TranslatorEquipped { get; set; }
public bool ProbeActive { get; set; }
public ClientState ClientState { get; set; }
private string PlayerName;
private bool IsReady;
private bool FlashlightActive;
private bool SuitedUp;
private bool ProbeLauncherEquipped;
private bool SignalscopeEquipped;
private bool TranslatorEquipped;
private bool ProbeActive;
private ClientState ClientState;
public override void Deserialize(QNetworkReader reader)
public PlayerInformationMessage()
{
base.Deserialize(reader);
PlayerName = reader.ReadString();
IsReady = reader.ReadBoolean();
FlashlightActive = reader.ReadBoolean();
SuitedUp = reader.ReadBoolean();
ProbeLauncherEquipped = reader.ReadBoolean();
SignalscopeEquipped = reader.ReadBoolean();
TranslatorEquipped = reader.ReadBoolean();
ProbeActive = reader.ReadBoolean();
ClientState = (ClientState)reader.ReadInt32();
var player = QSBPlayerManager.LocalPlayer;
PlayerName = player.Name;
IsReady = player.IsReady;
FlashlightActive = player.FlashlightActive;
SuitedUp = player.SuitedUp;
ProbeLauncherEquipped = player.ProbeLauncherEquipped;
SignalscopeEquipped = player.SignalscopeEquipped;
TranslatorEquipped = player.TranslatorEquipped;
ProbeActive = player.ProbeActive;
ClientState = player.State;
}
public override void Serialize(QNetworkWriter writer)
@ -43,5 +46,46 @@ namespace QSB.Player.Events
writer.Write(ProbeActive);
writer.Write((int)ClientState);
}
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
PlayerName = reader.ReadString();
IsReady = reader.ReadBoolean();
FlashlightActive = reader.ReadBoolean();
SuitedUp = reader.ReadBoolean();
ProbeLauncherEquipped = reader.ReadBoolean();
SignalscopeEquipped = reader.ReadBoolean();
TranslatorEquipped = reader.ReadBoolean();
ProbeActive = reader.ReadBoolean();
ClientState = (ClientState)reader.ReadInt32();
}
public override void OnReceiveRemote()
{
RequestStateResyncEvent._waitingForEvent = false;
if (QSBPlayerManager.PlayerExists(From))
{
var player = QSBPlayerManager.GetPlayer(From);
player.Name = PlayerName;
player.IsReady = IsReady;
player.FlashlightActive = FlashlightActive;
player.SuitedUp = SuitedUp;
player.ProbeLauncherEquipped = ProbeLauncherEquipped;
player.SignalscopeEquipped = SignalscopeEquipped;
player.TranslatorEquipped = TranslatorEquipped;
player.ProbeActive = ProbeActive;
if (QSBPlayerManager.LocalPlayer.IsReady && player.IsReady)
{
player.UpdateObjectsFromStates();
}
player.State = ClientState;
}
else
{
DebugLog.ToConsole($"Warning - got player information message about player that doesnt exist!", MessageType.Warning);
}
}
}
}

View File

@ -27,7 +27,7 @@ namespace QSB.Player.Events
{
DebugLog.DebugWrite($"[SERVER] Get ready event from {From} (ready = {Value})", MessageType.Success);
QSBPlayerManager.GetPlayer(From).IsReady = Value;
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
new PlayerInformationMessage().Send();
}
private void HandleClient()

View File

@ -65,7 +65,7 @@ namespace QSB.Player.Events
if (isHost)
{
ServerStateManager.Instance.FireChangeServerStateEvent(ServerStateManager.Instance.GetServerState());
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
new PlayerInformationMessage().Send();
if (WorldObjectManager.AllObjectsReady)
{
@ -75,7 +75,7 @@ namespace QSB.Player.Events
// if client, send player and client states
else
{
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
new PlayerInformationMessage().Send();
}
if (WorldObjectManager.AllObjectsReady)

View File

@ -4,10 +4,10 @@ using QSB.Animation.Player.Thrusters;
using QSB.Audio;
using QSB.CampfireSync.WorldObjects;
using QSB.ClientServerStateSync;
using QSB.Events;
using QSB.ItemSync.WorldObjects.Items;
using QSB.Player.TransformSync;
using QSB.QuantumSync;
using QSB.Messaging;
using QSB.Player.Events;
using QSB.RoastingSync;
using QSB.Tools;
using QSB.Tools.FlashlightTool;
@ -231,7 +231,7 @@ namespace QSB.Player
SuitedUp = Locator.GetPlayerBody().GetComponent<PlayerSpacesuit>().IsWearingSuit(true);
}
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
new PlayerInformationMessage().Send();
}
private QSBTool GetToolByType(ToolType type)

View File

@ -1,6 +1,5 @@
using OWML.Common;
using QSB.ItemSync.WorldObjects.Items;
using QSB.Player.Events;
using QSB.Player.TransformSync;
using QSB.Tools.FlashlightTool;
using QSB.Utility;
@ -77,25 +76,6 @@ namespace QSB.Player
public static bool PlayerExists(uint id) =>
id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
public static void HandleFullStateMessage(PlayerInformationMessage message)
{
var player = GetPlayer(message.AboutId);
player.Name = message.PlayerName;
player.IsReady = message.IsReady;
player.FlashlightActive = message.FlashlightActive;
player.SuitedUp = message.SuitedUp;
player.ProbeLauncherEquipped = message.ProbeLauncherEquipped;
player.SignalscopeEquipped = message.SignalscopeEquipped;
player.TranslatorEquipped = message.TranslatorEquipped;
player.ProbeActive = message.ProbeActive;
if (LocalPlayer.IsReady && player.IsReady)
{
player.UpdateObjectsFromStates();
}
player.State = message.ClientState;
}
public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject =>
PlayerSyncObjects.OfType<T>().Where(x => x != null);
@ -106,9 +86,6 @@ namespace QSB.Player
public static void RemoveSyncObject(PlayerSyncObject obj) => PlayerSyncObjects.Remove(obj);
public static bool IsBelongingToLocalPlayer(uint id) => id == LocalPlayerId ||
PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.IsLocalPlayer);
public static List<PlayerInfo> GetPlayersWithCameras(bool includeLocalCamera = true)
{
var cameraList = PlayerList.Where(x => x.Camera != null && x.PlayerId != LocalPlayerId).ToList();