From 78f89a342e38f893df3378404347ec4c4d125db1 Mon Sep 17 00:00:00 2001 From: AmazingAlek Date: Mon, 17 Aug 2020 19:19:41 +0200 Subject: [PATCH] player id stuff (#181) * player id stuff --- QSB/Animation/PlayerSuitEvent.cs | 1 - QSB/DeathSync/PlayerDeathEvent.cs | 1 - QSB/ElevatorSync/ElevatorEvent.cs | 1 - QSB/Events/EventList.cs | 1 - QSB/Events/PlayerJoinEvent.cs | 3 +-- QSB/Events/PlayerLeaveEvent.cs | 1 - QSB/Events/PlayerReadyEvent.cs | 2 -- QSB/Events/PlayerStatesRequestEvent.cs | 3 +-- QSB/Events/QSBEvent.cs | 4 ++-- QSB/GeyserSync/GeyserEvent.cs | 3 +-- QSB/Messaging/MessageHandler.cs | 3 +-- QSB/QSBNetworkManager.cs | 1 - QSB/TimeSync/ServerTimeEvent.cs | 3 +-- QSB/Tools/PlayerFlashlightEvent.cs | 1 - QSB/Tools/PlayerProbeEvent.cs | 1 - QSB/Tools/PlayerProbeLauncherEvent.cs | 1 - QSB/Tools/PlayerSignalscopeEvent.cs | 1 - QSB/Tools/PlayerTranslatorEvent.cs | 1 - QSB/TransformSync/PlayerSectorEvent.cs | 1 - 19 files changed, 7 insertions(+), 26 deletions(-) diff --git a/QSB/Animation/PlayerSuitEvent.cs b/QSB/Animation/PlayerSuitEvent.cs index 9c481aad..0a803e53 100644 --- a/QSB/Animation/PlayerSuitEvent.cs +++ b/QSB/Animation/PlayerSuitEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Animation private ToggleMessage CreateMessage(bool value) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = value }; diff --git a/QSB/DeathSync/PlayerDeathEvent.cs b/QSB/DeathSync/PlayerDeathEvent.cs index 397bc9c5..2b2b906e 100644 --- a/QSB/DeathSync/PlayerDeathEvent.cs +++ b/QSB/DeathSync/PlayerDeathEvent.cs @@ -22,7 +22,6 @@ namespace QSB.DeathSync private PlayerDeathMessage CreateMessage(DeathType type) => new PlayerDeathMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, DeathType = type }; diff --git a/QSB/ElevatorSync/ElevatorEvent.cs b/QSB/ElevatorSync/ElevatorEvent.cs index b858ad70..1cb5d9f5 100644 --- a/QSB/ElevatorSync/ElevatorEvent.cs +++ b/QSB/ElevatorSync/ElevatorEvent.cs @@ -22,7 +22,6 @@ namespace QSB.ElevatorSync private ElevatorMessage CreateMessage(int id, ElevatorDirection direction) => new ElevatorMessage { - FromId = LocalPlayerId, Direction = direction, ObjectId = id }; diff --git a/QSB/Events/EventList.cs b/QSB/Events/EventList.cs index 09669c24..25b26ae5 100644 --- a/QSB/Events/EventList.cs +++ b/QSB/Events/EventList.cs @@ -6,7 +6,6 @@ using QSB.GeyserSync; using QSB.TimeSync; using QSB.Tools; using QSB.TransformSync; -using QSB.Utility; using System.Collections.Generic; namespace QSB.Events diff --git a/QSB/Events/PlayerJoinEvent.cs b/QSB/Events/PlayerJoinEvent.cs index 566a84a3..4f366e58 100644 --- a/QSB/Events/PlayerJoinEvent.cs +++ b/QSB/Events/PlayerJoinEvent.cs @@ -22,8 +22,7 @@ namespace QSB.Events private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage { - FromId = PlayerTransformSync.LocalInstance.netId.Value, - AboutId = PlayerTransformSync.LocalInstance.netId.Value, + AboutId = LocalPlayerId, PlayerName = name }; diff --git a/QSB/Events/PlayerLeaveEvent.cs b/QSB/Events/PlayerLeaveEvent.cs index 3cad1a03..00b1d617 100644 --- a/QSB/Events/PlayerLeaveEvent.cs +++ b/QSB/Events/PlayerLeaveEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Events private PlayerLeaveMessage CreateMessage(uint id, uint[] objects) => new PlayerLeaveMessage { - FromId = LocalPlayerId, AboutId = id, ObjectIds = objects }; diff --git a/QSB/Events/PlayerReadyEvent.cs b/QSB/Events/PlayerReadyEvent.cs index 4c253320..53edee0f 100644 --- a/QSB/Events/PlayerReadyEvent.cs +++ b/QSB/Events/PlayerReadyEvent.cs @@ -1,5 +1,4 @@ using QSB.Messaging; -using QSB.Utility; namespace QSB.Events { @@ -21,7 +20,6 @@ namespace QSB.Events private ToggleMessage CreateMessage(bool ready) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = ready }; diff --git a/QSB/Events/PlayerStatesRequestEvent.cs b/QSB/Events/PlayerStatesRequestEvent.cs index 32dd4b48..d4d17a81 100644 --- a/QSB/Events/PlayerStatesRequestEvent.cs +++ b/QSB/Events/PlayerStatesRequestEvent.cs @@ -22,8 +22,7 @@ namespace QSB.Events private PlayerMessage CreateMessage() => new PlayerMessage { - FromId = PlayerTransformSync.LocalInstance.netId.Value, - AboutId = PlayerTransformSync.LocalInstance.netId.Value + AboutId = LocalPlayerId }; public override void OnServerReceive(PlayerMessage message) diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index 2cea526e..afd155df 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -1,7 +1,6 @@ using QSB.Messaging; using QSB.TransformSync; using QSB.Utility; -using UnityEngine.Networking; namespace QSB.Events { @@ -12,7 +11,7 @@ namespace QSB.Events public abstract class QSBEvent where T : PlayerMessage, new() { public abstract MessageType Type { get; } - public uint LocalPlayerId => PlayerRegistry.LocalPlayer.NetId; + public uint LocalPlayerId => PlayerRegistry.LocalPlayerId; private readonly MessageHandler _eventHandler; protected QSBEvent() @@ -61,6 +60,7 @@ namespace QSB.Events public void SendEvent(T message) { + message.FromId = PlayerRegistry.LocalPlayerId; UnityHelper.Instance.RunWhen(() => PlayerTransformSync.LocalInstance != null, () => Send(message)); } diff --git a/QSB/GeyserSync/GeyserEvent.cs b/QSB/GeyserSync/GeyserEvent.cs index 409e3e8b..86643636 100644 --- a/QSB/GeyserSync/GeyserEvent.cs +++ b/QSB/GeyserSync/GeyserEvent.cs @@ -22,8 +22,7 @@ namespace QSB.GeyserSync private GeyserMessage CreateMessage(int id, bool state) => new GeyserMessage { - FromId = PlayerRegistry.LocalPlayer.NetId, - AboutId = PlayerRegistry.LocalPlayer.NetId, + AboutId = LocalPlayerId, ObjectId = id, State = state }; diff --git a/QSB/Messaging/MessageHandler.cs b/QSB/Messaging/MessageHandler.cs index 6f99956c..717deded 100644 --- a/QSB/Messaging/MessageHandler.cs +++ b/QSB/Messaging/MessageHandler.cs @@ -1,5 +1,4 @@ -using QSB.Utility; -using System; +using System; using UnityEngine.Networking; namespace QSB.Messaging diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 0c2cde34..7b0dc9dc 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -11,7 +11,6 @@ using QSB.Utility; using UnityEngine; using UnityEngine.Events; using UnityEngine.Networking; -using UnityEngine.UI; namespace QSB { diff --git a/QSB/TimeSync/ServerTimeEvent.cs b/QSB/TimeSync/ServerTimeEvent.cs index d9151cd2..b6ab121b 100644 --- a/QSB/TimeSync/ServerTimeEvent.cs +++ b/QSB/TimeSync/ServerTimeEvent.cs @@ -21,8 +21,7 @@ namespace QSB.TimeSync private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage { - FromId = PlayerRegistry.LocalPlayer.NetId, - AboutId = PlayerRegistry.LocalPlayer.NetId, + AboutId = LocalPlayerId, ServerTime = time, LoopCount = count }; diff --git a/QSB/Tools/PlayerFlashlightEvent.cs b/QSB/Tools/PlayerFlashlightEvent.cs index 71d25b1d..6c4ca47c 100644 --- a/QSB/Tools/PlayerFlashlightEvent.cs +++ b/QSB/Tools/PlayerFlashlightEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Tools private ToggleMessage CreateMessage(bool value) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = value }; diff --git a/QSB/Tools/PlayerProbeEvent.cs b/QSB/Tools/PlayerProbeEvent.cs index 3ffaa036..e1049f1c 100644 --- a/QSB/Tools/PlayerProbeEvent.cs +++ b/QSB/Tools/PlayerProbeEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Tools private ToggleMessage CreateMessage(bool value) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = value }; diff --git a/QSB/Tools/PlayerProbeLauncherEvent.cs b/QSB/Tools/PlayerProbeLauncherEvent.cs index ffe606b1..61f999c3 100644 --- a/QSB/Tools/PlayerProbeLauncherEvent.cs +++ b/QSB/Tools/PlayerProbeLauncherEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Tools private ToggleMessage CreateMessage(bool value) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = value }; diff --git a/QSB/Tools/PlayerSignalscopeEvent.cs b/QSB/Tools/PlayerSignalscopeEvent.cs index 263d28ee..ec5fa51d 100644 --- a/QSB/Tools/PlayerSignalscopeEvent.cs +++ b/QSB/Tools/PlayerSignalscopeEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Tools private ToggleMessage CreateMessage(bool value) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = value }; diff --git a/QSB/Tools/PlayerTranslatorEvent.cs b/QSB/Tools/PlayerTranslatorEvent.cs index de5de210..8d187934 100644 --- a/QSB/Tools/PlayerTranslatorEvent.cs +++ b/QSB/Tools/PlayerTranslatorEvent.cs @@ -24,7 +24,6 @@ namespace QSB.Tools private ToggleMessage CreateMessage(bool value) => new ToggleMessage { - FromId = LocalPlayerId, AboutId = LocalPlayerId, ToggleValue = value }; diff --git a/QSB/TransformSync/PlayerSectorEvent.cs b/QSB/TransformSync/PlayerSectorEvent.cs index 6cdb4f7c..6fed38b6 100644 --- a/QSB/TransformSync/PlayerSectorEvent.cs +++ b/QSB/TransformSync/PlayerSectorEvent.cs @@ -23,7 +23,6 @@ namespace QSB.TransformSync private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage { - FromId = LocalPlayerId, AboutId = netId, ObjectId = sector.ObjectId };