Esempio n. 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);
        }
        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);
        }
Esempio n. 3
0
        public bool SendRawMap(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            try {
                int    usedLength = 0;
                byte[] buffer     = CompressRawMap(out usedLength);

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

                SendRaw(Opcode.LevelInitialise);
                int totalRead = 0;
                while (totalRead < usedLength)
                {
                    byte[] packet = new byte[1028]; // need each packet separate for Mono
                    packet[0] = Opcode.LevelDataChunk;
                    short length = (short)Math.Min(buffer.Length - totalRead, 1024);
                    NetUtils.WriteI16(length, packet, 1);
                    Buffer.BlockCopy(buffer, totalRead, packet, 3, length);
                    packet[1027] = (byte)(100 * (float)totalRead / buffer.Length);

                    SendRaw(packet);
                    if (ip != "127.0.0.1")
                    {
                        Thread.Sleep(Server.updateTimer.Interval > 1000 ? 100 : 10);
                    }
                    totalRead += length;
                }

                buffer    = new byte[7];
                buffer[0] = Opcode.LevelFinalise;
                NetUtils.WriteI16((short)level.Width, buffer, 1);
                NetUtils.WriteI16((short)level.Height, buffer, 3);
                NetUtils.WriteI16((short)level.Length, buffer, 5);
                SendRaw(buffer);
                Loading = false;

                if (HasCpeExt(CpeExt.EnvWeatherType))
                {
                    SendSetMapWeather(level.weather);
                }
                if (HasCpeExt(CpeExt.EnvColors))
                {
                    SendCurrentEnvColors();
                }
                if (HasCpeExt(CpeExt.EnvMapAppearance) || HasCpeExt(CpeExt.EnvMapAppearance, 2))
                {
                    SendCurrentMapAppearance();
                }

                if (OnSendMap != null)
                {
                    OnSendMap(this, buffer);
                }
                if (!level.guns)
                {
                    aiming = false;
                }
            } catch (Exception ex) {
                success = false;
                Command.all.Find("goto").Use(this, Server.mainLevel.name);
                SendMessage("There was an error sending the map data, you have been sent to the main level.");
                Server.ErrorLog(ex);
            } finally {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            if (HasCpeExt(CpeExt.BlockPermissions))
            {
                SendCurrentBlockPermissions();
            }
            return(success);
        }
Esempio n. 4
0
        bool SendRawMapCore(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            LevelAccess access = level.BuildAccess.Check(this);

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

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

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

                byte[] buffer = new byte[7];
                buffer[0] = Opcode.LevelFinalise;
                NetUtils.WriteI16((short)level.Width, buffer, 1);
                NetUtils.WriteI16((short)level.Height, buffer, 3);
                NetUtils.WriteI16((short)level.Length, buffer, 5);
                Send(buffer);
                AFKCooldown = DateTime.UtcNow.AddSeconds(2);
                Loading     = false;

                if (HasCpeExt(CpeExt.EnvWeatherType))
                {
                    Send(Packet.EnvWeatherType((byte)level.Weather));
                }
                if (HasCpeExt(CpeExt.EnvColors))
                {
                    SendCurrentEnvColors();
                }
                SendCurrentMapAppearance();
                if (HasCpeExt(CpeExt.BlockPermissions))
                {
                    SendCurrentBlockPermissions();
                }

                if (OnSendMap != null)
                {
                    OnSendMap(this, buffer);
                }
                if (!level.guns && aiming)
                {
                    aiming = false;
                    ClearBlockchange();
                }
            } 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.");
                Server.ErrorLog(ex);
            } finally {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(success);
        }