From 51fa8002df0b155b006f2cd42650b960a05b7bc2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 26 Jun 2016 11:07:58 +1000 Subject: [PATCH] Add /irccontrollers rank [rank] to set rank of IRC controllers, make server.properties saving threadsafe, make default rank of pass/setpass operator. --- Commands/Information/CmdLevels.cs | 2 +- Commands/Moderation/CmdIrcControllers.cs | 42 +++++++++++++++++++++--- Commands/other/CmdPass.cs | 11 +++---- Commands/other/CmdSetPass.cs | 11 +++---- Config/Properties.cs | 8 +++-- Network/ClassiCube.cs | 2 +- Network/IBeat.cs | 2 +- Server/Extra/Heart.cs | 2 +- 8 files changed, 56 insertions(+), 24 deletions(-) diff --git a/Commands/Information/CmdLevels.cs b/Commands/Information/CmdLevels.cs index e948f2eb6..05eb0cf8e 100644 --- a/Commands/Information/CmdLevels.cs +++ b/Commands/Information/CmdLevels.cs @@ -1,5 +1,5 @@ /* - Copyright 2012 MCGalaxy + Copyright 2012 MCForge Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may diff --git a/Commands/Moderation/CmdIrcControllers.cs b/Commands/Moderation/CmdIrcControllers.cs index 39023e141..f02090ccd 100644 --- a/Commands/Moderation/CmdIrcControllers.cs +++ b/Commands/Moderation/CmdIrcControllers.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; namespace MCGalaxy.Commands { - public sealed class CmdIrcControllers : Command { + public sealed class CmdIrcControllers : Command { public override string name { get { return "irccontrollers"; } } public override string shortcut { get { return "ircctrl"; } } public override string type { get { return CommandTypes.Moderation; } } @@ -36,6 +36,7 @@ namespace MCGalaxy.Commands { Server.ircControllers = PlayerList.Load("IRC_Controllers.txt"); Player.Message(p, "IRC Controllers reloaded!"); break; + case "add": if (parts.Length < 2) { Player.Message(p, "You need to provide a name to add."); return; } if (Server.ircControllers.Contains(parts[1])) { @@ -46,6 +47,7 @@ namespace MCGalaxy.Commands { Server.ircControllers.Save(); Player.Message(p, parts[1] + " added to the IRC controller list."); break; + case "remove": if (parts.Length < 2) { Player.Message(p, "You need to provide a name to remove."); return; } if (!Server.ircControllers.Contains(parts[1])) { @@ -56,19 +58,49 @@ namespace MCGalaxy.Commands { Server.ircControllers.Save(); Player.Message(p, parts[1] + " removed from the IRC controller list."); break; + case "list": string names = Server.ircControllers.All().Concatenate(", "); Player.Message(p, "IRC controllers list:"); Player.Message(p, names); break; - } + + case "rank": + if (parts.Length < 2) { + Group exist = Group.findPerm(Server.ircControllerRank); + if (exist == null) + Player.Message(p, "IRC controllers have permission level {0}.", (int)Server.ircControllerRank); + else + Player.Message(p, "IRC controllers have the rank {0}", exist.ColoredName); + return; + } + + Group grp = Group.FindOrShowMatches(p, parts[1]); + if (grp == null) return; + if (p != null && Server.ircControllerRank > p.group.Permission) { + Player.Message(p, "Cannot change the IRC controllers rank, as it is currently a rank higher than yours."); return; + } + if (p != null && grp.Permission > p.group.Permission) { + Player.Message(p, "Cannot set the IRC controllers rank to a rank higher than yours."); return; + } + + Server.ircControllerRank = grp.Permission; + SrvProperties.Save(); + Player.Message(p, "Set IRC controller rank to {0}%S.", grp.ColoredName); + break; + + default: + Help(p); break; + } } public override void Help(Player p) { - Player.Message(p, "%T/ircctrl [name]"); - Player.Message(p, "%HAdds or removes from list of IRC controllers"); - Player.Message(p, "%T/ircctrl "); + Player.Message(p, "%T/irccontrollers [name]"); + Player.Message(p, "%HAdds or removes [name] from list of IRC controllers"); + Player.Message(p, "%T/irccontrollers "); Player.Message(p, "%HReloads or outputslist of IRC controllers"); + Player.Message(p, "%T/irccontrollers rank [rank]"); + Player.Message(p, "%HSets which rank IRC controllers are treated as having in-game."); } } } diff --git a/Commands/other/CmdPass.cs b/Commands/other/CmdPass.cs index 9ec14120c..929389910 100644 --- a/Commands/other/CmdPass.cs +++ b/Commands/other/CmdPass.cs @@ -1,6 +1,6 @@ /* - Copyright 2012 MCGalaxy + Copyright 2012 MCForge Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may @@ -20,15 +20,14 @@ using System; using System.IO; using MCGalaxy.Util; -namespace MCGalaxy.Commands -{ - public sealed class CmdPass : Command - { + +namespace MCGalaxy.Commands { + public sealed class CmdPass : Command { public override string name { get { return "pass"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } + public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdPass() { } diff --git a/Commands/other/CmdSetPass.cs b/Commands/other/CmdSetPass.cs index 517612709..b68dfd785 100644 --- a/Commands/other/CmdSetPass.cs +++ b/Commands/other/CmdSetPass.cs @@ -1,6 +1,6 @@ /* - Copyright 2012 MCGalaxy + Copyright 2012 MCForge Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may @@ -19,15 +19,14 @@ using System; using System.IO; using MCGalaxy.Util; -namespace MCGalaxy.Commands -{ - public sealed class CmdSetPass : Command - { + +namespace MCGalaxy.Commands { + public sealed class CmdSetPass : Command { public override string name { get { return "setpass"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } + public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdSetPass() { } public override void Use(Player p, string message) diff --git a/Config/Properties.cs b/Config/Properties.cs index ec81fa8e4..c7a7d085c 100644 --- a/Config/Properties.cs +++ b/Config/Properties.cs @@ -70,11 +70,13 @@ namespace MCGalaxy { internal class ReviewPerms { public int viewPerm = -1, nextPerm = -1, clearPerm = -1; } public static void Save() { Save("properties/server.properties"); } - + static readonly object saveLock = new object(); public static void Save(string givenPath) { try { - using (CP437Writer w = new CP437Writer(givenPath)) - SaveProps(w); + lock (saveLock) { + using (CP437Writer w = new CP437Writer(givenPath)) + SaveProps(w); + } } catch (Exception ex) { Server.ErrorLog(ex); Server.s.Log("SAVE FAILED! " + givenPath); diff --git a/Network/ClassiCube.cs b/Network/ClassiCube.cs index ba4e63ce0..d7a85a740 100644 --- a/Network/ClassiCube.cs +++ b/Network/ClassiCube.cs @@ -1,5 +1,5 @@ /* - Copyright 2012 MCGalaxy + Copyright 2012 MCForge Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may diff --git a/Network/IBeat.cs b/Network/IBeat.cs index 94c533328..f70edb3da 100644 --- a/Network/IBeat.cs +++ b/Network/IBeat.cs @@ -1,5 +1,5 @@ /* - Copyright 2012 MCGalaxy + Copyright 2012 MCForge Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may diff --git a/Server/Extra/Heart.cs b/Server/Extra/Heart.cs index 9bcf471a7..6757a43a5 100644 --- a/Server/Extra/Heart.cs +++ b/Server/Extra/Heart.cs @@ -1,5 +1,5 @@ /* - Copyright 2012 MCGalaxy + Copyright 2012 MCForge Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may