From 3732811ae9a465adcec37f88c509da7b0bf21820 Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Fri, 21 Jun 2024 22:01:50 +0200 Subject: [PATCH 1/5] fix: properly handling minutes Seconds are only one byte big and not two, so the Minutes start at byte 3 and not 4. --- Shared/Packet/Packets/TagPacket.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shared/Packet/Packets/TagPacket.cs b/Shared/Packet/Packets/TagPacket.cs index 23f3cfc..2cf949e 100644 --- a/Shared/Packet/Packets/TagPacket.cs +++ b/Shared/Packet/Packets/TagPacket.cs @@ -15,14 +15,14 @@ public void Serialize(Span data) { MemoryMarshal.Write(data, ref UpdateType); MemoryMarshal.Write(data[1..], ref IsIt); MemoryMarshal.Write(data[2..], ref Seconds); - MemoryMarshal.Write(data[4..], ref Minutes); + MemoryMarshal.Write(data[3..], ref Minutes); } public void Deserialize(ReadOnlySpan data) { UpdateType = MemoryMarshal.Read(data); IsIt = MemoryMarshal.Read(data[1..]); Seconds = MemoryMarshal.Read(data[2..]); - Minutes = MemoryMarshal.Read(data[4..]); + Minutes = MemoryMarshal.Read(data[3..]); } [Flags] From c256b00eb93aec59ad7b7c784cec699f0c2905ce Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Fri, 21 Jun 2024 22:07:36 +0200 Subject: [PATCH 2/5] fix: let `tag start` also send the new role to the actual players Broadcast() with a sender never sends the packet to the sender. Therefore only other players got informed about the new role. But never the actual player that is supposed to change to that role. --- Server/Program.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index a0a7dd3..3facbc1 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -490,17 +490,22 @@ await c.Send(new ChangeStagePacket { int realTime = 1000 * time; await Task.Delay(realTime); await Task.WhenAll( - Parallel.ForEachAsync(seekers, async (seeker, _) => - await server.Broadcast(new TagPacket { + Parallel.ForEachAsync(seekers, async (seeker, _) => { + TagPacket packet = new TagPacket { UpdateType = TagPacket.TagUpdate.State, - IsIt = true - }, seeker)), - Parallel.ForEachAsync(server.Clients.Except(seekers), async (hider, _) => - await server.Broadcast(new TagPacket { + IsIt = true, + }; + await server.Broadcast(packet, seeker); + await seeker.Send(packet); + }), + Parallel.ForEachAsync(server.Clients.Except(seekers), async (hider, _) => { + TagPacket packet = new TagPacket { UpdateType = TagPacket.TagUpdate.State, - IsIt = false - }, hider) - ) + IsIt = false, + }; + await server.Broadcast(packet, hider); + await hider.Send(packet); + }) ); consoleLogger.Info($"Started game with seekers {string.Join(", ", seekerNames)}"); }); From db553ccf4abfa07d0a5e7c37d6fc24d05e03aba1 Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Fri, 21 Jun 2024 22:10:13 +0200 Subject: [PATCH 3/5] fix: `tag time` command send new time to all players --- Server/Program.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index 3facbc1..d9bf846 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -456,13 +456,18 @@ await c.Send(new ChangeStagePacket { return $"Invalid time for seconds {args[3]} (range: 0-59)"; TagPacket tagPacket = new TagPacket { UpdateType = TagPacket.TagUpdate.Time, - Minutes = minutes, - Seconds = seconds + Minutes = minutes, + Seconds = seconds, }; - if (args[1] == "*") - server.Broadcast(tagPacket); - else - client?.Send(tagPacket); + if (args[1] == "*") { + Parallel.ForEachAsync(server.Clients, async (client, _) => { + await server.Broadcast(tagPacket, client); + await client.Send(tagPacket); + }); + } else if (client != null) { + server.Broadcast(tagPacket, client); + client.Send(tagPacket); + } return $"Set time for {(args[1] == "*" ? "everyone" : args[1])} to {minutes}:{seconds}"; } case "seeking" when args.Length == 3: { From e160accf1a5549e0b5fdebcec5a059a2b8b7b64f Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Fri, 21 Jun 2024 22:10:52 +0200 Subject: [PATCH 4/5] fix: `tag seeking` command send new state to all players --- Server/Program.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index d9bf846..0ee539e 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -476,12 +476,17 @@ await c.Send(new ChangeStagePacket { if (!bool.TryParse(args[2], out bool seeking)) return $"Usage: tag seeking {args[1]} "; TagPacket tagPacket = new TagPacket { UpdateType = TagPacket.TagUpdate.State, - IsIt = seeking + IsIt = seeking, }; - if (args[1] == "*") - server.Broadcast(tagPacket); - else - client?.Send(tagPacket); + if (args[1] == "*") { + Parallel.ForEachAsync(server.Clients, async (client, _) => { + await server.Broadcast(tagPacket, client); + await client.Send(tagPacket); + }); + } else if (client != null) { + server.Broadcast(tagPacket, client); + client.Send(tagPacket); + } return $"Set {(args[1] == "*" ? "everyone" : args[1])} to {(seeking ? "seeker" : "hider")}"; } case "start" when args.Length > 2: { From 8e7988bca17964ab675dbed4524f0b5e28f2c2b7 Mon Sep 17 00:00:00 2001 From: Aubrey <32604996+Sanae6@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:22:06 -0600 Subject: [PATCH 5/5] Update TagPacket.cs --- Shared/Packet/Packets/TagPacket.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shared/Packet/Packets/TagPacket.cs b/Shared/Packet/Packets/TagPacket.cs index 2cf949e..9396366 100644 --- a/Shared/Packet/Packets/TagPacket.cs +++ b/Shared/Packet/Packets/TagPacket.cs @@ -9,7 +9,7 @@ public struct TagPacket : IPacket { public byte Seconds; public ushort Minutes; - public short Size => 6; + public short Size => 5; public void Serialize(Span data) { MemoryMarshal.Write(data, ref UpdateType); @@ -30,4 +30,4 @@ public enum TagUpdate : byte { Time = 1, State = 2 } -} \ No newline at end of file +}