Exemplo n.º 1
0
        internal static Player FindPlayerMatches(Player player, string namePart, SearchOptions options) {
            // Repeat last-used player name
            if (namePart == "-") {
                if (player.LastUsedPlayerName != null) {
                    namePart = player.LastUsedPlayerName;
                } else {
                    player.Message("Cannot repeat player name: you haven't used any names yet.");
                    return null;
                }
            }

            // in case someone tries to use the "!" prefix in an online-only search
            if (namePart.Length > 0 && namePart[0] == '!')
                namePart = namePart.Substring(1);

            // Make sure player name is valid
            if (!Player.ContainsValidCharacters(namePart)) {
                player.MessageInvalidPlayerName(namePart);
                return null;
            }

            Player[] matches = Server.FindPlayers(player, namePart, options);
            if (matches.Length == 0) {
                player.MessageNoPlayer(namePart);
                return null;
            } else if (matches.Length > 1) {
                player.MessageManyMatches("player", matches);
                return null;
            } else {
                player.LastUsedPlayerName = matches[0].Name;
                return matches[0];
            }
        }
Exemplo n.º 2
0
        public static PlayerInfo FindByPartialNameOrPrintMatches( [NotNull] Player player, [NotNull] string partialName ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( partialName == null ) throw new ArgumentNullException( "partialName" );
            CheckIfLoaded();
            if( partialName == "-" ) {
                if( player.LastUsedPlayerName != null ) {
                    partialName = player.LastUsedPlayerName;
                } else {
                    player.Message( "Cannot repeat player name: you haven't used any names yet." );
                    return null;
                }
            }
            if( !Player.ContainsValidCharacters( partialName ) ) {
                player.MessageInvalidPlayerName( partialName );
                return null;
            }
            PlayerInfo target = FindExact( partialName );
            if( target == null ) {
                PlayerInfo[] targets = FindByPartialName( partialName ).ToArray();
                if( targets.Length == 0 ) {
                    player.MessageNoPlayer( partialName );
                    return null;

                } else if( targets.Length > 1 ) {
                    Array.Sort( targets, new PlayerInfoComparer( player ) );
                    player.MessageManyMatches( "player", targets );
                    return null;
                }
                target = targets[0];
            }
            player.LastUsedPlayerName = target.Name;
            return target;
        }
Exemplo n.º 3
0
        internal static World FindWorldMatches(Player player, string name)
        {
            if (name == "-")
            {
                if (player.LastUsedWorldName != null)
                {
                    name = player.LastUsedWorldName;
                }
                else
                {
                    player.Message("Cannot repeat world name: you haven't used any names yet.");
                    return(null);
                }
            }
            player.LastUsedWorldName = name;
            World[] matches = WorldManager.FindWorlds(player, name);

            if (matches.Length == 0)
            {
                player.MessageNoWorld(name);
                return(null);
            }
            else if (matches.Length > 1)
            {
                player.MessageManyMatches("world", matches);
                return(null);
            }
            return(matches[0]);
        }
Exemplo n.º 4
0
        public static World FindWorldOrPrintMatches([NotNull] Player player, [NotNull] string worldName)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (worldName == null)
            {
                throw new ArgumentNullException("worldName");
            }
            if (worldName == "-")
            {
                if (player.LastUsedWorldName != null)
                {
                    worldName = player.LastUsedWorldName;
                }
                else
                {
                    player.Message("Cannot repeat world name: you haven't used any names yet.");
                    return(null);
                }
            }
            player.LastUsedWorldName = worldName;

            World[] matches = FindWorlds(player, worldName);

            if (matches.Length == 0)
            {
                player.MessageNoWorld(worldName);
                return(null);
            }

            if (matches.Length > 1)
            {
                player.MessageManyMatches("world", matches);
                return(null);
            }
            return(matches[0]);
        }
Exemplo n.º 5
0
        static void WorldSearchHandler(Player player, Command cmd)
        {
            string worldName = cmd.Next();
            if (worldName == null)
            {
                CdWorldSearch.PrintUsage(player);
                return;
            }
            if (worldName.Length < 2)
            {
                CdWorldSearch.PrintUsage(player);
                return;
            }
            else
            {
                worldName = worldName.ToLower();
                var WorldNames = WorldManager.Worlds
                                         .Where(w => w.Name.ToLower().Contains(worldName)).ToArray();

                if (WorldNames.Length <= 30)
                {
                    player.MessageManyMatches("worlds", WorldNames);
                }
                else
                {
                    int offset;
                    if (!cmd.NextInt(out offset)) offset = 0;

                    if (offset >= WorldNames.Count())
                        offset = Math.Max(0, WorldNames.Length - 30);

                    World[] WorldPart = WorldNames.Skip(offset).Take(30).ToArray();
                    player.MessageManyMatches("worlds", WorldPart);

                    if (offset + WorldNames.Length < WorldNames.Length)
                        player.Message("Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                        offset + 1, offset + WorldPart.Length, WorldNames.Length,
                                        "worldsearch", offset + WorldPart.Length);
                    else
                        player.Message("Showing matches {0}-{1} (out of {2}).",
                                        offset + 1, offset + WorldPart.Length, WorldNames.Length);
                    return;
                }
            }
        }
Exemplo n.º 6
0
        static void JoinHandler(Player player, Command cmd)
        {
            string worldName = cmd.Next();
            if (worldName == null)
            {
                CdJoin.PrintUsage(player);
                return;
            }

            if (worldName == "-")
            {
                if (player.LastUsedWorldName != null)
                {
                    worldName = player.LastUsedWorldName;
                }
                else
                {
                    player.Message("Cannot repeat world name: you haven't used any names yet.");
                    return;
                }
            }

            World[] worlds = WorldManager.FindWorlds(player, worldName);

            if (worlds.Length > 1)
            {
                player.MessageManyMatches("world", worlds);

            }
            else if (worlds.Length == 1)
            {
                World world = worlds[0];
                player.LastUsedWorldName = world.Name;
                switch (world.AccessSecurity.CheckDetailed(player.Info))
                {
                    case SecurityCheckResult.Allowed:
                    case SecurityCheckResult.WhiteListed:
                        if (world.IsFull)
                        {
                            player.Message("Cannot join {0}&S: world is full.", world.ClassyName);
                            return;
                        }
                        player.StopSpectating();
                        if (!player.JoinWorldNow(world, true, WorldChangeReason.ManualJoin))
                        {
                            player.Message("ERROR: Failed to join world. See log for details.");
                        }
                        break;
                    case SecurityCheckResult.BlackListed:
                        player.Message("Cannot join world {0}&S: you are blacklisted.",
                                        world.ClassyName);
                        break;
                    case SecurityCheckResult.RankTooLow:
                        player.Message("Cannot join world {0}&S: must be {1}+",
                                        world.ClassyName, world.AccessSecurity.MinRank.ClassyName);
                        break;
                }

            }
            else
            {
                // no worlds found - see if player meant to type in "/Join" and not "/TP"
                Player[] players = Server.FindPlayers(player, worldName, true);
                if (players.Length == 1)
                {
                    player.LastUsedPlayerName = players[0].Name;
                    player.StopSpectating();
                    player.ParseMessage("/TP " + players[0].Name, false, true);
                }
                else
                {
                    player.MessageNoWorld(worldName);
                }
            }
        }
Exemplo n.º 7
0
        private static void AnnounceHandler(Player player, Command cmd)
        {
            if (!Heartbeat.ClassiCube() || !player.ClassiCube)
            {
                player.Message("This is a ClassiCube only command!");
                return;
            }

            Player[] targetPlayers;
            string world = cmd.Next();
            if(string.IsNullOrEmpty(world))
            {
                CdAnnounce.PrintUsage(player);
                return;
            }

            if (world == "all")
            {
                targetPlayers = Server.Players;
            }
            else
            {
                World[] targetWorlds = WorldManager.FindWorlds(player, world);
                if (targetWorlds.Length > 1)
                {
                    player.MessageManyMatches("world", targetWorlds);
                    return;
                }
                else if (targetWorlds.Length == 1)
                {
                    targetPlayers = targetWorlds[0].Players;
                }
                else
                {
                    player.Message("No worlds found matching {0}! Please check your spelling.", world);
                    return;
                }
            }

            string message = cmd.Next();
            if (string.IsNullOrEmpty(message))
            {
                CdAnnounce.PrintUsage(player);
                return;
            }

            Packet packet = PacketWriter.MakeSpecialMessage(100, message);
            foreach (Player p in targetPlayers)
            {
                p.Send(packet);
            }
        }
Exemplo n.º 8
0
        public static PlayerInfo FindPlayerInfoOrPrintMatches([NotNull] Player player, [NotNull] string namePart,
                                                              SearchOptions options)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (namePart == null)
            {
                throw new ArgumentNullException("namePart");
            }
            CheckIfLoaded();

            bool includeSelf = (options & SearchOptions.IncludeSelf) != 0;
            bool returnSelf  = (options & SearchOptions.ReturnSelfIfOnlyMatch) != 0;

            // If name starts with '!', return matches for online players only
            if (namePart.Length > 1 && namePart[0] == '!')
            {
                namePart = namePart.Substring(1);
                Player targetPlayer = Server.FindPlayerOrPrintMatches(player, namePart, options);
                if (targetPlayer != null)
                {
                    return(targetPlayer.Info);
                }
                else
                {
                    player.Message("No online players found matching \"{0}\"", namePart);
                    return(null);
                }
            }

            // Repeat last-used player name
            if (namePart == "-")
            {
                if (player.LastUsedPlayerName != null)
                {
                    namePart = player.LastUsedPlayerName;
                }
                else
                {
                    player.Message("Cannot repeat player name: you haven't used any names yet.");
                    return(null);
                }
            }

            // Make sure player name is valid
            if (!Player.ContainsValidCharacters(namePart))
            {
                player.MessageInvalidPlayerName(namePart);
                return(null);
            }

            // Search for exact matches first
            PlayerInfo target = FindPlayerInfoExact(namePart);

            // If no exact match was found, look for partial matches
            if (target == null || target == player.Info && !includeSelf)
            {
                PlayerInfo[] targets = FindPlayers(namePart);

                if (!includeSelf)
                {
                    // special handling if IncludeSelf flag is not set
                    if (targets.Length > 1)
                    {
                        targets = targets.Where(p => p != player.Info).ToArray();
                    }
                    else if (!returnSelf && targets.Length == 1 && targets[0] == player.Info)
                    {
                        // special handling if ReturnSelfIfOnlyMatch flag is not set
                        targets = new PlayerInfo[0];
                    }
                }

                if (targets.Length == 0)
                {
                    // No matches
                    player.MessageNoPlayer(namePart);
                    return(null);
                }
                else if (targets.Length > 1)
                {
                    // More than one match
                    Array.Sort(targets, new PlayerInfoComparer(player));
                    player.MessageManyMatches("player", targets.Take(MatchesToPrint).ToArray());
                    return(null);
                } // else: one match!
                target = targets[0];
            }

            // If a single name has been found, set it as LastUsedPlayerName
            if (includeSelf || target != player.Info)
            {
                player.LastUsedPlayerName = target.Name;
            }
            return(target);
        }
Exemplo n.º 9
0
        public static PlayerInfo FindPlayerInfoOrPrintMatches([NotNull] Player player, [NotNull] string partialName)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (partialName == null)
            {
                throw new ArgumentNullException("partialName");
            }
            CheckIfLoaded();

            // If name starts with '!', return matches for online players only
            if (partialName.Length > 1 && partialName[0] == '!')
            {
                partialName = partialName.Substring(1);
                Player targetPlayer = Server.FindPlayerOrPrintMatches(player, partialName, false, true);
                if (targetPlayer != null)
                {
                    return(targetPlayer.Info);
                }
                else
                {
                    player.Message("No online players found matching \"{0}\"", partialName);
                    return(null);
                }
            }

            // Repeat last-used player name
            if (partialName == "-")
            {
                if (player.LastUsedPlayerName != null)
                {
                    partialName = player.LastUsedPlayerName;
                }
                else
                {
                    player.Message("Cannot repeat player name: you haven't used any names yet.");
                    return(null);
                }
            }

            // Make sure player name is valid
            if (!Player.ContainsValidCharacters(partialName))
            {
                player.MessageInvalidPlayerName(partialName);
                return(null);
            }

            // Search for exact matches first
            PlayerInfo target = FindPlayerInfoExact(partialName);

            // If no exact match was found, look for partial matches
            if (target == null)
            {
                PlayerInfo[] targets = FindPlayers(partialName);
                if (targets.Length == 0)
                {
                    // No matches
                    player.MessageNoPlayer(partialName);
                    return(null);
                }
                else if (targets.Length > 1)
                {
                    // More than one match
                    Array.Sort(targets, new PlayerInfoComparer(player));
                    player.MessageManyMatches("player", targets.Take(25).ToArray());
                    return(null);
                } // else: one match!
                target = targets[0];
            }

            // If a single name has been found, set it as LastUsedPlayerName
            player.LastUsedPlayerName = target.Name;
            return(target);
        }
Exemplo n.º 10
0
        internal static void ListHandler( Player player, Command cmd )
        {
            string Option = cmd.Next();
            if ( Option == null ) {
                CdList.PrintUsage( player );
                player.Message( "  Sections include: Staff, DisplayedNames, Idles, Portals, Rank, Top10, Emotes" );
                return;
            }
            switch ( Option.ToLower() ) {
                default:
                    CdList.PrintUsage( player );
                    player.Message( "  Sections include: Staff, DisplayedNames, Idles, Portals, Rank, Top10, Emotes" );
                    break;
                case "emotes":
                    string Usage = "Shows a list of all available emotes and their keywords. " +
                   "There are 31 emotes, spanning 3 pages. Use &h/List emotes 2&s and &h/List emotes 3&s to see pages 2 and 3.";
                    int page = 1;
                    if ( cmd.HasNext ) {
                        if ( !cmd.NextInt( out page ) ) {
                            player.Message( Usage );
                            return;
                        }
                    }
                    if ( page < 1 || page > 3 ) {
                        player.Message( Usage );
                        return;
                    }

                    var emoteChars = Chat.EmoteKeywords
                                         .Values
                                         .Distinct()
                                         .Skip( ( page - 1 ) * 11 )
                                         .Take( 11 );

                    player.Message( "List of emotes, page {0} of 3:", page );
                    foreach ( char ch in emoteChars ) {
                        char ch1 = ch;
                        string keywords = Chat.EmoteKeywords
                                              .Where( pair => pair.Value == ch1 )
                                              .Select( kvp => "{&F" + kvp.Key.UppercaseFirst() + "&7}" )
                                              .JoinToString( " " );
                        player.Message( "&F  {0} &7= {1}", ch, keywords );
                    }
                    if ( page < 3 )
                        player.Message( "Type /List Emotes {0} for the next page", page + 1 );

                    break;
                case "top10":
                    List<World> WorldNames = new List<World>( WorldManager.Worlds.Where( w => w.VisitCount > 0 )
                                         .OrderBy( c => c.VisitCount )
                                         .ToArray()
                                         .Reverse() );
                    string list = WorldNames.Take( 10 ).JoinToString( w => String.Format( "{0}&S: {1}", w.ClassyName, w.VisitCount ) );
                    if ( WorldNames.Count() < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    player.Message( "&WShowing worlds with the most visits: " + list );
                    WorldNames.Clear();
                    break;
                case "idles":
                case "idle":
                    var Idles = Server.Players.Where( p => p.IdleTime.TotalMinutes > 5 ).ToArray();
                    var visiblePlayers = Idles.Where( player.CanSee );
                    if ( visiblePlayers.Count() > 0 )
                        player.Message( "Listing players idle for 5 mins or more: {0}",
                                        visiblePlayers.JoinToString( r => String.Format( "{0}&S (Idle {1}", r.ClassyName, r.IdleTime.ToMiniString() ) ) );
                    else player.Message( "No players have been idle for more than 5 minutes" );
                    break;
                case "portals":
                    if ( player.World == null ) {
                        player.Message( "/List portals cannot be used from Console" );
                        return;
                    }
                    if ( player.World.Map.Portals == null ||
                        player.World.Map.Portals.Count == 0 ) {
                        player.Message( "There are no portals in {0}&S.", player.World.ClassyName );
                    } else {
                        String[] portalNames = new String[player.World.Map.Portals.Count];
                        StringBuilder output = new StringBuilder( "There are " + player.World.Map.Portals.Count + " portals in " + player.World.ClassyName + "&S: " );

                        for ( int i = 0; i < player.World.Map.Portals.Count; i++ ) {
                            portalNames[i] = ( ( fCraft.Portals.Portal )player.World.Map.Portals[i] ).Name;
                        }
                        output.Append( portalNames.JoinToString( ", " ) );
                        player.Message( output.ToString() );
                    }
                    break;
                case "staff":
                    var StaffNames = PlayerDB.PlayerInfoList
                                         .Where( r => r.Rank.Can( Permission.ReadStaffChat ) &&
                                             r.Rank.Can( Permission.Ban ) &&
                                             r.Rank.Can( Permission.Promote ) )
                                             .OrderBy( p => p.Rank )
                                             .ToArray();
                    if ( StaffNames.Length < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    if ( StaffNames.Length <= PlayersPerPage ) {
                        player.MessageManyMatches( "staff", StaffNames );
                    } else {
                        int offset;
                        if ( !cmd.NextInt( out offset ) ) offset = 0;
                        if ( offset >= StaffNames.Length )
                            offset = Math.Max( 0, StaffNames.Length - PlayersPerPage );
                        PlayerInfo[] StaffPart = StaffNames.Skip( offset ).Take( PlayersPerPage ).ToArray();
                        player.MessageManyMatches( "staff", StaffPart );
                        if ( offset + StaffPart.Length < StaffNames.Length )
                            player.Message( "Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + StaffPart.Length, StaffNames.Length,
                                            "staff", offset + StaffPart.Length );
                        else
                            player.Message( "Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + StaffPart.Length, StaffNames.Length );
                    }
                    break;

                case "rank":
                    string rankName = cmd.Next();
                    if ( rankName == null ) {
                        player.Message( "Usage: /List rank rankName" );
                        return;
                    }
                    Rank rank = RankManager.FindRank( rankName );
                    var RankNames = PlayerDB.PlayerInfoList
                                         .Where( r => r.Rank == rank )
                                             .ToArray();
                    if ( RankNames.Length < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    if ( RankNames.Length <= PlayersPerPage ) {
                        player.MessageManyMatches( "players", RankNames );
                    } else {
                        int offset;
                        if ( !cmd.NextInt( out offset ) ) offset = 0;
                        if ( offset >= RankNames.Length )
                            offset = Math.Max( 0, RankNames.Length - PlayersPerPage );
                        PlayerInfo[] RankPart = RankNames.Skip( offset ).Take( PlayersPerPage ).ToArray();
                        player.MessageManyMatches( "rank list", RankPart );
                        if ( offset + RankPart.Length < RankNames.Length )
                            player.Message( "Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + RankPart.Length, RankNames.Length,
                                            "rank " + rank.ClassyName, offset + RankPart.Length );
                        else
                            player.Message( "Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + RankPart.Length, RankNames.Length );
                    }
                    break;
                case "displayednames":
                case "displayedname":
                case "dn":
                    var DisplayedNames = PlayerDB.PlayerInfoList
                                             .Where( r => r.DisplayedName != null ).OrderBy( p => p.Rank ).ToArray();
                    if ( DisplayedNames.Length < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    if ( DisplayedNames.Length <= 15 ) {
                        player.MessageManyDisplayedNamesMatches( "DisplayedNames", DisplayedNames );
                    } else {
                        int offset;
                        if ( !cmd.NextInt( out offset ) ) offset = 0;
                        if ( offset >= DisplayedNames.Count() )
                            offset = Math.Max( 0, DisplayedNames.Length - 15 );
                        PlayerInfo[] DnPart = DisplayedNames.Skip( offset ).Take( 15 ).ToArray();
                        player.MessageManyDisplayedNamesMatches( "DisplayedNames", DnPart );
                        if ( offset + DisplayedNames.Length < DisplayedNames.Length )
                            player.Message( "Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + DnPart.Length, DisplayedNames.Length,
                                            "DisplayedNames", offset + DnPart.Length );
                        else
                            player.Message( "Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + DnPart.Length, DisplayedNames.Length );
                    }
                    break;
            }
        }
Exemplo n.º 11
0
        static void TPHandler2(Player player, Command cmd)
        {
            string name = cmd.Next();
            if (name == null)
            {

                return;
            }

            if (cmd.Next() != null)
            {
                cmd.Rewind();
                int x, y, z;
                if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z))
                {

                    if (x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024)
                    {
                        player.Message("Coordinates are outside the valid range!");

                    }
                    else
                    {
                        player.TeleportTo(new Position
                        {
                            X = (short)(x * 32 + 16),
                            Y = (short)(y * 32 + 16),
                            Z = (short)(z * 32 + 16),
                            R = player.Position.R,
                            L = player.Position.L
                        });
                    }
                }
                else
                {
                    return;
                }

            }
            else
            {
                Player[] matches = Server.FindPlayers(player, name, true);
                if (matches.Length == 1)
                {
                    Player target = matches[0];
                    World targetWorld = target.World;
                    if (targetWorld == null) PlayerOpException.ThrowNoWorld(target);

                    if (targetWorld == player.World)
                    {
                        player.TeleportTo(target.Position);

                    }
                    else
                    {
                        switch (targetWorld.AccessSecurity.CheckDetailed(player.Info))
                        {
                            case SecurityCheckResult.Allowed:
                            case SecurityCheckResult.WhiteListed:
                                if (targetWorld.IsFull)
                                {
                                    player.Message("Cannot teleport to {0}&S because world {1}&S is full.",
                                                    target.ClassyName,
                                                    targetWorld.ClassyName);
                                    return;
                                }
                                player.StopSpectating();
                                player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position);
                                break;
                            case SecurityCheckResult.BlackListed:
                                player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}",
                                                target.ClassyName,
                                                targetWorld.ClassyName);
                                break;
                            case SecurityCheckResult.RankTooLow:
                                player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
                                                target.ClassyName,
                                                targetWorld.ClassyName,
                                                targetWorld.AccessSecurity.MinRank.ClassyName);
                                break;
                            // TODO: case PermissionType.RankTooHigh:
                        }
                    }

                }
                else if (matches.Length > 1)
                {
                    player.MessageManyMatches("player", matches);

                }
                else
                {
                    // Try to guess if player typed "/TP" instead of "/Join"
                    World[] worlds = WorldManager.FindWorlds(player, name);

                    if (worlds.Length == 1)
                    {
                        player.LastUsedWorldName = worlds[0].Name;
                        player.StopSpectating();
                        player.ParseMessage("/Join " + worlds[0].Name, false);
                    }
                    else
                    {
                        player.MessageNoPlayer(name);
                    }
                }
            }
        }
Exemplo n.º 12
0
        static void JoinHandler( Player player, CommandReader cmd ) {
            string worldName = cmd.Next();
            if( worldName == null ) {
                CdJoin.PrintUsage( player );
                return;
            }

            if( worldName == "-" ) {
                if( player.LastUsedWorldName != null ) {
                    worldName = player.LastUsedWorldName;
                } else {
                    player.Message( "Cannot repeat world name: you haven't used any names yet." );
                    return;
                }
            }

            World[] worlds = WorldManager.FindWorlds( player, worldName );

            if( worlds.Length > 1 ) {
                player.MessageManyMatches( "world", worlds );

            } else if( worlds.Length == 1 ) {
                World world = worlds[0];
                player.LastUsedWorldName = world.Name;
                switch( world.AccessSecurity.CheckDetailed( player.Info ) ) {
                    case SecurityCheckResult.Allowed:
                    case SecurityCheckResult.WhiteListed:
                        if( world.IsFull ) {
                            player.Message( "Cannot join {0}&S: world is full.", world.ClassyName );
                            return;
                        }
                        player.StopSpectating();
                        if( !player.JoinWorldNow( world, true, WorldChangeContext.ManualJoin ) ) {
                            player.Message( "ERROR: Failed to join world. See log for details." );
                        }
                        break;
                    case SecurityCheckResult.BlackListed:
                        player.Message( "Cannot join world {0}&S: you are blacklisted.",
                                        world.ClassyName );
                        break;
                    case SecurityCheckResult.RankTooLow:
                        player.Message( "Cannot join world {0}&S: must be {1}+",
                                        world.ClassyName, world.AccessSecurity.MinRank.ClassyName );
                        break;
                    // TODO: Uncomment
                    //case SecurityCheckResult.RankTooHigh:
                    //    player.Message("Cannot join world {0}&S: must be {1}-",
                    //                    world.ClassyName, world.AccessSecurity.MaxRank.ClassyName);
                    //    break;
                }

            } else {
                player.MessageNoWorld( worldName );
            }
        }
Exemplo n.º 13
0
        static void SetSpawnHandler(Player player, Command cmd)
        {
            string playerName = cmd.Next();
            if (playerName == null)
            {
                player.World.Map.Spawn = player.Position;
                player.TeleportTo(player.World.Map.Spawn);
                player.Send(PacketWriter.MakeAddEntity(255, player.ListName, player.Position));
                player.Message("New spawn point saved.");
                Logger.Log(LogType.UserActivity, "{0} changed the spawned point.",
                            player.Name);

            }
            else if (player.Can(Permission.Bring))
            {
                Player[] infos = player.World.FindPlayers(player, playerName);
                if (infos.Length == 1)
                {
                    Player target = infos[0];
                    if (player.Can(Permission.Bring, target.Info.Rank))
                    {
                        target.Send(PacketWriter.MakeAddEntity(255, target.ListName, player.Position));
                    }
                    else
                    {
                        player.Message("You can only set spawn of players ranked {0}&S or lower.",
                                        player.Info.Rank.GetLimit(Permission.Bring).ClassyName);
                        player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName);
                    }

                }
                else if (infos.Length > 0)
                {
                    player.MessageManyMatches("player", infos);

                }
                else
                {
                    infos = Server.FindPlayers(player, playerName, true);
                    if (infos.Length > 0)
                    {
                        player.Message("You can only set spawn of players on the same world as you.");
                    }
                    else
                    {
                        player.MessageNoPlayer(playerName);
                    }
                }
            }
            else
            {
                player.MessageNoAccess(CdRealm);
            }
        }
Exemplo n.º 14
0
        internal static void ListHandler(Player player, Command cmd)
        {
            string Option = cmd.Next();

            if (Option == null)
            {
                CdList.PrintUsage(player);
                return;
            }
            if (Option.ToLower() == "staff")
            {
                var StaffNames = PlayerDB.PlayerInfoList
                                     .Where(r => r.Rank.Can(Permission.ReadStaffChat) &&
                                         r.Rank.Can(Permission.Ban) &&
                                         r.Rank.Can(Permission.Promote))
                                         .ToArray();

                if (StaffNames.Length <= PlayersPerPage)
                {
                    player.MessageManyMatches("staff", StaffNames);
                }

                else
                {
                    int offset;

                    if (!cmd.NextInt(out offset)) offset = 0;

                    if (offset >= StaffNames.Length)
                        offset = Math.Max(0, StaffNames.Length - PlayersPerPage);

                    PlayerInfo[] StaffPart = StaffNames.Skip(offset).Take(PlayersPerPage).ToArray();
                    player.MessageManyMatches("staff", StaffPart);

                    if (offset + StaffPart.Length < StaffNames.Length)
                        player.Message("Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                        offset + 1, offset + StaffPart.Length, StaffNames.Length,
                                        "staff", offset + StaffPart.Length);
                    else
                        player.Message("Showing matches {0}-{1} (out of {2}).",
                                        offset + 1, offset + StaffPart.Length, StaffNames.Length);
                }
            }

            if (Option.ToLower() == "displayednames" || Option.ToLower() == "displayedname" || Option.ToLower() == "dn")
            {

                var DisplayedNames = PlayerDB.PlayerInfoList
                                         .Where(r => r.DisplayedName != null).ToArray();
                if (DisplayedNames.Count() > 0)
                    player.Message("Listing all DisplayedNames: {0}",
                                    DisplayedNames.JoinToString(r => String.Format("{0}&S({1})", r.ClassyName, r.Name)));
                else player.Message("No players with DisplayedNames were found in the Player Database");
            }
        }
Exemplo n.º 15
0
        static void SetSpawnHandler( Player player, CommandReader cmd ) {
            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );


            string playerName = cmd.Next();
            if( playerName == null ) {
                Map map = player.WorldMap;
                map.Spawn = player.Position;
                player.TeleportTo( map.Spawn );
                player.Send( Packet.MakeAddEntity( Packet.SelfID, player.ListName, player.Position ) );
                player.Message( "New spawn point saved." );
                Logger.Log( LogType.UserActivity,
                            "{0} changed the spawned point.",
                            player.Name );

            } else if( player.Can( Permission.Bring ) ) {
                Player[] infos = playerWorld.FindPlayers( player, playerName );
                if( infos.Length == 1 ) {
                    Player target = infos[0];
                    player.LastUsedPlayerName = target.Name;
                    if( player.Can( Permission.Bring, target.Info.Rank ) ) {
                        target.Send( Packet.MakeAddEntity( Packet.SelfID, target.ListName, player.Position ) );
                    } else {
                        player.Message( "You may only set spawn of players ranked {0}&S or lower.",
                                        player.Info.Rank.GetLimit( Permission.Bring ).ClassyName );
                        player.Message( "{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName );
                    }

                } else if( infos.Length > 0 ) {
                    player.MessageManyMatches( "player", infos );

                } else {
                    infos = Server.FindPlayers( player, playerName, true, false, true );
                    if( infos.Length > 0 ) {
                        player.Message( "You may only set spawn of players on the same world as you." );
                    } else {
                        player.MessageNoPlayer( playerName );
                    }
                }
            } else {
                player.MessageNoAccess( CdSetSpawn );
            }
        }
Exemplo n.º 16
0
        private static void TeleportHandler(Player player, CommandReader cmd) {
            string name = cmd.Next();
            if (name == null) {
                CdTeleport.PrintUsage(player);
                return;
            }
            if (player.World.Name.ToLower() == "maze") {
                player.Message("Hey no cheating!");
                return;
            }
            if (name == "zone") {
                string zoneName = cmd.Next();
                if (zoneName == null) {
                    player.Message("No zone name specified. See &H/Help tpzone");
                    return;
                } else {
                    Zone zone = player.World.Map.Zones.Find(zoneName);
                    if (zone == null) {
                        player.MessageNoZone(zoneName);
                        return;
                    }
                    int zoneX = (zone.Bounds.XMin + zone.Bounds.XMax)/2;
                    int zoneY = (zone.Bounds.YMin + zone.Bounds.YMax)/2;
                    int zoneZ = (zone.Bounds.ZMin + zone.Bounds.ZMax)/2;
                    retry2:
                    if (player.World.map.GetBlock(zoneX, zoneY, zoneZ - 1) == Block.Air) {
                        zoneZ = zoneZ - 1;
                        goto retry2;
                    }
                    retry:
                    if (player.World.map.GetBlock(zoneX, zoneY, zoneZ) != Block.Air ||
                        player.World.map.GetBlock(zoneX, zoneY, zoneZ + 1) != Block.Air) {
                        zoneZ = zoneZ + 1;
                        goto retry;
                    }
					Position zPos = new Position((zoneX) * 32 + 16, (zoneY) * 32 + 16, (zoneZ) * 32 + 64);
					if (player.World != null) {
						player.LastWorld = player.World;
						player.LastPosition = player.Position;
					}
                    player.TeleportTo((zPos));
                    player.Message("&sTeleporting you to zone " + zone.ClassyName);
                    return;
                }
            }
            if (name == "random" || name == "rand") {
                Random rand = new Random();
                int x = rand.Next(0, player.WorldMap.Width);
                int y = rand.Next(0, player.WorldMap.Length);
                int z = player.Position.Z/32 + 1;
                retry2:
                if (player.World.map.GetBlock(x, y, z - 3) == Block.Air) {
                    z = z - 1;
                    goto retry2;
                }
                retry:
                if (player.World.map.GetBlock(x, y, z - 2) != Block.Air ||
                    player.World.map.GetBlock(x, y, z - 1) != Block.Air) {
                    z = z + 1;
                    goto retry;
                }

				if (player.World != null) {
					player.LastWorld = player.World;
					player.LastPosition = player.Position;
				}
                player.TeleportTo(new Position {
                    X = (short) (x*32 + 16),
                    Y = (short) (y*32 + 16),
                    Z = (short) (z*32 + 16),
                    R = player.Position.R,
                    L = player.Position.L
                });
                player.Message("Teleported to: ({0}, {1}, {2})", x, y, z);
                return;
            }

            if (cmd.Next() != null) {
                cmd.Rewind();
                int x, y, z, rot, lot;
                rot = player.Position.R;
                lot = player.Position.L;
                if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
                    if (cmd.HasNext) {
                        if (cmd.HasNext) {
                            if (cmd.NextInt(out rot) && cmd.NextInt(out lot)) {
                                if (rot > 255 || rot < 0) {
                                    player.Message("R must be inbetween 0 and 255. Set to player R");
                                }
                                if (lot > 255 || lot < 0) {
                                    player.Message("L must be inbetween 0 and 255. Set to player L");
                                }
                            }
                        }
                    }
                    if (x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024) {
                        player.Message("Coordinates are outside the valid range!");

					} else {
						if (player.World != null) {
							player.LastWorld = player.World;
							player.LastPosition = player.Position;
						}
                        player.TeleportTo(new Position {
                            X = (short) (x*32 + 16),
                            Y = (short) (y*32 + 16),
                            Z = (short) (z*32 + 48),
                            R = (byte) rot,
                            L = (byte) lot
                        });
                    }
                } else {
                    CdTeleport.PrintUsage(player);
                }

            } else {
                if (name == "-") {
                    if (player.LastUsedPlayerName != null) {
                        name = player.LastUsedPlayerName;
                    } else {
                        player.Message("Cannot repeat player name: you haven't used any names yet.");
                        return;
                    }
                }
                Player[] matches = Server.FindPlayers(player, name, SearchOptions.Default);
                if (matches.Length == 1) {
                    Player target = matches[0];
                    World targetWorld = target.World;
                    if (targetWorld == null) PlayerOpException.ThrowNoWorld(target);
                    if (target.Info.TPDeny && target.Info.Rank >= player.Info.Rank) {
                        player.Message("&CThis player does not want people teleporting to them");
                        player.Message("Cannot teleport to {0}&S.", target.ClassyName, targetWorld.ClassyName,
                            targetWorld.AccessSecurity.MinRank.ClassyName);
                        return;
                    }

					if (targetWorld == player.World) {
						if (player.World != null) {
							player.LastWorld = player.World;
							player.LastPosition = player.Position;
						}
                        player.TeleportTo(target.Position);

                    } else {
                        if (targetWorld.Name.StartsWith("PW_") &&
                            !targetWorld.AccessSecurity.ExceptionList.Included.Contains(player.Info)) {
                            player.Message(
                                "You cannot join due to that player being in a personal world that you cannot access.");
                            return;
                        }
                        switch (targetWorld.AccessSecurity.CheckDetailed(player.Info)) {
                            case SecurityCheckResult.Allowed:
                            case SecurityCheckResult.WhiteListed:
                                if (player.Info.Rank.Name == "Banned") {
                                    player.Message("&CYou can not change worlds while banned.");
                                    player.Message("Cannot teleport to {0}&S.", target.ClassyName,
                                        targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                    break;
                                }
                                if (targetWorld.IsFull) {
                                    player.Message("Cannot teleport to {0}&S because world {1}&S is full.",
                                        target.ClassyName, targetWorld.ClassyName);
                                    player.Message("Cannot teleport to {0}&S.", target.ClassyName,
                                        targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                    break;
                                }
                                player.StopSpectating();
                                player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position);
                                break;
                            case SecurityCheckResult.BlackListed:
                                player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}",
                                    target.ClassyName, targetWorld.ClassyName);
                                break;
                            case SecurityCheckResult.RankTooLow:
                                if (player.Info.Rank.Name == "Banned") {
                                    player.Message("&CYou can not change worlds while banned.");
                                    player.Message("Cannot teleport to {0}&S.", target.ClassyName,
                                        targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                    break;
                                }

                                if (targetWorld.IsFull) {
                                    if (targetWorld.IsFull) {
                                        player.Message("Cannot teleport to {0}&S because world {1}&S is full.",
                                            target.ClassyName, targetWorld.ClassyName);
                                        player.Message("Cannot teleport to {0}&S.", target.ClassyName,
                                            targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName);
                                        break;
                                    }
                                    player.StopSpectating();
                                    player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position);
                                    break;
                                }
                                player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
                                    target.ClassyName, targetWorld.ClassyName,
                                    targetWorld.AccessSecurity.MinRank.ClassyName);
                                break;
                        }
                    }

                } else if (matches.Length > 1) {
                    player.MessageManyMatches("player", matches);

                }
            }
        }
Exemplo n.º 17
0
        static void TeleportHandler( Player player, CommandReader cmd ) {
            string name = cmd.Next();
            if( name == null ) {
                CdTeleport.PrintUsage( player );
                return;
            }

            if( cmd.Next() != null ) {
                cmd.Rewind();
                int x, y, z;
                if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out z ) ) {

                    if( x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024 ) {
                        player.Message( "Coordinates are outside the valid range!" );

                    } else {
                        player.TeleportTo( new Position {
                            X = (short)(x * 32 + 16),
                            Y = (short)(y * 32 + 16),
                            Z = (short)(z * 32 + 16),
                            R = player.Position.R,
                            L = player.Position.L
                        } );
                    }
                } else {
                    CdTeleport.PrintUsage( player );
                }

            } else {
                if( name == "-" ) {
                    if( player.LastUsedPlayerName != null ) {
                        name = player.LastUsedPlayerName;
                    } else {
                        player.Message( "Cannot repeat player name: you haven't used any names yet." );
                        return;
                    }
                }
                Player[] matches = Server.FindPlayers( player, name, false, true, true );
                if( matches.Length == 1 ) {
                    Player target = matches[0];
                    World targetWorld = target.World;
                    if( targetWorld == null ) PlayerOpException.ThrowNoWorld( target );

                    if( targetWorld == player.World ) {
                        player.TeleportTo( target.Position );

                    } else {
                        switch( targetWorld.AccessSecurity.CheckDetailed( player.Info ) ) {
                            case SecurityCheckResult.Allowed:
                            case SecurityCheckResult.WhiteListed:
                                if( targetWorld.IsFull ) {
                                    player.Message( "Cannot teleport to {0}&S because world {1}&S is full.",
                                                    target.ClassyName,
                                                    targetWorld.ClassyName );
                                    return;
                                }
                                player.StopSpectating();
                                player.JoinWorld( targetWorld, WorldChangeReason.Tp, target.Position );
                                break;
                            case SecurityCheckResult.BlackListed:
                                player.Message( "Cannot teleport to {0}&S because you are blacklisted on world {1}",
                                                target.ClassyName,
                                                targetWorld.ClassyName );
                                break;
                            case SecurityCheckResult.RankTooLow:
                                player.Message( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
                                                target.ClassyName,
                                                targetWorld.ClassyName,
                                                targetWorld.AccessSecurity.MinRank.ClassyName );
                                break;
                        }
                    }

                } else if( matches.Length > 1 ) {
                    player.MessageManyMatches( "player", matches );

                } else {
                    player.MessageNoPlayer( name );
                }
            }
        }
Exemplo n.º 18
0
        internal static void ListHandler(Player player, Command cmd)
        {
            string Option = cmd.Next();
            if (Option == null)
            {
                CdList.PrintUsage(player);
                player.Message("  Sections include: Staff, DisplayedNames, Idles, Portals, Rank, Top10");
                return;
            }
            switch (Option.ToLower())
            {
                default:
                    CdList.PrintUsage(player);
                    player.Message("  Sections include: Staff, DisplayedNames, Idles, Portals, Rank, Top10");
                    break;
                case "top10":
                    List<World> WorldNames = new List<World>(WorldManager.Worlds.Where(w => w.VisitCount > 0)
                                         .OrderBy(c => c.VisitCount)
                                         .ToArray()
                                         .Reverse());
                    string list = WorldNames.Take(10).JoinToString(w => String.Format("{0}&S: {1}", w.ClassyName, w.VisitCount));
                    if (WorldNames.Count() < 1){
                        player.Message("&WNo results found");
                        return;
                    }
                    player.Message("&WShowing worlds with the most visits: " + list);
                    WorldNames.Clear();
                    break;
                case "idles":
                case "idle":
                    var Idles = Server.Players.Where(p => p.IdleTime.TotalMinutes > 5).ToArray();
                    var visiblePlayers = Idles.Where(player.CanSee);
                    if (Idles.Count() > 0)
                        player.Message("Listing players idle for 5 mins or more: {0}",
                                        visiblePlayers.JoinToString(r => String.Format("{0}", r.ClassyName)));
                    else player.Message("No players have been idle for more than 5 minutes");
                    break;
                case "portals":
                    if (player.World == null){
                        player.Message("/List portals cannot be used from Console");
                        return;
                    }
                    if (player.World.Portals == null ||
                        player.World.Portals.Count == 0){
                        player.Message("There are no portals in {0}&S.", player.World.ClassyName);
                    }
                    else
                    {
                        String[] portalNames = new String[player.World.Portals.Count];
                        StringBuilder output = new StringBuilder("There are " + player.World.Portals.Count + " portals in " + player.World.ClassyName + "&S: ");

                        for (int i = 0; i < player.World.Portals.Count; i++)
                        {
                            portalNames[i] = ((fCraft.Portals.Portal)player.World.Portals[i]).Name;
                        }
                        output.Append(portalNames.JoinToString(", "));
                        player.Message(output.ToString());
                    }
                    break;
                case "staff":
                    var StaffNames = PlayerDB.PlayerInfoList
                                         .Where(r => r.Rank.Can(Permission.ReadStaffChat) &&
                                             r.Rank.Can(Permission.Ban) &&
                                             r.Rank.Can(Permission.Promote))
                                             .OrderBy(p => p.Rank)
                                             .ToArray();
                    if (StaffNames.Length < 1){
                        player.Message("&WNo results found");
                        return;
                    }
                    if (StaffNames.Length <= PlayersPerPage){
                        player.MessageManyMatches("staff", StaffNames);
                    }else{
                        int offset;
                        if (!cmd.NextInt(out offset)) offset = 0;
                        if (offset >= StaffNames.Length)
                            offset = Math.Max(0, StaffNames.Length - PlayersPerPage);
                        PlayerInfo[] StaffPart = StaffNames.Skip(offset).Take(PlayersPerPage).ToArray();
                        player.MessageManyMatches("staff", StaffPart);
                        if (offset + StaffPart.Length < StaffNames.Length)
                            player.Message("Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + StaffPart.Length, StaffNames.Length,
                                            "staff", offset + StaffPart.Length);
                        else
                            player.Message("Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + StaffPart.Length, StaffNames.Length);
                    }
                    break;

                case "rank":
                    string rankName = cmd.Next();
                    if (rankName == null)
                    {
                        player.Message("Usage: /List rank rankName");
                        return;
                    }
                    Rank rank = RankManager.FindRank(rankName);
                    var RankNames = PlayerDB.PlayerInfoList
                                         .Where(r => r.Rank == rank)
                                             .ToArray();
                    if (RankNames.Length < 1){
                        player.Message("&WNo results found");
                        return;
                    }
                    if (RankNames.Length <= PlayersPerPage)
                    {
                        player.MessageManyMatches("players", RankNames);
                    }
                    else
                    {
                        int offset;
                        if (!cmd.NextInt(out offset)) offset = 0;
                        if (offset >= RankNames.Length)
                            offset = Math.Max(0, RankNames.Length - PlayersPerPage);
                        PlayerInfo[] RankPart = RankNames.Skip(offset).Take(PlayersPerPage).ToArray();
                        player.MessageManyMatches("rank list", RankPart);
                        if (offset + RankPart.Length < RankNames.Length)
                            player.Message("Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + RankPart.Length, RankNames.Length,
                                            "rank " + rank.ClassyName, offset + RankPart.Length);
                        else
                            player.Message("Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + RankPart.Length, RankNames.Length);
                    }
                    break;
                case "displayednames":
                case "displayedname":
                case "dn":
                    var DisplayedNames = PlayerDB.PlayerInfoList
                                             .Where(r => r.DisplayedName != null).OrderBy(p => p.Rank).ToArray();
                    if (DisplayedNames.Length < 1){
                        player.Message("&WNo results found");
                        return;
                    }
                    if (DisplayedNames.Length <= 15)
                    {
                        player.MessageManyDisplayedNamesMatches("DisplayedNames", DisplayedNames);
                    }
                    else
                    {
                        int offset;
                        if (!cmd.NextInt(out offset)) offset = 0;
                        if (offset >= DisplayedNames.Count())
                            offset = Math.Max(0, DisplayedNames.Length - 15);
                        PlayerInfo[] DnPart = DisplayedNames.Skip(offset).Take(15).ToArray();
                        player.MessageManyDisplayedNamesMatches("DisplayedNames", DnPart);
                        if (offset + DisplayedNames.Length < DisplayedNames.Length)
                            player.Message("Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + DnPart.Length, DisplayedNames.Length,
                                            "DisplayedNames", offset + DnPart.Length);
                        else
                            player.Message("Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + DnPart.Length, DisplayedNames.Length);
                    }
                    break;
            }
        }
Exemplo n.º 19
0
        static void InfoHandler( Player player, CommandReader cmd ) {
            string name = cmd.Next();
            if( name == null ) {
                // no name given, print own info
                PrintPlayerInfo( player, player.Info );
                return;

            } else if( name.Equals( player.Name, StringComparison.OrdinalIgnoreCase ) ) {
                // own name given
                player.LastUsedPlayerName = player.Name;
                PrintPlayerInfo( player, player.Info );
                return;

            } else if( !player.Can( Permission.ViewOthersInfo ) ) {
                // someone else's name or IP given, permission required.
                player.MessageNoAccess( Permission.ViewOthersInfo );
                return;
            }

            // repeat last-typed name
            if( name == "-" ) {
                if( player.LastUsedPlayerName != null ) {
                    name = player.LastUsedPlayerName;
                } else {
                    player.Message( "Cannot repeat player name: you haven't used any names yet." );
                    return;
                }
            }

            PlayerInfo[] infos;
            IPAddress ip;

            if( name.Contains( "/" ) ) {
                // IP range matching (CIDR notation)
                string ipString = name.Substring( 0, name.IndexOf( '/' ) );
                string rangeString = name.Substring( name.IndexOf( '/' ) + 1 );
                byte range;
                if( IPAddressUtil.IsIP( ipString ) && IPAddress.TryParse( ipString, out ip ) &&
                    Byte.TryParse( rangeString, out range ) && range <= 32 ) {
                    player.Message( "Searching {0}-{1}", ip.RangeMin( range ), ip.RangeMax( range ) );
                    infos = PlayerDB.FindPlayersCidr( ip, range );
                } else {
                    player.Message( "Info: Invalid IP range format. Use CIDR notation." );
                    return;
                }

            } else if( IPAddressUtil.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) {
                // find players by IP
                infos = PlayerDB.FindPlayers( ip );

            } else if( name.Equals( "*" ) ) {
                infos = (PlayerInfo[])PlayerDB.PlayerInfoList.Clone();

            } else if( name.Contains( "*" ) || name.Contains( "?" ) ) {
                // find players by regex/wildcard
                string regexString = "^" + RegexNonNameChars.Replace( name, "" ).Replace( "*", ".*" ).Replace( "?", "." ) + "$";
                Regex regex = new Regex( regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled );
                infos = PlayerDB.FindPlayers( regex );

            } else if( name.StartsWith( "@" ) ) {
                string rankName = name.Substring( 1 );
                Rank rank = RankManager.FindRank( rankName );
                if( rank == null ) {
                    player.MessageNoRank( rankName );
                    return;
                } else {
                    infos = PlayerDB.PlayerInfoList
                                    .Where( info => info.Rank == rank )
                                    .ToArray();
                }

            } else if( name.StartsWith( "!" ) ) {
                // find online players by partial matches
                name = name.Substring( 1 );
                infos = Server.FindPlayers( name, true )
                              .Select( p => p.Info )
                              .ToArray();

            } else {
                // find players by partial matching
                PlayerInfo tempInfo;
                if( !PlayerDB.FindPlayerInfo( name, out tempInfo ) ) {
                    infos = PlayerDB.FindPlayers( name );
                } else if( tempInfo == null ) {
                    player.MessageNoPlayer( name );
                    return;
                } else {
                    infos = new[] { tempInfo };
                }
            }

            Array.Sort( infos, new PlayerInfoComparer( player ) );

            if( infos.Length == 1 ) {
                // only one match found; print it right away
                player.LastUsedPlayerName = infos[0].Name;
                PrintPlayerInfo( player, infos[0] );

            } else if( infos.Length > 1 ) {
                // multiple matches found
                if( infos.Length <= PlayersPerPage ) {
                    // all fit to one page
                    player.MessageManyMatches( "player", infos );

                } else {
                    // pagination
                    int offset;
                    if( !cmd.NextInt( out offset ) ) offset = 0;
                    if( offset >= infos.Length ) {
                        offset = Math.Max( 0, infos.Length - PlayersPerPage );
                    }
                    PlayerInfo[] infosPart = infos.Skip( offset ).Take( PlayersPerPage ).ToArray();
                    player.MessageManyMatches( "player", infosPart );
                    if( offset + infosPart.Length < infos.Length ) {
                        // normal page
                        player.Message( "Showing {0}-{1} (out of {2}). Next: &H/Info {3} {4}",
                                        offset + 1, offset + infosPart.Length, infos.Length,
                                        name, offset + infosPart.Length );
                    } else {
                        // last page
                        player.Message( "Showing matches {0}-{1} (out of {2}).",
                                        offset + 1, offset + infosPart.Length, infos.Length );
                    }
                }

            } else {
                // no matches found
                player.MessageNoPlayer( name );
            }
        }
Exemplo n.º 20
0
        static void InfoHandler( Player player, CommandReader cmd ) {
            string name = cmd.Next();
            if( name == null ) {
                // no name given, print own info
                PrintPlayerInfo( player, player.Info );
                return;

            } else if( name.Equals( player.Name, StringComparison.OrdinalIgnoreCase ) ) {
                // own name given
                player.LastUsedPlayerName = player.Name;
                PrintPlayerInfo( player, player.Info );
                return;

            } else if( !player.Can( Permission.ViewOthersInfo ) ) {
                // someone else's name or IP given, permission required.
                player.MessageNoAccess( Permission.ViewOthersInfo );
                return;
            }

            // repeat last-typed name
            if( name == "-" ) {
                if( player.LastUsedPlayerName != null ) {
                    name = player.LastUsedPlayerName;
                } else {
                    player.Message( "Cannot repeat player name: you haven't used any names yet." );
                    return;
                }
            }

            PlayerInfo[] infos;
            IPAddress ip;

            if( IPAddressUtil.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) {
                // find players by IP
                infos = PlayerDB.FindByIP( ip ).ToArray();

            } else if( name.Contains( "*" ) || name.Contains( "?" ) ) {
                // find players by regex/wildcard
                infos = PlayerDB.FindByPattern( name ).ToArray();

            } else if( name.StartsWith( "@" ) ) {
                string rankName = name.Substring( 1 );
                Rank rank = RankManager.FindRank( rankName );
                if( rank == null ) {
                    player.Message( "Unknown rank: {0}", rankName );
                    return;
                } else {
                    using( PlayerDB.GetReadLock() ) {
                        infos = PlayerDB.List
                                        .Where( info => info.Rank == rank )
                                        .ToArray();
                    }
                }

            } else {
                // find players by partial matching
                PlayerInfo tempInfo;
                if( !PlayerDB.FindOneByPartialName( name, out tempInfo ) ) {
                    infos = PlayerDB.FindByPartialName( name ).ToArray();
                } else if( tempInfo == null ) {
                    player.MessageNoPlayer( name );
                    return;
                } else {
                    infos = new[] { tempInfo };
                }
            }

            Array.Sort( infos, new PlayerInfoComparer( player ) );

            if( infos.Length == 1 ) {
                // only one match found; print it right away
                player.LastUsedPlayerName = infos[0].Name;
                PrintPlayerInfo( player, infos[0] );

            } else if( infos.Length > 1 ) {
                // multiple matches found
                if( infos.Length <= PlayersPerPage ) {
                    // all fit to one page
                    player.MessageManyMatches( "player", infos );

                } else {
                    // pagination
                    int offset;
                    if( !cmd.NextInt( out offset ) ) offset = 0;
                    if( offset >= infos.Length ) {
                        offset = Math.Max( 0, infos.Length - PlayersPerPage );
                    }
                    PlayerInfo[] infosPart = infos.Skip( offset ).Take( PlayersPerPage ).ToArray();
                    player.MessageManyMatches( "player", infosPart );
                    if( offset + infosPart.Length < infos.Length ) {
                        // normal page
                        player.Message( "Showing {0}-{1} (out of {2}). Next: &H/Info {3} {4}",
                                        offset + 1, offset + infosPart.Length, infos.Length,
                                        name, offset + infosPart.Length );
                    } else {
                        // last page
                        player.Message( "Showing matches {0}-{1} (out of {2}).",
                                        offset + 1, offset + infosPart.Length, infos.Length );
                    }
                }

            } else {
                // no matches found
                player.MessageNoPlayer( name );
            }
        }