static void JoinHandler( Player player, Command cmd ) {
string worldName = cmd.Next();
if( worldName == null ) {
CdJoin.PrintUsage( player );
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 );
} else {
player.MessageNoWorld( worldName );
}
}
}