#region Arthea License /*********************************************************************** * Arthea MUD by R. Jennings (2007) http://arthea.googlecode.com/ * * By using this code you comply with the Artistic and GPLv2 Licenses. * ***********************************************************************/ #endregion using System; using Arthea.Connections.Players; using Arthea.Environment; namespace Arthea.Commands.Admin { /// <summary> /// Implements admin powers. /// </summary> public enum Powers { /// <summary> /// can save the world /// </summary> Save, /// <summary> /// can see ids and other useful info /// </summary> HolyLight, /// <summary> /// admins get bugs reported to them /// </summary> BugNet } /// <summary> /// Implementation of a grant command. /// </summary> public class GrantCommand : Command { #region [rgn] Constructors (1) /// <summary> /// Initializes a new instance of the <see cref="GrantCommand"/> class. /// </summary> public GrantCommand() : base("grant", "grants various powers for administrators", Levels.Admin) { } #endregion [rgn] #region [rgn] Methods (2) // [rgn] Public Methods (2) /// <summary> /// Processes the command for a player. /// </summary> /// <param name="player">The player.</param> /// <param name="argument">The argument.</param> public override void Process(Player player, String argument) { if (!argument) { player.WriteLine("Grant who what?"); return; } String arg = argument.FirstArg(); Player admin = Lists.Players.FindName(arg); if (admin == null) { player.WriteLine("No such admin."); return; } if (admin.Level != Levels.Admin) { player.WriteLine("{0} is not an admin.", admin.Name); return; } try { Powers power = (Powers) Enum.Parse(typeof (Powers), argument, true); if (admin.Powers[power]) { admin.Powers.Remove(power); player.WriteLine("You revoke the {0} power from {1}.", power, admin); player.Act(null, admin, Act.ToVictim, "You no longer have access to the {0} power.", power); } else { admin.Powers.Add(power); player.WriteLine("You grant {0} the {1} power.", admin, power); player.Act(null, admin, Act.ToVictim, "You have been granted access to the {0} power.", power); } } catch { Command cmd = Lists.Commands.FindName(argument); if (cmd == null || cmd.Level != Levels.Admin) { player.WriteLine("That is not an admin command."); ValidPowers(player); return; } if (admin.Powers[cmd]) { admin.Powers.Remove(cmd); player.WriteLine("You revoke the {0} command from {1}.", cmd, admin); player.Act(null, admin, Act.ToVictim, "You no longer have access to the {0} command.", cmd); } else { admin.Powers.Add(cmd); player.WriteLine("You grant {0} the {1} command.", admin, cmd); player.Act(null, admin, Act.ToVictim, "You have been granted access to the {0} command.", cmd); } } } /// <summary> /// Displays powers to a player. /// </summary> /// <param name="player">The player.</param> public static void ValidPowers(Player player) { player.WriteLine(); player.WriteLine("Powers:"); Columns.Show(player, 5, 10, Enum.GetNames(typeof (Powers))); player.WriteLine(); player.WriteLine("Commands:"); Columns.Show(player, 5, 10, Lists.Commands.FindAdmin()); } #endregion [rgn] } }