diff --git a/MCGalaxy/Commands/Bots/CmdBot.cs b/MCGalaxy/Commands/Bots/CmdBot.cs index 576d97cdb..19c527c3f 100644 --- a/MCGalaxy/Commands/Bots/CmdBot.cs +++ b/MCGalaxy/Commands/Bots/CmdBot.cs @@ -33,7 +33,9 @@ namespace MCGalaxy.Commands.Bots { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(3); if (args.Length < 2) { Help(p); return; } + if (!Formatter.ValidName(p, args[1], "bot")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "modify bots in this level")) return; string bot = args[1], value = args.Length > 2 ? args[2] : null; if (args[0].CaselessEq("add")) { @@ -54,7 +56,6 @@ namespace MCGalaxy.Commands.Bots { } void AddBot(Player p, string botName) { - if (!LevelInfo.ValidateAction(p, p.level, "add bots to this level")) return; PlayerBot bot = new PlayerBot(botName, p.level); TryAddBot(p, bot); } @@ -84,8 +85,6 @@ namespace MCGalaxy.Commands.Bots { } void RemoveBot(Player p, string botName) { - if (!LevelInfo.ValidateAction(p, p.level, "remove bots from this level")) return; - if (botName.CaselessEq("all")) { PlayerBot.RemoveLoadedBots(p.level, false); BotsFile.Save(p.level); @@ -101,8 +100,7 @@ namespace MCGalaxy.Commands.Bots { void SetBotText(Player p, string botName, string text) { PlayerBot bot = Matcher.FindBots(p, botName); if (bot == null) return; - if (!LevelInfo.ValidateAction(p, p.level, "set bot text of that bot")) return; - + if (text == null) { p.Message("Removed text shown when bot {0} %Sclicked on", bot.ColoredName); bot.ClickedOnText = null; @@ -117,8 +115,7 @@ namespace MCGalaxy.Commands.Bots { void SetDeathMessage(Player p, string botName, string text) { PlayerBot bot = Matcher.FindBots(p, botName); if (bot == null) return; - if (!LevelInfo.ValidateAction(p, p.level, "set kill message of that bot")) return; - + if (text == null) { p.Message("Reset shown when bot {0} %Skills someone", bot.ColoredName); bot.DeathMessage = null; @@ -131,7 +128,6 @@ namespace MCGalaxy.Commands.Bots { } void RenameBot(Player p, string botName, string newName) { - if (!LevelInfo.ValidateAction(p, p.level, "rename bots on this level")) return; if (newName == null) { p.Message("New name of bot required."); return; } if (!Formatter.ValidName(p, newName, "bot")) return; @@ -153,7 +149,6 @@ namespace MCGalaxy.Commands.Bots { } void CopyBot(Player p, string botName, string newName) { - if (!LevelInfo.ValidateAction(p, p.level, "copy bots on this level")) return; if (newName == null) { p.Message("Name of new bot required."); return; } if (!Formatter.ValidName(p, newName, "bot")) return; diff --git a/MCGalaxy/Commands/Bots/CmdBotSet.cs b/MCGalaxy/Commands/Bots/CmdBotSet.cs index 9da6b4c07..9024fe7df 100644 --- a/MCGalaxy/Commands/Bots/CmdBotSet.cs +++ b/MCGalaxy/Commands/Bots/CmdBotSet.cs @@ -35,7 +35,7 @@ namespace MCGalaxy.Commands.Bots { string[] args = message.SplitSpaces(); PlayerBot bot = Matcher.FindBots(p, args[0]); if (bot == null) return; - if (!LevelInfo.ValidateAction(p, p.level, "change AI of bots in this level")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "change AI of bots in this level")) return; if (args.Length == 1) { bot.Instructions.Clear(); diff --git a/MCGalaxy/Commands/Bots/CmdBotSummon.cs b/MCGalaxy/Commands/Bots/CmdBotSummon.cs index 5f6214d32..5ff82e4b5 100644 --- a/MCGalaxy/Commands/Bots/CmdBotSummon.cs +++ b/MCGalaxy/Commands/Bots/CmdBotSummon.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.Bots { public override void Use(Player p, string message, CommandData data) { if (message.Length == 0) { Help(p); return; } - if (!LevelInfo.ValidateAction(p, p.level, "summon that bot")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "summon that bot")) return; PlayerBot bot = Matcher.FindBots(p, message); if (bot == null) return; diff --git a/MCGalaxy/Commands/CPE/CmdEntityRot.cs b/MCGalaxy/Commands/CPE/CmdEntityRot.cs index bd7259ea3..337dac73c 100644 --- a/MCGalaxy/Commands/CPE/CmdEntityRot.cs +++ b/MCGalaxy/Commands/CPE/CmdEntityRot.cs @@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.CPE { message = "-own " + message; message = message.TrimEnd(); } - UseBotOrPlayer(p, message, "rotation"); + UseBotOrPlayer(p, data, message, "rotation"); } protected override void SetBotData(Player p, PlayerBot bot, string args) { diff --git a/MCGalaxy/Commands/CPE/CmdEnvironment.cs b/MCGalaxy/Commands/CPE/CmdEnvironment.cs index e44dbad27..9d664c199 100644 --- a/MCGalaxy/Commands/CPE/CmdEnvironment.cs +++ b/MCGalaxy/Commands/CPE/CmdEnvironment.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.CPE { } message = message.ToLower(); - if (!LevelInfo.ValidateAction(p, p.level, "set env settings of this level")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "set env settings of this level")) return; string[] args = message.SplitSpaces(); string opt = args[0]; diff --git a/MCGalaxy/Commands/CPE/CmdModel.cs b/MCGalaxy/Commands/CPE/CmdModel.cs index b45d3eee9..28cfafdf9 100644 --- a/MCGalaxy/Commands/CPE/CmdModel.cs +++ b/MCGalaxy/Commands/CPE/CmdModel.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands.CPE { message = "-own " + message; message = message.TrimEnd(); } - UseBotOrPlayer(p, message, "model"); + UseBotOrPlayer(p, data, message, "model"); } protected override void SetBotData(Player p, PlayerBot bot, string model) { diff --git a/MCGalaxy/Commands/CPE/CmdSkin.cs b/MCGalaxy/Commands/CPE/CmdSkin.cs index b97d0d9ce..ac0925c65 100644 --- a/MCGalaxy/Commands/CPE/CmdSkin.cs +++ b/MCGalaxy/Commands/CPE/CmdSkin.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.CPE { message = "-own " + message; message = message.TrimEnd(); } - UseBotOrPlayer(p, message, "skin"); + UseBotOrPlayer(p, data, message, "skin"); } protected override void SetBotData(Player p, PlayerBot bot, string skin) { diff --git a/MCGalaxy/Commands/CPE/CmdTexture.cs b/MCGalaxy/Commands/CPE/CmdTexture.cs index 07b846b27..aa1991df0 100644 --- a/MCGalaxy/Commands/CPE/CmdTexture.cs +++ b/MCGalaxy/Commands/CPE/CmdTexture.cs @@ -73,7 +73,7 @@ namespace MCGalaxy.Commands.CPE { } UpdateGlobal(p); } else if (scope == "level" || scope == "levelzip") { - if (!LevelInfo.ValidateAction(p, p.level, "set texture of this level")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "set texture of this level")) return; p.level.Config.Terrain = ""; p.level.Config.TexturePack = ""; diff --git a/MCGalaxy/Commands/Chat/CmdColor.cs b/MCGalaxy/Commands/Chat/CmdColor.cs index 2c95ff7bf..9a523e976 100644 --- a/MCGalaxy/Commands/Chat/CmdColor.cs +++ b/MCGalaxy/Commands/Chat/CmdColor.cs @@ -30,11 +30,11 @@ namespace MCGalaxy.Commands.Chatting { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("Colour"), new CommandAlias("XColor", "-own") }; } } - public override void Use(Player p, string message, CommandData data) { UseBotOrPlayer(p, message, "color"); } + public override void Use(Player p, string message, CommandData data) { + UseBotOrPlayer(p, data, message, "color"); + } protected override void SetBotData(Player p, PlayerBot bot, string colName) { - if (!LevelInfo.ValidateAction(p, p.level, "change color of that bot")) return; - string color = colName.Length == 0 ? "&1" : Matcher.FindColor(p, colName); if (color == null) return; diff --git a/MCGalaxy/Commands/Chat/CmdLoginMessage.cs b/MCGalaxy/Commands/Chat/CmdLoginMessage.cs index 1d74b2c19..1bab2c516 100644 --- a/MCGalaxy/Commands/Chat/CmdLoginMessage.cs +++ b/MCGalaxy/Commands/Chat/CmdLoginMessage.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Chatting { public override void Use(Player p, string message, CommandData data) { if (!MessageCmd.CanSpeak(p, name)) return; - UsePlayer(p, message, "login message"); + UsePlayer(p, data, message, "login message"); } protected override void SetPlayerData(Player p, Player who, string msg) { diff --git a/MCGalaxy/Commands/Chat/CmdLogoutMessage.cs b/MCGalaxy/Commands/Chat/CmdLogoutMessage.cs index 5a79f952d..310628bbc 100644 --- a/MCGalaxy/Commands/Chat/CmdLogoutMessage.cs +++ b/MCGalaxy/Commands/Chat/CmdLogoutMessage.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Chatting { public override void Use(Player p, string message, CommandData data) { if (!MessageCmd.CanSpeak(p, name)) return; - UsePlayer(p, message, "logout message"); + UsePlayer(p, data, message, "logout message"); } protected override void SetPlayerData(Player p, Player who, string msg) { diff --git a/MCGalaxy/Commands/Chat/CmdNick.cs b/MCGalaxy/Commands/Chat/CmdNick.cs index b2ffb5a10..f182e3fbb 100644 --- a/MCGalaxy/Commands/Chat/CmdNick.cs +++ b/MCGalaxy/Commands/Chat/CmdNick.cs @@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.Chatting { public override void Use(Player p, string message, CommandData data) { if (!MessageCmd.CanSpeak(p, name)) return; - UseBotOrPlayer(p, message, "nick"); + UseBotOrPlayer(p, data, message, "nick"); } protected override void SetBotData(Player p, PlayerBot bot, string nick) { diff --git a/MCGalaxy/Commands/Chat/CmdTColor.cs b/MCGalaxy/Commands/Chat/CmdTColor.cs index 1d4637896..77964128c 100644 --- a/MCGalaxy/Commands/Chat/CmdTColor.cs +++ b/MCGalaxy/Commands/Chat/CmdTColor.cs @@ -28,7 +28,9 @@ namespace MCGalaxy.Commands.Chatting { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("TColour"), new CommandAlias("XTColor", "-own") }; } } - public override void Use(Player p, string message, CommandData data) { UsePlayer(p, message, "title color"); } + public override void Use(Player p, string message, CommandData data) { + UsePlayer(p, data, message, "title color"); + } protected override void SetPlayerData(Player p, Player who, string colName) { string color = ""; diff --git a/MCGalaxy/Commands/Chat/CmdTitle.cs b/MCGalaxy/Commands/Chat/CmdTitle.cs index 59d5d7314..9bfd5001f 100644 --- a/MCGalaxy/Commands/Chat/CmdTitle.cs +++ b/MCGalaxy/Commands/Chat/CmdTitle.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Chatting { public override void Use(Player p, string message, CommandData data) { if (!MessageCmd.CanSpeak(p, name)) return; - UsePlayer(p, message, "title"); + UsePlayer(p, data, message, "title"); } protected override void SetPlayerData(Player p, Player who, string title) { diff --git a/MCGalaxy/Commands/EntityPropertyCmd.cs b/MCGalaxy/Commands/EntityPropertyCmd.cs index b352c308e..e52353662 100644 --- a/MCGalaxy/Commands/EntityPropertyCmd.cs +++ b/MCGalaxy/Commands/EntityPropertyCmd.cs @@ -19,7 +19,7 @@ namespace MCGalaxy.Commands { public abstract class EntityPropertyCmd : Command2 { - protected void UseBotOrPlayer(Player p, string message, string type) { + protected void UseBotOrPlayer(Player p, CommandData data, string message, string type) { if (message.Length == 0) { Help(p); return; } bool isBot = message.CaselessStarts("bot "); string[] args = message.SplitSpaces(isBot ? 3 : 2); @@ -34,7 +34,7 @@ namespace MCGalaxy.Commands { if (isBot) { if (!CheckExtraPerm(p, 2)) return; - if (!LevelInfo.ValidateAction(p, p.level, "change the " + type + " of that bot")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "change the " + type + " of that bot")) return; SetBotData(p, bot, args.Length > 2 ? args[2] : ""); } else { if (p != who && !CheckExtraPerm(p, 1)) return; @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands { } } - protected void UsePlayer(Player p, string message, string type) { + protected void UsePlayer(Player p, CommandData data, string message, string type) { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(2); if (!CheckOwn(p, args, "player name")) return; diff --git a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs index de21adc73..48f087a3e 100644 --- a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs +++ b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs @@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.Maintenance { lvl = Matcher.FindLevels(p, args[1]); if (lvl == null) return; } - if (!LevelInfo.ValidateAction(p, lvl, "change BlockDB state of this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "change BlockDB state of this level")) return; if (args[0].CaselessEq("clear")) { p.Message("Clearing &cALL %Sblock changes for {0}%S...", lvl.ColoredName); diff --git a/MCGalaxy/Commands/Moderation/CmdIrcControllers.cs b/MCGalaxy/Commands/Moderation/CmdIrcControllers.cs index 5d4435776..f3d96b8ed 100644 --- a/MCGalaxy/Commands/Moderation/CmdIrcControllers.cs +++ b/MCGalaxy/Commands/Moderation/CmdIrcControllers.cs @@ -72,10 +72,10 @@ namespace MCGalaxy.Commands.Moderation { Group grp = Matcher.FindRanks(p, parts[1]); if (grp == null) return; - if (ServerConfig.IRCControllerRank > p.Rank) { + if (ServerConfig.IRCControllerRank > data.Rank) { p.Message("Cannot change the IRC controllers rank, as it is currently a rank higher than yours."); return; } - if (grp.Permission > p.Rank) { + if (grp.Permission > data.Rank) { p.Message("Cannot set the IRC controllers rank to a rank higher than yours."); return; } diff --git a/MCGalaxy/Commands/Moderation/ZoneCmds.cs b/MCGalaxy/Commands/Moderation/ZoneCmds.cs index 2bd8678ae..cb1182e68 100644 --- a/MCGalaxy/Commands/Moderation/ZoneCmds.cs +++ b/MCGalaxy/Commands/Moderation/ZoneCmds.cs @@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Moderation { if (IsCreateCommand(opt)) { if (args.Length == 1) { Help(p); return; } - CreateZone(p, args, 1); + CreateZone(p, args, data, 1); } else if (IsDeleteCommand(opt)) { if (args.Length == 1) { Help(p); return; } DeleteZone(p, args); @@ -53,25 +53,25 @@ namespace MCGalaxy.Commands.Moderation { if (!zone.Access.CheckDetailed(p)) { p.Message("Hence, you cannot edit this zone."); return; } else if (opt.CaselessEq("edit")) { - EditZone(p, args, zone); + EditZone(p, args, data, zone); } else { SetZoneProp(p, args, zone); } } else { - CreateZone(p, args, 0); + CreateZone(p, args, data, 0); } } - void CreateZone(Player p, string[] args, int offset) { + void CreateZone(Player p, string[] args, CommandData data, int offset) { if (p.level.FindZoneExact(args[offset]) != null) { p.Message("A zone with that name already exists. Use %T/zedit %Sto change it."); return; } - if (!LevelInfo.ValidateAction(p, args[0], "create zones in this level")) return; + if (!LevelInfo.ValidateAction(p, data, args[0], "create zones in this level")) return; Zone z = new Zone(); z.Config.Name = args[offset]; - if (!PermissionCmd.Do(p, args, offset + 1, false, z.Access, p.level)) return; + if (!PermissionCmd.Do(p, args, offset + 1, false, z.Access, data, p.level)) return; p.Message("Creating zone " + z.ColoredName); p.Message("Place or break two blocks to determine the edges."); @@ -106,8 +106,8 @@ namespace MCGalaxy.Commands.Moderation { lvl.Save(true); } - void EditZone(Player p, string[] args, Zone zone) { - PermissionCmd.Do(p, args, 2, false, zone.Access, p.level); + void EditZone(Player p, string[] args, CommandData data, Zone zone) { + PermissionCmd.Do(p, args, 2, false, zone.Access, data, p.level); } void SetZoneProp(Player p, string[] args, Zone zone) { diff --git a/MCGalaxy/Commands/World/CmdBlockProperties.cs b/MCGalaxy/Commands/World/CmdBlockProperties.cs index 0d454a491..fbcdb4c5d 100644 --- a/MCGalaxy/Commands/World/CmdBlockProperties.cs +++ b/MCGalaxy/Commands/World/CmdBlockProperties.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.World { string[] args = message.SplitSpaces(4); if (args.Length < 3) { Help(p); return; } - BlockProps[] scope = GetScope(p, args[0]); + BlockProps[] scope = GetScope(p, data, args[0]); if (scope == null) return; Player pScope = scope == Block.Props ? null : p; @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.World { SetProperty(p, scope, block, prop, args); } - static BlockProps[] GetScope(Player p, string scope) { + static BlockProps[] GetScope(Player p, CommandData data, string scope) { if (scope.CaselessEq("core") || scope.CaselessEq("global")) return Block.Props; if (scope.CaselessEq("level")) { @@ -52,7 +52,7 @@ namespace MCGalaxy.Commands.World { p.Message("Cannot use level scope from {0}.", p.SuperName); return null; } - if (!LevelInfo.ValidateAction(p, p.level, "change block properties in this level")) return null; + if (!LevelInfo.ValidateAction(p, data, p.level, "change block properties in this level")) return null; return p.level.Props; } diff --git a/MCGalaxy/Commands/World/CmdCopyLVL.cs b/MCGalaxy/Commands/World/CmdCopyLVL.cs index 0e0e07760..a642cf527 100644 --- a/MCGalaxy/Commands/World/CmdCopyLVL.cs +++ b/MCGalaxy/Commands/World/CmdCopyLVL.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.World { string src = args[0]; src = Matcher.FindMaps(p, src); if (src == null) return; - if (!LevelInfo.ValidateAction(p, src, "copy this level")) return; + if (!LevelInfo.ValidateAction(p, data, src, "copy this level")) return; string dst = args[1]; if (!Formatter.ValidName(p, dst, "level")) return; diff --git a/MCGalaxy/Commands/World/CmdDeleteLvl.cs b/MCGalaxy/Commands/World/CmdDeleteLvl.cs index c4c601478..19b23d117 100644 --- a/MCGalaxy/Commands/World/CmdDeleteLvl.cs +++ b/MCGalaxy/Commands/World/CmdDeleteLvl.cs @@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.World { if (map == null) return; if (map.CaselessEq(ServerConfig.MainLevel)) { p.Message("Cannot delete the main level."); return; } - if (!LevelInfo.ValidateAction(p, map, "delete this level")) return; + if (!LevelInfo.ValidateAction(p, data, map, "delete this level")) return; p.Message("Created backup."); if (LevelActions.Delete(map)) return; diff --git a/MCGalaxy/Commands/World/CmdFixGrass.cs b/MCGalaxy/Commands/World/CmdFixGrass.cs index c09fbe39e..cf7c691e2 100644 --- a/MCGalaxy/Commands/World/CmdFixGrass.cs +++ b/MCGalaxy/Commands/World/CmdFixGrass.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.World { public override void Use(Player p, string message, CommandData data) { int totalFixed = 0; Level lvl = p.level; - if (!LevelInfo.ValidateAction(p, lvl, "use %T/fixgrass %Son this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "use %T/fixgrass %Son this level")) return; if (message.Length == 0) { Fix(p, lvl, ref totalFixed, true, true); diff --git a/MCGalaxy/Commands/World/CmdMain.cs b/MCGalaxy/Commands/World/CmdMain.cs index c9dca0808..99d3c6958 100644 --- a/MCGalaxy/Commands/World/CmdMain.cs +++ b/MCGalaxy/Commands/World/CmdMain.cs @@ -39,11 +39,11 @@ namespace MCGalaxy.Commands.World { } else { if (!CheckExtraPerm(p, 1)) return; if (!Formatter.ValidName(p, message, "level")) return; - if (!LevelInfo.ValidateAction(p, Server.mainLevel, "set main to another level")) return; + if (!LevelInfo.ValidateAction(p, data, Server.mainLevel, "set main to another level")) return; string map = Matcher.FindMaps(p, message); if (map == null) return; - if (!LevelInfo.ValidateAction(p, map, "set main to this level")) return; + if (!LevelInfo.ValidateAction(p, data, map, "set main to this level")) return; Server.SetMainLevel(map); SrvProperties.Save(); diff --git a/MCGalaxy/Commands/World/CmdMap.cs b/MCGalaxy/Commands/World/CmdMap.cs index 439f6736d..fa7fcc2e3 100644 --- a/MCGalaxy/Commands/World/CmdMap.cs +++ b/MCGalaxy/Commands/World/CmdMap.cs @@ -60,7 +60,7 @@ namespace MCGalaxy.Commands.World { if (!CheckExtraPerm(p, 1)) return; if (optName.CaselessEq(LevelOptions.RealmOwner) && !CheckExtraPerm(p, 2)) return; - if (!LevelInfo.ValidateAction(p, lvl, "change map settings of this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "change map settings of this level")) return; LevelOption opt = LevelOptions.Find(optName); if (opt == null) { diff --git a/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs b/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs index e2fc40a0f..b6dae828a 100644 --- a/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs +++ b/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs @@ -113,14 +113,15 @@ namespace MCGalaxy.Commands.World { string[] args = value.SplitSpaces(); if (args.Length < 4) { Command.Find("ResizeLvl").Help(p); return; } - if (CmdResizeLvl.DoResize(p, args)) return; + CommandData data = default(CommandData); data.Rank = p.Rank; + if (CmdResizeLvl.DoResize(p, args, data)) return; p.Message("Type %T/os map resize {0} {1} {2} confirm %Sif you're sure.", args[1], args[2], args[3]); } else if (cmd == "PERVISIT") { // Older realm maps didn't put you on visit whitelist, so make sure we put the owner here AccessController access = p.level.VisitAccess; if (!access.Whitelisted.CaselessContains(p.name)) { - access.Whitelist(Player.Console, p.level, p.name); + access.Whitelist(Player.Console, LevelPermission.Nobody, p.level, p.name); } UseCommand(p, "PerVisit", value); } else if (cmd == "PERBUILD") { @@ -179,13 +180,14 @@ namespace MCGalaxy.Commands.World { internal static bool SetPerms(Player p, Level lvl) { lvl.Config.RealmOwner = p.name; - lvl.BuildAccess.Whitelist(Player.Console, lvl, p.name); - lvl.VisitAccess.Whitelist(Player.Console, lvl, p.name); + const LevelPermission rank = LevelPermission.Nobody; + lvl.BuildAccess.Whitelist(Player.Console, rank, lvl, p.name); + lvl.VisitAccess.Whitelist(Player.Console, rank, lvl, p.name); Group grp = Group.Find(ServerConfig.OSPerbuildDefault); if (grp == null) return false; - lvl.BuildAccess.SetMin(Player.Console, lvl, grp); + lvl.BuildAccess.SetMin(Player.Console, rank, lvl, grp); return true; } @@ -219,80 +221,24 @@ namespace MCGalaxy.Commands.World { if (cmd == "LIST") { UseCommand(p, "ZoneList", ""); } else if (cmd == "ADD") { - if (name.Length == 0) { p.Message("You need to provide a player name."); return; } - AddBuildPlayer(p, name); + UseCommand(p, "PerBuild", "+" + name); } else if (IsDeleteCommand(cmd)) { - if (name.Length == 0) { p.Message("You need to provide a player name."); return; } - DeleteBuildPlayer(p, name); + UseCommand(p, "PerBuild", "-" + name); } else if (cmd == "BLOCK") { - if (name.Length == 0) { p.Message("You need to provide a player name."); return; } - name = PlayerInfo.FindMatchesPreferOnline(p, name); - if (name == null) return; - - if (name.CaselessEq(p.name)) { p.Message("You can't blacklist yourself"); return; } - RemoveVisitPlayer(p, name); + UseCommand(p, "PerVisit", "-" + name); } else if (cmd == "UNBLOCK") { - if (name.Length == 0) { p.Message("You need to provide a player name."); return; } - if (!Formatter.ValidName(p, name, "player")) return; - AddVisitPlayer(p, name); + UseCommand(p, "PerVisit", "+" + name); } else if (cmd == "BLACKLIST") { List blacklist = p.level.VisitAccess.Blacklisted; if (blacklist.Count > 0) { p.Message("Blacklisted players: " + blacklist.Join()); } else { - p.Message("There are no blacklisted players on this map."); + p.Message("No players are blacklisted from visiting this map."); } } else { p.MessageLines(zoneHelp); } } - - static void AddBuildPlayer(Player p, string rawArgs) { - string[] args = rawArgs.SplitSpaces(); - string reason = args.Length > 1 ? args[1] : ""; - string name = ModActionCmd.FindName(p, "zone", "os zone add", "", args[0], ref reason); - if (name == null) return; - - p.Message("Added zone for &b" + name); - LevelAccessController access = p.level.BuildAccess; - if (access.Blacklisted.CaselessRemove(name)) { - access.OnListChanged(p, p.level, name, true, true); - } - if (!access.Whitelisted.CaselessContains(name)) { - access.Whitelisted.Add(name); - access.OnListChanged(p, p.level, name, true, false); - } - } - - static void DeleteBuildPlayer(Player p, string name) { - if (!Formatter.ValidName(p, name, "player")) return; - - LevelAccessController access = p.level.BuildAccess; - if (access.Whitelisted.CaselessRemove(name)) { - access.OnListChanged(p, p.level, name, false, true); - } else { - p.Message(name + " was not whitelisted."); - } - } - - static void AddVisitPlayer(Player p, string name) { - List blacklist = p.level.VisitAccess.Blacklisted; - if (!blacklist.CaselessContains(name)) { - p.Message(name + " is not blacklisted."); return; - } - blacklist.CaselessRemove(name); - p.level.VisitAccess.OnListChanged(p, p.level, name, true, true); - } - - static void RemoveVisitPlayer(Player p, string name) { - List blacklist = p.level.VisitAccess.Blacklisted; - if (blacklist.CaselessContains(name)) { - p.Message(name + " is already blacklisted."); return; - } - blacklist.Add(name); - p.level.VisitAccess.OnListChanged(p, p.level, name, false, false); - } - static void HandleZones(Player p, string cmd, string args) { if (args.Length == 0) { p.Message("Arguments required. See %T/Help zone"); diff --git a/MCGalaxy/Commands/World/CmdPause.cs b/MCGalaxy/Commands/World/CmdPause.cs index ee121ea54..bf05ab074 100644 --- a/MCGalaxy/Commands/World/CmdPause.cs +++ b/MCGalaxy/Commands/World/CmdPause.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.World { } } - if (!LevelInfo.ValidateAction(p, lvl, "pause physics on this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "pause physics on this level")) return; bool enabled = lvl.PhysicsPaused; lvl.PhysicsPaused = !lvl.PhysicsPaused; diff --git a/MCGalaxy/Commands/World/CmdPhysics.cs b/MCGalaxy/Commands/World/CmdPhysics.cs index b37b69b0c..daa6559ac 100644 --- a/MCGalaxy/Commands/World/CmdPhysics.cs +++ b/MCGalaxy/Commands/World/CmdPhysics.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.World { if (lvl == null) return; } - if (!LevelInfo.ValidateAction(p, lvl, "set physics of this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "set physics of this level")) return; SetPhysics(lvl, state); } diff --git a/MCGalaxy/Commands/World/CmdRenameLvl.cs b/MCGalaxy/Commands/World/CmdRenameLvl.cs index 2851cfdb8..f25166c52 100644 --- a/MCGalaxy/Commands/World/CmdRenameLvl.cs +++ b/MCGalaxy/Commands/World/CmdRenameLvl.cs @@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.World { if (LevelInfo.MapExists(newName)) { p.Message("Level already exists."); return; } if (lvl == Server.mainLevel) { p.Message("Cannot rename the main level."); return; } - if (!LevelInfo.ValidateAction(p, lvl, "rename this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "rename this level")) return; List players = lvl.getPlayers(); lvl.Unload(); diff --git a/MCGalaxy/Commands/World/CmdResizeLvl.cs b/MCGalaxy/Commands/World/CmdResizeLvl.cs index 502f08ffc..57f88e31d 100644 --- a/MCGalaxy/Commands/World/CmdResizeLvl.cs +++ b/MCGalaxy/Commands/World/CmdResizeLvl.cs @@ -33,15 +33,15 @@ namespace MCGalaxy.Commands.World { string[] args = message.SplitSpaces(); if (args.Length < 4) { Help(p); return; } - if (DoResize(p, args)) return; + if (DoResize(p, args, data)) return; p.Message("Type %T/ResizeLvl {0} {1} {2} {3} confirm %Sif you're sure.", args[0], args[1], args[2], args[3]); } - public static bool DoResize(Player p, string[] args) { + public static bool DoResize(Player p, string[] args, CommandData data) { Level lvl = Matcher.FindLevels(p, args[0]); if (lvl == null) return true; - if (!LevelInfo.ValidateAction(p, lvl, "resize this level")) return false; + if (!LevelInfo.ValidateAction(p, data, lvl, "resize this level")) return false; ushort x = 0, y = 0, z = 0; if (!CmdNewLvl.CheckMapAxis(p, args[1], "Width", ref x)) return false; diff --git a/MCGalaxy/Commands/World/CmdRestore.cs b/MCGalaxy/Commands/World/CmdRestore.cs index 110f55d3e..d4b2e39b5 100644 --- a/MCGalaxy/Commands/World/CmdRestore.cs +++ b/MCGalaxy/Commands/World/CmdRestore.cs @@ -42,7 +42,7 @@ namespace MCGalaxy.Commands.World { lvl = p.level; } - if (!LevelInfo.ValidateAction(p, lvl, "restore a backup of this level")) return; + if (!LevelInfo.ValidateAction(p, data, lvl, "restore a backup of this level")) return; if (File.Exists(LevelInfo.BackupFilePath(lvl.name, args[0]))) { try { DoRestore(lvl, args[0]); diff --git a/MCGalaxy/Commands/World/CmdSetspawn.cs b/MCGalaxy/Commands/World/CmdSetspawn.cs index 1ba1fc4bd..f13673682 100644 --- a/MCGalaxy/Commands/World/CmdSetspawn.cs +++ b/MCGalaxy/Commands/World/CmdSetspawn.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.World { public override bool SuperUseable { get { return false; } } public override void Use(Player p, string message, CommandData data) { - if (!LevelInfo.ValidateAction(p, p.level, "set spawn of this level")) return; + if (!LevelInfo.ValidateAction(p, data, p.level, "set spawn of this level")) return; if (message.Length == 0) { p.Message("Spawn location set to your current location."); diff --git a/MCGalaxy/Commands/World/PermissionCmds.cs b/MCGalaxy/Commands/World/PermissionCmds.cs index 3f795eb28..3cdfa66ab 100644 --- a/MCGalaxy/Commands/World/PermissionCmds.cs +++ b/MCGalaxy/Commands/World/PermissionCmds.cs @@ -24,25 +24,26 @@ namespace MCGalaxy.Commands.World { public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public static bool Do(Player p, string[] args, int offset, bool max, AccessController access, Level lvl) { + public static bool Do(Player p, string[] args, int offset, bool max, + AccessController access, CommandData data, Level lvl) { for (int i = offset; i < args.Length; i++) { string arg = args[i]; if (arg[0] == '+' || arg[0] == '-') { - if (!SetList(p, access, arg, lvl)) return false; + if (!SetList(p, arg, access, data, lvl)) return false; } else if (max) { Group grp = Matcher.FindRanks(p, arg); if (grp == null) return false; - access.SetMax(p, lvl, grp); + access.SetMax(p, data.Rank, lvl, grp); } else { Group grp = Matcher.FindRanks(p, arg); if (grp == null) return false; - access.SetMin(p, lvl, grp); + access.SetMin(p, data.Rank, lvl, grp); } } return true; } - protected void DoLevel(Player p, string message, bool visit) { + protected void DoLevel(Player p, string message, CommandData data, bool visit) { const string maxPrefix = "-max "; bool max = message.CaselessStarts(maxPrefix); if (max) message = message.Substring(maxPrefix.Length); @@ -54,7 +55,7 @@ namespace MCGalaxy.Commands.World { } string map = args.Length == 1 ? p.level.name : Matcher.FindMaps(p, args[0]); - if (map == null) return; + if (map == null) return; Level lvl; LevelConfig cfg = LevelInfo.GetConfig(map, out lvl); int offset = args.Length == 1 ? 0 : 1; @@ -65,10 +66,11 @@ namespace MCGalaxy.Commands.World { } else { access = visit ? lvl.VisitAccess : lvl.BuildAccess; } - Do(p, args, offset, max, access, lvl); + Do(p, args, offset, max, access, data, lvl); } - static bool SetList(Player p, AccessController access, string name, Level lvl) { + static bool SetList(Player p, string name, + AccessController access, CommandData data, Level lvl) { bool include = name[0] == '+'; string mode = include ? "whitelist" : "blacklist"; name = name.Substring(1); @@ -86,9 +88,9 @@ namespace MCGalaxy.Commands.World { } if (include) { - access.Whitelist(p, lvl, name); + access.Whitelist(p, data.Rank, lvl, name); } else { - access.Blacklist(p, lvl, name); + access.Blacklist(p, data.Rank, lvl, name); } return true; } @@ -115,7 +117,7 @@ namespace MCGalaxy.Commands.World { get { return new[] { new CommandPerm(LevelPermission.Operator, "bypass max build rank restriction") }; } } - public override void Use(Player p, string message, CommandData data) { DoLevel(p, message, false); } + public override void Use(Player p, string message, CommandData data) { DoLevel(p, message, data, false); } public override void Help(Player p) { ShowHelp(p, "build on", "build"); } } @@ -129,7 +131,7 @@ namespace MCGalaxy.Commands.World { get { return new[] { new CommandPerm(LevelPermission.Operator, "bypass max visit rank restriction") }; } } - public override void Use(Player p, string message, CommandData data) { DoLevel(p, message, true); } + public override void Use(Player p, string message, CommandData data) { DoLevel(p, message, data, true); } public override void Help(Player p) { ShowHelp(p, "visit", "visit"); } } } \ No newline at end of file diff --git a/MCGalaxy/Commands/other/CmdSummon.cs b/MCGalaxy/Commands/other/CmdSummon.cs index 4c88a48d3..68acba4bc 100644 --- a/MCGalaxy/Commands/other/CmdSummon.cs +++ b/MCGalaxy/Commands/other/CmdSummon.cs @@ -48,7 +48,7 @@ namespace MCGalaxy.Commands.Misc { if (pl.level == p.level && pl != p && p.Rank > pl.Rank) { pl.AFKCooldown = DateTime.UtcNow.AddSeconds(2); pl.SendPos(Entities.SelfID, p.Pos, p.Rot); - pl.SendMessage("You were summoned by " + p.ColoredName + "%S."); + pl.Message("You were summoned by " + p.ColoredName + "%S."); } } Chat.MessageFromLevel(p, "λNICK %Ssummoned everyone"); @@ -76,7 +76,7 @@ namespace MCGalaxy.Commands.Misc { who.AFKCooldown = DateTime.UtcNow.AddSeconds(2); who.SendPos(Entities.SelfID, p.Pos, p.Rot); - who.SendMessage("You were summoned by " + p.ColoredName + "%S."); + who.Message("You were summoned by " + p.ColoredName + "%S."); } static bool CheckVisitPerm(Player p, Player who, bool confirmed) { diff --git a/MCGalaxy/CorePlugin/ModActionHandler.cs b/MCGalaxy/CorePlugin/ModActionHandler.cs index be6e8f519..59b822c11 100644 --- a/MCGalaxy/CorePlugin/ModActionHandler.cs +++ b/MCGalaxy/CorePlugin/ModActionHandler.cs @@ -202,7 +202,7 @@ namespace MCGalaxy.Core { LogAction(e, who, action + newRank.ColoredName); if (who != null && e.Announce) { - who.SendMessage("You are now ranked " + newRank.ColoredName + "%S, type /Help for your new set of commands."); + who.Message("You are now ranked " + newRank.ColoredName + "%S, type /Help for your new set of commands."); } if (Server.tempRanks.Remove(e.Target)) { ModerationTasks.TemprankCalcNextRun(); diff --git a/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs b/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs index 37a357b54..403832032 100644 --- a/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs @@ -36,7 +36,7 @@ namespace MCGalaxy.Drawing.Brushes { internal static Brush ProcessReplace(BrushArgs args, bool not) { string[] parts = args.Message.SplitSpaces(); if (args.Message.Length == 0) { - args.Player.SendMessage("You need at least one block to replace."); return null; + args.Player.Message("You need at least one block to replace."); return null; } int count = parts.Length == 1 ? 1 : parts.Length - 1; diff --git a/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs b/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs index 2d18b2e23..665958119 100644 --- a/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs @@ -102,7 +102,7 @@ namespace MCGalaxy.Drawing.Brushes { public override Brush Construct(BrushArgs args) { CopyState cState = args.Player.CurrentCopy; if (cState == null) { - args.Player.SendMessage("You haven't copied anything yet."); + args.Player.Message("You haven't copied anything yet."); return null; } diff --git a/MCGalaxy/Games/Countdown/CountdownGame.Round.cs b/MCGalaxy/Games/Countdown/CountdownGame.Round.cs index 88d3e92cb..8f2d87aa4 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.Round.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.Round.cs @@ -94,7 +94,7 @@ namespace MCGalaxy.Games { foreach (Player pl in players) { if (pl.level != Map) { - pl.SendMessage("Sending you to the correct map."); + pl.Message("Sending you to the correct map."); PlayerActions.ChangeMap(pl, Map.name); } @@ -223,7 +223,7 @@ namespace MCGalaxy.Games { UpdateAllStatus(); if (winner != null) { - winner.SendMessage("Congratulations, you won this round of countdown!"); + winner.Message("Congratulations, you won this round of countdown!"); PlayerActions.Respawn(winner); } else { Player[] players = Players.Items; diff --git a/MCGalaxy/Games/RoundsGame/LevelPicker.cs b/MCGalaxy/Games/RoundsGame/LevelPicker.cs index 08c047a59..6f1c4f0c6 100644 --- a/MCGalaxy/Games/RoundsGame/LevelPicker.cs +++ b/MCGalaxy/Games/RoundsGame/LevelPicker.cs @@ -97,7 +97,7 @@ namespace MCGalaxy.Games { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (pl.level != game.Map || pl.Supports(CpeExt.MessageTypes)) continue; - pl.SendMessage("You have " + VoteTime + " seconds to vote for the next map"); + pl.Message("You have " + VoteTime + " seconds to vote for the next map"); } Level map = game.Map; diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.cs index 2e16e8c57..7b022a561 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.cs @@ -203,7 +203,7 @@ namespace MCGalaxy.Games { int i = rnd.Next(0, transfers.Count); Player pl = transfers[i]; - pl.SendMessage("Going to the next map - &a" + Map.MapName); + pl.Message("Going to the next map - &a" + Map.MapName); PlayerActions.ChangeMap(pl, Map); transfers.RemoveAt(i); } diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs index 595b7ba3b..3cafd3542 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs @@ -125,7 +125,7 @@ namespace MCGalaxy.Games { if (lastKiller == killer.name) { infectCombo++; if (infectCombo >= 2) { - killer.SendMessage("You gained " + (2 + infectCombo) + " " + ServerConfig.Currency); + killer.Message("You gained " + (2 + infectCombo) + " " + ServerConfig.Currency); killer.SetMoney(killer.money + (2 + infectCombo)); Map.Message("&c" + killer.DisplayName + " %Sis on a rampage! " + (infectCombo + 1) + " infections in a row!"); } @@ -293,9 +293,9 @@ namespace MCGalaxy.Games { int reward = GetMoneyReward(pl, data, alive, rand); if (reward == -1) { - pl.SendMessage("You may not hide inside a block! No " + ServerConfig.Currency + " for you."); reward = 0; + pl.Message("You may not hide inside a block! No " + ServerConfig.Currency + " for you."); reward = 0; } else if (reward > 0) { - pl.SendMessage("&6You gained " + reward + " " + ServerConfig.Currency); + pl.Message("&6You gained " + reward + " " + ServerConfig.Currency); } pl.SetMoney(pl.money + reward); @@ -303,7 +303,7 @@ namespace MCGalaxy.Games { pl.Game.PledgeSurvive = false; if (pl.Game.Referee) { - pl.SendMessage("You gained one " + ServerConfig.Currency + " because you're a ref. Would you like a medal as well?"); + pl.Message("You gained one " + ServerConfig.Currency + " because you're a ref. Would you like a medal as well?"); pl.SetMoney(pl.money + 1); } diff --git a/MCGalaxy/Levels/AccessController.cs b/MCGalaxy/Levels/AccessController.cs index a925b2e59..31bf7cb9e 100644 --- a/MCGalaxy/Levels/AccessController.cs +++ b/MCGalaxy/Levels/AccessController.cs @@ -55,13 +55,13 @@ namespace MCGalaxy { } public bool CheckDetailed(Player p, bool ignoreRankPerm = false) { - AccessResult result = Check(p); - if (result == AccessResult.Allowed) return true; - if (result == AccessResult.Whitelisted) return true; - if (result == AccessResult.AboveMaxRank && ignoreRankPerm) return true; - if (result == AccessResult.BelowMinRank && ignoreRankPerm) return true; + AccessResult access = Check(p); + if (access == AccessResult.Allowed) return true; + if (access == AccessResult.Whitelisted) return true; + if (access == AccessResult.AboveMaxRank && ignoreRankPerm) return true; + if (access == AccessResult.BelowMinRank && ignoreRankPerm) return true; - if (result == AccessResult.Blacklisted) { + if (access == AccessResult.Blacklisted) { p.Message("You are blacklisted from {0} {1}", ActionIng, ColoredName); return false; } @@ -71,10 +71,10 @@ namespace MCGalaxy { whitelist = "(and " + Whitelisted.Join(pl => PlayerInfo.GetColoredName(p, pl)) + "%S) "; } - if (result == AccessResult.BelowMinRank) { + if (access == AccessResult.BelowMinRank) { p.Message("Only {2}%S+ {3}may {0} {1}", Action, ColoredName, Group.GetColoredName(Min), whitelist); - } else if (result == AccessResult.AboveMaxRank) { + } else if (access == AccessResult.AboveMaxRank) { p.Message("Only {2} %Sand below {3}may {0} {1}", Action, ColoredName, Group.GetColoredName(Max), whitelist); } @@ -104,29 +104,29 @@ namespace MCGalaxy { } - public bool SetMin(Player p, Level lvl, Group grp) { + public bool SetMin(Player p, LevelPermission plRank, Level lvl, Group grp) { string minType = "Min " + Type; - if (!CheckRank(p, Min, minType, false)) return false; - if (!CheckRank(p, grp.Permission, minType, true)) return false; + if (!CheckRank(p, plRank, Min, minType, false)) return false; + if (!CheckRank(p, plRank, grp.Permission, minType, true)) return false; Min = grp.Permission; OnPermissionChanged(p, lvl, grp, minType); return true; } - public bool SetMax(Player p, Level lvl, Group grp) { + public bool SetMax(Player p, LevelPermission plRank, Level lvl, Group grp) { string maxType = "Max " + Type; const LevelPermission ignore = LevelPermission.Nobody; - if (Max != ignore && !CheckRank(p, Max, maxType, false)) return false; - if (grp.Permission != ignore && !CheckRank(p, grp.Permission, maxType, true)) return false; + if (Max != ignore && !CheckRank(p, plRank, Max, maxType, false)) return false; + if (grp.Permission != ignore && !CheckRank(p, plRank, grp.Permission, maxType, true)) return false; Max = grp.Permission; OnPermissionChanged(p, lvl, grp, maxType); return true; } - public bool Whitelist(Player p, Level lvl, string target) { - if (!CheckList(p, target, true)) return false; + public bool Whitelist(Player p, LevelPermission plRank, Level lvl, string target) { + if (!CheckList(p, plRank, target, true)) return false; if (Whitelisted.CaselessContains(target)) { p.Message("{0} %Sis already whitelisted.", PlayerInfo.GetColoredName(p, target)); return true; @@ -141,8 +141,8 @@ namespace MCGalaxy { return true; } - public bool Blacklist(Player p, Level lvl, string target) { - if (!CheckList(p, target, false)) return false; + public bool Blacklist(Player p, LevelPermission plRank, Level lvl, string target) { + if (!CheckList(p, plRank, target, false)) return false; if (Blacklisted.CaselessContains(target)) { p.Message("{0} %Sis already blacklisted.", PlayerInfo.GetColoredName(p, target)); return true; @@ -175,8 +175,8 @@ namespace MCGalaxy { protected abstract void ApplyChanges(Player p, Level lvl, string msg); - bool CheckRank(Player p, LevelPermission perm, string type, bool newPerm) { - if (perm <= p.Rank) return true; + bool CheckRank(Player p, LevelPermission plRank, LevelPermission perm, string type, bool newPerm) { + if (perm <= plRank) return true; p.Message("You cannot change the {0} rank of {1}{2} higher than yours.", type.ToLower(), ColoredName, @@ -186,14 +186,14 @@ namespace MCGalaxy { /// Returns true if the player is allowed to modify these access permissions, /// and is also allowed to change the access permissions for the target player. - bool CheckList(Player p, string name, bool whitelist) { + bool CheckList(Player p, LevelPermission plRank, string name, bool whitelist) { if (p != null && !CheckDetailed(p)) { string mode = whitelist ? "whitelist" : "blacklist"; p.Message("Hence you cannot modify the {0} {1}.", Type, mode); return false; } Group group = PlayerInfo.GetGroup(name); - if (group.Permission <= p.Rank) return true; + if (group.Permission <= plRank) return true; if (!whitelist) { p.Message("You cannot blacklist players of a higher rank."); diff --git a/MCGalaxy/Levels/LevelActions.cs b/MCGalaxy/Levels/LevelActions.cs index c51f8b3a5..d0340cc09 100644 --- a/MCGalaxy/Levels/LevelActions.cs +++ b/MCGalaxy/Levels/LevelActions.cs @@ -218,9 +218,9 @@ namespace MCGalaxy { if (!announce) return; if (src == null || !Entities.CanSee(p, src)) { - p.SendMessage("&bMap reloaded"); + p.Message("&bMap reloaded"); } else { - p.SendMessage("&bMap reloaded by " + src.ColoredName); + p.Message("&bMap reloaded by " + src.ColoredName); } if (Entities.CanSee(src, p)) { src.Message("&4Finished reloading for " + p.ColoredName); diff --git a/MCGalaxy/Levels/LevelInfo.cs b/MCGalaxy/Levels/LevelInfo.cs index a9ad7580b..d3c92268f 100644 --- a/MCGalaxy/Levels/LevelInfo.cs +++ b/MCGalaxy/Levels/LevelInfo.cs @@ -137,10 +137,10 @@ namespace MCGalaxy { return cfg; } - internal static bool ValidateAction(Player p, string map, string action) { + internal static bool ValidateAction(Player p, CommandData data, string map, string action) { if (p == null) return true; Level lvl; LevelConfig cfg = GetConfig(map, out lvl); - if (lvl != null) return ValidateAction(p, lvl, action); + if (lvl != null) return ValidateAction(p, data, lvl, action); LevelAccessController visit = new LevelAccessController(cfg, map, true); LevelAccessController build = new LevelAccessController(cfg, map, false); @@ -150,7 +150,7 @@ namespace MCGalaxy { return true; } - internal static bool ValidateAction(Player p, Level lvl, string action) { + internal static bool ValidateAction(Player p, CommandData data, Level lvl, string action) { if (p == null) return true; if (!lvl.VisitAccess.CheckDetailed(p) || !lvl.BuildAccess.CheckDetailed(p)) { p.Message("Hence, you cannot {0}.", action); return false; diff --git a/MCGalaxy/Network/Player.Networking.cs b/MCGalaxy/Network/Player.Networking.cs index 26d50d05f..5197b6520 100644 --- a/MCGalaxy/Network/Player.Networking.cs +++ b/MCGalaxy/Network/Player.Networking.cs @@ -222,7 +222,7 @@ namespace MCGalaxy { } catch (Exception ex) { success = false; PlayerActions.ChangeMap(this, Server.mainLevel); - SendMessage("%WThere was an error sending the map, you have been sent to the main level."); + Message("%WThere was an error sending the map, you have been sent to the main level."); Logger.LogError(ex); } finally { Server.DoGC(); diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 6e93348cd..db111eaef 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -95,6 +95,7 @@ namespace MCGalaxy { public bool trainGrab; public bool onTrain, trainInvincible; + int mbRecursion; public bool frozen; public string following = ""; diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 2dbf0a35b..0a75bf778 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -50,7 +50,7 @@ namespace MCGalaxy { if (jailed || frozen || !canBuild) { RevertBlock(x, y, z); return; } if (!agreed) { - SendMessage(mustAgreeMsg); + Message(mustAgreeMsg); RevertBlock(x, y, z); return; } @@ -58,12 +58,12 @@ namespace MCGalaxy { bool deletingBlock = !painting && !placing; if (ServerConfig.verifyadmins && adminpen) { - SendMessage("%WYou must first verify with %T/Pass [Password]"); + Message("%WYou must first verify with %T/Pass [Password]"); RevertBlock(x, y, z); return; } if ( LSGame.Instance.Running && LSGame.Instance.Map == level && LSGame.Instance.IsPlayerDead(this) ) { - SendMessage("You are out of the round, and cannot build."); + Message("You are out of the round, and cannot build."); RevertBlock(x, y, z); return; } @@ -73,7 +73,7 @@ namespace MCGalaxy { if (cancelBlock) { cancelBlock = false; return; } if (old >= Block.Air_Flood && old <= Block.Door_Air_air) { - SendMessage("Block is active, you cannot disturb it."); + Message("Block is active, you cannot disturb it."); RevertBlock(x, y, z); return; } @@ -89,7 +89,7 @@ namespace MCGalaxy { if (diff > ReachDistance + 4) { Logger.Log(LogType.Warning, "{0} attempted to build with a {1} distance offset", name, diff); - SendMessage("You can't build that far away."); + Message("You can't build that far away."); RevertBlock(x, y, z); return; } } @@ -282,16 +282,16 @@ namespace MCGalaxy { RawHeldBlock = held; if ((action == 0 || held == Block.Air) && !level.Config.Deletable) { - SendMessage("Deleting blocks is disabled in this level."); + Message("Deleting blocks is disabled in this level."); RevertBlock(x, y, z); return; } else if (action == 1 && !level.Config.Buildable) { - SendMessage("Placing blocks is disabled in this level."); + Message("Placing blocks is disabled in this level."); RevertBlock(x, y, z); return; } if (held >= Block.Extended) { if (!hasBlockDefs || level.CustomBlockDefs[held] == null) { - SendMessage("Invalid block type: " + Block.ToRaw(held)); + Message("Invalid block type: " + Block.ToRaw(held)); RevertBlock(x, y, z); return; } } @@ -479,7 +479,7 @@ namespace MCGalaxy { } // People who are muted can't speak or vote - if (muted) { SendMessage("You are muted."); return; } //Muted: Only allow commands + if (muted) { Message("You are muted."); return; } //Muted: Only allow commands if (Server.voting) { if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) || @@ -490,7 +490,7 @@ namespace MCGalaxy { if (ZSGame.Instance.HandlesChatMessage(this, text)) return; // Put this after vote collection so that people can vote even when chat is moderated - if (Server.chatmod && !voice) { SendMessage("Chat moderation is on, you cannot speak."); return; } + if (Server.chatmod && !voice) { Message("Chat moderation is on, you cannot speak."); return; } // Filter out bad words if (ServerConfig.ProfanityFiltering) text = ProfanityFilter.Parse(text); @@ -524,17 +524,17 @@ namespace MCGalaxy { } if (text.CaselessContains("^detail.user=")) { - SendMessage("%WYou cannot use WoM detail strings in a chat message."); + Message("%WYou cannot use WoM detail strings in a chat message."); return true; } if (IsPartialSpaced(text)) { partialMessage += text.Substring(0, text.Length - 2) + " "; - SendMessage("&3Partial message: &f" + partialMessage); + Message("&3Partial message: &f" + partialMessage); return true; } else if (IsPartialJoined(text)) { partialMessage += text.Substring(0, text.Length - 2); - SendMessage("&3Partial message: &f" + partialMessage); + Message("&3Partial message: &f" + partialMessage); return true; } else if (partialMessage.Length > 0) { text = partialMessage + text; @@ -601,6 +601,8 @@ namespace MCGalaxy { public void HandleCommand(string cmd, string args, CommandData data) { cmd = cmd.ToLower(); + if (!ServerConfig.CmdSpamCheck && !CheckMBRecursion(data)) return; + try { Command command = GetCommand(ref cmd, ref args, data); if (command == null) return; @@ -610,13 +612,16 @@ namespace MCGalaxy { thread.IsBackground = true; thread.Start(); } catch (Exception e) { - Logger.LogError(e); SendMessage("Command failed."); + Logger.LogError(e); + Message("%WCommand failed"); } } public void HandleCommands(List cmds, CommandData data) { List messages = new List(cmds.Count); List commands = new List(cmds.Count); + if (!ServerConfig.CmdSpamCheck && !CheckMBRecursion(data)) return; + try { foreach (string raw in cmds) { string[] parts = raw.SplitSpaces(2); @@ -634,27 +639,40 @@ namespace MCGalaxy { thread.IsBackground = true; thread.Start(); } catch (Exception e) { - Logger.LogError(e); SendMessage("%WCommand failed."); + Logger.LogError(e); + Message("%WCommand failed."); } } + bool CheckMBRecursion(CommandData data) { + if (data.Context == CommandContext.MessageBlock) { + mbRecursion++; + // failsafe for when server has turned off command spam checking + if (mbRecursion >= 100) { + mbRecursion = 0; + Message("%WInfinite message block loop detected, aborting"); + return false; + } + } else { mbRecursion = 0; } + return true; + } + bool CheckCommand(string cmd) { - if (cmd.Length == 0) { SendMessage("No command entered."); return false; } + if (cmd.Length == 0) { Message("No command entered."); return false; } if (ServerConfig.AgreeToRulesOnEntry && !agreed && !(cmd == "agree" || cmd == "rules" || cmd == "disagree" || cmd == "pass" || cmd == "setpass")) { - SendMessage(mustAgreeMsg); return false; + Message(mustAgreeMsg); return false; } if (jailed) { - SendMessage("You cannot use any commands while jailed."); return false; + Message("You cannot use any commands while jailed."); return false; } if (ServerConfig.verifyadmins && adminpen && !(cmd == "pass" || cmd == "setpass")) { - SendMessage("%WYou must verify first with %T/Pass [Password]"); return false; + Message("%WYou must verify first with %T/Pass [Password]"); return false; } TimeSpan delta = cmdUnblocked - DateTime.UtcNow; if (delta.TotalSeconds > 0) { int secs = (int)Math.Ceiling(delta.TotalSeconds); - SendMessage("Blocked from using commands for " + - "another " + secs + " seconds"); return false; + Message("Blocked from using commands for another " + secs + " seconds"); return false; } return true; } @@ -666,7 +684,7 @@ namespace MCGalaxy { byte bindIndex; if (byte.TryParse(cmdName, out bindIndex) && bindIndex < CmdBindings.Length) { if (CmdArgsBindings[bindIndex] == null) { - SendMessage("No command is bound to: %T/" + cmdName); return null; + Message("No command is bound to: %T/" + cmdName); return null; } cmdName = CmdBindings[bindIndex]; @@ -684,7 +702,7 @@ namespace MCGalaxy { command = Command.Find("Mode"); } else { Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs); - SendMessage("Unknown command \"" + cmdName + "\"."); return null; + Message("Unknown command \"" + cmdName + "\"."); return null; } } @@ -695,13 +713,13 @@ namespace MCGalaxy { string reason = Command.GetDisabledReason(command.Enabled); if (reason != null) { - SendMessage("Command is disabled as " + reason); return null; + Message("Command is disabled as " + reason); return null; } if (level.IsMuseum && !command.museumUsable) { - SendMessage("Cannot use this command while in a museum."); return null; + Message("Cannot use this command while in a museum."); return null; } if (frozen && !command.UseableWhenFrozen) { - SendMessage("Cannot use this command while frozen."); return null; + Message("Cannot use this command while frozen."); return null; } return command; } diff --git a/MCGalaxy/Player/Player.Login.cs b/MCGalaxy/Player/Player.Login.cs index e4e96a9aa..4add03e02 100644 --- a/MCGalaxy/Player/Player.Login.cs +++ b/MCGalaxy/Player/Player.Login.cs @@ -112,7 +112,7 @@ namespace MCGalaxy { if (Server.noEmotes.Contains(name)) { parseEmotes = !ServerConfig.ParseEmotes; } hidden = group.CanExecute("Hide") && Server.hidden.Contains(name); - if (hidden) SendMessage("&8Reminder: You are still hidden."); + if (hidden) Message("&8Reminder: You are still hidden."); if (Chat.AdminchatPerms.UsableBy(Rank) && ServerConfig.AdminsJoinSilently) { hidden = true; adminchat = true; @@ -129,26 +129,26 @@ namespace MCGalaxy { } if (ServerConfig.AgreeToRulesOnEntry && Rank == LevelPermission.Guest && !Server.agreed.Contains(name)) { - SendMessage("&9You must read the &c/Rules &9and &c/Agree &9to them before you can build and use commands!"); + Message("&9You must read the &c/Rules &9and &c/Agree &9to them before you can build and use commands!"); agreed = false; } if (ServerConfig.verifyadmins && Rank >= ServerConfig.VerifyAdminsRank) { if (!Directory.Exists("extra/passwords") || !File.Exists("extra/passwords/" + name + ".dat")) - SendMessage("%WPlease set your admin verification password with %T/SetPass [Password]!"); + Message("%WPlease set your admin verification password with %T/SetPass [Password]!"); else - SendMessage("%Wcomplete admin verification with %T/Pass [Password]!"); + Message("%Wcomplete admin verification with %T/Pass [Password]!"); } if (group.CanExecute("Inbox") && Database.TableExists("Inbox" + name)) { int count = Database.CountRows("Inbox" + name); if (count > 0) { - SendMessage("You have &a" + count + " %Smessages in %T/Inbox"); + Message("You have &a" + count + " %Smessages in %T/Inbox"); } } if (ServerConfig.PositionUpdateInterval > 1000) - SendMessage("Lowlag mode is currently &aON."); + Message("Lowlag mode is currently &aON."); if (String.IsNullOrEmpty(appName)) { Logger.Log(LogType.UserActivity, "{0} [{1}] connected.", name, ip); @@ -221,10 +221,10 @@ namespace MCGalaxy { if (raw == null) { PlayerData.Create(this); Chat.MessageFrom(this, "λNICK %Shas connected for the first time!"); - SendMessage("Welcome " + ColoredName + "%S! This is your first visit."); + Message("Welcome " + ColoredName + "%S! This is your first visit."); } else { PlayerData.Apply((PlayerData)raw, this); - SendMessage("Welcome back " + FullName + "%S! You've been here " + TimesVisited + " times!"); + Message("Welcome back " + FullName + "%S! You've been here " + TimesVisited + " times!"); } gotSQLData = true; }