Verify some incoming packets

main
copygirl 4 years ago
parent 93703fdc5a
commit 120e6f63c5
  1. 8
      src/Items/CreativeBuilding.cs
  2. 7
      src/Items/Weapon.cs
  3. 4
      src/Objects/Player.cs
  4. 5
      src/Scenes/Server.cs

@ -113,6 +113,10 @@ public class CreativeBuilding : Node2D
{ {
if (Player.NetworkID != GetTree().GetRpcSenderId()) return; 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. // TODO: Test if starting block is valid.
// FIXME: Test if there is a player in the way. // FIXME: Test if there is a player in the way.
@ -130,7 +134,9 @@ public class CreativeBuilding : Node2D
{ {
if (Player.NetworkID != GetTree().GetRpcSenderId()) return; 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 start = new BlockPos(x, y);
var world = this.GetWorld(); var world = this.GetWorld();

@ -153,8 +153,8 @@ public class Weapon : Sprite
{ {
if (this.GetGame() is Server) { if (this.GetGame() is Server) {
if (Player.NetworkID != GetTree().GetRpcSenderId()) return; if (Player.NetworkID != GetTree().GetRpcSenderId()) return;
// TODO: Verify input. if (float.IsNaN(value = Mathf.PosMod(value, Mathf.Tau))) return;
// if ((value < 0) || (value > Mathf.Tau)) return;
RPC.Unreliable(SendAimAngle, value); RPC.Unreliable(SendAimAngle, value);
} else if (!(Player is LocalPlayer)) } else if (!(Player is LocalPlayer))
AimDirection = value; AimDirection = value;
@ -204,7 +204,8 @@ public class Weapon : Sprite
{ {
if (this.GetGame() is Server) { if (this.GetGame() is Server) {
if (Player.NetworkID != GetTree().GetRpcSenderId()) return; if (Player.NetworkID != GetTree().GetRpcSenderId()) return;
// TODO: Verify input. if (float.IsNaN(aimDirection = Mathf.PosMod(aimDirection, Mathf.Tau))) return;
if (FireInternal(aimDirection, toRight, seed)) if (FireInternal(aimDirection, toRight, seed))
RPC.Reliable(SendFire, aimDirection, toRight, seed); RPC.Reliable(SendFire, aimDirection, toRight, seed);
} else if (!(Player is LocalPlayer)) } else if (!(Player is LocalPlayer))

@ -52,7 +52,9 @@ public class Player : KinematicBody2D, IInitializable
public void ChangeAppearance(string displayName, Color color) public void ChangeAppearance(string displayName, Color color)
{ {
if (GetTree().GetRpcSenderId() != NetworkID) return; 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(DisplayName), displayName);
Rset(nameof(Color), color); Rset(nameof(Color), color);

@ -1,7 +1,6 @@
using System; using System;
using Godot; using Godot;
// TODO: Allow for initially private integrated server to open itself up to the public.
public class Server : Game public class Server : Game
{ {
internal Player LocalPlayer { get; private set; } internal Player LocalPlayer { get; private set; }
@ -20,11 +19,11 @@ public class Server : Game
public ushort StartSingleplayer() 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++) { for (var retries = 0; ; retries++) {
try { try {
IsSingleplayer = true; 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); var port = (ushort)GD.RandRange(42000, 43000);
Start(port, "127.0.0.1", 1); Start(port, "127.0.0.1", 1);
return port; return port;

Loading…
Cancel
Save