Пример #1
0
        static BlockDBUndoArgs ParseBlockDBUndoParams( Player player, CommandReader cmd, string cmdName, bool not ) {
            // check if command's being called by a worldless player (e.g. console)
            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );

            // ensure that BlockDB is enabled
            if( !BlockDB.IsEnabledGlobally ) {
                player.Message( "&W{0}: BlockDB is disabled on this server.", cmdName );
                return null;
            }
            if( !playerWorld.BlockDB.IsEnabled ) {
                player.Message( "&W{0}: BlockDB is disabled in this world.", cmdName );
                return null;
            }

            // parse the first parameter - either numeric or time limit
            string range = cmd.Next();
            if( range == null ) {
                CdUndoPlayer.PrintUsage( player );
                return null;
            }
            int countLimit;
            TimeSpan ageLimit = TimeSpan.Zero;
            if( !Int32.TryParse( range, out countLimit ) && !range.TryParseMiniTimeSpan( out ageLimit ) ) {
                player.Message( "{0}: First parameter should be a number or a timespan.", cmdName );
                return null;
            }
            if( ageLimit > DateTimeUtil.MaxTimeSpan ) {
                player.MessageMaxTimeSpan();
                return null;
            }

            // parse second and consequent parameters (player names)
            HashSet<PlayerInfo> targets = new HashSet<PlayerInfo>();
            bool allPlayers = false;
            while( true ) {
                string name = cmd.Next();
                if( name == null ) {
                    break;
                } else if( name == "*" ) {
                    // all players
                    if( not ) {
                        player.Message( "{0}: \"*\" not allowed (cannot undo \"everyone except everyone\")", cmdName );
                        return null;
                    }
                    if( allPlayers ) {
                        player.Message( "{0}: \"*\" was listed twice.", cmdName );
                        return null;
                    }
                    allPlayers = true;

                } else {
                    // individual player
                    PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches( player, name, SearchOptions.IncludeSelf );
                    if( target == null ) {
                        return null;
                    }
                    if( targets.Contains( target ) ) {
                        player.Message( "{0}: Player {1}&S was listed twice.",
                                        target.ClassyName, cmdName );
                        return null;
                    }
                    // make sure player has the permission
                    if( !not &&
                        player.Info != target && !player.Can( Permission.UndoAll ) &&
                        !player.Can( Permission.UndoOthersActions, target.Rank ) ) {
                        player.Message( "&W{0}: You may only undo actions of players ranked {1}&S or lower.",
                                        cmdName,
                                        player.Info.Rank.GetLimit( Permission.UndoOthersActions ).ClassyName );
                        player.Message( "Player {0}&S is ranked {1}",
                                        target.ClassyName, target.Rank.ClassyName );
                        return null;
                    }
                    targets.Add( target );
                }
            }
            if( targets.Count == 0 && !allPlayers ) {
                player.Message( "{0}: Specify at least one player name, or \"*\" to undo everyone.", cmdName );
                return null;
            }
            if( targets.Count > 0 && allPlayers ) {
                player.Message( "{0}: Cannot mix player names and \"*\".", cmdName );
                return null;
            }

            // undoing everyone ('*' in place of player name) requires UndoAll permission
            if( ( not || allPlayers ) && !player.Can( Permission.UndoAll ) ) {
                player.MessageNoAccess( Permission.UndoAll );
                return null;
            }

            // Queue UndoPlayerCallback to run
            return new BlockDBUndoArgs {
                Player = player,
                AgeLimit = ageLimit,
                CountLimit = countLimit,
                Area = player.WorldMap.Bounds,
                World = playerWorld,
                Targets = targets.ToArray(),
                Not = not
            };
        }
Пример #2
0
        static void UndoAreaHandler( Player player, Command cmd )
        {
            if( !BlockDB.IsEnabledGlobally ) {
                player.Message( "&WBlockDB is disabled on this server." );
                return;
            }

            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );
            if( !playerWorld.BlockDB.IsEnabled ) {
                player.Message( "&WBlockDB is disabled in this world." );
                return;
            }

            string name = cmd.Next();
            string range = cmd.Next();
            if( name == null || range == null ) {
                CdUndoArea.PrintUsage( player );
                return;
            }
            if( cmd.HasNext ) {
                CdUndoArea.PrintUsage( player );
                return;
            }

            PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches( player, name );
            if( target == null ) return;

            if( player.Info != target && !player.Can( Permission.UndoOthersActions, target.Rank ) ) {
                player.Message( "You may only undo actions of players ranked {0}&S or lower.",
                                player.Info.Rank.GetLimit( Permission.UndoOthersActions ).ClassyName );
                player.Message( "Player {0}&S is ranked {1}", target.ClassyName, target.Rank.ClassyName );
                return;
            }

            int count;
            TimeSpan span;
            if( Int32.TryParse( range, out count ) ) {
                UndoAreaCountArgs args = new UndoAreaCountArgs {
                    Target = target,
                    World = playerWorld,
                    MaxBlocks = count
                };
                player.SelectionStart( 2, UndoAreaCountSelectionCallback, args, Permission.UndoOthersActions );

            } else if( range.TryParseMiniTimespan( out span ) ) {
                if( span > DateTimeUtil.MaxTimeSpan ) {
                    player.MessageMaxTimeSpan();
                    return;
                }
                UndoAreaTimeArgs args = new UndoAreaTimeArgs {
                    Target = target,
                    Time = span,
                    World = playerWorld
                };
                player.SelectionStart( 2, UndoAreaTimeSelectionCallback, args, Permission.UndoOthersActions );

            } else {
                CdUndoArea.PrintUsage( player );
                return;
            }

            player.MessageNow( "UndoArea: Click 2 blocks or use &H/Mark&S to make a selection." );
        }
Пример #3
0
        static void UndoPlayerHandler( Player player, Command cmd )
        {
            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );

            if( !BlockDB.IsEnabledGlobally ) {
                player.Message( "&WBlockDB is disabled on this server." );
                return;
            }

            if( !playerWorld.BlockDB.IsEnabled ) {
                player.Message( "&WBlockDB is disabled in this world." );
                return;
            }

            string name = cmd.Next();
            string range = cmd.Next();
            if( name == null || range == null ) {
                CdUndoPlayer.PrintUsage( player );
                return;
            }
            if( cmd.HasNext ) {
                CdUndoPlayer.PrintUsage( player );
                return;
            }

            PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches( player, name );
            if( target == null ) return;

            if( player.Info != target && !player.Can( Permission.UndoOthersActions, target.Rank ) ) {
                player.Message( "You may only undo actions of players ranked {0}&S or lower.",
                                player.Info.Rank.GetLimit( Permission.UndoOthersActions ).ClassyName );
                player.Message( "Player {0}&S is ranked {1}", target.ClassyName, target.Rank.ClassyName );
                return;
            }

            int count;
            TimeSpan span;
            BlockDBEntry[] changes;
            if( Int32.TryParse( range, out count ) ) {
                if( !cmd.IsConfirmed ) {
                    player.Message( "Searching for last {0} changes made by {1}&s...",
                                    count, target.ClassyName );
                }
                changes = playerWorld.BlockDB.Lookup( target, count );
                if( changes.Length > 0 && !cmd.IsConfirmed ) {
                    player.Confirm( cmd, "Undo last {0} changes made by player {1}&S?",
                                    changes.Length, target.ClassyName );
                    return;
                }

            } else if( range.TryParseMiniTimespan( out span ) ) {
                if( span > DateTimeUtil.MaxTimeSpan ) {
                    player.MessageMaxTimeSpan();
                    return;
                }
                if( !cmd.IsConfirmed ) {
                    player.Message( "Searching for changes made by {0}&s in the last {1}...",
                                    target.ClassyName, span.ToMiniString() );
                }
                changes = playerWorld.BlockDB.Lookup( target, span );
                if( changes.Length > 0 && !cmd.IsConfirmed ) {
                    player.Confirm( cmd, "Undo changes ({0}) made by {1}&S in the last {2}?",
                                    changes.Length, target.ClassyName, span.ToMiniString() );
                    return;
                }

            } else {
                CdUndoPlayer.PrintUsage( player );
                return;
            }

            if( changes.Length == 0 ) {
                player.Message( "UndoPlayer: Found nothing to undo." );
                return;
            }

            BlockChangeContext context = BlockChangeContext.Drawn;
            if( player.Info == target ) {
                context |= BlockChangeContext.UndoneSelf;
            } else {
                context |= BlockChangeContext.UndoneOther;
            }

            int blocks = 0,
                blocksDenied = 0;

            UndoState undoState = player.DrawBegin( null );
            Map map = player.WorldMap;

            for( int i = 0; i < changes.Length; i++ ) {
                DrawOneBlock( player, map, changes[i].OldBlock,
                              changes[i].Coord, context,
                              ref blocks, ref blocksDenied, undoState );
            }

            Logger.Log( LogType.UserActivity,
                        "{0} undid {1} blocks changed by player {2} (on world {3})",
                        player.Name,
                        blocks,
                        target.Name,
                        playerWorld.Name );

            DrawingFinished( player, "UndoPlayer'ed", blocks, blocksDenied );
        }
Пример #4
0
        static void TimerHandler( Player player, Command 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.Stop();
                        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.IsNullOrEmpty( 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 );
        }
Пример #5
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);
        }
Пример #6
0
        static void RestartHandler( Player player, CommandReader cmd ) {
            string delayString = cmd.Next();
            TimeSpan delayTime = DefaultShutdownTime;
            string reason = "";

            if( delayString != null ) {
                if( delayString.Equals( "abort", StringComparison.OrdinalIgnoreCase ) ) {
                    if( Server.CancelShutdown() ) {
                        Logger.Log( LogType.UserActivity,
                                    "Restart aborted by {0}.", player.Name );
                        Server.Message( "&WRestart aborted by {0}", player.ClassyName );
                    } else {
                        player.MessageNow( "Cannot abort restart - too late." );
                    }
                    return;
                } else if( !delayString.TryParseMiniTimespan( out delayTime ) ) {
                    CdShutdown.PrintUsage( player );
                    return;
                }
                if( delayTime > DateTimeUtil.MaxTimeSpan ) {
                    player.MessageMaxTimeSpan();
                    return;
                }
                reason = cmd.NextAll();
            }

            if( delayTime.TotalMilliseconds > Int32.MaxValue - 1 ) {
                player.Message( "Restart: Delay is too long, maximum is {0}",
                                TimeSpan.FromMilliseconds( Int32.MaxValue - 1 ).ToMiniString() );
                return;
            }

            Server.Message( "&WServer restarting in {0}", delayTime.ToMiniString() );

            if( String.IsNullOrEmpty( reason ) ) {
                Logger.Log( LogType.UserActivity,
                            "{0} scheduled a restart ({1} delay).",
                            player.Name, delayTime.ToCompactString() );
                ShutdownParams sp = new ShutdownParams( ShutdownReason.Restarting, delayTime, true, true );
                Server.Shutdown( sp, false );
            } else {
                Server.Message( "&WRestart reason: {0}", reason );
                Logger.Log( LogType.UserActivity,
                            "{0} scheduled a restart ({1} delay). Reason: {2}",
                            player.Name, delayTime.ToCompactString(), reason );
                ShutdownParams sp = new ShutdownParams( ShutdownReason.Restarting, delayTime, true, true, reason, player );
                Server.Shutdown( sp, false );
            }
        }
Пример #7
0
        static void BlockDBHandler(Player player, Command cmd)
        {
            if (!BlockDB.IsEnabledGlobally)
            {
                player.Message("&WBlockDB is disabled on this server.");
                return;
            }

            string worldName = cmd.Next();
            if (worldName == null)
            {
                int total = 0;
                World[] autoEnabledWorlds = WorldManager.Worlds.Where(w => (w.BlockDB.EnabledState == YesNoAuto.Auto) && w.BlockDB.IsEnabled).ToArray();
                if (autoEnabledWorlds.Length > 0)
                {
                    total += autoEnabledWorlds.Length;
                    player.Message("BlockDB is auto-enabled on: {0}",
                                    autoEnabledWorlds.JoinToClassyString());
                }

                World[] manuallyEnabledWorlds = WorldManager.Worlds.Where(w => w.BlockDB.EnabledState == YesNoAuto.Yes).ToArray();
                if (manuallyEnabledWorlds.Length > 0)
                {
                    total += manuallyEnabledWorlds.Length;
                    player.Message("BlockDB is manually enabled on: {0}",
                                    manuallyEnabledWorlds.JoinToClassyString());
                }

                World[] manuallyDisabledWorlds = WorldManager.Worlds.Where(w => w.BlockDB.EnabledState == YesNoAuto.No).ToArray();
                if (manuallyDisabledWorlds.Length > 0)
                {
                    player.Message("BlockDB is manually disabled on: {0}",
                                    manuallyDisabledWorlds.JoinToClassyString());
                }

                if (total == 0)
                {
                    player.Message("BlockDB is not enabled on any world.");
                }
                return;
            }

            World world = WorldManager.FindWorldOrPrintMatches(player, worldName);
            if (world == null) return;
            BlockDB db = world.BlockDB;

            lock (db.SyncRoot)
            {
                string op = cmd.Next();
                if (op == null)
                {
                    if (!db.IsEnabled)
                    {
                        if (db.EnabledState == YesNoAuto.Auto)
                        {
                            player.Message("BlockDB is disabled (auto) on world {0}", world.ClassyName);
                        }
                        else
                        {
                            player.Message("BlockDB is disabled on world {0}", world.ClassyName);
                        }
                    }
                    else
                    {
                        if (db.IsPreloaded)
                        {
                            if (db.EnabledState == YesNoAuto.Auto)
                            {
                                player.Message("BlockDB is enabled (auto) and preloaded on world {0}", world.ClassyName);
                            }
                            else
                            {
                                player.Message("BlockDB is enabled and preloaded on world {0}", world.ClassyName);
                            }
                        }
                        else
                        {
                            if (db.EnabledState == YesNoAuto.Auto)
                            {
                                player.Message("BlockDB is enabled (auto) on world {0}", world.ClassyName);
                            }
                            else
                            {
                                player.Message("BlockDB is enabled on world {0}", world.ClassyName);
                            }
                        }
                        player.Message("    Change limit: {0}    Time limit: {1}",
                                        db.Limit == 0 ? "none" : db.Limit.ToString(),
                                        db.TimeLimit == TimeSpan.Zero ? "none" : db.TimeLimit.ToMiniString());
                    }
                    return;
                }

                switch (op.ToLower())
                {
                    case "on":
                        // enables BlockDB
                        if (db.EnabledState == YesNoAuto.Yes)
                        {
                            player.Message("BlockDB is already manually enabled on world {0}", world.ClassyName);

                        }
                        else if (db.EnabledState == YesNoAuto.Auto && db.IsEnabled)
                        {
                            db.EnabledState = YesNoAuto.Yes;
                            WorldManager.SaveWorldList();
                            player.Message("BlockDB was auto-enabled, and is now manually enabled on world {0}", world.ClassyName);

                        }
                        else
                        {
                            db.EnabledState = YesNoAuto.Yes;
                            WorldManager.SaveWorldList();
                            player.Message("BlockDB is now manually enabled on world {0}", world.ClassyName);
                        }
                        break;

                    case "off":
                        // disables BlockDB
                        if (db.EnabledState == YesNoAuto.No)
                        {
                            player.Message("BlockDB is already manually disabled on world {0}", world.ClassyName);

                        }
                        else if (db.IsEnabled)
                        {
                            if (cmd.IsConfirmed)
                            {
                                db.EnabledState = YesNoAuto.No;
                                WorldManager.SaveWorldList();
                                player.Message("BlockDB is now manually disabled on world {0}&S. Use &H/BlockDB {1} clear&S to delete all the data.",
                                                world.ClassyName, world.Name);
                            }
                            else
                            {
                                player.Confirm(cmd,
                                                "Disable BlockDB on world {0}&S? Block changes will stop being recorded.",
                                                world.ClassyName);
                            }
                        }
                        else
                        {
                            db.EnabledState = YesNoAuto.No;
                            WorldManager.SaveWorldList();
                            player.Message("BlockDB was auto-disabled, and is now manually disabled on world {0}&S.",
                                            world.ClassyName);
                        }
                        break;

                    case "auto":
                        if (db.EnabledState == YesNoAuto.Auto)
                        {
                            player.Message("BlockDB is already set to automatically enable/disable itself on world {0}", world.ClassyName);
                        }
                        else
                        {
                            db.EnabledState = YesNoAuto.Auto;
                            WorldManager.SaveWorldList();
                            if (db.IsEnabled)
                            {
                                player.Message("BlockDB is now auto-enabled on world {0}",
                                                world.ClassyName);
                            }
                            else
                            {
                                player.Message("BlockDB is now auto-disabled on world {0}",
                                                world.ClassyName);
                            }
                        }
                        break;

                    case "limit":
                        // sets or resets limit on the number of changes to store
                        if (db.IsEnabled)
                        {
                            string limitString = cmd.Next();
                            int limitNumber;

                            if (limitString == null)
                            {
                                player.Message("BlockDB: Limit for world {0}&S is {1}",
                                                world.ClassyName,
                                                (db.Limit == 0 ? "none" : db.Limit.ToString()));
                                return;
                            }

                            if (limitString.Equals("none", StringComparison.OrdinalIgnoreCase))
                            {
                                limitNumber = 0;

                            }
                            else if (!Int32.TryParse(limitString, out limitNumber))
                            {
                                CdBlockDB.PrintUsage(player);
                                return;

                            }
                            else if (limitNumber < 0)
                            {
                                player.Message("BlockDB: Limit must be non-negative.");
                                return;
                            }

                            if (!cmd.IsConfirmed && limitNumber != 0)
                            {
                                player.Confirm(cmd, "BlockDB: Change limit? Some old data for world {0}&S may be discarded.", world.ClassyName);

                            }
                            else
                            {
                                string limitDisplayString = (limitNumber == 0 ? "none" : limitNumber.ToString());
                                if (db.Limit == limitNumber)
                                {
                                    player.Message("BlockDB: Limit for world {0}&S is already set to {1}",
                                                   world.ClassyName, limitDisplayString);

                                }
                                else
                                {
                                    db.Limit = limitNumber;
                                    WorldManager.SaveWorldList();
                                    player.Message("BlockDB: Limit for world {0}&S set to {1}",
                                                   world.ClassyName, limitDisplayString);
                                }
                            }

                        }
                        else
                        {
                            player.Message("Block tracking is disabled on world {0}", world.ClassyName);
                        }
                        break;

                    case "timelimit":
                        // sets or resets limit on the age of changes to store
                        if (db.IsEnabled)
                        {
                            string limitString = cmd.Next();

                            if (limitString == null)
                            {
                                if (db.TimeLimit == TimeSpan.Zero)
                                {
                                    player.Message("BlockDB: There is no time limit for world {0}",
                                                    world.ClassyName);
                                }
                                else
                                {
                                    player.Message("BlockDB: Time limit for world {0}&S is {1}",
                                                    world.ClassyName, db.TimeLimit.ToMiniString());
                                }
                                return;
                            }

                            TimeSpan limit;
                            if (limitString.Equals("none", StringComparison.OrdinalIgnoreCase))
                            {
                                limit = TimeSpan.Zero;

                            }
                            else if (!limitString.TryParseMiniTimespan(out limit))
                            {
                                CdBlockDB.PrintUsage(player);
                                return;
                            }
                            if (limit > DateTimeUtil.MaxTimeSpan)
                            {
                                player.MessageMaxTimeSpan();
                                return;
                            }

                            if (!cmd.IsConfirmed && limit != TimeSpan.Zero)
                            {
                                player.Confirm(cmd, "BlockDB: Change time limit? Some old data for world {0}&S may be discarded.", world.ClassyName);

                            }
                            else
                            {

                                if (db.TimeLimit == limit)
                                {
                                    if (db.TimeLimit == TimeSpan.Zero)
                                    {
                                        player.Message("BlockDB: There is already no time limit for world {0}",
                                                        world.ClassyName);
                                    }
                                    else
                                    {
                                        player.Message("BlockDB: Time limit for world {0}&S is already set to {1}",
                                                        world.ClassyName, db.TimeLimit.ToMiniString());
                                    }
                                }
                                else
                                {
                                    db.TimeLimit = limit;
                                    WorldManager.SaveWorldList();
                                    if (db.TimeLimit == TimeSpan.Zero)
                                    {
                                        player.Message("BlockDB: Time limit removed for world {0}",
                                                        world.ClassyName);
                                    }
                                    else
                                    {
                                        player.Message("BlockDB: Time limit for world {0}&S set to {1}",
                                                        world.ClassyName, db.TimeLimit.ToMiniString());
                                    }
                                }
                            }

                        }
                        else
                        {
                            player.Message("Block tracking is disabled on world {0}", world.ClassyName);
                        }
                        break;

                    case "clear":
                        // wipes BlockDB data
                        bool hasData = (db.IsEnabled || File.Exists(db.FileName));
                        if (hasData)
                        {
                            if (cmd.IsConfirmed)
                            {
                                db.Clear();
                                player.Message("BlockDB: Cleared all data for {0}", world.ClassyName);
                            }
                            else
                            {
                                player.Confirm(cmd, "Clear BlockDB data for world {0}&S? This cannot be undone.",
                                                world.ClassyName);
                            }
                        }
                        else
                        {
                            player.Message("BlockDB: No data to clear for world {0}", world.ClassyName);
                        }
                        break;

                    case "preload":
                        // enables/disables BlockDB preloading
                        if (db.IsEnabled)
                        {
                            string param = cmd.Next();
                            if (param == null)
                            {
                                // shows current preload setting
                                player.Message("BlockDB preloading is {0} for world {1}",
                                                (db.IsPreloaded ? "ON" : "OFF"),
                                                world.ClassyName);

                            }
                            else if (param.Equals("on", StringComparison.OrdinalIgnoreCase))
                            {
                                // turns preload on
                                if (db.IsPreloaded)
                                {
                                    player.Message("BlockDB preloading is already enabled on world {0}", world.ClassyName);
                                }
                                else
                                {
                                    db.IsPreloaded = true;
                                    WorldManager.SaveWorldList();
                                    player.Message("BlockDB preloading is now enabled on world {0}", world.ClassyName);
                                }

                            }
                            else if (param.Equals("off", StringComparison.OrdinalIgnoreCase))
                            {
                                // turns preload off
                                if (!db.IsPreloaded)
                                {
                                    player.Message("BlockDB preloading is already disabled on world {0}", world.ClassyName);
                                }
                                else
                                {
                                    db.IsPreloaded = false;
                                    WorldManager.SaveWorldList();
                                    player.Message("BlockDB preloading is now disabled on world {0}", world.ClassyName);
                                }

                            }
                            else
                            {
                                CdBlockDB.PrintUsage(player);
                            }
                        }
                        else
                        {
                            player.Message("Block tracking is disabled on world {0}", world.ClassyName);
                        }
                        break;

                    default:
                        // unknown operand
                        CdBlockDB.PrintUsage(player);
                        return;
                }
            }
        }
Пример #8
0
        static void SetInfoHandler( Player player, Command cmd ) {
            string targetName = cmd.Next();
            string propertyName = cmd.Next();
            string valName = cmd.NextAll();

            if( targetName == null || propertyName == null ) {
                CdSetInfo.PrintUsage( player );
                return;
            }

            PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches( player, targetName );
            if( info == null ) return;

            switch( propertyName.ToLower() ) {
                case "timeskicked":
                    int oldTimesKicked = info.TimesKicked;
                    if( ValidateInt( valName, 0, 9999 ) ) {
                        info.TimesKicked = Int32.Parse( valName );
                        player.Message( "SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        oldTimesKicked,
                                        info.TimesKicked );
                        break;
                    } else {
                        player.Message( "SetInfo: TimesKicked value acceptible (Acceptible value range: 0-9999)" );
                        return;
                    }

                case "previousrank":
                    Rank newPreviousRank;
                    if( valName.Length > 0 ) {
                        newPreviousRank = RankManager.FindRank( valName );
                        if( newPreviousRank == null ) {
                            player.MessageNoRank( valName );
                            return;
                        }
                    } else {
                        newPreviousRank = null;
                    }

                    Rank oldPreviousRank = info.PreviousRank;

                    if( newPreviousRank == oldPreviousRank ) {
                        if( newPreviousRank == null ) {
                            player.Message( "SetInfo: PreviousRank for {0}&S is not set.",
                                            info.ClassyName );
                        } else {
                            player.Message( "SetInfo: PreviousRank for {0}&S is already set to {1}",
                                            info.ClassyName,
                                            newPreviousRank.ClassyName );
                        }
                        return;
                    }

                    if( oldPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S set to {1}&",
                                        info.ClassyName,
                                        newPreviousRank.ClassyName );
                    } else if( newPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName );
                    } else {
                        player.Message( "SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName,
                                        newPreviousRank.ClassyName );
                    }
                    break;

                case "totaltime":
                    TimeSpan newTotalTime;
                    TimeSpan oldTotalTime = info.TotalTime;
                    if( valName.TryParseMiniTimespan( out newTotalTime ) ) {
                        if( newTotalTime > DateTimeUtil.MaxTimeSpan ) {
                            player.MessageMaxTimeSpan();
                            return;
                        }
                        info.TotalTime = newTotalTime;
                        player.Message( "SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                        info.ClassyName,
                                        oldTotalTime.ToMiniString(),
                                        oldTotalTime.ToCompactString(),
                                        info.TotalTime.ToMiniString(),
                                        info.TotalTime.ToCompactString() );
                        break;
                    } else {
                        player.Message( "SetInfo: Could not parse value given for TotalTime." );
                        return;
                    }

                case "rankchangetype":
                    RankChangeType oldType = info.RankChangeType;
                    try {
                        info.RankChangeType = (RankChangeType)Enum.Parse( typeof( RankChangeType ), valName, true );
                    } catch( ArgumentException ) {
                        player.Message( "SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                        String.Join( ", ", Enum.GetNames( typeof( RankChangeType ) ) ) );
                        return;
                    }
                    player.Message( "SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                                    info.ClassyName,
                                    oldType,
                                    info.RankChangeType );
                    break;

                case "banreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "BanReason", info, info.BanReason, valName ) ) {
                        info.BanReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "unbanreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "UnbanReason", info, info.UnbanReason, valName ) ) {
                        info.UnbanReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "rankreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "RankReason", info, info.RankChangeReason, valName ) ) {
                        info.RankChangeReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "kickreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "KickReason", info, info.LastKickReason, valName ) ) {
                        info.LastKickReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "displayedname":
                    string oldDisplayedName = info.DisplayedName;
                    if( player.Can( Permission.UseColorCodes ) ) {
                        valName = Color.ReplacePercentCodes( valName );
                    }
                    if( valName.Length == 0 ) valName = null;
                    if( valName == info.DisplayedName ) {
                        if( valName == null ) {
                            player.Message( "SetInfo: DisplayedName for {0} is not set.",
                                            info.Name );
                        } else {
                            player.Message( "SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                            info.Name,
                                            valName );
                        }
                        return;
                    }
                    info.DisplayedName = valName;

                    if( oldDisplayedName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                        info.Name,
                                        valName );
                    } else if( valName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                        info.Name,
                                        oldDisplayedName );
                    } else {
                        player.Message( "SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                        info.Name,
                                        oldDisplayedName,
                                        valName );
                    }
                    break;

                default:
                    player.Message( "Only the following properties are editable: " +
                                    "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                                    "BanReason, UnbanReason, RankReason, KickReason, DisplayedName" );
                    return;
            }
            info.LastModified = DateTime.UtcNow;
        }
Пример #9
0
        static void SetInfoHandler( Player player, CommandReader cmd ) {
            string targetName = cmd.Next();
            string propertyName = cmd.Next();
            string valName = cmd.NextAll();

            if( targetName == null || propertyName == null ) {
                CdSetInfo.PrintUsage( player );
                return;
            }

            PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches( player, targetName );
            if( info == null ) return;

            switch( propertyName.ToLower() ) {
                case "banreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "BanReason", info, info.BanReason, valName ) ) {
                        info.BanReason = valName;
                    }
                    break;

                case "displayedname":
                    string oldDisplayedName = info.DisplayedName;
                    if( valName.Length == 0 ) valName = null;
                    if( valName == info.DisplayedName ) {
                        if( valName == null ) {
                            player.Message( "SetInfo: DisplayedName for {0} is not set.",
                                            info.Name );
                        } else {
                            player.Message( "SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                            info.Name,
                                            valName );
                        }
                        break;
                    }
                    info.DisplayedName = valName;

                    if( oldDisplayedName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                        info.Name,
                                        valName );
                    } else if( valName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                        info.Name,
                                        oldDisplayedName );
                    } else {
                        player.Message( "SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                        info.Name,
                                        oldDisplayedName,
                                        valName );
                    }
                    break;

                case "kickreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "KickReason", info, info.LastKickReason, valName ) ) {
                        info.LastKickReason = valName;
                    }
                    break;

                case "name":
                    if( valName.Equals( info.Name, StringComparison.OrdinalIgnoreCase ) ) {
                        player.Message( "SetInfo: You may change capitalization of player's real name. " +
                                        "If you'd like to make other changes to the way player's name is displayed, " +
                                        "use &H/SetInfo <Name> DisplayedName <NewName>" );
                        break;
                    }
                    string oldName = info.Name;
                    if( oldName != valName ) {
                        info.Name = valName;
                        player.Message( "Name capitalization changed from \"{0}\" to \"{1}\"",
                                        oldName, valName );
                    } else {
                        player.Message( "Name capitalization is already \"{0}\"", oldName );
                    }
                    break;

                case "previousrank":
                    Rank newPreviousRank;
                    if( valName.Length > 0 ) {
                        newPreviousRank = RankManager.FindRank( valName );
                        if( newPreviousRank == null ) {
                            player.MessageNoRank( valName );
                            break;
                        }
                    } else {
                        newPreviousRank = null;
                    }

                    Rank oldPreviousRank = info.PreviousRank;

                    if( newPreviousRank == oldPreviousRank ) {
                        if( newPreviousRank == null ) {
                            player.Message( "SetInfo: PreviousRank for {0}&S is not set.",
                                            info.ClassyName );
                        } else {
                            player.Message( "SetInfo: PreviousRank for {0}&S is already set to {1}",
                                            info.ClassyName,
                                            newPreviousRank.ClassyName );
                        }
                        break;
                    }
                    info.PreviousRank = newPreviousRank;

                    if( oldPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S set to {1}&",
                                        info.ClassyName,
                                        newPreviousRank.ClassyName );
                    } else if( newPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName );
                    } else {
                        player.Message( "SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName,
                                        newPreviousRank.ClassyName );
                    }
                    break;

                case "rankchangetype":
                    RankChangeType oldType = info.RankChangeType;
                    try {
                        info.RankChangeType = (RankChangeType)Enum.Parse( typeof( RankChangeType ), valName, true );
                    } catch( ArgumentException ) {
                        player.Message( "SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                        String.Join( ", ", Enum.GetNames( typeof( RankChangeType ) ) ) );
                        break;
                    }
                    player.Message( "SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                                    info.ClassyName,
                                    oldType,
                                    info.RankChangeType );
                    break;

                case "rankreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "RankReason", info, info.RankChangeReason, valName ) ) {
                        info.RankChangeReason = valName;
                    }
                    break;

                case "timeskicked":
                    int oldTimesKicked = info.TimesKicked;
                    if( ValidateInt( valName, 0, 9999 ) ) {
                        info.TimesKicked = Int32.Parse( valName );
                        player.Message( "SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        oldTimesKicked,
                                        info.TimesKicked );
                    } else {
                        player.Message( "SetInfo: TimesKicked value out of range (Acceptable value range: 0-9999)" );
                    }
                    break;

                case "totaltime":
                    TimeSpan newTotalTime;
                    TimeSpan oldTotalTime = info.TotalTime;
                    if( valName.TryParseMiniTimespan( out newTotalTime ) ) {
                        if( newTotalTime > DateTimeUtil.MaxTimeSpan ) {
                            player.MessageMaxTimeSpan();
                            break;
                        }
                        info.TotalTime = newTotalTime;
                        player.Message( "SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                        info.ClassyName,
                                        oldTotalTime.ToMiniString(),
                                        oldTotalTime.ToCompactString(),
                                        info.TotalTime.ToMiniString(),
                                        info.TotalTime.ToCompactString() );
                    } else {
                        player.Message( "SetInfo: Could not parse value given for TotalTime." );
                    }
                    break;

                case "unbanreason":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "UnbanReason", info, info.UnbanReason, valName ) ) {
                        info.UnbanReason = valName;
                    }
                    break;

                default:
                    player.Message( "Only the following properties are editable: " +
                                    "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                                    "BanReason, UnbanReason, RankReason, KickReason, DisplayedName" );
                    return;
            }
        }
Пример #10
0
        static void SetInfoHandler( Player player, CommandReader cmd ) {
            string targetName = cmd.Next();
            string propertyName = cmd.Next();
            string valName = cmd.NextAll();

            if( targetName == null || propertyName == null ) {
                CdSetInfo.PrintUsage( player );
                return;
            }

            PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches( player, targetName, SearchOptions.IncludeSelf );
            if( info == null ) return;

            switch( propertyName.ToLower() ) {
                case "timeskicked":
                case "tk":
                    int oldTimesKicked = info.TimesKicked;
                    if( ValidateInt( valName, 0, 9999 ) ) {
                        info.TimesKicked = Int32.Parse( valName );
                        player.Message( "SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        oldTimesKicked,
                                        info.TimesKicked );
                        break;
                    } else {
                        player.Message( "SetInfo: TimesKicked value out of range (acceptable: 0-9999)" );
                        return;
                    }

                case "previousrank":
                case "pr":
                    Rank newPreviousRank;
                    if( valName.Length > 0 ) {
                        newPreviousRank = RankManager.FindRank( valName );
                        if( newPreviousRank == null ) {
                            player.MessageNoRank( valName );
                            return;
                        }
                    } else {
                        newPreviousRank = null;
                    }

                    Rank oldPreviousRank = info.PreviousRank;

                    if( newPreviousRank == null && oldPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S is not set.",
                                        info.ClassyName );
                        return;
                    } else if( newPreviousRank == oldPreviousRank ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S is already set to {1}",
                                        info.ClassyName,
                                        newPreviousRank.ClassyName );
                        return;
                    }
                    info.PreviousRank = newPreviousRank;

                    if( oldPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S set to {1}&",
                                        info.ClassyName,
                                        newPreviousRank.ClassyName );
                    } else if( newPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName );
                    } else {
                        player.Message( "SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName,
                                        newPreviousRank.ClassyName );
                    }
                    break;

                case "totaltime":
                case "tt":
                    TimeSpan newTotalTime;
                    TimeSpan oldTotalTime = info.TotalTime;
                    if( valName.TryParseMiniTimeSpan( out newTotalTime ) ) {
                        if( newTotalTime > DateTimeUtil.MaxTimeSpan ) {
                            player.MessageMaxTimeSpan();
                            return;
                        }
                        info.TotalTime = newTotalTime;
                        player.Message( "SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                        info.ClassyName,
                                        oldTotalTime.ToMiniString(),
                                        oldTotalTime.ToCompactString(),
                                        info.TotalTime.ToMiniString(),
                                        info.TotalTime.ToCompactString() );
                        break;
                    } else {
                        player.Message( "SetInfo: Could not parse value given for TotalTime." );
                        return;
                    }

                case "rankchangetype":
                case "rct":
                    RankChangeType oldType = info.RankChangeType;
                    RankChangeType newType;
                    if(!EnumUtil.TryParse(valName, out newType, true)){
                        player.Message( "SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                        String.Join( ", ", Enum.GetNames( typeof( RankChangeType ) ) ) );
                        return;
                    }
                    info.RankChangeType = newType;
                    player.Message( "SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                                    info.ClassyName,
                                    oldType,
                                    info.RankChangeType );
                    break;

                case "banreason":
                case "br":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "BanReason", info, info.BanReason, valName ) ) {
                        info.BanReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "bandwidth":
                case "bw":
                    BandwidthUseMode oldMode = info.BandwidthUseMode;
                    BandwidthUseMode newMode;
                    if( !EnumUtil.TryParse( valName, out newMode, true ) ) {
                        player.Message( "SetInfo: Could not parse BandwidthUseMode. Allowed values: {0}",
                                        String.Join( ", ", Enum.GetNames( typeof( BandwidthUseMode ) ) ) );
                        return;
                    }
                    info.BandwidthUseMode = newMode;
                    player.Message( "SetInfo: BandwidthUseMode for {0}&S changed from {1} to {2}",
                                    info.ClassyName,
                                    oldMode, newMode );
                    break;

                case "unbanreason":
                case "ur":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "UnbanReason", info, info.UnbanReason, valName ) ) {
                        info.UnbanReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "rankreason":
                case "rr":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "RankReason", info, info.RankChangeReason, valName ) ) {
                        info.RankChangeReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "kickreason":
                case "kr":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "KickReason", info, info.LastKickReason, valName ) ) {
                        info.LastKickReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "displayedname":
                case "dn":
                    string oldDisplayedName = info.DisplayedName;
                    if( valName.Length == 0 ) valName = null;

                    if( valName != null && ( valName.Contains( '\n' ) || valName.Contains( "&n" ) || valName.Contains( "&N" ) ) ) {
                        player.Message( "SetInfo: DisplayedName may not contain line breaks." );
                        return;
                    }

                    if( valName == info.DisplayedName ) {
                        if( valName == null ) {
                            player.Message( "SetInfo: DisplayedName for {0} is not set.",
                                            info.Name );
                        } else {
                            player.Message( "SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                            info.Name,
                                            valName );
                        }
                        return;
                    }
                    info.DisplayedName = valName;

                    if( oldDisplayedName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                        info.Name,
                                        valName );
                    } else if( valName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                        info.Name,
                                        oldDisplayedName );
                    } else {
                        player.Message( "SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                        info.Name,
                                        oldDisplayedName,
                                        valName );
                    }
                    break;

                case "name":
                case "n":
                    if( valName.Equals( info.Name, StringComparison.OrdinalIgnoreCase ) ) {
                        info.Name = valName;
                    } else {
                        player.Message( "SetInfo: Only capitalization changes are allowed in the name. " +
                                        "Type out the whole name ({0}) please.",
                                        info.Name );
                        return;
                    }
                    break;

                default:
                    player.Message( "Only the following properties are editable: " +
                                    "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                                    "BanReason, UnbanReason, RankReason, KickReason, DisplayedName" );
                    return;
            }
            info.LastModified = DateTime.UtcNow;
        }
Пример #11
0
        static void RestartHandler(Player player, CommandReader cmd)
        {
            string   delayString = cmd.Next();
            TimeSpan delayTime   = DefaultShutdownTime;
            string   reason      = "";

            if (delayString != null)
            {
                if (delayString.Equals("abort", StringComparison.OrdinalIgnoreCase))
                {
                    if (Server.CancelShutdown())
                    {
                        Logger.Log(LogType.UserActivity,
                                   "Restart aborted by {0}.", player.Name);
                        Server.Message("&WRestart aborted by {0}", player.ClassyName);
                    }
                    else
                    {
                        player.MessageNow("Cannot abort restart - too late.");
                    }
                    return;
                }
                else if (!delayString.TryParseMiniTimespan(out delayTime))
                {
                    CdShutdown.PrintUsage(player);
                    return;
                }
                if (delayTime > DateTimeUtil.MaxTimeSpan)
                {
                    player.MessageMaxTimeSpan();
                    return;
                }
                reason = cmd.NextAll();
            }

            if (delayTime.TotalMilliseconds > Int32.MaxValue - 1)
            {
                player.Message("Restart: Delay is too long, maximum is {0}",
                               TimeSpan.FromMilliseconds(Int32.MaxValue - 1).ToMiniString());
                return;
            }

            Server.Message("&WServer restarting in {0}", delayTime.ToMiniString());

            if (String.IsNullOrEmpty(reason))
            {
                Logger.Log(LogType.UserActivity,
                           "{0} scheduled a restart ({1} delay).",
                           player.Name, delayTime.ToCompactString());
                ShutdownParams sp = new ShutdownParams(ShutdownReason.Restarting, delayTime, true, true);
                Server.Shutdown(sp, false);
            }
            else
            {
                Server.Message("&WRestart reason: {0}", reason);
                Logger.Log(LogType.UserActivity,
                           "{0} scheduled a restart ({1} delay). Reason: {2}",
                           player.Name, delayTime.ToCompactString(), reason);
                ShutdownParams sp = new ShutdownParams(ShutdownReason.Restarting, delayTime, true, true, reason, player);
                Server.Shutdown(sp, false);
            }
        }
Пример #12
0
        static void SetInfoHandler(Player player, CommandReader cmd)
        {
            string targetName   = cmd.Next();
            string propertyName = cmd.Next();
            string valName      = cmd.NextAll();

            if (targetName == null || propertyName == null)
            {
                CdSetInfo.PrintUsage(player);
                return;
            }

            PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches(player, targetName);

            if (info == null)
            {
                return;
            }

            switch (propertyName.ToLower())
            {
            case "banreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "BanReason", info, info.BanReason, valName))
                {
                    info.BanReason = valName;
                }
                break;

            case "displayedname":
                string oldDisplayedName = info.DisplayedName;
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (valName == info.DisplayedName)
                {
                    if (valName == null)
                    {
                        player.Message("SetInfo: DisplayedName for {0} is not set.",
                                       info.Name);
                    }
                    else
                    {
                        player.Message("SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                       info.Name,
                                       valName);
                    }
                    break;
                }
                info.DisplayedName = valName;

                if (oldDisplayedName == null)
                {
                    player.Message("SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                   info.Name,
                                   valName);
                }
                else if (valName == null)
                {
                    player.Message("SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                   info.Name,
                                   oldDisplayedName);
                }
                else
                {
                    player.Message("SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                   info.Name,
                                   oldDisplayedName,
                                   valName);
                }
                break;

            case "kickreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "KickReason", info, info.LastKickReason, valName))
                {
                    info.LastKickReason = valName;
                }
                break;

            case "name":
                if (valName.Equals(info.Name, StringComparison.OrdinalIgnoreCase))
                {
                    player.Message("SetInfo: You may change capitalization of player's real name. " +
                                   "If you'd like to make other changes to the way player's name is displayed, " +
                                   "use &H/SetInfo <Name> DisplayedName <NewName>");
                    break;
                }
                string oldName = info.Name;
                if (oldName != valName)
                {
                    info.Name = valName;
                    player.Message("Name capitalization changed from \"{0}\" to \"{1}\"",
                                   oldName, valName);
                }
                else
                {
                    player.Message("Name capitalization is already \"{0}\"", oldName);
                }
                break;

            case "previousrank":
                Rank newPreviousRank;
                if (valName.Length > 0)
                {
                    newPreviousRank = RankManager.FindRank(valName);
                    if (newPreviousRank == null)
                    {
                        player.MessageNoRank(valName);
                        break;
                    }
                }
                else
                {
                    newPreviousRank = null;
                }

                Rank oldPreviousRank = info.PreviousRank;

                if (newPreviousRank == oldPreviousRank)
                {
                    if (newPreviousRank == null)
                    {
                        player.Message("SetInfo: PreviousRank for {0}&S is not set.",
                                       info.ClassyName);
                    }
                    else
                    {
                        player.Message("SetInfo: PreviousRank for {0}&S is already set to {1}",
                                       info.ClassyName,
                                       newPreviousRank.ClassyName);
                    }
                    break;
                }
                info.PreviousRank = newPreviousRank;

                if (oldPreviousRank == null)
                {
                    player.Message("SetInfo: PreviousRank for {0}&S set to {1}&",
                                   info.ClassyName,
                                   newPreviousRank.ClassyName);
                }
                else if (newPreviousRank == null)
                {
                    player.Message("SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                   info.ClassyName,
                                   oldPreviousRank.ClassyName);
                }
                else
                {
                    player.Message("SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                   info.ClassyName,
                                   oldPreviousRank.ClassyName,
                                   newPreviousRank.ClassyName);
                }
                break;

            case "rankchangetype":
                RankChangeType oldType = info.RankChangeType;
                try {
                    info.RankChangeType = (RankChangeType)Enum.Parse(typeof(RankChangeType), valName, true);
                } catch (ArgumentException) {
                    player.Message("SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                   String.Join(", ", Enum.GetNames(typeof(RankChangeType))));
                    break;
                }
                player.Message("SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                               info.ClassyName,
                               oldType,
                               info.RankChangeType);
                break;

            case "rankreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "RankReason", info, info.RankChangeReason, valName))
                {
                    info.RankChangeReason = valName;
                }
                break;

            case "timeskicked":
                int oldTimesKicked = info.TimesKicked;
                if (ValidateInt(valName, 0, 9999))
                {
                    info.TimesKicked = Int32.Parse(valName);
                    player.Message("SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                   info.ClassyName,
                                   oldTimesKicked,
                                   info.TimesKicked);
                }
                else
                {
                    player.Message("SetInfo: TimesKicked value out of range (Acceptable value range: 0-9999)");
                }
                break;

            case "totaltime":
                TimeSpan newTotalTime;
                TimeSpan oldTotalTime = info.TotalTime;
                if (valName.TryParseMiniTimespan(out newTotalTime))
                {
                    if (newTotalTime > DateTimeUtil.MaxTimeSpan)
                    {
                        player.MessageMaxTimeSpan();
                        break;
                    }
                    info.TotalTime = newTotalTime;
                    player.Message("SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                   info.ClassyName,
                                   oldTotalTime.ToMiniString(),
                                   oldTotalTime.ToCompactString(),
                                   info.TotalTime.ToMiniString(),
                                   info.TotalTime.ToCompactString());
                }
                else
                {
                    player.Message("SetInfo: Could not parse value given for TotalTime.");
                }
                break;

            case "unbanreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "UnbanReason", info, info.UnbanReason, valName))
                {
                    info.UnbanReason = valName;
                }
                break;

            default:
                player.Message("Only the following properties are editable: " +
                               "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                               "BanReason, UnbanReason, RankReason, KickReason, DisplayedName");
                return;
            }
        }
Пример #13
0
        static void SetInfoHandler( Player player, CommandReader cmd ) {
            string targetName = cmd.Next();
            string propertyName = cmd.Next();
            string valName = cmd.NextAll();

            if( targetName == null || propertyName == null ) {
                CdSetInfo.PrintUsage( player );
                return;
            }

            PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, targetName, SearchOptions.IncludeSelf);
            if( info == null ) return;

            switch( propertyName.ToLower() ) {
                case "timeskicked":
                case "tk":
                    int oldTimesKicked = info.TimesKicked;
                    if( ValidateInt( valName, 0, 9999 ) ) {
                        info.TimesKicked = Int32.Parse( valName );
                        player.Message( "SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        oldTimesKicked,
                                        info.TimesKicked );
                        break;
                    } else {
                        player.Message( "SetInfo: TimesKicked value out of range (acceptable: 0-9999)" );
                        return;
                    }

                case "previousrank":
                case "pr":
                    Rank newPreviousRank;
                    if( valName.Length > 0 ) {
                        newPreviousRank = RankManager.FindRank( valName );
                        if( newPreviousRank == null ) {
                            player.MessageNoRank( valName );
                            return;
                        }
                    } else {
                        newPreviousRank = null;
                    }

                    Rank oldPreviousRank = info.PreviousRank;

                    if( newPreviousRank == null && oldPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S is not set.",
                                        info.ClassyName );
                        return;
                    } else if( newPreviousRank == oldPreviousRank ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S is already set to {1}",
                                        info.ClassyName,
                                        newPreviousRank.ClassyName );
                        return;
                    }
                    info.PreviousRank = newPreviousRank;

                    if( oldPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S set to {1}&",
                                        info.ClassyName,
                                        newPreviousRank.ClassyName );
                    } else if( newPreviousRank == null ) {
                        player.Message( "SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName );
                    } else {
                        player.Message( "SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                        info.ClassyName,
                                        oldPreviousRank.ClassyName,
                                        newPreviousRank.ClassyName );
                    }
                    break;

                case "totaltime":
                case "tt":
                    TimeSpan newTotalTime;
                    TimeSpan oldTotalTime = info.TotalTime;
                    if( valName.TryParseMiniTimespan( out newTotalTime ) ) {
                        if( newTotalTime > DateTimeUtil.MaxTimeSpan ) {
                            player.MessageMaxTimeSpan();
                            return;
                        }
                        info.TotalTime = newTotalTime;
                        player.Message( "SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                        info.ClassyName,
                                        oldTotalTime.ToMiniString(),
                                        oldTotalTime.ToCompactString(),
                                        info.TotalTime.ToMiniString(),
                                        info.TotalTime.ToCompactString() );
                        break;
                    } else {
                        player.Message( "SetInfo: Could not parse value given for TotalTime." );
                        return;
                    }

                case "donatedammount":
                case "da":
                    if (player != Player.Console) {
                        player.Message("&WYou are not able to Set a players Donated Ammount.");
                        return;
                    }
                    double old = info.Donated;
                    double result;
                    bool parsed = Double.TryParse(valName, out result);
                    if (parsed) {
                        info.Donated = result;
                        player.Message("SetInfo: DonatedAmmount for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        old.ToString(),
                                        info.Donated.ToString());
                        break;
                    }
                    else
                    {
                        player.Message("SetInfo: Could not parse value given for DonatedAmmount.");
                        return;
                    }

                case "blocksbuilt":
                case "bb":
                    if (player != Player.Console) {
                        player.Message("&WYou are not able to Set a players built amount.");
                        return;
                    }
                    int oldbb = info.BlocksBuilt;
                    int resultbb;
                    bool parsedbb = int.TryParse(valName, out resultbb);
                    if (parsedbb)
                    {
                        info.BlocksBuilt = resultbb;
                        player.Message("SetInfo: BlocksBuilt for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        oldbb.ToString(),
                                        info.BlocksBuilt.ToString());
                        break;
                    }
                    else
                    {
                        player.Message("SetInfo: Could not parse value given for BlocksBuilt.");
                        return;
                    }

                case "blocksdeleted":
                case "bd":
                    if (player != Player.Console) {
                        player.Message("&WYou are not able to Set a players built amount.");
                        return;
                    }
                    int oldbd = info.BlocksBuilt;
                    int resultbd;
                    bool parsedbd = int.TryParse(valName, out resultbd);
                    if (parsedbd)
                    {
                        info.BlocksDeleted = resultbd;
                        player.Message("SetInfo: BlocksDeleted for {0}&S changed from {1} to {2}",
                                        info.ClassyName,
                                        oldbd.ToString(),
                                        info.BlocksDeleted.ToString());
                        break;
                    }
                    else
                    {
                        player.Message("SetInfo: Could not parse value given for BlocksBuilt.");
                        return;
                    }

                case "rankchangetype":
                case "rct":
                    RankChangeType oldType = info.RankChangeType;
                    try {
                        info.RankChangeType = (RankChangeType)Enum.Parse( typeof( RankChangeType ), valName, true );
                    } catch( ArgumentException ) {
                        player.Message( "SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                        String.Join( ", ", Enum.GetNames( typeof( RankChangeType ) ) ) );
                        return;
                    }
                    player.Message( "SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                                    info.ClassyName,
                                    oldType,
                                    info.RankChangeType );
                    break;

                case "banreason":
                case "br":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "BanReason", info, info.BanReason, valName ) ) {
                        info.BanReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "unbanreason":
                case "ur":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "UnbanReason", info, info.UnbanReason, valName ) ) {
                        info.UnbanReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "rankreason":
                case "rr":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "RankReason", info, info.RankChangeReason, valName ) ) {
                        info.RankChangeReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "kickreason":
                case "kr":
                    if( valName.Length == 0 ) valName = null;
                    if( SetPlayerInfoField( player, "KickReason", info, info.LastKickReason, valName ) ) {
                        info.LastKickReason = valName;
                        break;
                    } else {
                        return;
                    }

                case "readtherules":
                case "rtr":
                case "hasrtr":
                    bool rtr;
                    bool.TryParse(valName, out rtr);
                    if (SetPlayerInfoField(player, "HasRTR", info, info.HasRTR.ToString(), rtr.ToString()))
                    {
                        info.HasRTR = rtr;
                        break;
                    }
                    else
                    {
                        return;
                    }

                case "displayedname":
                case "dn":
                case "nick":
                    string oldDisplayedName = info.DisplayedName;
                    if( valName.Length == 0 ) valName = null;
                    if( valName == info.DisplayedName ) {
                        if( valName == null ) {
                            player.Message( "SetInfo: DisplayedName for {0} is not set.",
                                            info.Name );
                        } else {
                            player.Message( "SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                            info.Name,
                                            valName );
                        }
                        return;
                    }
                    info.DisplayedName = valName;

                    if( oldDisplayedName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                        info.Name,
                                        valName );
                    } else if( valName == null ) {
                        player.Message( "SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                        info.Name,
                                        oldDisplayedName );
                    } else {
                        player.Message( "SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                        info.Name,
                                        oldDisplayedName,
                                        valName );
                    }
                    break;
                case "ip":
                case "ipaddress":
                case "lastip":
                    IPAddress oldIP = info.LastIP;
                    if( valName.Length == 0 ) valName = IPAddress.None.ToString(); 
                    if( valName == info.LastIP.ToString() ) {
                        if( valName == null ) {
                            player.Message( "SetInfo: LastIP for {0} is not set.",
                                            info.Name );
                        } else {
                            player.Message( "SetInfo: LastIP for {0} is already set to \"{1}&S\"",
                                            info.Name,
                                            info.LastIP.ToString() );
                        }
                        return;
                    }
                    if (IPAddress.TryParse(valName, out info.LastIP)) {
                        info.LastIP = IPAddress.Parse(valName);
                    }
                    if( oldIP == null ) {
                        player.Message( "SetInfo: LastIP for {0} set to \"{1}&S\"",
                                        info.Name,
                                        valName.ToString() );
                    } else if( valName == null ) {
                        player.Message( "SetInfo: LastIP for {0} was reset (was \"{1}&S\")",
                                        info.Name,
                                        oldIP.ToString() );
                    } else {
                        player.Message( "SetInfo: LastIP for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                        info.Name,
                                        oldIP.ToString(),
                                        valName.ToString() );
                    }
                    break;
                default:
                    player.Message( "Only the following properties are editable: " +
                                    "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                                    "BanReason, UnbanReason, RankReason, KickReason, DisplayedName" );
                    return;
            }
            info.LastModified = DateTime.UtcNow;
        }
Пример #14
0
        static void TimerHandler(Player player, 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)
                    {
                        if (timer.Message.Equals(""))
                        {
                            player.Message("  #{0} \"&7*CountDown*&s\" (started by {2}, {3} left)",
                                            timer.ID, timer.Message, timer.StartedBy, timer.TimeLeft.ToMiniString());
                        }
                        else
                        {
                            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 abortircMsg = "";
                        if (timer.Message.Equals(""))
                        {
                            abortMsg = String.Format("&S{0}&S aborted a &7CountDown&S with {1} left",
                                                             player.ClassyName, timer.TimeLeft.ToMiniString());
                            abortircMsg = String.Format("\u212C&S{0}&S aborted a &7CountDown&S with {1} left",
                                                             player.ClassyName, timer.TimeLeft.ToMiniString());
                        }
                        else
                        {
                            abortMsg = String.Format("&S{0}&S aborted a &7Timer&S with {1} left: &7{2}",
                                                             player.ClassyName, timer.TimeLeft.ToMiniString(), timer.Message);
                            abortircMsg = String.Format( "\u212C&S{0}&S aborted a &7Timer&S with {1} left: \u211C{2}",
                                                             player.ClassyName, timer.TimeLeft.ToMiniString(), timer.Message);
                        }
                        Server.Players.Message(abortMsg);
                        IRC.SendChannelMessage(abortircMsg);
                    }
                }
                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 ircMessage;
            string message = cmd.NextAll();
            if (String.IsNullOrEmpty(message))
            {
                sayMessage = String.Format("&2[&7CountDown Started&2][&7{1}&2] &2-&7{0}",
                                            player.Name,
                                            duration.ToMiniString());
                ircMessage = String.Format( "\u212C&2[&7{1} CountDown Started&2] -\u211C{0}",
                                            player.Name,
                                            duration.ToMiniString());
            }
            else
            {
                sayMessage = String.Format("&2[&7Timer Started&2][&7{1}&2] &7{2} &2-&7{0}",
                                            player.Name,
                                            duration.ToMiniString(),
                                            message);
                ircMessage = String.Format( "\u212C&2[&7{1} Timer Started&2][&7{0}&2] \u211C{2}",
                                            player.Name,
                                            duration.ToMiniString(),
                                            message);
            }
            Server.Players.Message(sayMessage);
            IRC.SendChannelMessage(ircMessage);
            ChatTimer.Start(duration, message, player.Name);
        }