public static World FindWorldOrPrintMatches(Player player, string worldName) { if (player == null) { throw new ArgumentNullException("player"); } if (worldName == null) { throw new ArgumentNullException("worldName"); } List <World> matches = new List <World>(FindWorlds(worldName)); SearchingForWorldEventArgs e = new SearchingForWorldEventArgs(player, worldName, matches, false); RaiseSearchingForWorldEvent(e); matches = e.Matches; if (matches.Count == 0) { player.NoWorldMessage(worldName); return(null); } else if (matches.Count > 1) { player.ManyMatchesMessage("world", matches.ToArray()); return(null); } else { return(matches[0]); } }
internal static void Unignore(Player player, Command cmd) { string name = cmd.Next(); if (name != null) { PlayerInfo targetInfo; if (!PlayerDB.FindPlayerInfo(name, out targetInfo)) { PlayerInfo[] infos = PlayerDB.FindPlayers(name); if (infos.Length == 1) { targetInfo = infos[0]; } else if (infos.Length > 1) { player.ManyMatchesMessage("player", infos); return; } else { player.NoPlayerMessage(name); return; } } else if (targetInfo == null) { player.NoPlayerMessage(name); return; } if (player.Unignore(targetInfo)) { player.MessageNow("You are no longer ignoring {0}", targetInfo.GetClassyName()); } else { player.MessageNow("You are not currently ignoring {0}", targetInfo.GetClassyName()); } } else { PlayerInfo[] ignoreList = player.GetIgnoreList(); if (ignoreList.Length > 0) { player.MessageNow("Ignored players: {0}", ignoreList.JoinToClassyString()); } else { player.MessageNow("You are not currently ignoring anyone."); } return; } }
internal static void Join( Player player, Command cmd ) { string worldName = cmd.Next(); if( worldName == null ) { cdJoin.PrintUsage( player ); return; } World[] worlds = WorldManager.FindWorlds( worldName ); SearchingForWorldEventArgs e = new SearchingForWorldEventArgs( player, worldName, worlds.ToList(), true ); WorldManager.RaiseSearchingForWorldEvent( e ); worlds = e.Matches.ToArray(); if( worlds.Length > 1 ) { player.ManyMatchesMessage( "world", worlds ); } else if( worlds.Length == 1 ) { World world = worlds[0]; 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.GetClassyName() ); return; } player.StopSpectating(); if( !player.Session.JoinWorldNow( world, false, true ) ) { 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.GetClassyName(), world.AccessSecurity.MinRank.GetClassyName() ); break; case SecurityCheckResult.RankTooLow: player.Message( "Cannot join world {0}&S: must be {1}+", world.GetClassyName(), world.AccessSecurity.MinRank.GetClassyName() ); break; } } else { // no worlds found - see if player meant to type in "/join" and not "/tp" Player[] players = Server.FindPlayers( player, worldName ); if( players.Length == 1 ) { player.StopSpectating(); player.ParseMessage( "/tp " + players[0].Name, false ); } else { player.NoWorldMessage( worldName ); } } }
internal static void Unignore( Player player, Command cmd ) { string name = cmd.Next(); if( name != null ) { PlayerInfo targetInfo; if( !PlayerDB.FindPlayerInfo( name, out targetInfo ) ) { PlayerInfo[] infos = PlayerDB.FindPlayers( name ); if( infos.Length == 1 ) { targetInfo = infos[0]; } else if( infos.Length > 1 ) { player.ManyMatchesMessage( "player", infos ); return; } else { player.NoPlayerMessage( name ); return; } } else if( targetInfo == null ) { player.NoPlayerMessage( name ); return; } if( player.Unignore( targetInfo ) ) { player.MessageNow( "You are no longer ignoring {0}", targetInfo.GetClassyName() ); } else { player.MessageNow( "You are not currently ignoring {0}", targetInfo.GetClassyName() ); } } else { PlayerInfo[] ignoreList = player.GetIgnoreList(); if( ignoreList.Length > 0 ) { player.MessageNow( "Ignored players: {0}", ignoreList.JoinToClassyString() ); } else { player.MessageNow( "You are not currently ignoring anyone." ); } return; } }
public static World FindWorldOrPrintMatches( Player player, string worldName ) { if( player == null ) throw new ArgumentNullException( "player" ); if( worldName == null ) throw new ArgumentNullException( "worldName" ); List<World> matches = new List<World>( FindWorlds( worldName ) ); SearchingForWorldEventArgs e = new SearchingForWorldEventArgs( player, worldName, matches, false ); RaiseSearchingForWorldEvent( e ); matches = e.Matches; if( matches.Count == 0 ) { player.NoWorldMessage( worldName ); return null; } else if( matches.Count > 1 ) { player.ManyMatchesMessage( "world", matches.ToArray() ); return null; } else { return matches[0]; } }
/// <summary>Find player by name using autocompletion (returns only whose whom player can see) /// Returns null and prints message if none or multiple players matched.</summary> /// <param name="player">Player who initiated the search. This is where messages are sent.</param> /// <param name="name">Full or partial name of the search target.</param> /// <param name="includeHidden">Whether to include hidden players in the search.</param> /// <returns>Player object, or null if no player was found.</returns> public static Player FindPlayerOrPrintMatches( Player player, string name, bool includeHidden ) { if( player == null ) throw new ArgumentNullException( "player" ); if( name == null ) throw new ArgumentNullException( "name" ); Player[] matches; if( includeHidden ) { matches = FindPlayers( name ); } else { matches = FindPlayers( player, name ); } if( matches.Length == 0 ) { player.NoPlayerMessage( name ); return null; } else if( matches.Length > 1 ) { player.ManyMatchesMessage( "player", matches ); return null; } else { return matches[0]; } }
internal static void Info( Player player, Command cmd ) { string name = cmd.Next(); if( name == null ) { name = player.Name; } else if( !player.Can( Permission.ViewOthersInfo ) ) { player.NoAccessMessage( Permission.ViewOthersInfo ); return; } IPAddress ip; PlayerInfo[] infos; if( Server.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) { // find players by IP infos = PlayerDB.FindPlayers( ip, PlayerDB.NumberOfMatchesToPrint ); } else if( name.Contains( "*" ) || name.Contains( "." ) ) { // find players by regex/wildcard string regexString = "^" + RegexNonNameChars.Replace( name, "" ).Replace( "*", ".*" ) + "$"; Regex regex = new Regex( regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled ); infos = PlayerDB.FindPlayers( regex, PlayerDB.NumberOfMatchesToPrint ); } else { // find players by partial matching PlayerInfo tempInfo; if( !PlayerDB.FindPlayerInfo( name, out tempInfo ) ) { infos = PlayerDB.FindPlayers( name, PlayerDB.NumberOfMatchesToPrint ); } else if( tempInfo == null ) { player.NoPlayerMessage( name ); return; } else { infos = new[] { tempInfo }; } } if( infos.Length == 1 ) { PrintPlayerInfo( player, infos[0] ); } else if( infos.Length > 1 ) { player.ManyMatchesMessage( "player", infos ); if( infos.Length == PlayerDB.NumberOfMatchesToPrint ) { player.Message( "NOTE: Only first {0} matches are shown.", PlayerDB.NumberOfMatchesToPrint ); } } else { player.NoPlayerMessage( name ); } }
internal static void Info(Player player, Command cmd) { string name = cmd.Next(); if (name == null) { name = player.Name; } else if (!player.Can(Permission.ViewOthersInfo)) { player.NoAccessMessage(Permission.ViewOthersInfo); return; } IPAddress ip; PlayerInfo[] infos; if (Server.IsIP(name) && IPAddress.TryParse(name, out ip)) { // find players by IP infos = PlayerDB.FindPlayers(ip, PlayerDB.NumberOfMatchesToPrint); } else if (name.Contains("*") || name.Contains(".")) { // find players by regex/wildcard string regexString = "^" + RegexNonNameChars.Replace(name, "").Replace("*", ".*") + "$"; Regex regex = new Regex(regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled); infos = PlayerDB.FindPlayers(regex, PlayerDB.NumberOfMatchesToPrint); } else { // find players by partial matching PlayerInfo tempInfo; if (!PlayerDB.FindPlayerInfo(name, out tempInfo)) { infos = PlayerDB.FindPlayers(name, PlayerDB.NumberOfMatchesToPrint); } else if (tempInfo == null) { player.NoPlayerMessage(name); return; } else { infos = new[] { tempInfo }; } } if (infos.Length == 1) { PrintPlayerInfo(player, infos[0]); } else if (infos.Length > 1) { player.ManyMatchesMessage("player", infos); if (infos.Length == PlayerDB.NumberOfMatchesToPrint) { player.Message("NOTE: Only first {0} matches are shown.", PlayerDB.NumberOfMatchesToPrint); } } else { player.NoPlayerMessage(name); } }