From 5a748f9e1921697adb69d4a70a34cf7f6dc308ca Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 8 Jul 2018 14:57:13 +1000 Subject: [PATCH] Fix messages sometimes wrongly going to IRC opchannel from chat rewrite --- MCGalaxy/Blocks/Block.Convert.cs | 2 +- MCGalaxy/Chat/Chat.cs | 2 +- MCGalaxy/Chat/ChatTokens.cs | 2 +- MCGalaxy/Commands/Bots/CmdBots.cs | 2 +- MCGalaxy/Commands/CPE/CmdTexture.cs | 2 +- MCGalaxy/Commands/CPE/CustomBlockCommand.cs | 10 +++++----- MCGalaxy/Commands/Fun/WeaponCmd.cs | 4 ++-- MCGalaxy/Commands/Maintenance/CmdBlockDB.cs | 2 +- MCGalaxy/Commands/Moderation/CmdLocation.cs | 2 +- MCGalaxy/Commands/Moderation/ZoneCmds.cs | 4 ++++ MCGalaxy/Commands/World/CmdMap.cs | 2 +- MCGalaxy/Commands/World/CmdPause.cs | 3 ++- MCGalaxy/Commands/World/CmdPhysics.cs | 15 ++++++++------- MCGalaxy/Commands/World/CmdRestore.cs | 12 +++++------- MCGalaxy/Commands/building/CmdDrill.cs | 1 + MCGalaxy/Commands/building/CmdReplaceAll.cs | 1 + MCGalaxy/Commands/building/CmdUndo.cs | 2 +- MCGalaxy/Commands/other/CmdBack.cs | 1 + MCGalaxy/Commands/other/CmdTpA.cs | 1 + MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs | 2 +- MCGalaxy/Network/IRCPlugin/IRCHandlers.cs | 14 ++++++++++---- MCGalaxy/Player/Player.Fields.cs | 2 +- MCGalaxy/Player/Player.Login.cs | 1 + 23 files changed, 52 insertions(+), 37 deletions(-) diff --git a/MCGalaxy/Blocks/Block.Convert.cs b/MCGalaxy/Blocks/Block.Convert.cs index 4eb7c69e6..babb57585 100644 --- a/MCGalaxy/Blocks/Block.Convert.cs +++ b/MCGalaxy/Blocks/Block.Convert.cs @@ -46,7 +46,7 @@ namespace MCGalaxy { } public static BlockID Parse(Player p, string input) { - BlockDefinition[] defs = p == null ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs; + BlockDefinition[] defs = Player.IsSuper(p) ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs; BlockID block; // raw ID is treated specially, before names if (BlockID.TryParse(input, out block)) { diff --git a/MCGalaxy/Chat/Chat.cs b/MCGalaxy/Chat/Chat.cs index 436d725f2..f727ced40 100644 --- a/MCGalaxy/Chat/Chat.cs +++ b/MCGalaxy/Chat/Chat.cs @@ -83,7 +83,7 @@ namespace MCGalaxy { public static bool FilterAll(Player pl, object arg) { return true; } public static bool FilterGlobal(Player pl, object arg) { - return pl.level.SeesServerWideChat && !pl.Ignores.All && pl.Chatroom == null; + return pl.SuperUser || (pl.level.SeesServerWideChat && !pl.Ignores.All && pl.Chatroom == null); } public static bool FilterLevel(Player pl, object arg) { diff --git a/MCGalaxy/Chat/ChatTokens.cs b/MCGalaxy/Chat/ChatTokens.cs index 857d8db83..9f9707e8e 100644 --- a/MCGalaxy/Chat/ChatTokens.cs +++ b/MCGalaxy/Chat/ChatTokens.cs @@ -131,7 +131,7 @@ namespace MCGalaxy { static string TokenPlaytime(Player p) { return p.TotalTime.Shorten(); } static string TokenFirst(Player p) { return p.FirstLogin.ToString(); } static string TokenVisits(Player p) { return p.TimesVisited.ToString(); } - static string TokenKicked(Player p) { return p.TimesBeenKicked.ToString(); } + static string TokenKicked(Player p) { return p.TimesBeenKicked.ToString(); } static string TokenIP(Player p) { return p.ip; } static string TokenModel(Player p) { return p.Model; } static string TokenSkin(Player p) { return p.SkinName; } diff --git a/MCGalaxy/Commands/Bots/CmdBots.cs b/MCGalaxy/Commands/Bots/CmdBots.cs index 25e05c4d1..7ba85a306 100644 --- a/MCGalaxy/Commands/Bots/CmdBots.cs +++ b/MCGalaxy/Commands/Bots/CmdBots.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Bots { public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override void Use(Player p, string message) { - Level lvl = p == null ? null : p.level; + Level lvl = Player.IsSuper(p) ? null : p.level; string[] args = message.SplitSpaces(2); int ignored, offset = 0; diff --git a/MCGalaxy/Commands/CPE/CmdTexture.cs b/MCGalaxy/Commands/CPE/CmdTexture.cs index 0f1dacde9..2e73e684d 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, p.level, "set texture of this level")) return; p.level.Config.Terrain = ""; p.level.Config.TexturePack = ""; diff --git a/MCGalaxy/Commands/CPE/CustomBlockCommand.cs b/MCGalaxy/Commands/CPE/CustomBlockCommand.cs index 8739cd661..a32d37556 100644 --- a/MCGalaxy/Commands/CPE/CustomBlockCommand.cs +++ b/MCGalaxy/Commands/CPE/CustomBlockCommand.cs @@ -87,7 +87,7 @@ namespace MCGalaxy.Commands.CPE { return; } } else { - target = GetFreeBlock(global, p == null ? null : p.level); + target = GetFreeBlock(global, Player.IsSuper(p) ? null : p.level); if (target == Block.Invalid) { Player.Message(p, "There are no custom block ids left, " + "you must " + cmd +" remove a custom block first."); @@ -251,7 +251,7 @@ namespace MCGalaxy.Commands.CPE { if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; } RemoveBlockProps(global, block, p); - BlockDefinition.Remove(def, defs, p == null ? null : p.level); + BlockDefinition.Remove(def, defs, Player.IsSuper(p) ? null : p.level); string scope = global ? "global" : "level"; Player.Message(p, "Removed " + scope + " custom block " + def.Name + "(" + def.BlockID + ")"); @@ -382,7 +382,7 @@ namespace MCGalaxy.Commands.CPE { string value = parts[3], blockName = def.Name; float fTemp; bool temp = false, changedFallback = false; - Level level = p == null ? null : p.level; + Level level = Player.IsSuper(p) ? null : p.level; string arg = MapPropertyName(parts[2].ToLower()); switch (arg) { @@ -515,7 +515,7 @@ namespace MCGalaxy.Commands.CPE { // in case the list is modified before we finish the command. if (old != null) { - block = GetFreeBlock(global, p == null ? null : p.level); + block = GetFreeBlock(global, Player.IsSuper(p) ? null : p.level); if (block == Block.Invalid) { Player.Message(p, "There are no custom block ids left, " + "you must " + cmd + " remove a custom block first."); @@ -531,7 +531,7 @@ namespace MCGalaxy.Commands.CPE { Player.Message(p, "Created a new " + scope + " custom block " + def.Name + "(" + def.BlockID + ")"); block = def.GetBlock(); - BlockDefinition.Add(def, defs, p == null ? null : p.level); + BlockDefinition.Add(def, defs, Player.IsSuper(p) ? null : p.level); UpdateBlockProps(global, p, block, props); return true; } diff --git a/MCGalaxy/Commands/Fun/WeaponCmd.cs b/MCGalaxy/Commands/Fun/WeaponCmd.cs index 6268f0fd5..4fb42c41a 100644 --- a/MCGalaxy/Commands/Fun/WeaponCmd.cs +++ b/MCGalaxy/Commands/Fun/WeaponCmd.cs @@ -23,11 +23,11 @@ using MCGalaxy.Tasks; using BlockID = System.UInt16; namespace MCGalaxy.Commands.Fun { - public abstract class WeaponCmd : Command { - + public abstract class WeaponCmd : Command { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } + public override bool SuperUseable { get { return false; } } protected abstract string Weapon { get; } public override void Use(Player p, string message) { diff --git a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs index 30b95b814..c16a5e601 100644 --- a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs +++ b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Maintenance { string[] args = message.SplitSpaces(); if (args.Length == 1 && Player.IsSuper(p)) { SuperRequiresArgs(p, "map name"); return; } - Level lvl = p == null ? null : p.level; + Level lvl = Player.IsSuper(p) ? null : p.level; if (args.Length > 1) { lvl = Matcher.FindLevels(p, args[1]); if (lvl == null) return; diff --git a/MCGalaxy/Commands/Moderation/CmdLocation.cs b/MCGalaxy/Commands/Moderation/CmdLocation.cs index c4517eb1b..acf511210 100644 --- a/MCGalaxy/Commands/Moderation/CmdLocation.cs +++ b/MCGalaxy/Commands/Moderation/CmdLocation.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Moderation { public override void Use(Player p, string message) { if (message.Length == 0) { - if (Player.IsSuper(p)) { SuperRequiresArgs(p, "name"); return; } + if (Player.IsSuper(p)) { SuperRequiresArgs(p, "player name"); return; } message = p.name; } diff --git a/MCGalaxy/Commands/Moderation/ZoneCmds.cs b/MCGalaxy/Commands/Moderation/ZoneCmds.cs index fe0f21bc7..a9f14b6fd 100644 --- a/MCGalaxy/Commands/Moderation/ZoneCmds.cs +++ b/MCGalaxy/Commands/Moderation/ZoneCmds.cs @@ -27,6 +27,7 @@ namespace MCGalaxy.Commands.Moderation { public override string name { get { return "Zone"; } } public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return false; } } + public override bool SuperUseable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("ZRemove", "del"), new CommandAlias("ZDelete", "del"), @@ -181,6 +182,7 @@ namespace MCGalaxy.Commands.Moderation { public override string name { get { return "ZoneTest"; } } public override string shortcut { get { return "ZTest"; } } public override string type { get { return CommandTypes.Moderation; } } + public override bool SuperUseable { get { return false; } } public override void Use(Player p, string message) { Player.Message(p, "Place or delete a block where you would like to check for zones."); @@ -216,6 +218,7 @@ namespace MCGalaxy.Commands.Moderation { public override string name { get { return "ZoneList"; } } public override string shortcut { get { return "Zones"; } } public override string type { get { return CommandTypes.Moderation; } } + public override bool SuperUseable { get { return false; } } public override bool UseableWhenFrozen { get { return true; } } public override void Use(Player p, string message) { @@ -239,6 +242,7 @@ namespace MCGalaxy.Commands.Moderation { public override string shortcut { get { return "ZMark"; } } public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return false; } } + public override bool SuperUseable { get { return false; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("zm") }; } } diff --git a/MCGalaxy/Commands/World/CmdMap.cs b/MCGalaxy/Commands/World/CmdMap.cs index 06196d0eb..f46d016ad 100644 --- a/MCGalaxy/Commands/World/CmdMap.cs +++ b/MCGalaxy/Commands/World/CmdMap.cs @@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World { string optName = null, value = null; if (IsMapOption(args)) { - if (Player.IsSuper(p)) { SuperRequiresArgs(p, "level"); return; } + if (Player.IsSuper(p)) { SuperRequiresArgs(p, "level name"); return; } lvl = p.level; optName = args[0]; diff --git a/MCGalaxy/Commands/World/CmdPause.cs b/MCGalaxy/Commands/World/CmdPause.cs index ab6b3e46c..21ecf1584 100644 --- a/MCGalaxy/Commands/World/CmdPause.cs +++ b/MCGalaxy/Commands/World/CmdPause.cs @@ -26,7 +26,8 @@ namespace MCGalaxy.Commands.World { public override void Use(Player p, string message) { int seconds = 30; - Level lvl = p != null ? p.level : Server.mainLevel; + Level lvl = Player.IsSuper(p) ? Server.mainLevel : p.level; + if (message.Length > 0) { string[] parts = message.SplitSpaces(); if (parts.Length == 1) { diff --git a/MCGalaxy/Commands/World/CmdPhysics.cs b/MCGalaxy/Commands/World/CmdPhysics.cs index ecba615d3..e233796e3 100644 --- a/MCGalaxy/Commands/World/CmdPhysics.cs +++ b/MCGalaxy/Commands/World/CmdPhysics.cs @@ -30,17 +30,18 @@ namespace MCGalaxy.Commands.World { if (message.CaselessEq("kill")) { KillPhysics(p); return; } string[] args = message.SplitSpaces(); - Level level = p != null ? p.level : Server.mainLevel; - int state = 0, stateIndex = args.Length == 1 ? 0 : 1; - if (!CommandParser.GetInt(p, args[stateIndex], "Physics state", ref state, 0, 5)) return; + Level lvl = Player.IsSuper(p) ? Server.mainLevel : p.level; + + int state = 0, stateI = args.Length == 1 ? 0 : 1; + if (!CommandParser.GetInt(p, args[stateI], "Physics state", ref state, 0, 5)) return; if (args.Length == 2) { - level = Matcher.FindLevels(p, args[0]); - if (level == null) return; + lvl = Matcher.FindLevels(p, args[0]); + if (lvl == null) return; } - if (!LevelInfo.ValidateAction(p, level, "set physics of this level")) return; - SetPhysics(level, state); + if (!LevelInfo.ValidateAction(p, lvl, "set physics of this level")) return; + SetPhysics(lvl, state); } internal static string[] states = new string[] { "&cOFF", "&aNormal", "&aAdvanced", diff --git a/MCGalaxy/Commands/World/CmdRestore.cs b/MCGalaxy/Commands/World/CmdRestore.cs index 0a7c99d90..665157963 100644 --- a/MCGalaxy/Commands/World/CmdRestore.cs +++ b/MCGalaxy/Commands/World/CmdRestore.cs @@ -36,12 +36,10 @@ namespace MCGalaxy.Commands.World { lvl = Matcher.FindLevels(p, args[1]); if (lvl == null) return; } else { - if (p != null && p.level != null) { - lvl = p.level; - } else { - Player.Message(p, "You must provide a level name when using /restore from console."); - return; + if (Player.IsSuper(p)) { + SuperRequiresArgs(p, "level name"); return; } + lvl = p.level; } if (!LevelInfo.ValidateAction(p, lvl, "restore a backup of this level")) return; @@ -98,9 +96,9 @@ namespace MCGalaxy.Commands.World { public override void Help(Player p) { Player.Message(p, "%T/Restore %H- lists all backups for the current map"); - Player.Message(p, "%T/Restore [number] [name]"); + Player.Message(p, "%T/Restore [number] "); Player.Message(p, "%HRestores a previous backup for the given map."); - Player.Message(p, "%H If [name] is not given, your current map is used."); + Player.Message(p, "%H If is not given, your current map is used."); } } } diff --git a/MCGalaxy/Commands/building/CmdDrill.cs b/MCGalaxy/Commands/building/CmdDrill.cs index 4c965a414..0e5e6b91a 100644 --- a/MCGalaxy/Commands/building/CmdDrill.cs +++ b/MCGalaxy/Commands/building/CmdDrill.cs @@ -26,6 +26,7 @@ namespace MCGalaxy.Commands.Building { public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } + public override bool SuperUseable { get { return false; } } public override void Use(Player p, string message) { ushort dist = 20; diff --git a/MCGalaxy/Commands/building/CmdReplaceAll.cs b/MCGalaxy/Commands/building/CmdReplaceAll.cs index 9aff5c7c6..93009f576 100644 --- a/MCGalaxy/Commands/building/CmdReplaceAll.cs +++ b/MCGalaxy/Commands/building/CmdReplaceAll.cs @@ -27,6 +27,7 @@ namespace MCGalaxy.Commands.Building { public override string shortcut { get { return "ra"; } } public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return false; } } + public override bool SuperUseable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } public override void Use(Player p, string message) { diff --git a/MCGalaxy/Commands/building/CmdUndo.cs b/MCGalaxy/Commands/building/CmdUndo.cs index 28741bc6b..74413adf1 100644 --- a/MCGalaxy/Commands/building/CmdUndo.cs +++ b/MCGalaxy/Commands/building/CmdUndo.cs @@ -109,7 +109,7 @@ namespace MCGalaxy.Commands.Building { internal static TimeSpan GetDelta(Player p, string name, string[] parts, int offset) { TimeSpan delta = TimeSpan.Zero; string timespan = parts.Length > offset ? parts[parts.Length - 1] : "30m"; - bool canAll = p == null || p.name.CaselessEq(name) || p.group.MaxUndo == undoMax; + bool canAll = p == null || p.name.CaselessEq(name) || p.group.MaxUndo == undoMax; if (timespan.CaselessEq("all")) { return TimeSpan.FromSeconds(canAll ? int.MaxValue : p.group.MaxUndo); diff --git a/MCGalaxy/Commands/other/CmdBack.cs b/MCGalaxy/Commands/other/CmdBack.cs index cdf15414d..e5d78246f 100644 --- a/MCGalaxy/Commands/other/CmdBack.cs +++ b/MCGalaxy/Commands/other/CmdBack.cs @@ -19,6 +19,7 @@ namespace MCGalaxy.Commands.Misc { public sealed class CmdBack : Command { public override string name { get { return "Back"; } } public override string type { get { return CommandTypes.Other; } } + public override bool SuperUseable { get { return false; } } public override void Use(Player p, string message) { if (p.PreTeleportMap == null) { diff --git a/MCGalaxy/Commands/other/CmdTpA.cs b/MCGalaxy/Commands/other/CmdTpA.cs index 9e8a1afa7..46d1329ce 100644 --- a/MCGalaxy/Commands/other/CmdTpA.cs +++ b/MCGalaxy/Commands/other/CmdTpA.cs @@ -22,6 +22,7 @@ namespace MCGalaxy.Commands.Misc { public sealed class CmdTpA : Command { public override string name { get { return "TPA"; } } public override string type { get { return CommandTypes.Other; } } + public override bool SuperUseable { get { return false; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("TPAccept", "accept"), new CommandAlias("TPDeny", "deny") }; } } diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs index 2f8fe542d..0f971e69a 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs @@ -55,7 +55,7 @@ namespace MCGalaxy.Games { Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { - if (p.level == null || p.level != Map || p.Game.Referee) continue; + if (p.level != Map || p.Game.Referee) continue; Alive.Add(p); } Infected.Clear(); diff --git a/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs b/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs index 79ad6a1c8..0dd7405eb 100644 --- a/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs +++ b/MCGalaxy/Network/IRCPlugin/IRCHandlers.cs @@ -32,9 +32,10 @@ namespace MCGalaxy.Network { readonly IRCBot bot; readonly Player ircGuest = new Player("IRC"); + readonly Player ircOp = new Player("IRC"); - public IRCHandlers(IRCBot bot) { - this.bot = bot; + public IRCHandlers(IRCBot bot) { + this.bot = bot; ircGuest.group = Group.GuestRank; } @@ -131,8 +132,12 @@ namespace MCGalaxy.Network { if (scopeFilter(ircGuest, arg) && (filter == null || filter(ircGuest, arg))) { bot.Say(msg, false); } else { - // TODO: Check filters!!!!! - bot.Say(msg, true); + ircOp.group = Group.Find(ServerConfig.IRCControllerRank); + if (ircOp.group == null) ircOp.group = Group.NobodyRank; + + if (scopeFilter(ircOp, arg) && (filter == null || filter(ircOp, arg))) { + bot.Say(msg, true); + } } } @@ -291,6 +296,7 @@ namespace MCGalaxy.Network { cmd.Use(p, cmdArgs); } catch (Exception ex) { Player.Message(p, "CMD Error: " + ex); + Logger.LogError(ex); } return true; } diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 7ad3e6a1b..ff168d8c8 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -181,7 +181,7 @@ namespace MCGalaxy { public DateTime lastCmdTime; public sbyte c4circuitNumber = -1; - public Level level = Server.mainLevel; + public Level level; public bool Loading = true; //True if player is loading a map. internal int UsingGoto = 0, GeneratingMap = 0, LoadingMuseum = 0, UsingDelay = 0; public Vec3U16 lastClick = Vec3U16.Zero; diff --git a/MCGalaxy/Player/Player.Login.cs b/MCGalaxy/Player/Player.Login.cs index 1872e9859..e69f834dd 100644 --- a/MCGalaxy/Player/Player.Login.cs +++ b/MCGalaxy/Player/Player.Login.cs @@ -44,6 +44,7 @@ namespace MCGalaxy { if (cancelconnecting) { cancelconnecting = false; return; } hasCpe = buffer[offset + 130] == 0x42 && ServerConfig.EnableCPE; + level = Server.mainLevel; Loading = true; if (disconnected) return;