A text scanner that aids parsing chat commands and their arguments. Breaks up a message into tokens at spaces. Treats quoted strings as whole tokens.
Inheritance: ICloneable
		public static void SetParamIteration(Player p, CommandReader cmd)
		{
			string strParam = cmd.Next();
			if (string.IsNullOrWhiteSpace(strParam))
			{
				p.Message("Error: missing param variable name");
				return;
			}

			strParam = strParam.ToLower();

			try
			{
				CheckParamVar(strParam);

				double from = ReadDoubleParam(cmd, "lower bound");
				double to = ReadDoubleParam(cmd, "upper bound");
				double step = ReadDoubleParam(cmd, "step");

				if (step == 0 ||
				    (to - from)/step < 0)
					throw new ArgumentException("wrong iteration bounds/step combination");

				p.Message("Iteration for " + strParam + " from " + from + " to " + to + " with step " + step + ". " +
				          ((to - from)/step + 1) + " steps.");

				GetPlayerParametrizationParamsStorage(p)[VarNameToIdx(strParam[0])] = new double[] {from, to, step};
			}
			catch (Exception e)
			{
				p.Message("Error: " + e.Message);
			}
		}
示例#2
1
        static void SayHandler(Player player, CommandReader cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.DetectChatSpam()) return;

            if (player.Can(Permission.Say))
            {
                string msg = cmd.NextAll().Trim();
                if (msg.Length > 0)
                {
                    Chat.SendSay(player, msg);
                }
                else
                {
                    CdSay.PrintUsage(player);
                }
            }
            else
            {
                player.MessageNoAccess(Permission.Say);
            }
        }
示例#3
0
 static void BanHandler( Player player, CommandReader cmd ) {
     string targetName = cmd.Next();
     if( targetName == null ) {
         CdBan.PrintUsage( player );
         return;
     }
     PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches( player,
                                                                targetName,
                                                                SearchOptions.ReturnSelfIfOnlyMatch );
     if( target == null ) return;
     if( target == player.Info ) {
         player.Message( "You cannot &H/Ban&S yourself." );
         return;
     }
     string reason = cmd.NextAll();
     try {
         Player targetPlayer = target.PlayerObject;
         target.Ban( player, reason, true, true );
         WarnIfOtherPlayersOnIP( player, target, targetPlayer );
     } catch( PlayerOpException ex ) {
         player.Message( ex.MessageColored );
         if( ex.ErrorCode == PlayerOpExceptionCode.ReasonRequired ) {
             FreezeIfAllowed( player, target );
         }
     }
 }
示例#4
0
 static void BumHandler(Player player, CommandReader cmd)
 {
     string newModeName = cmd.Next();
     if (newModeName == null)
     {
         player.Message("&sBytes Sent: {0}  Per Second: {1:0.0}", player.BytesSent, player.BytesSentRate);
         player.Message("&sBytes Received: {0}  Per Second: {1:0.0}", player.BytesReceived, player.BytesReceivedRate);
         player.Message("&sBandwidth mode: {0}",player.BandwidthUseMode);
                         
                         
                         
         return;
     }
     else if (player.Can(Permission.EditPlayerDB))
     {
         var newMode = (BandwidthUseMode)Enum.Parse(typeof(BandwidthUseMode), newModeName, true);
         player.Message("&sBandwidth mode: {0} --> {1}", player.BandwidthUseMode, newMode.ToString());
         player.BandwidthUseMode = newMode;
         player.Info.BandwidthUseMode = newMode;
         return;
     }
     else
     {
         player.Message("You need {0}&s to change your BandwidthUseMode", RankManager.GetMinRankWithAnyPermission(Permission.EditPlayerDB).ClassyName);
         return;
     }
     
 }
		public static void SetParametrization(Player p, CommandReader cmd)
		{
			string strFunc = cmd.Next();
			if (string.IsNullOrWhiteSpace(strFunc))
			{
				p.Message("Error: empty parametrization expression");
				return;
			}
			if (strFunc.Length < 3)
			{
				p.Message("Error: expression is too short (should be like x=f(t,u,v))");
				return;
			}

			strFunc = strFunc.ToLower();

			try
			{
				string coordVar = SimpleParser.PreparseAssignment(ref strFunc);
				CheckCoordVar(coordVar);

				Expression expression = SimpleParser.Parse(strFunc, new string[] { "t", "u", "v" });

				p.Message("Expression parsed as " + coordVar + "=" + expression.Print());

				GetPlayerParametrizationCoordsStorage(p)[VarNameToIdx(coordVar[0])] = expression;
			}
			catch (Exception e)
			{
				p.Message("Error: "+e.Message);
			}
		}
示例#6
0
		protected FuncDrawOperation(Player player, CommandReader cmd)
			: base(player)
        {
			string strFunc = cmd.Next();
            if (string.IsNullOrWhiteSpace(strFunc))
            {
                player.Message("&WEmpty function expression");
                return;
            }
            if (strFunc.Length < 3)
            {
                player.Message("&WExpression is too short (should be like z=f(x,y))");
                return;
            }
			
			strFunc = strFunc.ToLower();

			_vaxis = GetAxis(SimpleParser.PreparseAssignment(ref strFunc));

			_expression = SimpleParser.Parse(strFunc, GetVarArray(_vaxis));
			
			player.Message("Expression parsed as "+_expression.Print());
			string scalingStr=cmd.Next();
			_scaler = new Scaler(scalingStr);
        }
示例#7
0
        private static void TrollHandler( Player player, CommandReader cmd ) {
            string Name = cmd.Next();
            if ( Name == null ) {
                player.Message( "Player not found. Please specify valid name." );
                return;
            }
            if ( !Player.IsValidPlayerName( Name ) )
                return;
            Player target = Server.FindPlayerOrPrintMatches( player, Name, SearchOptions.Default );
            if ( target == null )
                return;
            string options = cmd.Next();
            if ( options == null ) {
                CdTroll.PrintUsage( player );
                return;
            }
            string Message = cmd.NextAll();
            if ( Message.Length < 1 && options.ToLower() != "leave" ) {
                player.Message( "&WError: Please enter a message for {0}.", target.ClassyName );
                return;
            }
            switch ( options.ToLower() ) {
                case "pm":
                    if ( player.Can( Permission.UseColorCodes ) && Message.Contains( "%" ) ) {
                        Message = Chat.ReplacePercentColorCodes( Message, false );
                    }
                    Server.Players.Message( "&Pfrom {0}: {1}",
                        target.Name, Message );
                    break;

                case "st":
                case "staff":
                    Chat.SendStaff( target, Message );
                    break;

                case "i":
                case "impersonate":
                case "msg":
                case "message":
                case "m":
                    Server.Message( "{0}&S&F: {1}",
                                      target.ClassyName, Message );
                    break;

                case "leave":
                case "disconnect":
                case "gtfo":
                    Server.Players.Message( "&SPlayer {0}&S left the server.",
                        target.ClassyName );
                    break;

                default:
                    player.Message( "Invalid option. Please choose st, ac, pm, message or leave" );
                    break;
            }
        }
示例#8
0
        public override MapGeneratorParameters CreateParameters(Player player, CommandReader cmd)
        {
            string themeName = cmd.Next();

            if (themeName == null)
            {
                return(CreateDefaultParameters());
            }

            MapGenTheme theme;
            RealisticMapGenTerrainType terrainType;

            string templateName = cmd.Next();

            if (templateName == null)
            {
                player.Message("SetGen: Realistic MapGen requires both a theme and a terrainType. " +
                               "See &H/Help SetGen Realistic&S or check wiki.fCraft.net for details");
                return(null);
            }

            // parse theme
            bool swapThemeAndTemplate;

            if (EnumUtil.TryParse(themeName, out theme, true))
            {
                swapThemeAndTemplate = false;
            }
            else if (EnumUtil.TryParse(templateName, out theme, true))
            {
                swapThemeAndTemplate = true;
            }
            else
            {
                player.Message("SetGen: Unrecognized theme \"{0}\". Available themes are: {1}",
                               themeName,
                               Enum.GetNames(typeof(MapGenTheme)).JoinToString());
                return(null);
            }

            // parse terrainType
            if (swapThemeAndTemplate && !EnumUtil.TryParse(themeName, out terrainType, true))
            {
                MessageTemplateList(themeName, player);
                return(null);
            }
            else if (!EnumUtil.TryParse(templateName, out terrainType, true))
            {
                MessageTemplateList(templateName, player);
                return(null);
            }

            // TODO: optional parameters for preset customization
            return(CreateParameters(terrainType, theme));
        }
示例#9
0
        static void RollHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.DetectChatSpam())
            {
                return;
            }

            Random rand = new Random();
            int    n1;
            int    min, max;

            if (cmd.NextInt(out n1))
            {
                int n2;
                if (!cmd.NextInt(out n2))
                {
                    n2 = 1;
                }
                min = Math.Min(n1, n2);
                max = Math.Max(n1, n2);
            }
            else
            {
                min = 1;
                max = 100;
            }
            if (max == Int32.MaxValue - 1)
            {
                player.Message("Roll: Given values must be between {0} and {1}",
                               Int32.MinValue,
                               Int32.MaxValue - 1);
                return;
            }

            int num = rand.Next(min, max + 1);

            Server.Message(player,
                           "{0}{1} rolled {2} ({3}...{4})",
                           player.ClassyName,
                           ChatColor.Silver,
                           num,
                           min,
                           max);
            player.Message("{0}You rolled {1} ({2}...{3})",
                           ChatColor.Silver,
                           num,
                           min,
                           max);
        }
示例#10
0
        static void MassRankHandler(Player player, CommandReader cmd)
        {
            string fromRankName = cmd.Next();
            string toRankName   = cmd.Next();
            string reason       = cmd.NextAll();

            if (fromRankName == null || toRankName == null)
            {
                CdMassRank.PrintUsage(player);
                return;
            }

            Rank fromRank = RankManager.FindRank(fromRankName);

            if (fromRank == null)
            {
                player.MessageNoRank(fromRankName);
                return;
            }

            Rank toRank = RankManager.FindRank(toRankName);

            if (toRank == null)
            {
                player.MessageNoRank(toRankName);
                return;
            }

            if (fromRank == toRank)
            {
                player.Message("Ranks must be different");
                return;
            }

            int playerCount;

            using (PlayerDB.GetReadLock()) {
                playerCount = PlayerDB.List.Count(t => t.Rank == fromRank);
            }
            string verb = (fromRank > toRank ? "demot" : "promot");

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "MassRank: {0}e {1} players?", verb.UppercaseFirst(), playerCount);
                return;
            }

            player.Message("MassRank: {0}ing {1} players...",
                           verb, playerCount);

            int affected = PlayerDB.MassRankChange(player, fromRank, toRank, reason);

            player.Message("MassRank: done, {0} records affected.", affected);
        }
示例#11
0
 /// <summary> Creates a copy of an existing command. </summary>
 public CommandReader([NotNull] CommandReader other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     Offset      = other.Offset;
     Descriptor  = other.Descriptor;
     RawMessage  = other.RawMessage;
     Name        = other.Name;
     IsConfirmed = other.IsConfirmed;
 }
示例#12
0
        /// <summary> Parses and calls a specified command. </summary>
        /// <param name="player"> Player who issued the command. </param>
        /// <param name="cmd"> Command to be parsed and executed. </param>
        /// <param name="fromConsole"> Whether this command is being called from a non-player (e.g. Console). </param>
        /// <returns> True if the command was called, false if something prevented it from being called. </returns>
        public static bool ParseCommand([NotNull] Player player, [NotNull] CommandReader cmd, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            CommandDescriptor descriptor = GetDescriptor(cmd.Name, true);

            if (descriptor == null)
            {
                player.Message("Unknown command \"{0}\". See &H/Commands", cmd.Name);
                return(false);
            }

            if (!descriptor.IsConsoleSafe && fromConsole)
            {
                player.Message("You cannot use this command from console.");
            }
            else
            {
                if (descriptor.Permissions != null)
                {
                    if (!descriptor.CanBeCalledBy(player.Info.Rank))
                    {
                        player.MessageNoAccess(descriptor);
                    }
                    else if (!descriptor.Call(player, cmd, true))
                    {
                        player.Message("Command was canceled.");
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    if (descriptor.Call(player, cmd, true))
                    {
                        return(true);
                    }
                    else
                    {
                        player.Message("Command was canceled.");
                    }
                }
            }
            return(false);
        }
示例#13
0
        static void CopySlotHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            int slotNumber;

            if (cmd.NextInt(out slotNumber))
            {
                if (cmd.HasNext)
                {
                    CdCopySlot.PrintUsage(player);
                    return;
                }
                if (slotNumber < 1 || slotNumber > player.Info.Rank.CopySlots)
                {
                    player.Message("CopySlot: Select a number between 1 and {0}", player.Info.Rank.CopySlots);
                }
                else
                {
                    player.CopySlot = slotNumber - 1;
                    CopyState info = player.GetCopyState();
                    if (info == null)
                    {
                        player.Message("Selected copy slot {0} (unused).", slotNumber);
                    }
                    else
                    {
                        player.Message("Selected copy slot {0}: {1} blocks from {2}, {3} old.",
                                       slotNumber,
                                       info.Blocks.Length,
                                       info.OriginWorld,
                                       DateTime.UtcNow.Subtract(info.CopyTime).ToMiniString());
                    }
                }
            }
            else
            {
                CopyState[] slots = player.CopyStates;
                player.Message("Using {0} of {1} slots. Selected slot: {2}",
                               slots.Count(info => info != null),
                               player.Info.Rank.CopySlots,
                               player.CopySlot + 1);
                for (int i = 0; i < slots.Length; i++)
                {
                    if (slots[i] != null)
                    {
                        player.Message("  {0}: {1} blocks from {2}, {3} old",
                                       i + 1,
                                       slots[i].Blocks.Length,
                                       slots[i].OriginWorld,
                                       DateTime.UtcNow.Subtract(slots[i].CopyTime).ToMiniString());
                    }
                }
            }
        }
示例#14
0
        /// <summary> Parses and calls a specified command. </summary>
        /// <param name="player"> Player who issued the command. </param>
        /// <param name="cmd"> Command to be parsed and executed. </param>
        /// <param name="fromConsole"> Whether this command is being called from a non-player (e.g. Console). </param>
        /// <returns> True if the command was called, false if something prevented it from being called. </returns>
        /// <exception cref="ArgumentNullException"> player or cmd is null. </exception>
        public static bool ParseCommand([NotNull] Player player, [NotNull] CommandReader cmd, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            CommandDescriptor descriptor = cmd.Descriptor;

            if (descriptor == null)
            {
                if (CommandManager.ParseUnknownCommand(player, cmd))
                {
                    return(true);
                }
                player.Message("Unknown command \"{0}\". See &H/Commands", cmd.Name);
                return(false);
            }
            if (!descriptor.IsConsoleSafe && fromConsole)
            {
                player.Message("You cannot use this command from console.");
                return(false);
            }

            if (descriptor.Permissions != null)
            {
                if (!descriptor.CanBeCalledBy(player.Info.Rank))
                {
                    player.MessageNoAccess(descriptor);
                    return(false);
                }

                if (descriptor.MinRank != RankManager.LowestRank && !player.Info.ClassicubeVerified)
                {
                    player.Message("As you had an older minecraft.net account, you must have an admin verify your " +
                                   "new classicube.net account actually is you with /verify before you can use non-guest commands.");
                    return(false);
                }
            }

            if (descriptor.Call(player, cmd, true))
            {
                return(true);
            }
            else
            {
                player.Message("Command was cancelled.");
                return(false);
            }
        }
示例#15
0
 static void ClearHandler([NotNull] Player player, [NotNull] CommandReader cmd)
 {
     if (cmd.HasNext)
     {
         CdClear.PrintUsage(player);
         return;
     }
     for (int i = 0; i < LinesToClear; i++)
     {
         player.Message("");
     }
 }
示例#16
0
 private static void ModelHandler(Player player, CommandReader cmd) {
     PlayerInfo otherPlayer = InfoCommands.FindPlayerInfo(player, cmd, cmd.Next() ?? player.Name);
     if (otherPlayer == null) return;
      
     if (!player.IsStaff && otherPlayer != player.Info) {
         Rank staffRank = RankManager.GetMinRankWithAnyPermission(Permission.ReadStaffChat);
         if (staffRank != null) {
             player.Message("You must be {0}&s+ to change another players Model", staffRank.ClassyName);
         } else {
             player.Message("No ranks have the ReadStaffChat permission so no one can change other players Model, yell at the owner.");
         }
         return;
     }
     if (otherPlayer.Rank.Index < player.Info.Rank.Index) {
         player.Message("Cannot change the Model of someone higher rank than you.");
         return;
     }
     if (otherPlayer == null) {
         player.Message("Your current Model: &f" + player.Info.Mob);
         return;
     }
     string model = cmd.Next();
     if (string.IsNullOrEmpty(model)) {
         player.Message("Current Model for {0}: &f{1}", otherPlayer.Name, otherPlayer.Mob);
         return;
     }
     if (otherPlayer.IsOnline && otherPlayer.Rank.Index >= player.Info.Rank.Index) {
         if (!validEntities.Contains(model.ToLower())) {
             Block block;
             if (Map.GetBlockByName(model, false, out block)) {
                 model = block.GetHashCode().ToString();
             } else {
                 player.Message("Model not valid, see &h/Help Model&s.");
                 return;
             }
         }
         if (otherPlayer.Mob.ToLower() == model.ToLower()) {
             player.Message("&f{0}&s's model is already set to &f{1}", otherPlayer.Name, model);
             return;
         }
         if (otherPlayer.IsOnline) {
             otherPlayer.PlayerObject.Message("&f{0}&shanged your model from &f{1} &sto &f{2}", (otherPlayer.PlayerObject == player ? "&sC" : player.Name + " &sc"), otherPlayer.Mob, model);
         }
         if (otherPlayer.PlayerObject != player) {
             player.Message("&sChanged model of &f{0} &sfrom &f{1} &sto &f{2}", otherPlayer.Name, otherPlayer.Mob, model);
         }
         otherPlayer.oldMob = otherPlayer.Mob;
         otherPlayer.Mob = model;
     } else {
         player.Message("Player not found/online or lower rank than you");
     }
 }
示例#17
0
        internal static bool RaiseCommandCallingEvent([NotNull] CommandReader cmd, [NotNull] Player player)
        {
            var h = CommandCalling;

            if (h == null)
            {
                return(false);
            }
            var e = new CommandCallingEventArgs(cmd, player);

            h(null, e);
            return(e.Cancel);
        }
示例#18
0
        static void StaffHandler( Player player, CommandReader cmd ) {
            if( player.Info.IsMuted ) {
                player.MessageMuted();
                return;
            }

            if( player.DetectChatSpam() ) return;

            string message = cmd.NextAll().Trim( ' ' );
            if( message.Length > 0 ) {
                Chat.SendStaff( player, message );
            }
        }
示例#19
0
        internal static bool RaiseCommandCallingEvent(CommandReader cmd, CommandDescriptor descriptor, Player player)
        {
            var h = CommandCalling;

            if (h == null)
            {
                return(false);
            }
            var e = new CommandCallingEventArgs(cmd, descriptor, player);

            h(null, e);
            return(e.Cancel);
        }
示例#20
0
        static void RedoHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            if (cmd.HasNext)
            {
                CdRedo.PrintUsage(player);
                return;
            }

            World playerWorld = player.World;

            if (playerWorld == null)
            {
                PlayerOpException.ThrowNoWorld(player);
            }

            UndoState redoState = player.RedoPop();

            if (redoState == null)
            {
                player.MessageNow("There is currently nothing to redo.");
                return;
            }

            string msg = "Redo: ";

            if (redoState.Op != null && !redoState.Op.IsDone)
            {
                redoState.Op.Cancel();
                msg += String.Format("Cancelled {0} (was {1}% done). ",
                                     redoState.Op.Description,
                                     redoState.Op.PercentDone);
            }

            // no need to set player.drawingInProgress here because this is done on the user thread
            Logger.Log(LogType.UserActivity,
                       "Player {0} initiated /Redo affecting {1} blocks (on world {2})",
                       player.Name,
                       redoState.Buffer.Count,
                       playerWorld.Name);

            msg += String.Format("Restoring {0} blocks. Type &H/Undo&S to reverse.",
                                 redoState.Buffer.Count);
            player.MessageNow(msg);

            var op = new UndoDrawOperation(player, redoState, true);

            op.Prepare(new Vector3I[0]);
            op.Begin();
        }
示例#21
0
 public override MapGeneratorParameters CreateParameters( Player player, CommandReader cmd ) {
     string themeName = cmd.Next();
     MapGeneratorParameters newParams;
     if( themeName != null ) {
         newParams = CreateParameters( themeName );
         if( newParams == null ) {
             player.Message( "SetGen: \"{0}\" is not a recognized flat theme name. Available themes are: {1}",
                             themeName, Presets.JoinToString() );
             return null;
         }
     } else {
         newParams = CreateDefaultParameters();
     }
     return newParams;
 }
示例#22
0
        static void ConfirmCommandCallback([NotNull] Player player, [NotNull] object tag, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }
            CommandReader cmd = (CommandReader)tag;

            cmd.Rewind();
            cmd.IsConfirmed = true;
            CommandManager.ParseCommand(player, cmd, fromConsole);
        }
示例#23
0
        static void InfoSwapHandler(Player player, CommandReader cmd)
        {
            string p1Name = cmd.Next();
            string p2Name = cmd.Next();

            if (p1Name == null || p2Name == null)
            {
                CdInfoSwap.PrintUsage(player);
                return;
            }

            PlayerInfo p1 = PlayerDB.FindByPartialNameOrPrintMatches(player, p1Name);

            if (p1 == null)
            {
                return;
            }
            PlayerInfo p2 = PlayerDB.FindByPartialNameOrPrintMatches(player, p2Name);

            if (p2 == null)
            {
                return;
            }

            if (p1 == p2)
            {
                player.Message("InfoSwap: Please specify 2 different players.");
                return;
            }

            if (p1.IsOnline || p2.IsOnline)
            {
                player.Message("InfoSwap: Both players must be offline to swap info.");
                return;
            }

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "InfoSwap: Swap stats of players {0}&S and {1}&S?", p1.ClassyName, p2.ClassyName);
            }
            else
            {
                PlayerDB.SwapPlayerInfo(p1, p2);
                player.Message("InfoSwap: Stats of {0}&S and {1}&S have been swapped.",
                               p1.ClassyName, p2.ClassyName);
            }
        }
示例#24
0
        static void IgnoreHandler(Player player, CommandReader cmd)
        {
            string name = cmd.Next();

            if (name != null)
            {
                if (cmd.HasNext)
                {
                    CdIgnore.PrintUsage(player);
                    return;
                }
                PlayerInfo targetInfo = PlayerDB.FindByPartialNameOrPrintMatches(player, name);
                if (targetInfo == null)
                {
                    return;
                }

                if (targetInfo == player.Info)
                {
                    player.MessageNow("You cannot ignore yourself.");
                    return;
                }

                if (player.Ignore(targetInfo))
                {
                    player.MessageNow("You are now ignoring {0}", targetInfo.ClassyName);
                }
                else
                {
                    player.MessageNow("You are already ignoring {0}", targetInfo.ClassyName);
                }
            }
            else
            {
                PlayerInfo[] ignoreList = player.IgnoreList;
                if (ignoreList.Length > 0)
                {
                    player.MessageNow("Ignored players: {0}", ignoreList.JoinToClassyString());
                }
                else
                {
                    player.MessageNow("You are not currently ignoring anyone.");
                }
            }
        }
示例#25
0
        static void DoNotMarkHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool doNotMark = !player.DisableClickToMark;

            if (cmd.HasNext && !cmd.NextOnOff(out doNotMark))
            {
                CdDoNotMark.PrintUsage(player);
            }
            player.DisableClickToMark = doNotMark;
            if (doNotMark)
            {
                player.Message("Click-to-mark disabled.");
            }
            else
            {
                player.Message("Click-to-mark re-enabled.");
            }
        }
示例#26
0
        public override MapGeneratorParameters CreateParameters( Player player, CommandReader cmd ) {
            string themeName = cmd.Next();
            if( themeName == null ) {
                return CreateDefaultParameters();
            }

            MapGenTheme theme;
            RealisticMapGenTerrainType terrainType;

            string templateName = cmd.Next();
            if( templateName == null ) {
                player.Message( "SetGen: Realistic MapGen requires both a theme and a terrainType. " +
                                "See &H/Help SetGen Realistic&S or check wiki.fCraft.net for details" );
                return null;
            }

            // parse theme
            bool swapThemeAndTemplate;
            if( EnumUtil.TryParse( themeName, out theme, true ) ) {
                swapThemeAndTemplate = false;

            } else if( EnumUtil.TryParse( templateName, out theme, true ) ) {
                swapThemeAndTemplate = true;

            } else {
                player.Message( "SetGen: Unrecognized theme \"{0}\". Available themes are: {1}",
                                themeName,
                                Enum.GetNames( typeof( MapGenTheme ) ).JoinToString() );
                return null;
            }

            // parse terrainType
            if( swapThemeAndTemplate && !EnumUtil.TryParse( themeName, out terrainType, true ) ) {
                MessageTemplateList( themeName, player );
                return null;
            } else if( !EnumUtil.TryParse( templateName, out terrainType, true ) ) {
                MessageTemplateList( templateName, player );
                return null;
            }

            // TODO: optional parameters for preset customization
            return CreateParameters( terrainType, theme );
        }
示例#27
0
        static void MassRankHandler( Player player, CommandReader cmd ) {
            string fromRankName = cmd.Next();
            string toRankName = cmd.Next();
            string reason = cmd.NextAll();
            if( fromRankName == null || toRankName == null ) {
                CdMassRank.PrintUsage( player );
                return;
            }

            Rank fromRank = RankManager.FindRank( fromRankName );
            if( fromRank == null ) {
                player.MessageNoRank( fromRankName );
                return;
            }

            Rank toRank = RankManager.FindRank( toRankName );
            if( toRank == null ) {
                player.MessageNoRank( toRankName );
                return;
            }

            if( fromRank == toRank ) {
                player.Message( "Ranks must be different" );
                return;
            }

            int playerCount;
            using( PlayerDB.GetReadLock() ) {
                playerCount = PlayerDB.List.Count( t => t.Rank == fromRank );
            }
            string verb = (fromRank > toRank ? "demot" : "promot");

            if( !cmd.IsConfirmed ) {
                player.Confirm( cmd, "MassRank: {0}e {1} players?", verb.UppercaseFirst(), playerCount );
                return;
            }

            player.Message( "MassRank: {0}ing {1} players...",
                            verb, playerCount );

            int affected = PlayerDB.MassRankChange( player, fromRank, toRank, reason );
            player.Message( "MassRank: done, {0} records affected.", affected );
        }
		public InequalityDrawOperation(Player player, CommandReader cmd)
			: base(player)
		{
			string strFunc = cmd.Next();
			if (string.IsNullOrWhiteSpace(strFunc))
				throw new ArgumentException("empty inequality expression");
			if (strFunc.Length < 3)
				throw new ArgumentException("expression is too short (should be like f(x,y,z)>g(x,y,z))");
			
			strFunc = strFunc.ToLower();

			_expression = SimpleParser.Parse(strFunc, new string[] { "x", "y", "z" });
			if (!_expression.IsInEquality())
				throw new ArgumentException("the expression given is not an inequality (should be like f(x,y,z)>g(x,y,z))");

			player.Message("Expression parsed as " + _expression.Print());
			string scalingStr = cmd.Next();
			_scaler = new Scaler(scalingStr);
		}
示例#29
0
 static void BanHandler( Player player, CommandReader cmd ) {
     string targetName = cmd.Next();
     if( targetName == null ) {
         CdBan.PrintUsage( player );
         return;
     }
     PlayerInfo target = PlayerDB.FindByPartialNameOrPrintMatches( player, targetName );
     if( target == null ) return;
     string reason = cmd.NextAll();
     try {
         Player targetPlayer = target.PlayerObject;
         target.Ban( player, reason, true, true );
         WarnIfOtherPlayersOnIP( player, target, targetPlayer );
     } catch( PlayerOpException ex ) {
         player.Message( ex.MessageColored );
         if( ex.ErrorCode == PlayerOpExceptionCode.ReasonRequired ) {
             FreezeIfAllowed( player, target );
         }
     }
 }
示例#30
0
        static void StaffHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.DetectChatSpam())
            {
                return;
            }

            string message = cmd.NextAll().Trim(' ');

            if (message.Length > 0)
            {
                Chat.SendStaff(player, message);
            }
        }
示例#31
0
        static void RollHandler(Player player, CommandReader cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.DetectChatSpam())
            {
                return;
            }

            Random rand = new Random();
            int    n1;
            int    min, max;

            if (cmd.NextInt(out n1))
            {
                int n2;
                if (!cmd.NextInt(out n2))
                {
                    n2 = 1;
                }
                min = Math.Min(n1, n2);
                max = Math.Max(n1, n2);
            }
            else
            {
                min = 1;
                max = 100;
            }

            int num = rand.Next(min, max + 1);

            Server.Message(player,
                           "{0}{1} rolled {2} ({3}...{4})",
                           player.ClassyName, Color.Silver, num, min, max);
            player.Message("{0}You rolled {1} ({2}...{3})",
                           Color.Silver, num, min, max);
        }
示例#32
0
        void HandleCommandMessage([NotNull] string rawMessage, bool fromConsole)
        {
            if (rawMessage == null)
            {
                throw new ArgumentNullException("rawMessage");
            }
            if (rawMessage.EndsWith("//"))
            {
                rawMessage = rawMessage.Substring(0, rawMessage.Length - 1);
            }
            CommandReader cmd = new CommandReader(rawMessage);

            if (cmd.Descriptor == null)
            {
                MessageNow("Unknown command \"{0}\". See &H/Commands", cmd.Name);
            }
            else if (Info.IsFrozen && !cmd.Descriptor.UsableByFrozenPlayers)
            {
                MessageNow("&WYou cannot use this command while frozen.");
            }
            else
            {
                if (!cmd.Descriptor.DisableLogging)
                {
                    Logger.Log(LogType.UserCommand,
                               "{0}: {1}",
                               Name,
                               rawMessage);
                }
                if (cmd.Descriptor.RepeatableSelection)
                {
                    selectionRepeatCommand = cmd;
                }
                SendToSpectators(cmd.RawMessage);
                CommandManager.ParseCommand(this, cmd, fromConsole);
                if (!cmd.Descriptor.NotRepeatable)
                {
                    LastCommand = cmd;
                }
            }
        }
示例#33
0
        static void PaintHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnPaintOn = (!player.IsPainting);

            if (cmd.HasNext && !cmd.NextOnOff(out turnPaintOn))
            {
                CdPaint.PrintUsage(player);
                return;
            }

            if (turnPaintOn)
            {
                player.IsPainting = true;
                player.Message("Paint mode: ON");
            }
            else
            {
                player.IsPainting = false;
                player.Message("Paint mode: OFF");
            }
        }
示例#34
0
        public override MapGeneratorParameters CreateParameters(Player player, CommandReader cmd)
        {
            string themeName = cmd.Next();
            MapGeneratorParameters newParams;

            if (themeName != null)
            {
                newParams = CreateParameters(themeName);
                if (newParams == null)
                {
                    player.Message("SetGen: \"{0}\" is not a recognized flat theme name. Available themes are: {1}",
                                   themeName, Presets.JoinToString());
                    return(null);
                }
            }
            else
            {
                newParams = CreateDefaultParameters();
            }
            return(newParams);
        }
 /// <summary> Calls this command. </summary>
 /// <param name="player"> Player who called the command. </param>
 /// <param name="cmd"> Command arguments. </param>
 /// <param name="raiseEvent"> Whether CommandCalling and CommandCalled events should be raised. </param>
 /// <returns> True if the command was called succesfully.
 /// False if the call was cancelled by the CommandCalling event. </returns>
 public bool Call([NotNull] Player player, [NotNull] CommandReader cmd, bool raiseEvent)
 {
     if (player == null)
     {
         throw new ArgumentNullException("player");
     }
     if (cmd == null)
     {
         throw new ArgumentNullException("cmd");
     }
     if (raiseEvent && CommandManager.RaiseCommandCallingEvent(cmd, this, player))
     {
         return(false);
     }
     Handler(player, cmd);
     if (raiseEvent)
     {
         CommandManager.RaiseCommandCalledEvent(cmd, this, player);
     }
     return(true);
 }
示例#36
0
        static void GrassHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnGrassOn = (player.GetBind(Block.Dirt) != Block.Grass);

            if (cmd.HasNext && !cmd.NextOnOff(out turnGrassOn))
            {
                CdGrass.PrintUsage(player);
                return;
            }

            if (turnGrassOn)
            {
                player.Bind(Block.Dirt, Block.Grass);
                player.Message("Grass: ON. Dirt blocks are replaced with grass.");
            }
            else
            {
                player.ResetBind(Block.Dirt);
                player.Message("Grass: OFF");
            }
        }
示例#37
0
        static void LavaHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnLavaOn = (player.GetBind(Block.Red) != Block.Lava);

            if (cmd.HasNext && !cmd.NextOnOff(out turnLavaOn))
            {
                CdLava.PrintUsage(player);
                return;
            }

            if (turnLavaOn)
            {
                player.Bind(Block.Red, Block.Lava);
                player.Message("Lava: ON. Red blocks are replaced with lava.");
            }
            else
            {
                player.ResetBind(Block.Red);
                player.Message("Lava: OFF");
            }
        }
示例#38
0
        static void SolidHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnSolidOn = (player.GetBind(Block.Stone) != Block.Admincrete);

            if (cmd.HasNext && !cmd.NextOnOff(out turnSolidOn))
            {
                CdSolid.PrintUsage(player);
                return;
            }

            if (turnSolidOn)
            {
                player.Bind(Block.Stone, Block.Admincrete);
                player.Message("Solid: ON. Stone blocks are replaced with admincrete.");
            }
            else
            {
                player.ResetBind(Block.Stone);
                player.Message("Solid: OFF");
            }
        }
示例#39
0
        static void UnignoreHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            string name = cmd.Next();

            if (name != null)
            {
                if (cmd.HasNext)
                {
                    // too many parameters given
                    CdUnignore.PrintUsage(player);
                    return;
                }
                // A name was given -- let's find the target
                PlayerInfo targetInfo = PlayerDB.FindPlayerInfoOrPrintMatches(player,
                                                                              name,
                                                                              SearchOptions.ReturnSelfIfOnlyMatch);
                if (targetInfo == null)
                {
                    return;
                }
                if (targetInfo == player.Info)
                {
                    player.Message("You cannot &H/Ignore&S (or &H/Unignore&S) yourself.");
                    return;
                }

                if (player.Unignore(targetInfo))
                {
                    player.MessageNow("You are no longer ignoring {0}", targetInfo.ClassyName);
                }
                else
                {
                    player.MessageNow("You are not currently ignoring {0}", targetInfo.ClassyName);
                }
            }
            else
            {
                ListIgnoredPlayers(player);
            }
        }
示例#40
0
        static void StaticHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnStaticOn = (!player.IsRepeatingSelection);

            if (cmd.HasNext && !cmd.NextOnOff(out turnStaticOn))
            {
                CdStatic.PrintUsage(player);
                return;
            }

            if (turnStaticOn)
            {
                player.Message("Static: On");
                player.IsRepeatingSelection = true;
            }
            else
            {
                player.Message("Static: Off");
                player.IsRepeatingSelection = false;
                player.SelectionCancel();
            }
        }
示例#41
0
		public ManifoldDrawOperation(Player p, CommandReader cmd) : base (p)
		{
			_expressions = PrepareParametrizedManifold.GetPlayerParametrizationCoordsStorage(p);
			if (null == _expressions[0])
				throw new InvalidExpressionException("x is undefined");
			if (null == _expressions[1])
				throw new InvalidExpressionException("y is undefined");
			if (null == _expressions[2])
				throw new InvalidExpressionException("z is undefined");

			_paramIterations = PrepareParametrizedManifold.GetPlayerParametrizationParamsStorage(p);
			if (null==_paramIterations[0] && null==_paramIterations[1] && null==_paramIterations[2])
				throw new InvalidExpressionException("all parametrization variables are undefined");

			if (GetNumOfSteps(0) * GetNumOfSteps(1) * GetNumOfSteps(2) > MaxIterationSteps)
				throw new InvalidExpressionException("too many iteration steps (over " + MaxIterationSteps + ")");

			_scaler=new Scaler(cmd.Next());

			p.Message("Going to draw the following parametrization:\nx=" + _expressions[0].Print()+
				"\ny=" + _expressions[1].Print() + "\nz=" + _expressions[2].Print());
		}
示例#42
0
        static void ReplyHandler( Player player, CommandReader cmd ) {
            string messageText = cmd.NextAll();
            if( messageText.Length == 0 ) {
                player.Message( "Reply: No message to send!" );
                return;
            }
            string targetName = player.lastPrivateMessageSender;
            if( targetName != null ) {
                Player targetPlayer = Server.FindPlayerExact( player,
                                                              targetName,
                                                              SearchOptions.IncludeHidden );
                if( targetPlayer != null ) {
                    if( player.CanSee( targetPlayer ) ) {
                        if( targetPlayer.IsDeaf ) {
                            player.Message( "Cannot PM {0}&S: they are currently deaf.", targetPlayer.ClassyName );
                        } else if( targetPlayer.IsIgnoring( player.Info ) ) {
                            player.Message( "&WCannot PM {0}&W: you are ignored.", targetPlayer.ClassyName );
                        } else {
                            Chat.SendPM( player, targetPlayer, messageText );
                            player.MessageNow( "&Pto {0}: {1}", targetPlayer.Name, messageText );
                        }
                    } else {
                        player.Message( "Reply: Cannot send message; player {0}&S is offline.",
                                        PlayerDB.FindExactClassyName( targetName ) );
                        if( targetPlayer.CanHear( player ) ) {
                            Chat.SendPM( player, targetPlayer, messageText );
                            player.Info.DecrementMessageWritten();
                        }
                    }
                } else {
                    player.Message( "Reply: Cannot send message; player {0}&S is offline.",
                                    PlayerDB.FindExactClassyName( targetName ) );
                }

            } else {
                player.Message( "Reply: You have not sent any messages yet." );
            }
        }
示例#43
0
		public EqualityDrawOperation(Player player, CommandReader cmd)
			: base(player)
		{
			string strFunc = cmd.Next();
            if (string.IsNullOrWhiteSpace(strFunc))
            {
                player.Message("empty equality expression");
                return;
            }
            if (strFunc.Length < 3)
            {
                player.Message("expression is too short (should be like f(x,y,z)=g(x,y,z))");
                return;
            }

			strFunc = strFunc.ToLower();

			_expression = SimpleParser.ParseAsEquality(strFunc, new string[] { "x", "y", "z" });
			
			player.Message("Expression parsed as " + _expression.Print());
			string scalingStr = cmd.Next();
			_scaler = new Scaler(scalingStr);
		}
示例#44
0
 static void DeafenHandler([NotNull] Player player, [NotNull] CommandReader cmd)
 {
     if (cmd.HasNext)
     {
         CdDeafen.PrintUsage(player);
         return;
     }
     if (!player.IsDeaf)
     {
         for (int i = 0; i < LinesToClear; i++)
         {
             player.MessageNow("");
         }
         player.MessageNow("Deafened mode: ON");
         player.MessageNow("You will not see ANY messages until you type &H/Deafen&S again.");
         player.IsDeaf = true;
     }
     else
     {
         player.IsDeaf = false;
         player.MessageNow("Deafened mode: OFF");
     }
 }
示例#45
0
        static void MeHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.DetectChatSpam())
            {
                return;
            }

            string msg = cmd.NextAll().Trim(' ');

            if (msg.Length > 0)
            {
                Chat.SendMe(player, msg);
            }
            else
            {
                CdMe.PrintUsage(player);
            }
        }
示例#46
0
        static void RedoHandler( Player player, CommandReader cmd ) {
            if( cmd.HasNext ) {
                CdRedo.PrintUsage( player );
                return;
            }

            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );

            UndoState redoState = player.RedoPop();
            if( redoState == null ) {
                player.MessageNow( "There is currently nothing to redo." );
                return;
            }

            string msg = "Redo: ";
            if( redoState.Op != null && !redoState.Op.IsDone ) {
                redoState.Op.Cancel();
                msg += String.Format( "Cancelled {0} (was {1}% done). ",
                                     redoState.Op.Description,
                                     redoState.Op.PercentDone );
            }

            // no need to set player.drawingInProgress here because this is done on the user thread
            Logger.Log( LogType.UserActivity,
                        "Player {0} initiated /Redo affecting {1} blocks (on world {2})",
                        player.Name,
                        redoState.Buffer.Count,
                        playerWorld.Name );

            msg += String.Format( "Restoring {0} blocks. Type &H/Undo&S to reverse.",
                                  redoState.Buffer.Count );
            player.MessageNow( msg );

            var op = new UndoDrawOperation( player, redoState, true );
            op.Prepare( new Vector3I[0] );
            op.Begin();
        }
示例#47
0
        static void UndoHandler( Player player, CommandReader cmd ) {
            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );
            if( cmd.HasNext ) {
                player.Message( "Undo command takes no parameters. Did you mean to do &H/UndoPlayer&S or &H/UndoArea&S?" );
                return;
            }

            string msg = "Undo: ";
            UndoState undoState = player.UndoPop();
            if( undoState == null ) {
                player.MessageNow( "There is currently nothing to undo." );
                return;
            }

            // Cancel the last DrawOp, if still in progress
            if( undoState.Op != null && !undoState.Op.IsDone && !undoState.Op.IsCancelled ) {
                undoState.Op.Cancel();
                msg += String.Format( "Cancelled {0} (was {1}% done). ",
                                     undoState.Op.Description,
                                     undoState.Op.PercentDone );
            }

            // Check if command was too massive.
            if( undoState.IsTooLargeToUndo ) {
                if( undoState.Op != null ) {
                    player.MessageNow( "Cannot undo {0}: too massive.", undoState.Op.Description );
                } else {
                    player.MessageNow( "Cannot undo: too massive." );
                }
                return;
            }

            // no need to set player.drawingInProgress here because this is done on the user thread
            Logger.Log( LogType.UserActivity,
                        "Player {0} initiated /Undo affecting {1} blocks (on world {2})",
                        player.Name,
                        undoState.Buffer.Count,
                        playerWorld.Name );

            msg += String.Format( "Restoring {0} blocks. Type &H/Redo&S to reverse.",
                                  undoState.Buffer.Count );
            player.MessageNow( msg );

            var op = new UndoDrawOperation( player, undoState, false );
            op.Prepare( new Vector3I[0] );
            op.Begin();
        }
示例#48
0
 static void ReplaceBrushHandler( Player player, CommandReader cmd ) {
     var replaceBrush = ReplaceBrushBrushFactory.Instance.MakeBrush( player, cmd );
     if( replaceBrush == null ) return;
     ReplaceHandlerInternal( replaceBrush, player, cmd );
 }
示例#49
0
        static void ReplaceHandlerInternal( IBrush factory, Player player, CommandReader cmd ) {
            CuboidDrawOperation op = new CuboidDrawOperation( player );
            IBrushInstance brush = factory.MakeInstance( player, cmd, op );
            if( brush == null ) return;
            op.Brush = brush;

            player.SelectionStart( 2, DrawOperationCallback, op, Permission.Draw );
            player.MessageNow( "{0}: Click or &H/Mark&S 2 blocks.",
                               op.Brush.InstanceDescription );
        }
示例#50
0
        static void BindHandler( Player player, CommandReader cmd ) {
            if( !cmd.HasNext ) {
                player.Message( "All bindings have been reset." );
                player.ResetAllBinds();
                return;
            }

            Block originalBlock;
            if( !cmd.NextBlock( player, false, out originalBlock ) ) return;

            if( !cmd.HasNext ) {
                if( player.GetBind( originalBlock ) != originalBlock ) {
                    player.Message( "{0} is no longer bound to {1}",
                                    originalBlock,
                                    player.GetBind( originalBlock ) );
                    player.ResetBind( originalBlock );
                } else {
                    player.Message( "{0} is not bound to anything.",
                                    originalBlock );
                }
                return;
            }

            Block replacementBlock;
            if( !cmd.NextBlock( player, false, out replacementBlock ) ) return;

            if( cmd.HasNext ) {
                CdBind.PrintUsage( player );
                return;
            }

            Permission permission = Permission.Build;
            switch( replacementBlock ) {
                case Block.Grass:
                    permission = Permission.PlaceGrass;
                    break;
                case Block.Admincrete:
                    permission = Permission.PlaceAdmincrete;
                    break;
                case Block.Water:
                    permission = Permission.PlaceWater;
                    break;
                case Block.Lava:
                    permission = Permission.PlaceLava;
                    break;
            }
            if( player.Can( permission ) ) {
                player.Bind( originalBlock, replacementBlock );
                player.Message( "{0} is now replaced with {1}", originalBlock, replacementBlock );
            } else {
                player.Message( "&WYou do not have {0} permission.", permission );
            }
        }
示例#51
0
        static void CutHandler( Player player, CommandReader cmd ) {
            Block fillBlock = Block.Air;
            if( cmd.HasNext ) {
                if( !cmd.NextBlock( player, false, out fillBlock ) ) return;
                if( cmd.HasNext ) {
                    CdCut.PrintUsage( player );
                    return;
                }
            }

            CutDrawOperation op = new CutDrawOperation( player ) {
                Brush = new NormalBrush( fillBlock )
            };

            player.SelectionStart( 2, DrawOperationCallback, op, Permission.Draw );
            player.Message( "{0}: Click 2 or &H/Mark&S 2 blocks.",
                            op.Description );
        }
示例#52
0
        static void GrassHandler( Player player, CommandReader cmd ) {
            bool turnGrassOn = (player.GetBind( Block.Dirt ) != Block.Grass);

            if( cmd.HasNext && !cmd.NextOnOff( out turnGrassOn ) ) {
                CdGrass.PrintUsage( player );
                return;
            }

            if( turnGrassOn ) {
                player.Bind( Block.Dirt, Block.Grass );
                player.Message( "Grass: ON. Dirt blocks are replaced with grass." );
            } else {
                player.ResetBind( Block.Dirt );
                player.Message( "Grass: OFF" );
            }
        }
示例#53
0
        static void PaintHandler( Player player, CommandReader cmd ) {
            bool turnPaintOn = (!player.IsPainting);

            if( cmd.HasNext && !cmd.NextOnOff( out turnPaintOn ) ) {
                CdPaint.PrintUsage( player );
                return;
            }

            if( turnPaintOn ) {
                player.IsPainting = true;
                player.Message( "Paint mode: ON" );
            } else {
                player.IsPainting = false;
                player.Message( "Paint mode: OFF" );
            }
        }
示例#54
0
 internal static void RaiseCommandCalledEvent(CommandReader cmd, CommandDescriptor descriptor, Player player)
 {
     CommandCalledEvent.Raise(new CommandCalledEventArgs(cmd, descriptor, player));
 }
示例#55
0
        static void TimerHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            string param = cmd.Next();

            // List timers
            if (param == null)
            {
                ChatTimer[] list = ChatTimer.TimerList.OrderBy(timer => timer.TimeLeft).ToArray();
                if (list.Length == 0)
                {
                    player.Message("No timers running.");
                }
                else
                {
                    player.Message("There are {0} timers running:", list.Length);
                    foreach (ChatTimer timer in list)
                    {
                        player.Message("  #{0} \"{1}&S\" (started by {2}, {3} left)",
                                       timer.Id,
                                       timer.Message,
                                       timer.StartedBy,
                                       timer.TimeLeft.ToMiniString());
                    }
                }
                return;
            }

            // Abort a timer
            if (param.Equals("abort", StringComparison.OrdinalIgnoreCase))
            {
                int timerId;
                if (cmd.NextInt(out timerId))
                {
                    ChatTimer timer = ChatTimer.FindTimerById(timerId);
                    if (timer == null || !timer.IsRunning)
                    {
                        player.Message("Given timer (#{0}) does not exist.", timerId);
                    }
                    else
                    {
                        timer.Abort();
                        string abortMsg = String.Format("&Y(Timer) {0}&Y aborted a timer with {1} left: {2}",
                                                        player.ClassyName,
                                                        timer.TimeLeft.ToMiniString(),
                                                        timer.Message);
                        Chat.SendSay(player, abortMsg);
                    }
                }
                else
                {
                    CdTimer.PrintUsage(player);
                }
                return;
            }

            // Start a timer
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }
            if (player.DetectChatSpam())
            {
                return;
            }
            TimeSpan duration;

            if (!param.TryParseMiniTimeSpan(out duration))
            {
                CdTimer.PrintUsage(player);
                return;
            }
            if (duration > DateTimeUtil.MaxTimeSpan)
            {
                player.MessageMaxTimeSpan();
                return;
            }
            if (duration < ChatTimer.MinDuration)
            {
                player.Message("Timer: Must be at least 1 second.");
                return;
            }

            string sayMessage;
            string message = cmd.NextAll();

            if (String.IsNullOrWhiteSpace(message))
            {
                sayMessage = String.Format("&Y(Timer) {0}&Y started a {1} timer",
                                           player.ClassyName,
                                           duration.ToMiniString());
            }
            else
            {
                sayMessage = String.Format("&Y(Timer) {0}&Y started a {1} timer: {2}",
                                           player.ClassyName,
                                           duration.ToMiniString(),
                                           message);
            }
            Chat.SendSay(player, sayMessage);
            ChatTimer.Start(duration, message, player.Name);
        }
示例#56
0
 static void CopySlotHandler( Player player, CommandReader cmd ) {
     int slotNumber;
     if( cmd.NextInt( out slotNumber ) ) {
         if( cmd.HasNext ) {
             CdCopySlot.PrintUsage( player );
             return;
         }
         if( slotNumber < 1 || slotNumber > player.Info.Rank.CopySlots ) {
             player.Message( "CopySlot: Select a number between 1 and {0}", player.Info.Rank.CopySlots );
         } else {
             player.CopySlot = slotNumber - 1;
             CopyState info = player.GetCopyState();
             if( info == null ) {
                 player.Message( "Selected copy slot {0} (unused).", slotNumber );
             } else {
                 player.Message( "Selected copy slot {0}: {1} blocks from {2}, {3} old.",
                                 slotNumber, info.Blocks.Length,
                                 info.OriginWorld, DateTime.UtcNow.Subtract( info.CopyTime ).ToMiniString() );
             }
         }
     } else {
         CopyState[] slots = player.CopyStates;
         player.Message( "Using {0} of {1} slots. Selected slot: {2}",
                         slots.Count( info => info != null ), player.Info.Rank.CopySlots, player.CopySlot + 1 );
         for( int i = 0; i < slots.Length; i++ ) {
             if( slots[i] != null ) {
                 player.Message( "  {0}: {1} blocks from {2}, {3} old",
                                 i + 1, slots[i].Blocks.Length,
                                 slots[i].OriginWorld,
                                 DateTime.UtcNow.Subtract( slots[i].CopyTime ).ToMiniString() );
             }
         }
     }
 }
示例#57
0
 static void CopyHandler( Player player, CommandReader cmd ) {
     if( cmd.HasNext ) {
         CdCopy.PrintUsage( player );
         return;
     }
     player.SelectionStart( 2, CopyCallback, null, CdCopy.Permissions );
     player.MessageNow( "Copy: Click or &H/Mark&S 2 blocks." );
 }
示例#58
0
        static void WaterHandler( Player player, CommandReader cmd ) {
            bool turnWaterOn = (player.GetBind( Block.Aqua ) != Block.Water ||
                                player.GetBind( Block.Cyan ) != Block.Water ||
                                player.GetBind( Block.Blue ) != Block.Water);

            if( cmd.HasNext && !cmd.NextOnOff( out turnWaterOn ) ) {
                CdWater.PrintUsage( player );
                return;
            }

            if( turnWaterOn ) {
                player.Bind( Block.Aqua, Block.Water );
                player.Bind( Block.Cyan, Block.Water );
                player.Bind( Block.Blue, Block.Water );
                player.Message( "Water: ON. Blue blocks are replaced with water." );
            } else {
                player.ResetBind( Block.Aqua, Block.Cyan, Block.Blue );
                player.Message( "Water: OFF" );
            }
        }
示例#59
0
        static void MirrorHandler( Player player, CommandReader cmd ) {
            CopyState originalInfo = player.GetCopyState();
            if( originalInfo == null ) {
                player.MessageNow( "Nothing to flip! Copy something first." );
                return;
            }

            // clone to avoid messing up any paste-in-progress
            CopyState info = new CopyState( originalInfo );

            bool flipX = false, flipY = false, flipH = false;
            string axis;
            while( (axis = cmd.Next()) != null ) {
                foreach( char c in axis.ToLower() ) {
                    if( c == 'x' ) flipX = true;
                    if( c == 'y' ) flipY = true;
                    if( c == 'z' ) flipH = true;
                }
            }

            if( !flipX && !flipY && !flipH ) {
                CdMirror.PrintUsage( player );
                return;
            }

            Block block;

            if( flipX ) {
                int left = 0;
                int right = info.Bounds.Width - 1;
                while( left < right ) {
                    for( int y = info.Bounds.Length - 1; y >= 0; y-- ) {
                        for( int z = info.Bounds.Height - 1; z >= 0; z-- ) {
                            block = info.Blocks[left, y, z];
                            info.Blocks[left, y, z] = info.Blocks[right, y, z];
                            info.Blocks[right, y, z] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if( flipY ) {
                int left = 0;
                int right = info.Bounds.Length - 1;
                while( left < right ) {
                    for( int x = info.Bounds.Width - 1; x >= 0; x-- ) {
                        for( int z = info.Bounds.Height - 1; z >= 0; z-- ) {
                            block = info.Blocks[x, left, z];
                            info.Blocks[x, left, z] = info.Blocks[x, right, z];
                            info.Blocks[x, right, z] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if( flipH ) {
                int left = 0;
                int right = info.Bounds.Height - 1;
                while( left < right ) {
                    for( int x = info.Bounds.Width - 1; x >= 0; x-- ) {
                        for( int y = info.Bounds.Length - 1; y >= 0; y-- ) {
                            block = info.Blocks[x, y, left];
                            info.Blocks[x, y, left] = info.Blocks[x, y, right];
                            info.Blocks[x, y, right] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if( flipX ) {
                if( flipY ) {
                    if( flipH ) {
                        player.Message( "Flipped copy along all axes." );
                    } else {
                        player.Message( "Flipped copy along X (east/west) and Y (north/south) axes." );
                    }
                } else {
                    if( flipH ) {
                        player.Message( "Flipped copy along X (east/west) and Z (vertical) axes." );
                    } else {
                        player.Message( "Flipped copy along X (east/west) axis." );
                    }
                }
            } else {
                if( flipY ) {
                    if( flipH ) {
                        player.Message( "Flipped copy along Y (north/south) and Z (vertical) axes." );
                    } else {
                        player.Message( "Flipped copy along Y (north/south) axis." );
                    }
                } else {
                    player.Message( "Flipped copy along Z (vertical) axis." );
                }
            }

            player.SetCopyState( info );
        }
示例#60
0
        static void LavaHandler( Player player, CommandReader cmd ) {
            bool turnLavaOn = (player.GetBind( Block.Red ) != Block.Lava);

            if( cmd.HasNext && !cmd.NextOnOff( out turnLavaOn ) ) {
                CdLava.PrintUsage( player );
                return;
            }

            if( turnLavaOn ) {
                player.Bind( Block.Red, Block.Lava );
                player.Message( "Lava: ON. Red blocks are replaced with lava." );
            } else {
                player.ResetBind( Block.Red );
                player.Message( "Lava: OFF" );
            }
        }