Пример #1
0
        bool SendRawMapCore(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            AFKCooldown = DateTime.UtcNow.AddSeconds(2);
            SendMapMotd();
            AccessResult access = level.BuildAccess.Check(this);

            AllowBuild = access == AccessResult.Whitelisted || access == AccessResult.Allowed;

            try {
                Send(Packet.LevelInitalise());

                if (hasBlockDefs)
                {
                    if (oldLevel != null && oldLevel != level)
                    {
                        RemoveOldLevelCustomBlocks(oldLevel);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);

                    if (Supports(CpeExt.InventoryOrder))
                    {
                        BlockDefinition.SendLevelInventoryOrder(this);
                    }
                }

                using (LevelChunkStream s = new LevelChunkStream(this))
                    LevelChunkStream.CompressMap(this, s);

                // Force players to read the MOTD (clamped to 3 seconds at most)
                if (level.Config.LoadDelay > 0)
                {
                    System.Threading.Thread.Sleep(level.Config.LoadDelay);
                }

                byte[] buffer = Packet.LevelFinalise(level.Width, level.Height, level.Length);
                Send(buffer);
                Loading = false;

                OnJoinedLevelEvent.Call(this, oldLevel, level);
            } catch (Exception ex) {
                success = false;
                PlayerActions.ChangeMap(this, Server.mainLevel);
                SendMessage("There was an error sending the map data, you have been sent to the main level.");
                Logger.LogError(ex);
            } finally {
                Server.DoGC();
            }
            return(success);
        }
Пример #2
0
        bool SendRawMapCore(Level prev, Level level)
        {
            bool success = true;

            try {
                if (level.blocks == null)
                {
                    throw new InvalidOperationException("Tried to join unloaded level");
                }

                useCheckpointSpawn  = false;
                lastCheckpointIndex = -1;

                AFKCooldown = DateTime.UtcNow.AddSeconds(2);
                ZoneIn      = null;
                SendMapMotd();
                AllowBuild = level.BuildAccess.CheckAllowed(this);

                int volume = level.blocks.Length;
                if (Supports(CpeExt.FastMap))
                {
                    Send(Packet.LevelInitaliseExt(volume));
                }
                else
                {
                    Send(Packet.LevelInitalise());
                }

                if (hasBlockDefs)
                {
                    if (prev != null && prev != level)
                    {
                        RemoveOldLevelCustomBlocks(prev);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);

                    if (Supports(CpeExt.InventoryOrder))
                    {
                        BlockDefinition.SendLevelInventoryOrder(this);
                    }
                }

                using (LevelChunkStream dst = new LevelChunkStream(this))
                    using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst))
                    {
                        if (level.MightHaveCustomBlocks())
                        {
                            LevelChunkStream.CompressMap(this, stream, dst);
                        }
                        else
                        {
                            LevelChunkStream.CompressMapSimple(this, stream, dst);
                        }
                    }

                // Force players to read the MOTD (clamped to 3 seconds at most)
                if (level.Config.LoadDelay > 0)
                {
                    System.Threading.Thread.Sleep(level.Config.LoadDelay);
                }

                byte[] buffer = Packet.LevelFinalise(level.Width, level.Height, level.Length);
                Send(buffer);
                Loading = false;

                OnSentMapEvent.Call(this, prev, level);
            } catch (Exception ex) {
                success = false;
                PlayerActions.ChangeMap(this, Server.mainLevel);
                Message("&WThere was an error sending the map, you have been sent to the main level.");
                Logger.LogError(ex);
            } finally {
                Server.DoGC();
            }
            return(success);
        }