Example #1
0
        internal static void Help(Player player, Command cmd)
        {
            string commandName = cmd.Next();

            if (commandName == "commands")
            {
                cdCommands.Handler(player, cmd);
            }
            else if (commandName != null)
            {
                CommandDescriptor descriptor = CommandManager.GetDescriptor(commandName);
                if (descriptor == null)
                {
                    player.Message("Unknown command: \"{0}\"", commandName);
                    return;
                }
                StringBuilder sb = new StringBuilder(Color.Help);
                sb.Append(descriptor.Usage).Append("&N");

                if (descriptor.Aliases != null)
                {
                    sb.Append("Aliases: &H");
                    sb.Append(descriptor.Aliases.JoinToString("&S, &H"));
                    sb.Append("&N");
                }

                if (descriptor.HelpHandler != null)
                {
                    sb.Append(descriptor.HelpHandler(player));
                }
                else if (descriptor.Help != null)
                {
                    sb.Append(descriptor.Help);
                }
                else
                {
                    sb.Append("No help is available for this command.");
                }

                player.MessagePrefixed(HelpPrefix, sb.ToString());

                if (descriptor.Permissions != null && descriptor.Permissions.Length > 0)
                {
                    player.NoAccessMessage(descriptor.Permissions);
                }
            }
            else
            {
                player.Message("To see a list of all commands, write &H/help commands");
                player.Message("To see detailed help for a command, write &H/help CommandName");
                if (player != Player.Console)
                {
                    player.Message("To see your stats, write &H/info");
                }
                player.Message("To list available worlds, write &H/worlds");
                player.Message("To send private messages, write &H@PlayerName Message");
                player.Message("To message all players of a rank, write &H@@Rank Message");
            }
        }
Example #2
0
        internal static void Commands(Player player, Command cmd)
        {
            string param = cmd.Next();

            CommandDescriptor[] cd;

            if (param == null)
            {
                player.Message("List of available commands:");
                cd = CommandManager.GetCommands(false);
            }
            else if (param.StartsWith("@"))
            {
                string rankName = param.Substring(1);
                Rank   rank     = RankManager.FindRank(rankName);
                if (rank == null)
                {
                    player.Message("Unknown rank: {0}", rankName);
                    return;
                }
                else
                {
                    player.Message("List of commands available to {0}&S:", rank.GetClassyName());
                    cd = CommandManager.GetCommands(rank, true);
                }
            }
            else if (param.Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                player.Message("List of ALL commands:");
                cd = CommandManager.GetCommands();
            }
            else if (param.Equals("hidden", StringComparison.OrdinalIgnoreCase))
            {
                player.Message("List of hidden commands:");
                cd = CommandManager.GetCommands(true);
            }
            else if (Enum.GetNames(typeof(CommandCategory)).Contains(param, StringComparer.OrdinalIgnoreCase))
            {
                CommandCategory category = (CommandCategory)Enum.Parse(typeof(CommandCategory), param, true);
                player.Message("List of {0} commands:", category);
                cd = CommandManager.GetCommands(category, false);
            }
            else if (Enum.GetNames(typeof(Permission)).Contains(param, StringComparer.OrdinalIgnoreCase))
            {
                Permission permission = (Permission)Enum.Parse(typeof(Permission), param, true);
                player.Message("List of commands that need {0} permission:", permission);
                cd = CommandManager.GetCommands(permission, true);
            }
            else
            {
                cdCommands.PrintUsage(player);
                return;
            }

            string[] commandNames = cd.Select(desc => desc.Name).ToArray();

            player.MessagePrefixed("&S   ", "&S   " + String.Join(", ", commandNames));
        }
Example #3
0
        /// <summary> Prints a command HelpSection syntax to the given player.
        /// If that fails, it will print the usage instead </summary>
        public void PrintHelpSection(Player player, string sectionName)
        {
            string sectionHelp;

            if (HelpSections != null && HelpSections.TryGetValue(sectionName.ToLower(), out sectionHelp))
            {
                player.MessagePrefixed("&S    ", sectionHelp);
            }
            else
            {
                PrintUsage(player);   //if sectionName was incorrect
            }
        }
Example #4
0
        static void CommandsHandler( Player player, CommandReader cmd ) {
            string param = cmd.Next();
            if( cmd.HasNext ) {
                CdCommands.PrintUsage( player );
                return;
            }
            CommandDescriptor[] cd;
            CommandCategory category;

            string prefix;

            if( param == null ) {
                prefix = "Available commands";
                cd = CommandManager.GetCommands( player.Info.Rank, false );

            } else if( param.StartsWith( "@" ) ) {
                string rankName = param.Substring( 1 );
                Rank rank = RankManager.FindRank( rankName );
                if( rank == null ) {
                    player.MessageNoRank( rankName );
                    return;
                } else {
                    prefix = String.Format( "Commands available to {0}&S", rank.ClassyName );
                    cd = CommandManager.GetCommands( rank, false );
                }

            } else if( param.Equals( "all", StringComparison.OrdinalIgnoreCase ) ) {
                prefix = "All commands";
                cd = CommandManager.GetCommands();

            } else if( param.Equals( "hidden", StringComparison.OrdinalIgnoreCase ) ) {
                prefix = "Hidden commands";
                cd = CommandManager.GetCommands( true );

            } else if( EnumUtil.TryParse( param, out category, true ) ) {
                prefix = String.Format( "{0} commands", category );
                cd = CommandManager.GetCommands( category, false );

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

            player.MessagePrefixed( "&S  ", "{0}: {1}", prefix, cd.JoinToClassyString() );
        }
Example #5
0
        static void HelpHandler( Player player, CommandReader cmd ) {
            string commandName = cmd.Next();

            if( commandName != null ) {
                CommandDescriptor descriptor = CommandManager.GetDescriptor( commandName, true );
                if( descriptor == null ) {
                    player.Message( "Unknown command: \"{0}\"", commandName );
                    return;
                }

                string sectionName = cmd.Next();
                if( sectionName != null ) {
                    string sectionHelp;
                    if( descriptor.HelpSections != null &&
                        descriptor.HelpSections.TryGetValue( sectionName.ToLower(), out sectionHelp ) ) {
                        player.MessagePrefixed( HelpPrefix, sectionHelp );
                    } else {
                        player.Message( "No help found for \"{0}\"", sectionName );
                    }
                } else {
                    StringBuilder sb = new StringBuilder( Color.Help );
                    sb.Append( descriptor.Usage )
                      .Append( "\n&S" );

                    if( descriptor.Aliases != null ) {
                        sb.AppendFormat( "Aliases: &H{0}\n&S", descriptor.Aliases.JoinToString() );
                    }

                    if( String.IsNullOrEmpty( descriptor.Help ) ) {
                        sb.Append( "No help is available for this command." );
                    } else {
                        sb.Append( descriptor.Help );
                    }

                    if( descriptor.Permissions != null && descriptor.Permissions.Length > 0 ) {
                        Rank minRank = descriptor.MinRank;
                        if( minRank == null ) {
                            sb.Append( "\nNot available to any rank" );
                        } else {
                            sb.AppendFormat( "\nAvailable to {0}&S+", minRank.ClassyName );
                        }
                        sb.AppendFormat( " (permissions: {0})", descriptor.Permissions.JoinToString() );
                    } else {
                        sb.Append( "\nAvailable to players of all ranks." );
                    }

                    player.MessagePrefixed( HelpPrefix, sb.ToString() );
                }

            } else {
                player.Message( "  To see a list of all commands, write &H/Commands" );
                player.Message( "  To see detailed help for a command, write &H/Help Command" );
                if( player != Player.Console ) {
                    player.Message( "  To see your stats, write &H/Info" );
                }
                player.Message( "  To list available worlds, write &H/Worlds" );
                player.Message( "  To join a world, write &H/Join WorldName" );
                player.Message( "  To send private messages, write &H@PlayerName Message" );
            }
        }
Example #6
0
        internal static void HelpHandler( Player player, Command cmd ) {
            string commandName = cmd.Next();

            if( commandName == "commands" ) {
                CdCommands.Call( player, cmd, false );

            } else if( commandName != null ) {
                CommandDescriptor descriptor = CommandManager.GetDescriptor( commandName, true );
                if( descriptor == null ) {
                    player.Message( "Unknown command: \"{0}\"", commandName );
                    return;
                }

                string sectionName = cmd.Next();
                if( sectionName != null ) {
                    string sectionHelp;
                    if( descriptor.HelpSections != null && descriptor.HelpSections.TryGetValue( sectionName.ToLower(), out sectionHelp ) ) {
                        player.MessagePrefixed( HelpPrefix, sectionHelp );
                    } else {
                        player.Message( "No help found for \"{0}\"", sectionName );
                    }
                } else {
                    StringBuilder sb = new StringBuilder( Color.Help );
                    sb.Append( descriptor.Usage ).Append( '\n' );

                    if( descriptor.Aliases != null ) {
                        sb.Append( "Aliases: &H" );
                        sb.Append( descriptor.Aliases.JoinToString() );
                        sb.Append( "\n&S" );
                    }

                    if( String.IsNullOrEmpty( descriptor.Help ) ) {
                        sb.Append( "No help is available for this command." );
                    } else {
                        sb.Append( descriptor.Help );
                    }

                    player.MessagePrefixed( HelpPrefix, sb.ToString() );

                    if( descriptor.Permissions != null && descriptor.Permissions.Length > 0 ) {
                        player.MessageNoAccess( descriptor );
                    }
                }

            } else {
                player.Message( "  To see a list of all commands, write &H/Commands" );
                player.Message( "  To see detailed help for a command, write &H/Help Command" );
                if( player != Player.Console ) {
                    player.Message( "  To see your stats, write &H/Info" );
                }
                player.Message( "  To list available worlds, write &H/Worlds" );
                player.Message( "  To join a world, write &H/Join WorldName" );
                player.Message( "  To send private messages, write &H@PlayerName Message" );
            }
        }
Example #7
0
        static void WorldsHandler(Player player, Command cmd)
        {
            string param = cmd.Next();
            World[] worlds;

            string listName;
            string extraParam;
            int offset = 0;

            if (param == null || Int32.TryParse(param, out offset))
            {
                listName = "available worlds";
                extraParam = "";
                worlds = WorldManager.Worlds.Where(w => !w.IsRealm).Where(player.CanSee).ToArray();

            }
            else
            {
                switch (Char.ToLower(param[0]))
                {
                    case 'a':
                        listName = "worlds";
                        extraParam = "all ";
                        worlds = WorldManager.Worlds;
                        break;
                    case 'h':
                        listName = "hidden worlds";
                        extraParam = "hidden ";
                        worlds = WorldManager.Worlds.Where(w => !player.CanSee(w)).ToArray();
                        break;
                    case 'r':
                        listName = "Available Realms";
                        extraParam = "realms";
                        worlds = WorldManager.Worlds.Where(w => w.IsRealm).ToArray();
                        break;
                    case 'p':
                        listName = "populated worlds";
                        extraParam = "populated ";
                        worlds = WorldManager.Worlds.Where(w => w.Players.Any(player.CanSee)).ToArray();
                        break;
                    case '@':
                        if (param.Length == 1)
                        {
                            CdWorlds.PrintUsage(player);
                            return;
                        }
                        string rankName = param.Substring(1);
                        Rank rank = RankManager.FindRank(rankName);
                        if (rank == null)
                        {
                            player.MessageNoRank(rankName);
                            return;
                        }
                        listName = String.Format("worlds where {0}&S+ can build", rank.ClassyName);
                        extraParam = "@" + rank.Name + " ";
                        worlds = WorldManager.Worlds.Where(w => (w.BuildSecurity.MinRank <= rank) && player.CanSee(w))
                                                    .ToArray();
                        break;
                    default:
                        CdWorlds.PrintUsage(player);
                        return;
                }
                if (cmd.HasNext && !cmd.NextInt(out offset))
                {
                    CdWorlds.PrintUsage(player);
                    return;
                }
            }

            if (worlds.Length == 0)
            {
                player.Message("There are no {0}.", listName);

            }
            else if (worlds.Length <= WorldNamesPerPage || player.IsSuper)
            {
                player.MessagePrefixed("&S  ", "&SThere are {0} {1}: {2}",
                                        worlds.Length, listName, worlds.JoinToClassyString());

            }
            else
            {
                if (offset >= worlds.Length)
                {
                    offset = Math.Max(0, worlds.Length - WorldNamesPerPage);
                }
                World[] worldsPart = worlds.Skip(offset).Take(WorldNamesPerPage).ToArray();
                player.MessagePrefixed("&S   ", "&S{0}: {1}",
                                        listName.UppercaseFirst(), worldsPart.JoinToClassyString());

                if (offset + worldsPart.Length < worlds.Length)
                {
                    player.Message("Showing {0}-{1} (out of {2}). Next: &H/Worlds {3}{1}",
                                    offset + 1, offset + worldsPart.Length, worlds.Length, extraParam);
                }
                else
                {
                    player.Message("Showing worlds {0}-{1} (out of {2}).",
                                    offset + 1, offset + worldsPart.Length, worlds.Length);
                }
            }
        }
        internal static void CommandsHandler( Player player, Command cmd )
        {
            string param = cmd.Next();
            CommandDescriptor[] cd;
            CommandCategory category;

            if (param == null)
            {
                player.Message("&SFor &aBuilding &Scommands, type &a/Commands building" +
                               "\n&SFor &fChat &Scommands, type &a/Commands chat" +
                               "\n&SFor &fInfo &Scommands, type &a/Commands info" +
                               "\n&SFor &3Moderation &scommands, type &a/Commands moderation" +
                               "\n&SFor &9World &Scommands, type &a/Commands world" +
                               "\n&SFor &bZone &Scommands, type &a/Commands zone" +
                               (CommandManager.GetCommands(CommandCategory.Math, false).Length > 0
                                    ? "\n&SFor &cFunction drawing &Scommands, type &a/Commands math"
                                    : "") +
                               (CommandManager.GetCommands(CommandCategory.Fun, false).Length > 0
                                    ? "\n&SFor &dFun &Scommands, type &a/Commands fun"
                                    : ""));
                return;
            }

            string prefix;

            if( param == null ) {
                prefix = "Available commands";
                cd = CommandManager.GetCommands( player.Info.Rank, false );

            } else if( param.StartsWith( "@" ) ) {
                string rankName = param.Substring( 1 );
                Rank rank = RankManager.FindRank( rankName );
                if( rank == null ) {
                    player.Message( "Unknown rank: {0}", rankName );
                    return;
                } else {
                    prefix = String.Format( "Commands available to {0}&S", rank.ClassyName );
                    cd = CommandManager.GetCommands( rank, false );
                }

            } else if( param.Equals( "all", StringComparison.OrdinalIgnoreCase ) ) {
                prefix = "All commands";
                cd = CommandManager.GetCommands();

            } else if( param.Equals( "hidden", StringComparison.OrdinalIgnoreCase ) ) {
                prefix = "Hidden commands";
                cd = CommandManager.GetCommands( true );

            } else if( EnumUtil.TryParse( param, out category, true ) ) {
                prefix = String.Format( "{0} commands", category );
                cd = CommandManager.GetCommands( category, false );

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

            player.MessagePrefixed( "&S  ", "{0}: {1}", prefix, cd.JoinToClassyString() );
        }
Example #9
0
 static void LPRHandler(Player player, CommandReader cmd)
 {
     string name = cmd.Next();
     PlayerInfo[] infos;
     Rank rank = RankManager.FindRank(player.Info.Rank.Name);
     if (name != null)
     {
         rank = RankManager.FindRank(name);
         if (rank == null)
         {
             player.MessageNoRank(name);
             return;
         }
     }
     infos = PlayerDB.PlayerInfoList.Where(info => info.PreviousRank == rank).OrderBy(c => c.TimeSinceRankChange).ToArray();
     int offset;
     if (!cmd.NextInt(out offset)) offset = 0;            
     if (offset >= infos.Count())
     {
         offset = Math.Max(0, infos.Count() - PlayersPerPage);
     }
     var playersPart = infos.Skip(offset).Take(10).ToArray();
     player.MessagePrefixed("&S   ", "&SPlayers who previously had rank ({1}&s): {0}", playersPart.JoinToString((r => String.Format("&n{0}&S (Had current rank ({2}&s) for: {1})", r.ClassyName, r.TimeSinceRankChange.ToMiniString(), r.Rank.ClassyName))), rank.ClassyName);
     player.Message("Showing players {0}-{1} (out of {2}).", offset + 1, offset + playersPart.Length, infos.Count());
 }
Example #10
0
        static void InfoHandler( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            PlayerInfo info = FindPlayerInfo(player, cmd, "");
            if (info == null) return;
            Player target = info.PlayerObject;

            // hide online status when hidden
            if( target != null && !player.CanSee( target ) ) {
                target = null;
            }

            if( info.LastIP.Equals( IPAddress.None ) ) {
                player.Message( "About {0}&S: Never seen before.",
                                info.ClassyName);

            } else {
                StringBuilder firstLine = new StringBuilder();
                if( info.DisplayedName != null ) {
                    firstLine.AppendFormat( "About {0}&S ({1}): ", info.ClassyName, info.Name );
                } else {
                    firstLine.AppendFormat( "About {0}&S: ", info.ClassyName );
                }
                if( target != null ) {
                    if( info.IsHidden ) {
                        firstLine.AppendFormat( "HIDDEN" );
                    } else {
                        firstLine.AppendFormat( "Online now" );
                    }
                    if( target.IsDeaf ) {
                        firstLine.Append( " (deaf)" );
                    }                    
                    if( player.Can( Permission.ViewPlayerIPs ) ) {
                        firstLine.AppendFormat( " from {0}", info.LastIP );
                    }
                    if( target.IdBotTime > InfoIdleThreshold ) {
                        firstLine.AppendFormat( " (idle {0})", target.IdBotTime.ToMiniString() );
                    }

                } else {
                    firstLine.AppendFormat( "Last seen {0} ago", info.TimeSinceLastSeen.ToMiniString());
                    if( player.Can( Permission.ViewPlayerIPs ) ) {
                        firstLine.AppendFormat( " from {0}", info.LastIP );
                    }
                    if( info.LeaveReason != LeaveReason.Unknown ) {
                        firstLine.AppendFormat( " ({0})", info.LeaveReason );
                    }
                }
                player.Message( firstLine.ToString() );


                if (info.Email != null && (player == Player.Console || player.Info == info))
                {
                    // Show login information
                    player.Message("  <{0}> {1} logins since {2:d MMM yyyy}.",
                                    Color.StripColors(info.Email),
                                    info.TimesVisited,
                                    info.FirstLoginDate);
                }
                else
                {
                    // Show login information
                    player.Message("  {0} logins since {1:d MMM yyyy}.",
                                    info.TimesVisited,
                                    info.FirstLoginDate);
                }
                             
            }

            if( info.IsFrozen ) {
                player.Message( "  Frozen {0} ago by {1}",
                                info.TimeSinceFrozen.ToMiniString(),
                                info.FrozenByClassy );
            }

            if (info.IsMuted)
            {
                player.Message( "  Muted for {0} by {1}",
                                info.TimeMutedLeft.ToMiniString(),
                                info.MutedByClassy );
            }

            // Show ban information
            IPBanInfo ipBan = IPBanList.Get( info.LastIP );
            switch( info.BanStatus ) {
                case BanStatus.Banned:
                    if( ipBan != null ) {
                        player.Message( "  Account and IP are &CBANNED" );
                    } else if( String.IsNullOrEmpty( info.BanReason ) ) {
                        player.Message( "  Account is &CBANNED" );
                    } else {
                        player.Message( "  Account is &CBANNED&S ({0}&S)", info.BanReason );
                    }
                    break;
                case BanStatus.IPBanExempt:
                    if( ipBan != null ) {
                        player.Message( "  IP is &CBANNED&S, but account is exempt." );
                    } else {
                        player.Message( "  IP is not banned, and account is exempt." );
                    }
                    break;
                case BanStatus.NotBanned:
                    if( ipBan != null ) {
                        if( String.IsNullOrEmpty( ipBan.BanReason ) ) {
                            player.Message( "  IP is &CBANNED" );
                        } else {
                            player.Message( "  IP is &CBANNED&S ({0}&S)", ipBan.BanReason );
                        }
                    }
                    break;
            }


            if( !info.LastIP.Equals( IPAddress.None ) ) {
                // Show alts
                List<PlayerInfo> altNames = new List<PlayerInfo>();
                int bannedAltCount = 0;
                foreach( PlayerInfo playerFromSameIP in PlayerDB.FindPlayers( info.LastIP ) ) {
                    if( playerFromSameIP == info ) continue;
                    altNames.Add( playerFromSameIP );
                    if( playerFromSameIP.IsBanned ) {
                        bannedAltCount++;
                    }
                }

                if( altNames.Count > 0 ) {
                    altNames.Sort( new PlayerInfoComparer( player ) );
                    if( altNames.Count > MaxAltsToPrint ) {
                        if( bannedAltCount > 0 ) {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  Over {0} accounts ({1} banned) on IP: {2}  &Setc",
                                                    MaxAltsToPrint,
                                                    bannedAltCount,
                                                    altNames.Take( 15 ).ToArray().JoinToClassyString() );
                        } else {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  Over {0} accounts on IP: {1} &Setc",
                                                    MaxAltsToPrint,
                                                    altNames.Take( 15 ).ToArray().JoinToClassyString() );
                        }
                    } else {
                        if( bannedAltCount > 0 ) {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  {0} accounts ({1} banned) on IP: {2}",
                                                    altNames.Count,
                                                    bannedAltCount,
                                                    altNames.ToArray().JoinToClassyString() );
                        } else {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  {0} accounts on IP: {1}",
                                                    altNames.Count,
                                                    altNames.ToArray().JoinToClassyString() );
                        }
                    }
                }
            }


            // Stats

            if (info.BlocksDrawn > 0)
            {
                player.Message("  Built &f{0:N0} &sDeleted &f{1:N0}&s Drew &f{2:N1}&sk",
                                info.BlocksBuilt,
                                info.BlocksDeleted,
                                info.BlocksDrawn / 1000d);
            }
            else
            {
                player.Message("  Built &f{0:N0} &sDeleted &f{1:N0}",
                                info.BlocksBuilt,
                                info.BlocksDeleted);
            }
            float blocks = ((info.BlocksBuilt) - info.BlocksDeleted);
            player.Message("  Wrote {0:N0} messages.", info.MessagesWritten);
            // More stats
            if (info.TimesBannedOthers > 0 || info.TimesKickedOthers > 0)
            {
                player.Message( "  Kicked {0}, banned {1}",
                                info.TimesKickedOthers,
                                info.TimesBannedOthers);
            }

            if( info.TimesKicked > 0 ) {
                if( info.LastKickDate != DateTime.MinValue ) {
                    player.Message( "  Got kicked {0} times. Last kick {1} ago by {2}",
                                    info.TimesKicked,
                                    info.TimeSinceLastKick.ToMiniString(),
                                    info.LastKickByClassy );
                } else {
                    player.Message( "  Got kicked {0} times.", info.TimesKicked );
                }
                if( info.LastKickReason != null ) {
                    player.Message( "  Kick reason: {0}", info.LastKickReason );
                }
            }


            // Promotion/demotion
            if( info.PreviousRank == null ) {
                if( info.RankChangedBy == null ) {
                    player.Message( "  Rank is {0}&S (default).",
                                    info.Rank.ClassyName );
                } else {
                    player.Message( "  Promoted to {0}&S by {1}&S {2} ago.",
                                    info.Rank.ClassyName,
                                    info.RankChangedByClassy,
                                    info.TimeSinceRankChange.ToMiniString() );
                    if( info.RankChangeReason != null ) {
                        player.Message( "  Promotion reason: {0}", info.RankChangeReason );
                    }
                }
            } else if( info.PreviousRank <= info.Rank ) {
                player.Message( "  Promoted from {0}&S to {1}&S by {2}&S {3} ago.",
                                info.PreviousRank.ClassyName,
                                info.Rank.ClassyName,
                                info.RankChangedByClassy,
                                info.TimeSinceRankChange.ToMiniString() );
                if( info.RankChangeReason != null ) {
                    player.Message( "  Promotion reason: {0}", info.RankChangeReason );
                }
            } else {
                player.Message( "  Demoted from {0}&S to {1}&S by {2}&S {3} ago.",
                                info.PreviousRank.ClassyName,
                                info.Rank.ClassyName,
                                info.RankChangedByClassy,
                                info.TimeSinceRankChange.ToMiniString() );
                if( info.RankChangeReason != null ) {
                    player.Message( "  Demotion reason: {0}", info.RankChangeReason );
                }
            }

            

            if (!info.LastIP.Equals(IPAddress.None))
            {
                // Time on the server
                TimeSpan totalTime = info.TotalTime;
                if (target != null)
                {
                    totalTime = totalTime.Add(info.TimeSinceLastLogin);
                }
                if (info.IsOnline && target != null)
                {
                    player.Message("  Total time: {0:F1} hours. This session: {1:F1} hours.",
                                    totalTime.TotalHours,
                                    target.Info.TimeSinceLastLogin.TotalHours);
                }
                else
                {
                    player.Message("  Total time: {0:F1} hours",
                                    totalTime.TotalHours);
                }
            }
        }
Example #11
0
        private static void CommandsHandler(Player player, CommandReader cmd) {
            string param = cmd.Next();
            CommandDescriptor[] cd;
            CommandCategory category;
            string prefix;
            if (param == null) {
                player.Message("&sCommand Categories:");
                player.Message("&h  /cmds Building");
                player.Message("&h  /cmds Chat");
                player.Message("&h  /cmds Info");
                player.Message("&h  /cmds Maintenance");
                player.Message("&h  /cmds Moderation");
                player.Message("&h  /cmds World");
                player.Message("&h  /cmds New");
                player.Message("&h  /cmds All");
                return;
			}
			Array items = CommandManager.GetCommands(player.Info.Rank, false);
			string output = "";
            if (param.StartsWith("*") && param.EndsWith("*")) {
                foreach (CommandDescriptor item in items) {
                    if (item.Name.ToLower().Contains(param.ToLower().Trim('*'))) {
                        output += item.MinRank.Color + item.Name + "&s, ";
                    }
                }
                player.Message("&sCommands containing \"{0}\":", param.Trim('*'));
				if (output.EndsWith(", ")) {
					player.Message(output.Remove(output.Length - 2) + ".");
				} else {
					player.Message("There are no commands containing \"{0}\"", param.Trim('*'));
				}
                return;
            } else if (param.EndsWith("*")) {
                foreach (CommandDescriptor item in items) {
                    if (item.Name.ToLower().StartsWith(param.ToLower().Trim('*'))) {
                        output += item.MinRank.Color + item.Name + "&s, ";
                    }
                }
                player.Message("&sCommands starting with \"{0}\":", param.Trim('*'));
				if (output.EndsWith(", ")) {
					player.Message(output.Remove(output.Length - 2) + ".");
				} else {
					player.Message("There are no commands starting with \"{0}\"", param.Trim('*'));
				}
                return;
			} else if (param.StartsWith("*")) {
                foreach (CommandDescriptor item in items) {
                    if (item.Name.ToLower().EndsWith(param.ToLower().Trim('*'))) {
                        output += item.MinRank.Color + item.Name + "&s, ";
                    }
                }
                player.Message("&sCommands ending with \"{0}\":", param.Trim('*'));
				if (output.EndsWith(", ")) {
					player.Message(output.Remove(output.Length - 2) + ".");
				} else {
					player.Message("There are no commands ending with \"{0}\"", param.Trim('*'));
				}
				return;
			} else if (param.StartsWith("@")) {
                string rankName = param.Substring(1);
                Rank rank = RankManager.FindRank(rankName);
                if (rank == null) {
                    player.MessageNoRank(rankName);
                    return;
                }
                prefix = String.Format("Commands available to {0}&S", rank.ClassyName);
                cd = CommandManager.GetCommands(rank, false);
            } else if (param.Equals("all", StringComparison.OrdinalIgnoreCase)) {
                prefix = "All commands";
                cd = CommandManager.GetCommands();
            } else if (param.Equals("hidden", StringComparison.OrdinalIgnoreCase)) {
                prefix = "Hidden commands";
                cd = CommandManager.GetCommands(true);
            } else if (EnumUtil.TryComplete(param, out category, true)) {
                prefix = String.Format("{0} commands", category);
                cd = CommandManager.GetCommands(category, false);
            } else {
                CdCommands.PrintUsage(player);
                return;
            }
            player.MessagePrefixed("&S  ", "{0}: {1}", prefix, cd.JoinToClassyString());
        }
Example #12
0
 /// <summary> Prints a command HelpSection syntax to the given player. 
 /// If that fails, it will print the usage instead </summary>
 public void PrintHelpSection(Player player, string sectionName)
 {
     string sectionHelp;
     if (HelpSections != null && HelpSections.TryGetValue(sectionName.ToLower(), out sectionHelp))
     {
         player.MessagePrefixed("&S    ", sectionHelp);
     }
     else
     {
         PrintUsage(player); //if sectionName was incorrect
     }
 }
Example #13
0
        internal static void CommandsHandler(Player player, Command cmd)
        {
            string param = cmd.Next();
            CommandDescriptor[] cd;

            if (param == null)
            {
                player.Message("&SCommands Available:\n" +
                "&SFor &aBuilding &Scommands, type &a/Commands building" +
                "\n&SFor &fChat &Scommands, type &a/Commands chat" +
                "\n&SFor &fInfo &Scommands, type &a/Commands info" +
                "\n&SFor &3Moderation &scommands, type &a/Commands moderation" +
                "\n&SFor &9World &Scommands, type &a/Commands world" +
                "\n&SFor &bZone &Scommands, type &a/Commands zone");
            }

            else if (param.StartsWith("@"))
            {
                string rankName = param.Substring(1);
                Rank rank = RankManager.FindRank(rankName);
                if (rank == null)
                {
                    player.Message("Unknown rank: {0}", rankName);
                    return;
                }
                else
                {
                    player.Message("List of commands available to {0}&S:", rank.ClassyName);
                    cd = CommandManager.GetCommands(rank, true);
                    player.MessagePrefixed("&S  ", "&S  " + cd.JoinToClassyString());
                }

            }
            else if (param.Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                player.Message("List of ALL commands:");
                cd = CommandManager.GetCommands();
                player.MessagePrefixed("&S  ", "&S  " + cd.JoinToClassyString());

            }
            else if (param.Equals("hidden", StringComparison.OrdinalIgnoreCase))
            {
                player.Message("List of hidden commands:");
                cd = CommandManager.GetCommands(true);
                player.MessagePrefixed("&S  ", "&S  " + cd.JoinToClassyString());

            }
            else if (Enum.GetNames(typeof(CommandCategory)).Contains(param, StringComparer.OrdinalIgnoreCase))
            {
                CommandCategory category = (CommandCategory)Enum.Parse(typeof(CommandCategory), param, true);
                player.Message("List of {0} commands:", category);
                cd = CommandManager.GetCommands(category, false);
                player.MessagePrefixed("&S  ", "&S  " + cd.JoinToClassyString());

            }
            else
            {
                CdCommands.PrintUsage(player);
                return;
            }
        }
Example #14
0
        internal static void Commands( Player player, Command cmd ) {
            string param = cmd.Next();
            CommandDescriptor[] cd;

            if( param == null ) {
                player.Message( "List of available commands:" );
                cd = CommandManager.GetCommands( false );

            } else if( param.StartsWith( "@" ) ) {
                string rankName = param.Substring( 1 );
                Rank rank = RankManager.FindRank( rankName );
                if( rank == null ) {
                    player.Message( "Unknown rank: {0}", rankName );
                    return;
                } else {
                    player.Message( "List of commands available to {0}&S:", rank.GetClassyName() );
                    cd = CommandManager.GetCommands( rank, true );
                }

            } else if( param.Equals( "all", StringComparison.OrdinalIgnoreCase ) ) {
                player.Message( "List of ALL commands:" );
                cd = CommandManager.GetCommands();

            } else if( param.Equals( "hidden", StringComparison.OrdinalIgnoreCase ) ) {
                player.Message( "List of hidden commands:" );
                cd = CommandManager.GetCommands( true );

            } else if( Enum.GetNames( typeof( CommandCategory ) ).Contains( param, StringComparer.OrdinalIgnoreCase ) ) {
                CommandCategory category = (CommandCategory)Enum.Parse( typeof( CommandCategory ), param, true );
                player.Message( "List of {0} commands:", category );
                cd = CommandManager.GetCommands( category, false );

            } else if( Enum.GetNames( typeof( Permission ) ).Contains( param, StringComparer.OrdinalIgnoreCase ) ) {
                Permission permission = (Permission)Enum.Parse( typeof( Permission ), param, true );
                player.Message( "List of commands that need {0} permission:", permission );
                cd = CommandManager.GetCommands( permission, true );

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

            string[] commandNames = cd.Select( desc => desc.Name ).ToArray();

            player.MessagePrefixed( "&S   ", "&S   " + String.Join( ", ", commandNames ) );
        }
Example #15
0
        internal static void Help( Player player, Command cmd ) {
            string commandName = cmd.Next();

            if( commandName == "commands" ) {
                cdCommands.Handler( player, cmd );

            } else if( commandName != null ) {
                CommandDescriptor descriptor = CommandManager.GetDescriptor( commandName );
                if( descriptor == null ) {
                    player.Message( "Unknown command: \"{0}\"", commandName );
                    return;
                }
                StringBuilder sb = new StringBuilder( Color.Help );
                sb.Append( descriptor.Usage ).Append( "&N" );

                if( descriptor.Aliases != null ) {
                    sb.Append( "Aliases: &H" );
                    sb.Append( descriptor.Aliases.JoinToString( "&S, &H" ) );
                    sb.Append( "&N" );
                }

                if( descriptor.HelpHandler != null ) {
                    sb.Append( descriptor.HelpHandler( player ) );
                } else if( descriptor.Help != null ) {
                    sb.Append( descriptor.Help );
                } else {
                    sb.Append( "No help is available for this command." );
                }

                player.MessagePrefixed( HelpPrefix, sb.ToString() );

                if( descriptor.Permissions != null && descriptor.Permissions.Length > 0 ) {
                    player.NoAccessMessage( descriptor.Permissions );
                }

            } else {
                player.Message( "To see a list of all commands, write &H/help commands" );
                player.Message( "To see detailed help for a command, write &H/help CommandName" );
                if( player != Player.Console ) {
                    player.Message( "To see your stats, write &H/info" );
                }
                player.Message( "To list available worlds, write &H/worlds" );
                player.Message( "To send private messages, write &H@PlayerName Message" );
                player.Message( "To message all players of a rank, write &H@@Rank Message" );
            }
        }
Example #16
0
        static void BanInfoHandler( Player player, CommandReader cmd ) {
            string name = cmd.Next();
            if( cmd.HasNext ) {
                CdBanInfo.PrintUsage( player );
                return;
            }

            IPAddress address;
            PlayerInfo info = null;

            if( name == null ) {
                name = player.Name;
            } else if( !player.Can( Permission.ViewOthersInfo ) ) {
                player.MessageNoAccess( Permission.ViewOthersInfo );
                return;
            }

            if( IPAddressUtil.IsIP( name ) && IPAddress.TryParse( name, out address ) ) {
                IPBanInfo banInfo = IPBanList.Get( address );
                if( banInfo != null ) {
                    player.Message( "{0} was banned by {1}&S on {2:dd MMM yyyy} ({3} ago)",
                                    banInfo.Address,
                                    banInfo.BannedByClassy,
                                    banInfo.BanDate,
                                    banInfo.TimeSinceLastAttempt );
                    if( !String.IsNullOrEmpty( banInfo.PlayerName ) ) {
                        player.Message( "  Banned by association with {0}",
                                        banInfo.PlayerNameClassy );
                    }
                    if( banInfo.Attempts > 0 ) {
                        player.Message( "  There have been {0} attempts to log in, most recently {1} ago by {2}",
                                        banInfo.Attempts,
                                        banInfo.TimeSinceLastAttempt.ToMiniString(),
                                        banInfo.LastAttemptNameClassy );
                    }
                    if( banInfo.BanReason != null ) {
                        player.Message( "  Ban reason: {0}", banInfo.BanReason );
                    }
                } else {
                    player.Message( "{0} is currently NOT banned.", address );
                }

            } else {
                info = PlayerDB.FindPlayerInfoOrPrintMatches( player, name );
                if( info == null ) return;

                address = info.LastIP;

                IPBanInfo ipBan = IPBanList.Get( info.LastIP );
                switch( info.BanStatus ) {
                    case BanStatus.Banned:
                        if( ipBan != null ) {
                            player.Message( "Player {0}&S and their IP are &CBANNED", info.ClassyName );
                        } else {
                            player.Message( "Player {0}&S is &CBANNED&S (but their IP is not).", info.ClassyName );
                        }
                        break;
                    case BanStatus.IPBanExempt:
                        if( ipBan != null ) {
                            player.Message( "Player {0}&S is exempt from an existing IP ban.", info.ClassyName );
                        } else {
                            player.Message( "Player {0}&S is exempt from IP bans.", info.ClassyName );
                        }
                        break;
                    case BanStatus.NotBanned:
                        if( ipBan != null ) {
                            player.Message( "Player {0}&s is not banned, but their IP is.", info.ClassyName );
                        } else {
                            player.Message( "Player {0}&s is not banned.", info.ClassyName );
                        }
                        break;
                }

                if( info.BanDate != DateTime.MinValue ) {
                    player.Message( "  Last ban by {0}&S on {1:dd MMM yyyy} ({2} ago).",
                                    info.BannedByClassy,
                                    info.BanDate,
                                    info.TimeSinceBan.ToMiniString() );
                    if( info.BanReason != null ) {
                        player.Message( "  Last ban reason: {0}", info.BanReason );
                    }
                } else {
                    player.Message( "No past bans on record." );
                }

                if( info.UnbanDate != DateTime.MinValue && !info.IsBanned ) {
                    player.Message( "  Unbanned by {0}&S on {1:dd MMM yyyy} ({2} ago).",
                                    info.UnbannedByClassy,
                                    info.UnbanDate,
                                    info.TimeSinceUnban.ToMiniString() );
                    if( info.UnbanReason != null ) {
                        player.Message( "  Last unban reason: {0}", info.UnbanReason );
                    }
                }

                if( info.BanDate != DateTime.MinValue ) {
                    TimeSpan banDuration;
                    if( info.IsBanned ) {
                        banDuration = info.TimeSinceBan;
                        player.Message( "  Ban duration: {0} so far",
                                        banDuration.ToMiniString() );
                    } else {
                        banDuration = info.UnbanDate.Subtract( info.BanDate );
                        player.Message( "  Previous ban's duration: {0}",
                                        banDuration.ToMiniString() );
                    }
                }
            }

            // Show alts
            if( !address.Equals( IPAddress.None ) ) {
                List<PlayerInfo> altNames = new List<PlayerInfo>();
                int bannedAltCount = 0;
                foreach( PlayerInfo playerFromSameIP in PlayerDB.FindPlayers( address ) ) {
                    if( playerFromSameIP == info ) continue;
                    altNames.Add( playerFromSameIP );
                    if( playerFromSameIP.IsBanned ) {
                        bannedAltCount++;
                    }
                }

                if( altNames.Count > 0 ) {
                    altNames.Sort( new PlayerInfoComparer( player ) );
                    if( altNames.Count > MaxAltsToPrint ) {
                        if( bannedAltCount > 0 ) {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  Over {0} accounts ({1} banned) on IP: {2} &Setc",
                                                    MaxAltsToPrint,
                                                    bannedAltCount,
                                                    altNames.Take( 15 ).ToArray().JoinToClassyString() );
                        } else {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  Over {0} accounts on IP: {1} &Setc",
                                                    MaxAltsToPrint,
                                                    altNames.Take( 15 ).ToArray().JoinToClassyString() );
                        }
                    } else {
                        if( bannedAltCount > 0 ) {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  {0} accounts ({1} banned) on IP: {2}",
                                                    altNames.Count,
                                                    bannedAltCount,
                                                    altNames.ToArray().JoinToClassyString() );
                        } else {
                            player.MessagePrefixed( "&S  ",
                                                    "&S  {0} accounts on IP: {1}",
                                                    altNames.Count,
                                                    altNames.ToArray().JoinToClassyString() );
                        }
                    }
                }
            }
        }
Example #17
0
        static void PlayersHandler( Player player, CommandReader cmd ) {
            string param = cmd.Next();
            Player[] players;
            string worldName = null;
            string qualifier;
            int offset = 0;

            if( param == null || Int32.TryParse( param, out offset ) ) {
                // No world name given; Start with a list of all players.
                players = Server.Players;
                qualifier = "online";
                if( cmd.HasNext ) {
                    CdPlayers.PrintUsage( player );
                    return;
                }

            } else {
                // Try to find the world
                World world = WorldManager.FindWorldOrPrintMatches( player, param );
                if( world == null ) return;

                worldName = param;
                // If found, grab its player list
                players = world.Players;
                qualifier = String.Format( "in world {0}&S", world.ClassyName );

                if( cmd.HasNext && !cmd.NextInt( out offset ) ) {
                    CdPlayers.PrintUsage( player );
                    return;
                }
            }

            if( players.Length > 0 ) {
                // Filter out hidden players, and sort
                Player[] visiblePlayers = players.Where( player.CanSee )
                                                 .OrderBy( p => p, PlayerListSorter.Instance )
                                                 .ToArray();


                if( visiblePlayers.Length == 0 ) {
                    player.Message( "There are no players {0}", qualifier );

                } else if( visiblePlayers.Length <= PlayersPerPage || player.IsSuper ) {
                    player.MessagePrefixed( "&S  ", "&SThere are {0} players {1}: {2}",
                                            visiblePlayers.Length, qualifier, visiblePlayers.JoinToClassyString() );

                } else {
                    if( offset >= visiblePlayers.Length ) {
                        offset = Math.Max( 0, visiblePlayers.Length - PlayersPerPage );
                    }
                    Player[] playersPart = visiblePlayers.Skip( offset ).Take( PlayersPerPage ).ToArray();
                    player.MessagePrefixed( "&S   ", "&SPlayers {0}: {1}",
                                            qualifier, playersPart.JoinToClassyString() );

                    if( offset + playersPart.Length < visiblePlayers.Length ) {
                        player.Message( "Showing {0}-{1} (out of {2}). Next: &H/Players {3}{1}",
                                        offset + 1, offset + playersPart.Length,
                                        visiblePlayers.Length,
                                        (worldName == null ? "" : worldName + " ") );
                    } else {
                        player.Message( "Showing players {0}-{1} (out of {2}).",
                                        offset + 1, offset + playersPart.Length,
                                        visiblePlayers.Length );
                    }
                }
            } else {
                player.Message( "There are no players {0}", qualifier );
            }
        }
Example #18
0
        internal static void Worlds( Player player, Command cmd ) {
            string param = cmd.Next();
            bool listVisible = true,
                 listHidden = false,
                 listAllLoaded = false;
            if( !String.IsNullOrEmpty( param ) ) {
                switch( Char.ToLower( param[0] ) ) {
                    case 'a':
                        listHidden = true;
                        break;
                    case 'h':
                        listVisible = false;
                        listHidden = true;
                        break;
                    case 'l':
                        listAllLoaded = true;
                        listVisible = false;
                        listHidden = false;
                        break;
                    default:
                        cdWorlds.PrintUsage( player );
                        return;
                }
            }

            StringBuilder sb = new StringBuilder();
            bool first = true;
            int count = 0;

            World[] worldListCache = WorldManager.WorldList;
            foreach( World world in worldListCache ) {
                bool visible = player.CanJoin( world ) && !world.IsHidden;
                if( (world.IsLoaded && listAllLoaded) || (visible && listVisible) || (!visible && listHidden) ) {
                    if( !first ) {
                        sb.Append( ", " );
                    }
                    sb.Append( world.GetClassyName() );
                    count++;
                    first = false;
                }
            }

            if( listAllLoaded ) {
                player.MessagePrefixed( "&S   ", "There are " + count + " loaded worlds: " + sb );
            } else if( listVisible && !listHidden ) {
                player.MessagePrefixed( "&S   ", "There are " + count + " available worlds: " + sb );
            } else if( !listVisible ) {
                player.MessagePrefixed( "&S   ", "There are " + count + " hidden worlds: " + sb );
            } else {
                player.MessagePrefixed( "&S   ", "There are " + count + " worlds total: " + sb );
            }
        }