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(); } }
public BlockDBEntry[] Lookup(Vector3I coords) { if (!IsEnabled || !IsEnabledGlobally) { throw new InvalidOperationException("Trying to lookup on disabled BlockDB."); } List <BlockDBEntry> results = new List <BlockDBEntry>(); if (!World.LoadMap().InBounds(coords)) { return(results.ToArray()); } if (isPreloaded) { lock ( SyncRoot ) { fixed(BlockDBEntry *entries = cacheStore) { for (int i = 0; i < CacheSize; i++) { if (entries[i].X == coords.X && entries[i].Y == coords.Y && entries[i].Z == coords.Z) { results.Add(entries[i]); } } } } } else { Flush(); byte[] bytes = Load(); int entryCount = bytes.Length / BlockDBEntry.Size; fixed(byte *parr = bytes) { BlockDBEntry *entries = (BlockDBEntry *)parr; for (int i = 0; i < entryCount; i++) { if (entries[i].X == coords.X && entries[i].Y == coords.Y && entries[i].Z == coords.Z) { results.Add(entries[i]); } } } } return(results.ToArray()); }
public static void Start(Player player) { Map map = MapGeneratorOld.GenerateEmpty(64, 128, 16); map.Save("maps/minefield.fcm"); if (_world != null) { WorldManager.RemoveWorld(_world); } WorldManager.AddWorld(Player.Console, "Minefield", map, true); _map = map; _world = WorldManager.FindWorldExact("Minefield"); SetUpRed(); SetUpMiddleWater(); SetUpGreen(); SetUpMines(); _map.Spawn = new Position(_map.Width / 2, 5, _ground + 3).ToVector3I().ToPlayerCoords(); _world.LoadMap(); _world.gameMode = GameMode.MineField; _world.EnableTNTPhysics(Player.Console, false); Server.Message("{0}&S started a game of MineField on world Minefield!", player.ClassyName); WorldManager.SaveWorldList(); Server.RequestGC(); }
public BlockDBEntry[] Lookup([NotNull] PlayerInfo info, [NotNull] BoundingBox area, TimeSpan span) { if (!IsEnabled || !IsEnabledGlobally) { throw new InvalidOperationException("Trying to lookup on disabled BlockDB."); } if (info == null) { throw new ArgumentNullException("info"); } if (area == null) { throw new ArgumentNullException("area"); } long ticks = DateTime.UtcNow.Subtract(span).ToUnixTime(); Dictionary <int, BlockDBEntry> results = new Dictionary <int, BlockDBEntry>(); Map map = World.LoadMap(); if (isPreloaded) { lock ( SyncRoot ) { fixed(BlockDBEntry *entries = cacheStore) { for (int i = CacheSize - 1; i >= 0; i--) { if (entries[i].Timestamp < ticks) { break; } if (entries[i].PlayerID == info.ID && area.Contains(entries[i].X, entries[i].Y, entries[i].Z)) { int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z); results[index] = entries[i]; } } } } } else { Flush(); byte[] bytes = Load(); int entryCount = bytes.Length / BlockDBEntry.Size; fixed(byte *parr = bytes) { BlockDBEntry *entries = (BlockDBEntry *)parr; for (int i = entryCount - 1; i >= 0; i--) { if (entries[i].Timestamp < ticks) { break; } if (entries[i].PlayerID == info.ID && area.Contains(entries[i].X, entries[i].Y, entries[i].Z)) { int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z); results[index] = entries[i]; } } } } return(results.Values.ToArray()); }
public BlockDBEntry[] Lookup([NotNull] PlayerInfo info, int max) { if (!IsEnabled || !IsEnabledGlobally) { throw new InvalidOperationException("Trying to lookup on disabled BlockDB."); } if (info == null) { throw new ArgumentNullException("info"); } Dictionary <int, BlockDBEntry> results = new Dictionary <int, BlockDBEntry>(); int count = 0; Map map = World.LoadMap(); if (isPreloaded) { lock ( SyncRoot ) { fixed(BlockDBEntry *entries = cacheStore) { for (int i = CacheSize - 1; i >= 0; i--) { if (entries[i].PlayerID == info.ID) { int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z); results[index] = entries[i]; count++; if (count >= max) { break; } } } } } } else { Flush(); byte[] bytes = Load(); int entryCount = bytes.Length / BlockDBEntry.Size; fixed(byte *parr = bytes) { BlockDBEntry *entries = (BlockDBEntry *)parr; for (int i = entryCount - 1; i >= 0; i--) { if (entries[i].PlayerID == info.ID) { int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z); results[index] = entries[i]; count++; if (count >= max) { break; } } } } } return(results.Values.ToArray()); }
public static World AddWorld( string name, Map map, bool neverUnload ) { lock( worldListLock ) { if( worlds.ContainsKey( name ) ) return null; if( !Player.IsValidName( name ) ) return null; World newWorld = new World( name ); newWorld.neverUnload = neverUnload; if( map != null ) { // if a map is given newWorld.map = map; if( !neverUnload ) { newWorld.UnloadMap();// UnloadMap also saves the map } else { newWorld.SaveMap( null ); } } else { // generate default map if( neverUnload ) newWorld.LoadMap(); } worlds.Add( name, newWorld ); newWorld.updateTaskId = AddTask( UpdateBlocks, Config.GetInt( ConfigKey.TickInterval ), newWorld ); if( Config.GetInt( ConfigKey.SaveInterval ) > 0 ) { int saveInterval = Config.GetInt( ConfigKey.SaveInterval ) * 1000; newWorld.saveTaskId = AddTask( SaveMap, saveInterval, newWorld, saveInterval ); } if( Config.GetInt( ConfigKey.BackupInterval ) > 0 ) { int backupInterval = Config.GetInt( ConfigKey.BackupInterval ) * 1000 * 60; newWorld.backupTaskId = AddTask( AutoBackup, backupInterval, newWorld, (Config.GetBool( ConfigKey.BackupOnStartup ) ? 0 : backupInterval) ); } newWorld.UpdatePlayerList(); return newWorld; } }
public static void Start( Player player ) { Map map = MapGeneratorOld.GenerateEmpty( 64, 128, 16 ); map.Save( "maps/minefield.fcm" ); if ( _world != null ) { WorldManager.RemoveWorld( _world ); } WorldManager.AddWorld( Player.Console, "Minefield", map, true ); _map = map; _world = WorldManager.FindWorldExact( "Minefield" ); SetUpRed(); SetUpMiddleWater(); SetUpGreen(); SetUpMines(); _map.Spawn = new Position( _map.Width / 2, 5, _ground + 3 ).ToVector3I().ToPlayerCoords(); _world.LoadMap(); _world.gameMode = GameMode.MineField; _world.EnableTNTPhysics( Player.Console, false ); Server.Message( "{0}&S started a game of MineField on world Minefield!", player.ClassyName ); WorldManager.SaveWorldList(); Server.RequestGC(); }
public static World AddWorld( Player player, string name, Map map, bool neverUnload ) { if( name == null ) throw new ArgumentNullException( "name" ); if( !World.IsValidName( name ) ) { throw new WorldOpException( name, WorldOpExceptionCode.InvalidWorldName ); } lock( WorldListLock ) { if( Worlds.ContainsKey( name.ToLower() ) ) { throw new WorldOpException( name, WorldOpExceptionCode.DuplicateWorldName ); } if( RaiseWorldCreatingEvent( player, name, map ) ) { throw new WorldOpException( name, WorldOpExceptionCode.PluginDenied ); } World newWorld = new World( name, neverUnload ); if( map != null ) { newWorld.Map = map; map.World = newWorld; /* string accessSecurityString = map.GetMeta( "security", "access" ); if( accessSecurityString != null ) { try { newWorld.AccessSecurity = new SecurityController( XElement.Parse( accessSecurityString ) ); } catch( XmlException ex ) { Logger.Log( "WorldManager.AddWorld: Error loading stored access permissions: {0}", LogType.Error, ex ); } } string buildSecurityString = map.GetMeta( "security", "build" ); if( buildSecurityString != null ) { try { newWorld.BuildSecurity = new SecurityController( XElement.Parse( buildSecurityString ) ); } catch( XmlException ex ) { Logger.Log( "WorldManager.AddWorld: Error loading stored build permissions: {0}", LogType.Error, ex ); } } */ // if a map is given if( neverUnload ) { newWorld.StartTasks(); }else{ newWorld.UnloadMap( false ); } } else if( neverUnload ){ newWorld.LoadMap(); map = newWorld.Map; } Worlds.Add( name.ToLower(), newWorld ); UpdateWorldList(); RaiseWorldCreatedEvent( player, newWorld ); return newWorld; } }
public static World AddWorld(Player player, string name, Map map, bool neverUnload) { if (name == null) { throw new ArgumentNullException("name"); } if (!World.IsValidName(name)) { throw new WorldOpException(name, WorldOpExceptionCode.InvalidWorldName); } lock ( WorldListLock ) { if (Worlds.ContainsKey(name.ToLower())) { throw new WorldOpException(name, WorldOpExceptionCode.DuplicateWorldName); } if (RaiseWorldCreatingEvent(player, name, map)) { throw new WorldOpException(name, WorldOpExceptionCode.PluginDenied); } World newWorld = new World(name, neverUnload); if (map != null) { newWorld.Map = map; map.World = newWorld; /* * string accessSecurityString = map.GetMeta( "security", "access" ); * if( accessSecurityString != null ) { * try { * newWorld.AccessSecurity = new SecurityController( XElement.Parse( accessSecurityString ) ); * } catch( XmlException ex ) { * Logger.Log( "WorldManager.AddWorld: Error loading stored access permissions: {0}", LogType.Error, ex ); * } * } * * string buildSecurityString = map.GetMeta( "security", "build" ); * if( buildSecurityString != null ) { * try { * newWorld.BuildSecurity = new SecurityController( XElement.Parse( buildSecurityString ) ); * } catch( XmlException ex ) { * Logger.Log( "WorldManager.AddWorld: Error loading stored build permissions: {0}", LogType.Error, ex ); * } * } */ // if a map is given if (neverUnload) { newWorld.StartTasks(); } else { newWorld.UnloadMap(false); } } else if (neverUnload) { newWorld.LoadMap(); map = newWorld.Map; } Worlds.Add(name.ToLower(), newWorld); UpdateWorldList(); RaiseWorldCreatedEvent(player, newWorld); return(newWorld); } }
static void Init(Player player) { world = player.World; if (!GameRunning) return; //bool foundBackup = true; //not used try { Map backupMap = MapConversion.MapUtility.Load("./maps/CTFBackup.fcm"); world.MapChangedBy = player.Name; world = world.ChangeMap(backupMap); } catch (Exception ex) { player.Message( "Could not load CTF backup map."); Logger.Log(LogType.Error, "Error loading CTF backup map: {0}", ex.Message); //foundBackup = false; map = world.LoadMap(); } InitProperties(); Player.PlacingBlock += PlayerPlacing; Player.JoinedWorld += PlayerChangedWorld; Player.Moved += PlayerMoved; RedTeam.RoundsWon = 0; BlueTeam.RoundsWon = 0; InitZones(); }