From 0ea046961a00193ce95cf702a79ecbebe777b8d2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 30 Nov 2016 17:44:47 +1100 Subject: [PATCH] Core: Prevent modifying bots on worlds you don't have perbuild access to. --- MCGalaxy/Commands/Bots/CmdBotAdd.cs | 7 ++++++- MCGalaxy/Commands/Bots/CmdBotRemove.cs | 18 ++++++++++++------ MCGalaxy/Commands/Bots/CmdBotSet.cs | 5 +++++ MCGalaxy/Commands/Bots/CmdBotSummon.cs | 19 ++++++++++++------- MCGalaxy/Commands/Chat/CmdNick.cs | 5 +++++ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/MCGalaxy/Commands/Bots/CmdBotAdd.cs b/MCGalaxy/Commands/Bots/CmdBotAdd.cs index bbb90a171..cbbbdd83c 100644 --- a/MCGalaxy/Commands/Bots/CmdBotAdd.cs +++ b/MCGalaxy/Commands/Bots/CmdBotAdd.cs @@ -26,7 +26,12 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - if (p == null) { MessageInGameOnly(p); return; } + if (p == null) { MessageInGameOnly(p); return; } + + if (!p.level.BuildAccess.CheckDetailed(p)) { + Player.Message(p, "Hence, you cannot add bots to this map."); + return; + } if (!Formatter.ValidName(p, message, "bot")) return; PlayerBot bot = new PlayerBot(message, p.level, p.pos[0], p.pos[1], p.pos[2], p.rot[0], 0); diff --git a/MCGalaxy/Commands/Bots/CmdBotRemove.cs b/MCGalaxy/Commands/Bots/CmdBotRemove.cs index aea9db2a9..eda01d60c 100644 --- a/MCGalaxy/Commands/Bots/CmdBotRemove.cs +++ b/MCGalaxy/Commands/Bots/CmdBotRemove.cs @@ -27,17 +27,23 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - if (p == null) { MessageInGameOnly(p); return; } + if (p == null) { MessageInGameOnly(p); return; } + + if (!p.level.BuildAccess.CheckDetailed(p)) { + Player.Message(p, "Hence, you cannot change remove bots from this map."); + return; + } + if (message.CaselessEq("all")) { PlayerBot.RemoveAllFromLevel(p.level); return; } - PlayerBot who = PlayerBot.FindMatchesPreferLevel(p, message); - if (who == null) return; - if (!p.level.name.CaselessEq(who.level.name)) { - Player.Message(p, who.ColoredName + " %Sis in a different level."); return; + PlayerBot bot = PlayerBot.FindMatchesPreferLevel(p, message); + if (bot == null) return; + if (!p.level.name.CaselessEq(bot.level.name)) { + Player.Message(p, bot.ColoredName + " %Sis in a different level."); return; } - PlayerBot.Remove(who); + PlayerBot.Remove(bot); Player.Message(p, "Removed bot."); } diff --git a/MCGalaxy/Commands/Bots/CmdBotSet.cs b/MCGalaxy/Commands/Bots/CmdBotSet.cs index 0d94a03ab..2b6735987 100644 --- a/MCGalaxy/Commands/Bots/CmdBotSet.cs +++ b/MCGalaxy/Commands/Bots/CmdBotSet.cs @@ -35,6 +35,11 @@ namespace MCGalaxy.Commands { string[] args = message.Split(' '); PlayerBot bot = PlayerBot.FindMatchesPreferLevel(p, args[0]); if (bot == null) return; + + if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) { + Player.Message(p, "Hence, you cannot change the AI of bots on this map."); + return; + } if (args.Length == 1) { bot.Instructions.Clear(); diff --git a/MCGalaxy/Commands/Bots/CmdBotSummon.cs b/MCGalaxy/Commands/Bots/CmdBotSummon.cs index aab7e885d..36c8877d4 100644 --- a/MCGalaxy/Commands/Bots/CmdBotSummon.cs +++ b/MCGalaxy/Commands/Bots/CmdBotSummon.cs @@ -29,14 +29,19 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (message == "") { Help(p); return; } if (p == null) { MessageInGameOnly(p); return; } - - PlayerBot who = PlayerBot.FindMatchesPreferLevel(p, message); - if (who == null) return; - if (!p.level.name.CaselessEq(who.level.name)) { - Player.Message(p, who.name + " is in a different level."); return; + + if (!p.level.BuildAccess.CheckDetailed(p)) { + Player.Message(p, "Hence, you cannot summon bots on this map."); + return; } - who.SetPos(p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); - BotsFile.UpdateBot(who); + + PlayerBot bot = PlayerBot.FindMatchesPreferLevel(p, message); + if (bot == null) return; + if (!p.level.name.CaselessEq(bot.level.name)) { + Player.Message(p, bot.name + " is in a different level."); return; + } + bot.SetPos(p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); + BotsFile.UpdateBot(bot); } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/Chat/CmdNick.cs b/MCGalaxy/Commands/Chat/CmdNick.cs index 7f1976f64..55fb1e3b5 100644 --- a/MCGalaxy/Commands/Chat/CmdNick.cs +++ b/MCGalaxy/Commands/Chat/CmdNick.cs @@ -34,6 +34,11 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { UseBotOrPlayer(p, message, "nick"); } protected override void SetBotData(Player p, PlayerBot bot, string[] args) { + if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) { + Player.Message(p, "Hence, you cannot change that bot's nickname."); + return; + } + string newName = args.Length > 2 ? args[2] : ""; if (newName == "") { bot.DisplayName = bot.name;