UnloadMap() private method

private UnloadMap ( bool expectedPendingFlag ) : void
expectedPendingFlag bool
return void
Beispiel #1
0
        internal static void ReplaceWorld([NotNull] World oldWorld, [NotNull] World newWorld)
        {
            if (oldWorld == null)
            {
                throw new ArgumentNullException("oldWorld");
            }
            if (newWorld == null)
            {
                throw new ArgumentNullException("newWorld");
            }

            lock ( SyncRoot ) {
                if (oldWorld == newWorld)
                {
                    throw new WorldOpException(oldWorld.Name, WorldOpExceptionCode.NoChangeNeeded);
                }

                if (!WorldIndex.ContainsValue(oldWorld))
                {
                    throw new WorldOpException(oldWorld.Name, WorldOpExceptionCode.WorldNotFound);
                }

                if (WorldIndex.ContainsValue(newWorld))
                {
                    throw new InvalidOperationException("New world already exists on the list.");
                }

                // cycle load/unload on the new world to save it under the new name
                newWorld.Name = oldWorld.Name;
                if (newWorld.Preload)
                {
                    newWorld.SaveMap();
                }
                else
                {
                    newWorld.UnloadMap(false);
                }

                WorldIndex[oldWorld.Name.ToLower()] = newWorld;
                oldWorld.Map = null;

                // change the main worlds, if needed
                if (oldWorld == MainWorld)
                {
                    MainWorld = newWorld;
                }
                foreach (Rank rank in RankManager.Ranks)
                {
                    if (rank.MainWorld == oldWorld)
                    {
                        rank.MainWorld = newWorld;
                    }
                }

                SaveWorldList();
                UpdateWorldList();
            }
        }
Beispiel #2
0
        internal static void ReplaceWorld(World oldWorld, World newWorld)
        {
            if (oldWorld == null)
            {
                throw new ArgumentNullException("oldWorld");
            }
            if (newWorld == null)
            {
                throw new ArgumentNullException("newWorld");
            }

            lock ( WorldListLock ) {
                if (oldWorld == newWorld)
                {
                    throw new WorldOpException(oldWorld.Name, WorldOpExceptionCode.NoChangeNeeded);
                }

                if (!Worlds.ContainsValue(oldWorld))
                {
                    throw new WorldOpException(oldWorld.Name, WorldOpExceptionCode.WorldNotFound);
                }

                if (Worlds.ContainsValue(newWorld))
                {
                    throw new InvalidOperationException("New world already exists on the list.");
                }

                // cycle load/unload on the new world to save it under the new name
                newWorld.Name = oldWorld.Name;
                newWorld.UnloadMap(false);

                Worlds[oldWorld.Name.ToLower()] = newWorld;

                // change the main world, if needed
                if (oldWorld == MainWorld)
                {
                    MainWorld = newWorld;
                }

                UpdateWorldList();
            }
        }
Beispiel #3
0
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int         packetsSent         = 0;
            bool        canFlush            = false;
            int         maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);
            BlockUpdate update = new BlockUpdate();

            while (packetsSent < maxPacketsPerUpdate)
            {
                if (!updates.Dequeue(ref update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }
                HasChangedSinceSave = true;
                compressedCopyCache = null;
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    Packet packet = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, update.BlockType);
                    World.Players.SendLowPriority(update.Origin, packet);
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }
Beispiel #4
0
        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;
            }
        }
Beispiel #5
0
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int  packetsSent         = 0;
            bool canFlush            = false;
            int  maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);

            while (packetsSent < maxPacketsPerUpdate)
            {
                BlockUpdate update;
                if (!updates.TryDequeue(out update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    //non classicube players get fallbacks instead of the real blocks
                    Packet packet  = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, update.BlockType);
                    Packet packet2 = PacketWriter.MakeSetBlock(update.X, update.Y, update.Z, Map.GetFallbackBlock(update.BlockType));

                    World.Players.Where(p => p.usesCPE).SendLowPriority(update.Origin, packet);
                    World.Players.Where(p => !p.usesCPE).SendLowPriority(update.Origin, packet2);
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }
Beispiel #6
0
        internal static void ReplaceWorld( World oldWorld, World newWorld ) {
            if( oldWorld == null ) throw new ArgumentNullException( "oldWorld" );
            if( newWorld == null ) throw new ArgumentNullException( "newWorld" );

            lock( WorldListLock ) {
                if( oldWorld == newWorld ) {
                    throw new WorldOpException( oldWorld.Name, WorldOpExceptionCode.NoChangeNeeded );
                }

                if( !Worlds.ContainsValue( oldWorld ) ) {
                    throw new WorldOpException( oldWorld.Name, WorldOpExceptionCode.WorldNotFound );
                }

                if( Worlds.ContainsValue( newWorld ) ) {
                    throw new InvalidOperationException( "New world already exists on the list." );
                }

                // cycle load/unload on the new world to save it under the new name
                newWorld.Name = oldWorld.Name;
                newWorld.UnloadMap( false );

                Worlds[oldWorld.Name.ToLower()] = newWorld;

                // change the main world, if needed
                if( oldWorld == MainWorld ) {
                    MainWorld = newWorld;
                }

                UpdateWorldList();
            }
        }
Beispiel #7
0
        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;
            }
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        // Applies pending updates and sends them to players (if applicable).
        internal void ProcessUpdates()
        {
            if (World == null)
            {
                throw new InvalidOperationException("Map must be assigned to a world to process updates.");
            }

            if (World.IsLocked)
            {
                if (World.IsPendingMapUnload)
                {
                    World.UnloadMap(true);
                }
                return;
            }

            int         packetsSent         = 0;
            bool        canFlush            = false;
            int         maxPacketsPerUpdate = Server.CalculateMaxPacketsPerUpdate(World);
            BlockUpdate update = new BlockUpdate();

            while (packetsSent < maxPacketsPerUpdate)
            {
                if (!updates.TryDequeue(out update))
                {
                    if (World.IsFlushing)
                    {
                        canFlush = true;
                    }
                    break;
                }

                HasChangedSinceSave = true;
                if (!InBounds(update.X, update.Y, update.Z))
                {
                    continue;
                }
                int blockIndex = Index(update.X, update.Y, update.Z);
                Blocks[blockIndex] = (byte)update.BlockType;

                if (!World.IsFlushing)
                {
                    Player[] players = World.Players;
                    for (int i = 0; i < players.Length; i++)
                    {
                        Player p = players[i];
                        if (p == update.Origin)
                        {
                            continue;
                        }
                        p.SendBlock(new Vector3I(update.X, update.Y, update.Z), update.BlockType);
                    }
                }
                packetsSent++;
            }

            if (drawOps.Count > 0)
            {
                lock ( drawOpLock ) {
                    if (drawOps.Count > 0)
                    {
                        packetsSent += ProcessDrawOps(maxPacketsPerUpdate - packetsSent);
                    }
                }
            }
            else if (canFlush)
            {
                World.EndFlushMapBuffer();
            }

            if (packetsSent == 0 && World.IsPendingMapUnload)
            {
                World.UnloadMap(true);
            }
        }