diff --git a/Assets/Scripts/Networking/GameProtocol.cs b/Assets/Scripts/Networking/GameProtocol.cs index 2fbde4a..c25e90f 100644 --- a/Assets/Scripts/Networking/GameProtocol.cs +++ b/Assets/Scripts/Networking/GameProtocol.cs @@ -22,6 +22,7 @@ namespace NeonTea.Quakeball.Networking { RegisterPacket(typeof(SelfIdentPckt)); RegisterPacket(typeof(MultiplePlayerUpdatesPckt)); RegisterPacket(typeof(PlayerUpdatePckt)); + RegisterPacket(typeof(PlayerJumpPckt)); } public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) { diff --git a/Assets/Scripts/Networking/Instances/Client.cs b/Assets/Scripts/Networking/Instances/Client.cs index f89fb2a..823b036 100644 --- a/Assets/Scripts/Networking/Instances/Client.cs +++ b/Assets/Scripts/Networking/Instances/Client.cs @@ -76,13 +76,9 @@ namespace NeonTea.Quakeball.Networking.Instances { foreach (PlayerUpdatePckt pckt in multiple.Updates) { HandleUpdatePlayer(pckt); } - } - } - - public override void UpdateLocalPlayer() { - if (SelfIdentified && Server != null) { - PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreatePacket(); - Peer.SendUnreliable(Server.uid, pckt); + } else if (packet is PlayerJumpPckt) { + PlayerJumpPckt jump = (PlayerJumpPckt)packet; + // Jump! } } @@ -92,5 +88,19 @@ namespace NeonTea.Quakeball.Networking.Instances { } Players[pckt.PlayerId].Controlled.GetComponent().QueuePacket(pckt); } + + public override void UpdateLocalPlayer() { + if (SelfIdentified && Server != null) { + PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreatePacket(); + Peer.SendUnreliable(Server.uid, pckt); + } + } + + public override void LocalPlayerJump() { + if (SelfIdentified && Server != null) { + PlayerJumpPckt jump = new PlayerJumpPckt(); + Peer.SendReliable(Server.uid, jump); + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Networking/Instances/NetInstance.cs b/Assets/Scripts/Networking/Instances/NetInstance.cs index 0a7fc38..70c6cca 100644 --- a/Assets/Scripts/Networking/Instances/NetInstance.cs +++ b/Assets/Scripts/Networking/Instances/NetInstance.cs @@ -17,7 +17,9 @@ namespace NeonTea.Quakeball.Networking.Instances { public abstract void Connected(Connection conn); public abstract void Disconnected(Connection conn); public abstract void Handle(Connection conn, Packet packet); + public abstract void UpdateLocalPlayer(); + public abstract void LocalPlayerJump(); public void Stop() { if (Peer != null) { diff --git a/Assets/Scripts/Networking/Instances/Server.cs b/Assets/Scripts/Networking/Instances/Server.cs index 6377ff3..1eb39dd 100644 --- a/Assets/Scripts/Networking/Instances/Server.cs +++ b/Assets/Scripts/Networking/Instances/Server.cs @@ -80,6 +80,13 @@ namespace NeonTea.Quakeball.Networking.Instances { updatePckt.PlayerId = conn.uid; Players[conn.uid].Controlled.GetComponent().QueuePacket(updatePckt); } + } else if (packet is PlayerJumpPckt) { + PlayerJumpPckt jump = (PlayerJumpPckt)packet; + if (Players[conn.uid].Controlled != null) { + // Check if Players[conn.uid].Controlled can jump, and do the following if true + jump.PlayerId = conn.uid; + SendReliableToAll(jump); + } } } @@ -106,6 +113,11 @@ namespace NeonTea.Quakeball.Networking.Instances { SendUnreliableToAll(pckt); } + public override void LocalPlayerJump() { + PlayerJumpPckt jump = new PlayerJumpPckt(LocalPlayer.Id); + SendReliableToAll(jump); + } + private void AddPlayer(NetPlayer player) { Players.Add(player.Id, player); PlayerList.Add(player); diff --git a/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs b/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs new file mode 100644 index 0000000..c548352 --- /dev/null +++ b/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs @@ -0,0 +1,39 @@ +using UnityEngine; +using NeonTea.Quakeball.TeaNet.Packets; + +using System.Collections.Generic; + +namespace NeonTea.Quakeball.Networking.Packets { + public class MultiplePlayerUpdatesPckt : Packet { + + public List Updates = new List(); + + public MultiplePlayerUpdatesPckt() { } + + public MultiplePlayerUpdatesPckt(List players) { + foreach (NetPlayer p in players) { + if (p.Controlled == null) { + continue; + } + Updates.Add(p.Controlled.CreatePacket(p.Id)); + } + } + + public override void Read(ByteBuffer buffer) { + Updates.Clear(); + int count = buffer.ReadInt(); + for (int i = 0; i < count; i++) { + PlayerUpdatePckt pckt = new PlayerUpdatePckt(); + pckt.Read(buffer); + Updates.Add(pckt); + } + } + + public override void Write(ByteBuffer buffer) { + buffer.Write(Updates.Count); + foreach (PlayerUpdatePckt p in Updates) { + p.Write(buffer); + } + } + } +} diff --git a/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs.meta b/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs.meta new file mode 100644 index 0000000..260a0fe --- /dev/null +++ b/Assets/Scripts/Networking/Packets/MultiplePlayerUpdatesPckt.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 505fbc702b619804a8ab46b6211db974 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs b/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs index b7696df..7b939f2 100644 --- a/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs +++ b/Assets/Scripts/Networking/Packets/PlayerUpdatePckt.cs @@ -1,59 +1,21 @@ using UnityEngine; using NeonTea.Quakeball.TeaNet.Packets; -using System.Collections.Generic; -using NeonTea.Quakeball.Networking; - namespace NeonTea.Quakeball.Networking.Packets { - public class MultiplePlayerUpdatesPckt : Packet { - - public List Updates = new List(); - - public MultiplePlayerUpdatesPckt() { } - - public MultiplePlayerUpdatesPckt(List players) { - foreach (NetPlayer p in players) { - if (p.Controlled == null) { - continue; - } - Updates.Add(p.Controlled.CreatePacket(p.Id)); - } - } - - public override void Read(ByteBuffer buffer) { - Updates.Clear(); - int count = buffer.ReadInt(); - for (int i = 0; i < count; i++) { - PlayerUpdatePckt pckt = new PlayerUpdatePckt(); - pckt.Read(buffer); - Updates.Add(pckt); - } - } - - public override void Write(ByteBuffer buffer) { - buffer.Write(Updates.Count); - foreach (PlayerUpdatePckt p in Updates) { - p.Write(buffer); - } - } - } - public class PlayerUpdatePckt : Packet { public ulong PlayerId; public Vector3 MoveDirection; public byte MoveStyle; - public bool Jumping; public float Pitch; public float Yaw; public PlayerUpdatePckt() { } - public PlayerUpdatePckt(Vector3 moveDirection, byte moveStyle, bool jumping, float pitch, float yaw, ulong id = 0) { + public PlayerUpdatePckt(Vector3 moveDirection, byte moveStyle, float pitch, float yaw, ulong id = 0) { MoveDirection = moveDirection; MoveStyle = moveStyle; - Jumping = jumping; Pitch = pitch; Yaw = yaw; PlayerId = id; @@ -66,7 +28,6 @@ namespace NeonTea.Quakeball.Networking.Packets { float z = buffer.ReadFloat(); MoveDirection = new Vector3(x, y, z); MoveStyle = buffer.Read(); - Jumping = buffer.ReadBool(); Pitch = buffer.ReadFloat(); Yaw = buffer.ReadFloat(); } @@ -77,9 +38,23 @@ namespace NeonTea.Quakeball.Networking.Packets { buffer.Write(MoveDirection.y); buffer.Write(MoveDirection.z); buffer.Write(MoveStyle); - buffer.Write(Jumping); buffer.Write(Pitch); buffer.Write(Yaw); } } + + public class PlayerJumpPckt : Packet { + public ulong PlayerId; + + public PlayerJumpPckt() { } + public PlayerJumpPckt(ulong id) { PlayerId = id; } + + public override void Read(ByteBuffer buffer) { + PlayerId = buffer.ReadULong(); + } + + public override void Write(ByteBuffer buffer) { + buffer.Write(PlayerId); + } + } } diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index 3761538..4e485cd 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -65,7 +65,7 @@ namespace NeonTea.Quakeball.Players { /// Creates a PlayerUpdatePckt representing this Player's current status, for sending to other peers. public PlayerUpdatePckt CreatePacket(ulong id = 0) { - return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Jumping, Pitch, Yaw, id); + return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Pitch, Yaw, id); } /// Updates this Player with the given packet, and sets it to null. No reusing packets. @@ -74,7 +74,6 @@ namespace NeonTea.Quakeball.Players { Yaw = packet.Yaw; MoveDirection = packet.MoveDirection; CurrentMoveStyle = packet.MoveStyle; - Jumping = packet.Jumping; packet = null; }