diff --git a/src/Items/CreativeBuilding.cs b/src/Items/CreativeBuilding.cs index 725d84d..26b5125 100644 --- a/src/Items/CreativeBuilding.cs +++ b/src/Items/CreativeBuilding.cs @@ -113,6 +113,10 @@ public class CreativeBuilding : Node2D { if (Player.NetworkID != GetTree().GetRpcSenderId()) return; + // TODO: Make sure position is a reasonable distance away. + if (!Enum.IsDefined(typeof(Facing), direction)) return; + if ((length < 1) || (length > MaxLength)) return; + // TODO: Test if starting block is valid. // FIXME: Test if there is a player in the way. @@ -130,7 +134,9 @@ public class CreativeBuilding : Node2D { if (Player.NetworkID != GetTree().GetRpcSenderId()) return; - // TODO: Do additional verification on the packet. + // TODO: Make sure position is a reasonable distance away. + if (!Enum.IsDefined(typeof(Facing), direction)) return; + if ((length < 1) || (length > MaxLength)) return; var start = new BlockPos(x, y); var world = this.GetWorld(); diff --git a/src/Items/Weapon.cs b/src/Items/Weapon.cs index 7fac9d2..1b5b1f4 100644 --- a/src/Items/Weapon.cs +++ b/src/Items/Weapon.cs @@ -153,8 +153,8 @@ public class Weapon : Sprite { if (this.GetGame() is Server) { if (Player.NetworkID != GetTree().GetRpcSenderId()) return; - // TODO: Verify input. - // if ((value < 0) || (value > Mathf.Tau)) return; + if (float.IsNaN(value = Mathf.PosMod(value, Mathf.Tau))) return; + RPC.Unreliable(SendAimAngle, value); } else if (!(Player is LocalPlayer)) AimDirection = value; @@ -204,7 +204,8 @@ public class Weapon : Sprite { if (this.GetGame() is Server) { if (Player.NetworkID != GetTree().GetRpcSenderId()) return; - // TODO: Verify input. + if (float.IsNaN(aimDirection = Mathf.PosMod(aimDirection, Mathf.Tau))) return; + if (FireInternal(aimDirection, toRight, seed)) RPC.Reliable(SendFire, aimDirection, toRight, seed); } else if (!(Player is LocalPlayer)) diff --git a/src/Objects/Player.cs b/src/Objects/Player.cs index fb8c3c4..20c6fd8 100644 --- a/src/Objects/Player.cs +++ b/src/Objects/Player.cs @@ -52,7 +52,9 @@ public class Player : KinematicBody2D, IInitializable public void ChangeAppearance(string displayName, Color color) { if (GetTree().GetRpcSenderId() != NetworkID) return; - // TODO: Validate input. + if (displayName == null) return; + // TODO: Verify display name some more. + if (color.a < 1.0F) return; Rset(nameof(DisplayName), displayName); Rset(nameof(Color), color); diff --git a/src/Scenes/Server.cs b/src/Scenes/Server.cs index c83eda8..eef08b6 100644 --- a/src/Scenes/Server.cs +++ b/src/Scenes/Server.cs @@ -1,7 +1,6 @@ using System; using Godot; -// TODO: Allow for initially private integrated server to open itself up to the public. public class Server : Game { internal Player LocalPlayer { get; private set; } @@ -20,11 +19,11 @@ public class Server : Game public ushort StartSingleplayer() { + // TODO: When get_local_port is available, just use port 0 for an auto-assigned port. + // Also see this PR: https://github.com/godotengine/godot/pull/48235 for (var retries = 0; ; retries++) { try { IsSingleplayer = true; - // TODO: When `get_local_port` is available, just use port 0 for an auto-assigned port. - // Also see this PR: https://github.com/godotengine/godot/pull/48235 var port = (ushort)GD.RandRange(42000, 43000); Start(port, "127.0.0.1", 1); return port;