From 5665ae3715f6601838fd12d4d2f4a9485a84c8d9 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 26 Feb 2016 09:39:08 +1100 Subject: [PATCH] Should not be able to place /portal and /mb in levels you do not have perbuild on. (Thanks goodlyay) --- Commands/CmdOverseer.cs | 2 +- Commands/building/CmdMessageBlock.cs | 40 +++++++++++++++++----------- Commands/building/CmdPortal.cs | 9 ++++--- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Commands/CmdOverseer.cs b/Commands/CmdOverseer.cs index dfb047de9..8a24833c4 100644 --- a/Commands/CmdOverseer.cs +++ b/Commands/CmdOverseer.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands { public override string name { get { return "overseer"; } } public override string shortcut { get { return "os"; } } - public override string type { get { return "commands"; } } + public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public CmdOverseer() { } diff --git a/Commands/building/CmdMessageBlock.cs b/Commands/building/CmdMessageBlock.cs index 0bcab81f8..a2a97f8f3 100644 --- a/Commands/building/CmdMessageBlock.cs +++ b/Commands/building/CmdMessageBlock.cs @@ -70,29 +70,37 @@ namespace MCGalaxy.Commands { message.StartsWith(cmd + " ", StringComparison.OrdinalIgnoreCase); } - public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { + void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { p.ClearBlockchange(); CatchPos cpos = (CatchPos)p.blockchangeObject; - - cpos.message = cpos.message.Replace("'", "\\'"); - cpos.message = Colors.EscapeColors(cpos.message); - //safe against SQL injections because no user input is given here - DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "` WHERE X=" + (int)x + " AND Y=" + (int)y + " AND Z=" + (int)z); - Database.AddParams("@Message", cpos.message); - - if (Messages.Rows.Count == 0) - Database.executeQuery("INSERT INTO `Messages" + p.level.name + "` (X, Y, Z, Message) VALUES (" + (int)x + ", " + (int)y + ", " + (int)z + ", @Message)"); - else - Database.executeQuery("UPDATE `Messages" + p.level.name + "` SET Message=@Message WHERE X=" + (int)x + " AND Y=" + (int)y + " AND Z=" + (int)z); - - Messages.Dispose(); - Player.SendMessage(p, "Message block placed."); p.level.Blockchange(p, x, y, z, cpos.type); - p.SendBlockchange(x, y, z, cpos.type); + + if (p.level.GetTile(x, y, z) == cpos.type) { + p.SendBlockchange(x, y, z, cpos.type); + UpdateDatabase(p, cpos, x, y, z); + Player.SendMessage(p, "Message block created."); + } else { + Player.SendMessage(p, "Failed to create a message block."); + } if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } + + void UpdateDatabase(Player p, CatchPos cpos, ushort x, ushort y, ushort z) { + cpos.message = cpos.message.Replace("'", "\\'"); + cpos.message = Colors.EscapeColors(cpos.message); + //safe against SQL injections because no user input is given here + DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "` WHERE X=" + x + " AND Y=" + y + " AND Z=" + z); + Database.AddParams("@Message", cpos.message); + + if (Messages.Rows.Count == 0) + Database.executeQuery("INSERT INTO `Messages" + p.level.name + "` (X, Y, Z, Message) VALUES (" + x + ", " + y + ", " + z + ", @Message)"); + else + Database.executeQuery("UPDATE `Messages" + p.level.name + "` SET Message=@Message WHERE X=" + x + " AND Y=" + y + " AND Z=" + z); + + Messages.Dispose(); + } struct CatchPos { public string message; public byte type; } diff --git a/Commands/building/CmdPortal.cs b/Commands/building/CmdPortal.cs index 3cc9ae30d..f4c2b1d8b 100644 --- a/Commands/building/CmdPortal.cs +++ b/Commands/building/CmdPortal.cs @@ -57,12 +57,15 @@ namespace MCGalaxy.Commands { p.ClearBlockchange(); data.entries = new List(); p.blockchangeObject = data; - p.Blockchange += new Player.BlockchangeEventHandler(EntryChange); + p.Blockchange += EntryChange; } - void EntryChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { + void EntryChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { + PortalData bp = (PortalData)p.blockchangeObject; + if (!p.level.CheckAffectPermissions(p, x, y, z, type, extType)) { + p.RevertBlock(x, y, z); return; + } p.ClearBlockchange(); - PortalData bp = (PortalData)p.blockchangeObject; if (bp.Multi && type == Block.red && bp.entries.Count > 0) { ExitChange(p, x, y, z, type, extType); return; }