From 69a109f830489ad01468ed59fc875b3098e3b07b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 8 Jun 2017 09:52:50 +1000 Subject: [PATCH] After rank change, resend block permissions, and reset mode types and block bindings if no longer permitted to place those blocks, fixes #303 and fixes #297 --- MCGalaxy/Commands/CommandParser.cs | 2 +- MCGalaxy/Commands/Fun/CmdCountdown.cs | 5 --- MCGalaxy/Commands/Fun/CmdGun.cs | 2 +- MCGalaxy/Commands/Fun/CmdMissile.cs | 2 +- MCGalaxy/Commands/Information/CmdHelp.cs | 2 +- MCGalaxy/Commands/Moderation/CmdBlockSet.cs | 2 +- MCGalaxy/Commands/Moderation/ModActionCmd.cs | 31 ++++++++++++++++--- MCGalaxy/Commands/building/CmdBind.cs | 2 +- MCGalaxy/Commands/building/CmdMessageBlock.cs | 2 +- MCGalaxy/Commands/building/CmdMode.cs | 2 +- MCGalaxy/Commands/building/CmdPlace.cs | 2 +- MCGalaxy/Commands/building/CmdPortal.cs | 2 +- .../BrushFactories/FrequencyBrushes.cs | 2 +- .../Drawing/BrushFactories/ReplaceBrushes.cs | 2 +- .../Drawing/BrushFactories/SimpleBrushes.cs | 6 ++-- MCGalaxy/Games/Countdown/CountdownMapGen.cs | 7 ++++- MCGalaxy/Player/Player.Handlers.cs | 9 +++--- MCGalaxy/Player/Player.cs | 15 +-------- MCGalaxy/util/Formatting/Formatter.cs | 2 +- 19 files changed, 54 insertions(+), 45 deletions(-) diff --git a/MCGalaxy/Commands/CommandParser.cs b/MCGalaxy/Commands/CommandParser.cs index f7cad14e6..a60628cac 100644 --- a/MCGalaxy/Commands/CommandParser.cs +++ b/MCGalaxy/Commands/CommandParser.cs @@ -151,7 +151,7 @@ namespace MCGalaxy.Commands { public static bool GetBlockIfAllowed(Player p, string input, out ExtBlock block, bool allowSkip = false) { if (!GetBlock(p, input, out block, allowSkip)) return false; if (allowSkip && block == ExtBlock.Invalid) return true; - return IsBlockAllowed(p, "draw with ", block); + return IsBlockAllowed(p, "draw with", block); } /// Returns whether the player is allowed to place/modify/delete the given block. diff --git a/MCGalaxy/Commands/Fun/CmdCountdown.cs b/MCGalaxy/Commands/Fun/CmdCountdown.cs index 1da9fd188..7053c73c8 100644 --- a/MCGalaxy/Commands/Fun/CmdCountdown.cs +++ b/MCGalaxy/Commands/Fun/CmdCountdown.cs @@ -202,11 +202,6 @@ namespace MCGalaxy.Commands.Fun { if (!CmdNewLvl.CheckMapVolume(p, width, height, length)) return; Level lvl = CountdownMapGen.Generate(width, height, length); - lvl.Deletable = false; - lvl.Buildable = false; - lvl.permissionbuild = LevelPermission.Nobody; - lvl.motd = "Welcome to the Countdown map! -hax"; - Level oldLvl = LevelInfo.FindExact("countdown"); if (oldLvl != null) LevelActions.Replace(oldLvl, lvl); else LevelInfo.Loaded.Add(lvl); diff --git a/MCGalaxy/Commands/Fun/CmdGun.cs b/MCGalaxy/Commands/Fun/CmdGun.cs index a784b93b6..b7189d43e 100644 --- a/MCGalaxy/Commands/Fun/CmdGun.cs +++ b/MCGalaxy/Commands/Fun/CmdGun.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.Fun { protected override void PlacedMark(Player p, ushort x, ushort y, ushort z, ExtBlock block) { p.RevertBlock(x, y, z); - if (!CommandParser.IsBlockAllowed(p, "place ", block)) return; + if (!CommandParser.IsBlockAllowed(p, "place", block)) return; Thread gunThread = new Thread(() => DoShoot(p, block)); gunThread.Name = "MCG_Gun"; diff --git a/MCGalaxy/Commands/Fun/CmdMissile.cs b/MCGalaxy/Commands/Fun/CmdMissile.cs index c64cc2f6e..1c5e9f772 100644 --- a/MCGalaxy/Commands/Fun/CmdMissile.cs +++ b/MCGalaxy/Commands/Fun/CmdMissile.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Fun { p.aiming = false; } p.RevertBlock(x, y, z); - if (!CommandParser.IsBlockAllowed(p, "place ", block)) return; + if (!CommandParser.IsBlockAllowed(p, "place", block)) return; MissileArgs args = new MissileArgs(); args.player = p; diff --git a/MCGalaxy/Commands/Information/CmdHelp.cs b/MCGalaxy/Commands/Information/CmdHelp.cs index bdc3eb0a9..800ccfec7 100644 --- a/MCGalaxy/Commands/Information/CmdHelp.cs +++ b/MCGalaxy/Commands/Information/CmdHelp.cs @@ -165,7 +165,7 @@ namespace MCGalaxy.Commands.Info { default: Player.Message(p, "Block \"" + message + "\" appears as &b" + Block.Name(Block.Convert(b))); break; } - Formatter.MessageBlock(p, "use ", b); + Formatter.MessageBlock(p, "use", b); return true; } diff --git a/MCGalaxy/Commands/Moderation/CmdBlockSet.cs b/MCGalaxy/Commands/Moderation/CmdBlockSet.cs index 8ae32c5cf..3f8ac4db8 100644 --- a/MCGalaxy/Commands/Moderation/CmdBlockSet.cs +++ b/MCGalaxy/Commands/Moderation/CmdBlockSet.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Moderation { byte block = Block.Byte(args[0]); if (block == Block.Invalid) { Player.Message(p, "Could not find block entered"); return; } - if (!CommandParser.IsBlockAllowed(p, "change permissions of ", (ExtBlock)block)) return; + if (!CommandParser.IsBlockAllowed(p, "change permissions of", (ExtBlock)block)) return; if (args.Length == 2 && args[1][0] == '+') { Group grp = GetGroup(p, args[1].Substring(1)); diff --git a/MCGalaxy/Commands/Moderation/ModActionCmd.cs b/MCGalaxy/Commands/Moderation/ModActionCmd.cs index ca3be9add..0c6c40139 100644 --- a/MCGalaxy/Commands/Moderation/ModActionCmd.cs +++ b/MCGalaxy/Commands/Moderation/ModActionCmd.cs @@ -67,7 +67,7 @@ namespace MCGalaxy.Commands.Moderation { if (isNumber) { // e.g. line is: 1) Do not do X if (ruleNum == -1) ruleNum = 0; - ruleNum *= 10; + ruleNum *= 10; ruleNum += (c - '0'); } else { sections[ruleNum] = rule.Substring(i); @@ -109,13 +109,36 @@ namespace MCGalaxy.Commands.Moderation { who.SetPrefix(); who.Send(Packet.UserType(who)); + who.SendCurrentBlockPermissions(); Entities.SpawnEntities(who, false); + CheckBlockBindings(who); + } + + static void CheckBlockBindings(Player who) { + ExtBlock block = who.ModeBlock; + if (block != ExtBlock.Air && !CommandParser.IsBlockAllowed(who, "place", block)) { + who.ModeBlock = ExtBlock.Air; + Player.Message(who, " Hence, &b{0} %Smode was turned &cOFF", + who.level.BlockName(block)); + } + + for (int i = 0; i < who.BlockBindings.Length; i++) { + block = who.BlockBindings[i]; + ExtBlock defaultBinding = ExtBlock.FromRaw((byte)i); + if (block == defaultBinding) continue; + + if (!CommandParser.IsBlockAllowed(who, "place", block)) { + who.BlockBindings[i] = defaultBinding; + Player.Message(who, " Hence, binding for &b{0} %Swas unbound", + who.level.BlockName(defaultBinding)); + } + } } - /// Finds the matching name(s) for the input name, + /// Finds the matching name(s) for the input name, /// and requires a confirmation message for non-existent players. - internal static string FindName(Player p, string action, string cmd, + internal static string FindName(Player p, string action, string cmd, string cmdSuffix, string name, ref string reason) { if (!Formatter.ValidName(p, name, "player")) return null; string match = MatchName(p, ref name); @@ -155,7 +178,7 @@ namespace MCGalaxy.Commands.Moderation { } - /// Attempts to either parse the message directly as an IP, + /// Attempts to either parse the message directly as an IP, /// or finds the IP of the account whose name matches the message. /// "@input" can be used to always find IP by matching account name.
/// Warns the player if the input matches both an IP and an account name.
diff --git a/MCGalaxy/Commands/building/CmdBind.cs b/MCGalaxy/Commands/building/CmdBind.cs index b6f97d792..1aba2a0fc 100644 --- a/MCGalaxy/Commands/building/CmdBind.cs +++ b/MCGalaxy/Commands/building/CmdBind.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building { ExtBlock src, dst; if (!CommandParser.GetBlock(p, args[0], out src)) return; if (!CommandParser.GetBlock(p, args[1], out dst)) return; - if (!CommandParser.IsBlockAllowed(p, "bind a block to ", dst)) return; + if (!CommandParser.IsBlockAllowed(p, "bind a block to", dst)) return; if (src.IsPhysicsType) { Player.Message(p, "Physics blocks cannot be bound to another block."); return; } diff --git a/MCGalaxy/Commands/building/CmdMessageBlock.cs b/MCGalaxy/Commands/building/CmdMessageBlock.cs index c1206259a..1727725d0 100644 --- a/MCGalaxy/Commands/building/CmdMessageBlock.cs +++ b/MCGalaxy/Commands/building/CmdMessageBlock.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Building { string block = args[0].ToLower(); data.Block = GetBlock(p, block, ref allMessage); if (data.Block.IsInvalid) return; - if (!CommandParser.IsBlockAllowed(p, "place a message block of ", data.Block)) return; + if (!CommandParser.IsBlockAllowed(p, "place a message block of", data.Block)) return; if (allMessage) { data.Message = message; diff --git a/MCGalaxy/Commands/building/CmdMode.cs b/MCGalaxy/Commands/building/CmdMode.cs index e1a2c1f16..3ca60d178 100644 --- a/MCGalaxy/Commands/building/CmdMode.cs +++ b/MCGalaxy/Commands/building/CmdMode.cs @@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.Building { ExtBlock block; if (!CommandParser.GetBlock(p, message, out block)) return; if (block == ExtBlock.Air) { Player.Message(p, "Cannot use Air Mode."); return; } - if (!CommandParser.IsBlockAllowed(p, "place ", (ExtBlock)block)) return; + if (!CommandParser.IsBlockAllowed(p, "place", block)) return; if (p.ModeBlock == block) { Player.Message(p, "&b{0} %Smode: &cOFF", p.level.BlockName(p.ModeBlock)); diff --git a/MCGalaxy/Commands/building/CmdPlace.cs b/MCGalaxy/Commands/building/CmdPlace.cs index c18e74702..28d82dabb 100644 --- a/MCGalaxy/Commands/building/CmdPlace.cs +++ b/MCGalaxy/Commands/building/CmdPlace.cs @@ -55,7 +55,7 @@ namespace MCGalaxy.Commands.Building { Player.Message(p, "Invalid parameters"); return; } - if (!CommandParser.IsBlockAllowed(p, "place ", block)) return; + if (!CommandParser.IsBlockAllowed(p, "place", block)) return; x = Clamp(x, p.level.Width); y = Clamp(y, p.level.Height); diff --git a/MCGalaxy/Commands/building/CmdPortal.cs b/MCGalaxy/Commands/building/CmdPortal.cs index ea6db1c1c..be3e938c6 100644 --- a/MCGalaxy/Commands/building/CmdPortal.cs +++ b/MCGalaxy/Commands/building/CmdPortal.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building { data.Block = GetBlock(p, block); if (data.Block == ExtBlock.Invalid) return; - if (!CommandParser.IsBlockAllowed(p, "place a portal of ", data.Block)) return; + if (!CommandParser.IsBlockAllowed(p, "place a portal of", data.Block)) return; Player.Message(p, "Place an &aEntry block %Sfor the portal"); p.ClearBlockchange(); diff --git a/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs b/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs index c8a3b7d33..3a602c7b3 100644 --- a/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Drawing.Brushes { GetRaw(parts, filter, args, out blocks, out count); // check if we're allowed to place the held block - if (blocks[0].IsInvalid && !CommandParser.IsBlockAllowed(p, "draw with ", blocks[0])) return null; + if (blocks[0].IsInvalid && !CommandParser.IsBlockAllowed(p, "draw with", blocks[0])) return null; for (int i = 0, j = 0; i < parts.Length; i++ ) { if (parts[i] == "") continue; diff --git a/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs b/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs index b9d2b3238..121fc79bd 100644 --- a/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/ReplaceBrushes.cs @@ -66,7 +66,7 @@ namespace MCGalaxy.Drawing.Brushes { static bool GetTargetBlock(BrushArgs args, string[] parts, out ExtBlock target) { target = default(ExtBlock); if (parts.Length == 1) { - if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return false; + if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return false; target = args.Block; return true; } diff --git a/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs b/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs index 5e093fed9..297dccc90 100644 --- a/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Drawing.Brushes { public override Brush Construct(BrushArgs args) { if (args.Message == "") { - if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return null; + if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null; return new SolidBrush(args.Block); } @@ -61,7 +61,7 @@ namespace MCGalaxy.Drawing.Brushes { public override Brush Construct(BrushArgs args) { if (args.Message == "") { - if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return null; + if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null; return new CheckeredBrush(args.Block, ExtBlock.Air); } string[] parts = args.Message.SplitSpaces(); @@ -125,7 +125,7 @@ namespace MCGalaxy.Drawing.Brushes { public override Brush Construct(BrushArgs args) { if (args.Message == "") { - if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return null; + if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null; return new StripedBrush(args.Block, ExtBlock.Air); } string[] parts = args.Message.SplitSpaces(); diff --git a/MCGalaxy/Games/Countdown/CountdownMapGen.cs b/MCGalaxy/Games/Countdown/CountdownMapGen.cs index ff62bbe66..181d784d4 100644 --- a/MCGalaxy/Games/Countdown/CountdownMapGen.cs +++ b/MCGalaxy/Games/Countdown/CountdownMapGen.cs @@ -19,6 +19,7 @@ using System; namespace MCGalaxy.Games { + /// Generates a map for countdown. public static class CountdownMapGen { public static Level Generate(int width, int height, int length) { @@ -31,7 +32,11 @@ namespace MCGalaxy.Games { MakeSquares(lvl); lvl.permissionvisit = LevelPermission.Guest; - lvl.permissionbuild = LevelPermission.Admin; + lvl.permissionbuild = LevelPermission.Nobody; + lvl.Deletable = false; + lvl.Buildable = false; + lvl.motd = "Welcome to the Countdown map! -hax"; + lvl.spawnx = (ushort)(lvl.Width / 2); lvl.spawny = (ushort)(lvl.Height / 2 + 4); lvl.spawnz = (ushort)(lvl.Length / 2); diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 1171343a9..47fd7b757 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -107,12 +107,11 @@ namespace MCGalaxy { } } + byte blockRaw = block.BlockID; + block = BlockBindings[block.RawID]; if (!CheckManualChange(oldB, block, doDelete)) { RevertBlock(x, y, z); return; } - - byte blockRaw = block.BlockID; - block = BlockBindings[block.RawID]; //Ignores updating blocks that are the same and send block only to the player byte newB = (painting || action == 1) ? block.BlockID : Block.air; @@ -135,10 +134,10 @@ namespace MCGalaxy { internal bool CheckManualChange(byte old, ExtBlock block, bool replaceMode) { if (!BlockPerms.CanModify(this, old) && !Block.BuildIn(old) && !Block.AllowBreak(old)) { - Formatter.MessageBlock(this, replaceMode ? "replace " : "delete ", old); + Formatter.MessageBlock(this, replaceMode ? "replace" : "delete", old); return false; } - return CommandParser.IsBlockAllowed(this, "place ", block); + return CommandParser.IsBlockAllowed(this, "place", block); } bool DeleteBlock(byte old, ushort x, ushort y, ushort z, ExtBlock block) { diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index 78dacb0eb..b1248b33a 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -330,7 +330,7 @@ namespace MCGalaxy { OnPlayerDisconnectEvent.Call(this, discMsg); if (PlayerDisconnect != null) PlayerDisconnect(this, discMsg); - if (Server.AutoLoad && level.unload && !level.IsMuseum && IsAloneOnCurrentLevel()) + if (Server.AutoLoad && level.unload && !level.IsMuseum && !level.HasPlayers()) level.Unload(true); Dispose(); } catch ( Exception e ) { @@ -355,9 +355,6 @@ namespace MCGalaxy { Server.s.Log(name + " kicked (" + chatMsg + "%S)."); } } - - [Obsolete] - public static void SaveUndo(Player p) { } public void Dispose() { connections.Remove(this); @@ -371,16 +368,6 @@ namespace MCGalaxy { spyChatRooms.Clear(); } - public bool IsAloneOnCurrentLevel() { - lock (PlayerInfo.Online.locker) { - Player[] players = PlayerInfo.Online.Items; - foreach (Player p in players) { - if (p != this && p.level == level) return false; - } - return true; - } - } - #endregion #region == OTHER == diff --git a/MCGalaxy/util/Formatting/Formatter.cs b/MCGalaxy/util/Formatting/Formatter.cs index d4508de81..eaad85ad6 100644 --- a/MCGalaxy/util/Formatting/Formatter.cs +++ b/MCGalaxy/util/Formatting/Formatter.cs @@ -96,7 +96,7 @@ namespace MCGalaxy { BlockPerms perms = BlockPerms.List[block]; PrintRanks(perms.MinRank, perms.Allowed, perms.Disallowed, builder); - builder.Append( " %Scan ").Append(action); + builder.Append( " %Scan ").Append(action).Append(' '); builder.Append(Block.Name(block)).Append("."); Player.Message(p, builder.ToString()); }