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); }
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); }