Don't sent blockdefs > client max supported block

This commit is contained in:
UnknownShadow200 2018-03-09 19:25:42 +11:00
parent b3e49e0010
commit 9f7913081e
4 changed files with 20 additions and 14 deletions

View File

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

View File

@ -235,6 +235,7 @@ namespace MCGalaxy {
for (int i = 0; i < defs.Length; i++) {
BlockDefinition def = defs[i];
if (def == BlockDefinition.GlobalDefs[i]) continue;
if (def.BlockID > MaxRawBlock) continue;
Send(Packet.UndefineBlock(def, hasExtBlocks));
}
}

View File

@ -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];

View File

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