From be9145bd8dff53397300e248a54e227094307bfa Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 17 Nov 2018 17:41:10 +1100 Subject: [PATCH] Fix /spawn not being denied when MOTD denies client-side respawning (thanks tornato) --- MCGalaxy/Commands/World/CmdSpawn.cs | 5 +++++ MCGalaxy/Levels/Hacks.cs | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/MCGalaxy/Commands/World/CmdSpawn.cs b/MCGalaxy/Commands/World/CmdSpawn.cs index 9c9270057..25cd0e428 100644 --- a/MCGalaxy/Commands/World/CmdSpawn.cs +++ b/MCGalaxy/Commands/World/CmdSpawn.cs @@ -25,6 +25,11 @@ namespace MCGalaxy.Commands.World { public override bool SuperUseable { get { return false; } } public override void Use(Player p, string message, CommandData data) { + if (!Hacks.CanUseRespawn(p, p.level)) { + p.Message("You cannot use %T/Spawn %Son this map."); + p.isFlying = false; return; + } + if (message.Length > 0) { Help(p); return; } PlayerActions.Respawn(p); } diff --git a/MCGalaxy/Levels/Hacks.cs b/MCGalaxy/Levels/Hacks.cs index a9b5c23e7..ab142d658 100644 --- a/MCGalaxy/Levels/Hacks.cs +++ b/MCGalaxy/Levels/Hacks.cs @@ -19,25 +19,38 @@ using System; using MCGalaxy.Network; namespace MCGalaxy { + /// Assistant class for parsing MOTD flags. (-hax, +fly etc) + /// CanUse methods also check MOTD of zone player is in. public static class Hacks { + /// Returns whether the player is currently able to use any hacks at all. public static bool CanUseHacks(Player p, Level lvl) { byte[] packet = MakeHackControl(p, lvl.GetMotd(p)); return packet[1] != 0 && packet[2] != 0 && packet[3] != 0 && packet[4] != 0 && packet[5] != 0; } + /// Returns whether the player is currently able to fly. public static bool CanUseFly(Player p, Level lvl) { return MakeHackControl(p, lvl.GetMotd(p))[1] != 0; } + /// Returns whether the player is currently able to use noclip. public static bool CanUseNoclip(Player p, Level lvl) { return MakeHackControl(p, lvl.GetMotd(p))[2] != 0; } + /// Returns whether the player is currently able to move at faster speeds. public static bool CanUseSpeed(Player p, Level lvl) { return MakeHackControl(p, lvl.GetMotd(p))[3] != 0; } + /// Returns whether the player is currently able to respawn. + public static bool CanUseRespawn(Player p, Level lvl) { + return MakeHackControl(p, lvl.GetMotd(p))[4] != 0; + } + + /// Parses the MOTD flags and returns resulting HackControl packet. + /// "+ophax" permission is determined by p.Rank >= LevelPermission.Operator public static byte[] MakeHackControl(Player p, string motd) { motd = Colors.Strip(motd); bool isOp = p.Rank >= LevelPermission.Operator;