From 9f7913081eae84fbefee0b503f1ab78ff1e5a850 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 9 Mar 2018 19:25:42 +1100 Subject: [PATCH] Don't sent blockdefs > client max supported block --- MCGalaxy/Blocks/BlockDefinitions.cs | 14 +++++++++----- MCGalaxy/Network/Player.Networking.cs | 5 +++-- MCGalaxy/Player/Player.CPE.cs | 8 +------- MCGalaxy/Player/Player.cs | 7 +++++++ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index da30cc0a7..f8d83bef2 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -178,7 +178,7 @@ namespace MCGalaxy { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (!global && pl.level != level) continue; - if (!pl.hasBlockDefs) continue; + if (!pl.hasBlockDefs || def.BlockID > pl.MaxRawBlock) continue; if (global && pl.level.CustomBlockDefs[block] != GlobalDefs[block]) continue; pl.Send(def.MakeDefinePacket(pl)); @@ -199,7 +199,7 @@ namespace MCGalaxy { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (!global && pl.level != level) continue; - if (!pl.hasBlockDefs) continue; + if (!pl.hasBlockDefs || def.BlockID > pl.MaxRawBlock) continue; if (global && pl.level.CustomBlockDefs[block] != null) continue; pl.Send(Packet.UndefineBlock(def, pl.hasExtBlocks)); @@ -216,7 +216,7 @@ namespace MCGalaxy { if (!global && pl.level != level) continue; if (global && pl.level.CustomBlockDefs[block] != GlobalDefs[block]) continue; - if (!pl.Supports(CpeExt.InventoryOrder)) continue; + if (!pl.Supports(CpeExt.InventoryOrder) || def.BlockID > pl.MaxRawBlock) continue; pl.Send(Packet.SetInventoryOrder(def, pl.hasExtBlocks)); } } @@ -242,17 +242,21 @@ namespace MCGalaxy { internal static void SendLevelCustomBlocks(Player pl) { BlockDefinition[] defs = pl.level.CustomBlockDefs; + BlockID_ maxRaw = pl.MaxRawBlock; for (int i = 0; i < defs.Length; i++) { BlockDefinition def = defs[i]; - if (def != null) pl.Send(def.MakeDefinePacket(pl)); + if (def == null || def.BlockID > maxRaw) continue; + pl.Send(def.MakeDefinePacket(pl)); } } internal static void SendLevelInventoryOrder(Player pl) { BlockDefinition[] defs = pl.level.CustomBlockDefs; + BlockID_ maxRaw = pl.MaxRawBlock; for (int b = 0; b < defs.Length; b++) { BlockDefinition def = defs[b]; - if (def != null && def.InventoryOrder >= 0) { + if (def == null || def.BlockID > maxRaw) continue; + if (def.InventoryOrder >= 0) { pl.Send(Packet.SetInventoryOrder(def, pl.hasExtBlocks)); } } diff --git a/MCGalaxy/Network/Player.Networking.cs b/MCGalaxy/Network/Player.Networking.cs index 0dc603deb..8070c3476 100644 --- a/MCGalaxy/Network/Player.Networking.cs +++ b/MCGalaxy/Network/Player.Networking.cs @@ -234,7 +234,8 @@ namespace MCGalaxy { BlockDefinition[] defs = oldLevel.CustomBlockDefs; for (int i = 0; i < defs.Length; i++) { BlockDefinition def = defs[i]; - if (def == BlockDefinition.GlobalDefs[i]) continue; + if (def == BlockDefinition.GlobalDefs[i]) continue; + if (def.BlockID > MaxRawBlock) continue; Send(Packet.UndefineBlock(def, hasExtBlocks)); } } @@ -278,7 +279,7 @@ namespace MCGalaxy { } if (!hasCustomBlocks) block = Block.ConvertCPE((BlockRaw)block); // doesn't support CPE blocks - NetUtils.WriteBlock(block, buffer, 7, hasExtBlocks); + NetUtils.WriteBlock(block, buffer, 7, hasExtBlocks); Socket.SendLowPriority(buffer); } diff --git a/MCGalaxy/Player/Player.CPE.cs b/MCGalaxy/Player/Player.CPE.cs index f2c49c7ce..7f8c7441c 100644 --- a/MCGalaxy/Player/Player.CPE.cs +++ b/MCGalaxy/Player/Player.CPE.cs @@ -158,14 +158,8 @@ namespace MCGalaxy { SendAllBlockPermissions(); } - int NumBlockPermissions() { - if (hasExtBlocks) return Block.MaxRaw + 1; - if (hasBlockDefs) return Block.Count; - return hasCustomBlocks ? Block.CpeCount : Block.OriginalCount; - } - void SendAllBlockPermissions() { - int count = NumBlockPermissions(); + int count = MaxRawBlock + 1; int size = hasExtBlocks ? 5 : 4; byte[] bulk = new byte[count * size]; diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index f7988d4e2..9ca51ade9 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -58,6 +58,13 @@ namespace MCGalaxy { } } + public BlockID MaxRawBlock { get { + if (hasExtBlocks) return 767; + if (hasBlockDefs) return 255; + return hasCustomBlocks ? Block.CpeMaxBlock : Block.OriginalMaxBlock; + } + } + internal void Connect(Socket s) { try { Socket = new TcpSocket(this, s);