diff --git a/Assets/Scripts/Networking/Instances/Client.cs b/Assets/Scripts/Networking/Instances/Client.cs index edf85e2..78b4f00 100644 --- a/Assets/Scripts/Networking/Instances/Client.cs +++ b/Assets/Scripts/Networking/Instances/Client.cs @@ -81,7 +81,9 @@ namespace NeonTea.Quakeball.Networking.Instances { Players[jump.PlayerId].Controlled.Jump(); } else if (packet is PlayerSyncPacket) { PlayerSyncPacket syncPckt = (PlayerSyncPacket)packet; - Players[syncPckt.PlayerId].Controlled.ProcessSyncPacket(syncPckt); + if (syncPckt.Unsynced || syncPckt.PlayerId != LocalPlayer.Id) { + Players[syncPckt.PlayerId].Controlled.ProcessSyncPacket(syncPckt); + } } } diff --git a/Assets/Scripts/Networking/Instances/Server.cs b/Assets/Scripts/Networking/Instances/Server.cs index 0b1bdc2..6613bdf 100644 --- a/Assets/Scripts/Networking/Instances/Server.cs +++ b/Assets/Scripts/Networking/Instances/Server.cs @@ -92,7 +92,9 @@ namespace NeonTea.Quakeball.Networking.Instances { PlayerSyncPacket syncPckt = (PlayerSyncPacket)packet; if (Players[conn.uid].Controlled != null) { syncPckt.PlayerId = conn.uid; - Players[conn.uid].Controlled.ProcessSyncPacket(syncPckt); + if (!Players[conn.uid].Controlled.ProcessSyncPacket(syncPckt)) { + Players[conn.uid].Unsynced = true; + } } } } diff --git a/Assets/Scripts/Networking/NetPlayer.cs b/Assets/Scripts/Networking/NetPlayer.cs index 3955812..f3500a2 100644 --- a/Assets/Scripts/Networking/NetPlayer.cs +++ b/Assets/Scripts/Networking/NetPlayer.cs @@ -5,6 +5,7 @@ namespace NeonTea.Quakeball.Networking { public class NetPlayer { public ulong Id; public Player Controlled; + public bool Unsynced = false; public NetPlayer(ulong id, Player obj = null) { Id = id; diff --git a/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs b/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs index c65a506..587ce56 100644 --- a/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs +++ b/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs @@ -39,7 +39,7 @@ namespace NeonTea.Quakeball.Networking.Packets { public class MultipleSyncsPckt : Packet { - public List Updates = new List(); + public List Syncs = new List(); public MultipleSyncsPckt() { } @@ -48,23 +48,23 @@ namespace NeonTea.Quakeball.Networking.Packets { if (p.Controlled == null) { continue; } - //Updates.Add(p.Controlled.CreatePacket(p.Id)); + Syncs.Add(p.Controlled.CreateSyncPacket(p.Id, p.Unsynced)); } } public override void Read(ByteBuffer buffer) { - Updates.Clear(); + Syncs.Clear(); int count = buffer.ReadInt(); for (int i = 0; i < count; i++) { PlayerSyncPacket pckt = new PlayerSyncPacket(); pckt.Read(buffer); - Updates.Add(pckt); + Syncs.Add(pckt); } } public override void Write(ByteBuffer buffer) { - buffer.Write(Updates.Count); - foreach (PlayerSyncPacket p in Updates) { + buffer.Write(Syncs.Count); + foreach (PlayerSyncPacket p in Syncs) { p.Write(buffer); } } diff --git a/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs b/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs index df892a2..bdc4a8b 100644 --- a/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs +++ b/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs @@ -55,25 +55,29 @@ namespace NeonTea.Quakeball.Networking.Packets { public class PlayerSyncPacket : Packet { public ulong PlayerId; + public bool Unsynced; public Vector3 Location; public Vector3 GroundVelocity; public PlayerSyncPacket() { } - public PlayerSyncPacket(ulong id, Vector3 location, Vector3 groundVelocity) { + public PlayerSyncPacket(ulong id, bool unsynced, Vector3 location, Vector3 groundVelocity) { PlayerId = id; + Unsynced = unsynced; Location = location; GroundVelocity = groundVelocity; } public override void Read(ByteBuffer buffer) { PlayerId = buffer.ReadULong(); + Unsynced = buffer.ReadBool(); Location = buffer.ReadVector3(); GroundVelocity = buffer.ReadVector3(); } public override void Write(ByteBuffer buffer) { - buffer.ReadULong(); + buffer.Write(PlayerId); + buffer.Write(Unsynced); buffer.Write(Location); buffer.Write(GroundVelocity); } diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index b6ed5c4..eb213a4 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -75,12 +75,12 @@ namespace NeonTea.Quakeball.Players { } /// Creates a PlayerSyncPacket representing this Player's position and velocity, for sending to the server. - public PlayerSyncPacket CreateSyncPacket(ulong id = 0) { - return new PlayerSyncPacket(id, transform.position, GroundVelocity); + public PlayerSyncPacket CreateSyncPacket(ulong id = 0, bool unsynced = false) { + return new PlayerSyncPacket(id, unsynced, transform.position, GroundVelocity); } /// Applies the sync packet, checking it for cheatiness if shouldApply is false. - public void ProcessSyncPacket(PlayerSyncPacket syncPckt, bool shouldApplyWithoutInspection = true) { + public bool ProcessSyncPacket(PlayerSyncPacket syncPckt, bool shouldApplyWithoutInspection = true) { bool ShouldApply = shouldApplyWithoutInspection; if (!shouldApplyWithoutInspection) { // TODO: Gaze into the crystal ball to determine the nefariousness level of the packet and update ShouldApply accordingly. @@ -89,6 +89,7 @@ namespace NeonTea.Quakeball.Players { transform.position = syncPckt.Location; GroundVelocity = syncPckt.Location; } + return ShouldApply; } /// The normal of the ground below the player. If there is no ground, it's Vector3.up by default.