internal static void WorldRename( Player player, Command cmd ) {
string oldName = cmd.Next();
string newName = cmd.Next();
if( oldName == null || newName == null ) {
cdWorldRename.PrintUsage( player );
return;
}
World oldWorld = WorldManager.FindWorldOrPrintMatches( player, oldName );
if( oldWorld == null ) return;
oldName = oldWorld.Name;
if( !cmd.IsConfirmed && File.Exists( Path.Combine( Paths.MapPath, newName + ".fcm" ) ) ) {
player.AskForConfirmation( cmd, "Renaming this world will overwrite an existing map file \"{0}.fcm\".", newName );
return;
}
try {
WorldManager.RenameWorld( oldWorld, newName, true );
} catch( WorldOpException ex ) {
switch( ex.ErrorCode ) {
case WorldOpExceptionCode.NoChangeNeeded:
player.MessageNow( "Rename: World is already named \"{0}\"", oldName );
return;
case WorldOpExceptionCode.DuplicateWorldName:
player.MessageNow( "Rename: Another world named \"{0}\" already exists.", newName );
return;
case WorldOpExceptionCode.InvalidWorldName:
player.MessageNow( "Rename: Invalid world name: \"{0}\"", newName );
return;
case WorldOpExceptionCode.MapMoveError:
player.MessageNow( "Rename: World \"{0}\" was renamed to \"{1}\", but the map file could not be moved due to an error: {2}",
oldName, newName, ex.InnerException );
return;
default:
player.MessageNow( "Unexpected error occured while renaming world \"{0}\"", oldName );
Logger.Log( "WorldCommands.Rename: Unexpected error while renaming world {0} to {1}: {2}",
LogType.Error, oldWorld.Name, newName, ex );
return;
}
}
WorldManager.SaveWorldList();
Logger.Log( "{0} renamed the world \"{1}\" to \"{2}\".", LogType.UserActivity,
player.Name, oldName, newName );
Server.SendToAll( "{0}&S renamed the world \"{1}\" to \"{2}\"",
player.GetClassyName(), oldName, newName );
}