fCraft.World.LoadMap C# (CSharp) Method

LoadMap() private method

private LoadMap ( ) : Map
return Map
        public Map LoadMap()
        {
            var tempMap = Map;
            if ( tempMap != null )
                return tempMap;

            lock ( SyncRoot ) {
                if ( Map != null )
                    return Map;

                if ( File.Exists( MapFileName ) ) {
                    try {
                        Map = MapUtility.Load( MapFileName );
                    } catch ( Exception ex ) {
                        Logger.Log( LogType.Error,
                                    "World.LoadMap: Failed to load map ({0}): {1}",
                                    MapFileName, ex );
                    }
                }

                // or generate a default one
                if ( Map == null ) {
                    Server.Message( "&WMapfile is missing for world {0}&W. A new map has been created.", ClassyName );
                    Logger.Log( LogType.Warning,
                                "World.LoadMap: Map file missing for world {0}. Generating default flatgrass map.",
                                Name );
                    Map = MapGeneratorOld.GenerateFlatgrass( 128, 128, 64 );
                }
                return Map;
            }
        }

Usage Example

Example #1
0
        static void Main( string[] args ) {
            World world = new World( "" );
            world.OnLog += Log;
            world.OnURLChange += SetURL;

            if( world.Init() ) {
                if( args.Length == 1 ) {
                    world.LoadMap( args[0] );
                } else {
                    world.LoadMap( Map.DefaultFileName );
                }

                UpdaterResult update = Updater.CheckForUpdates( world );
                if( update.UpdateAvailable ) {
                    Console.WriteLine( "** A new version of fCraft is available: v{0:0.000}, released {1:0} day(s) ago. **",
                                       Decimal.Divide( update.NewVersionNumber, 1000 ),
                                       DateTime.Now.Subtract( update.ReleaseDate ).TotalDays );
                }

                System.Diagnostics.Process.GetCurrentProcess().PriorityClass = world.config.GetBasePriority();

                if( world.Start() ) {
                    Console.Title = "fCraft " + Updater.GetVersionString() + " - " + world.config.GetString( "ServerName" );
                    string input = "";
                    Console.WriteLine( "** To shut down the server, type /exit **" );
                    while( (input = Console.ReadLine()) != "/exit" ) {
                        Player.Console.ParseMessage( input, true );
                    }
                    world.ShutDown();
                } else {
                    Console.WriteLine( "** Failed to start the server **" );
                    world.ShutDown();
                    Console.ReadLine();
                }
            } else {
                Console.WriteLine( "** Failed to initialize the server **" );
                world.ShutDown();
                Console.ReadLine();
            }
        }
All Usage Examples Of fCraft.World::LoadMap