From 646e84a1634802d663301240edc2bc0d0f702387 Mon Sep 17 00:00:00 2001 From: Chicken Bones Date: Tue, 9 Jul 2013 20:19:51 +1000 Subject: [PATCH] Added termination markers to replace DataInputStream.available to see if it fixes crashes --- codechicken/multipart/TileMultipart.scala | 4 +-- .../multipart/handler/PacketHandlers.scala | 35 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index 27aa398..60b06a4 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -294,7 +294,7 @@ class TileMultipart extends TileEntity partList.clear() } - def writeDesc(packet:PacketCustom) + def writeDesc(packet:MCDataOutput) { packet.writeByte(partList.size) partList.foreach{part => @@ -614,7 +614,7 @@ object TileMultipart MultipartGenerator.addPart(world, pos, part) } case 254 => if(tilemp != null) { - tilemp.remPart_impl(tilemp.partList(packet.readUnsignedByte())) + tilemp.remPart_impl(tilemp.partList(packet.readUnsignedByte)) } case _ => if(tilemp != null) { tilemp.partList(i).read(packet) diff --git a/codechicken/multipart/handler/PacketHandlers.scala b/codechicken/multipart/handler/PacketHandlers.scala index 2449ea3..97bdeff 100644 --- a/codechicken/multipart/handler/PacketHandlers.scala +++ b/codechicken/multipart/handler/PacketHandlers.scala @@ -52,21 +52,24 @@ object MultipartCPH extends IClientPacketHandler def handleCompressedTileDesc(packet:PacketCustom, world:World) { val cc = new ChunkCoordIntPair(packet.readInt, packet.readInt) - while(packet.more) + val num = packet.readUnsignedShort + for(i <- 0 until num) TileMultipart.handleDescPacket(world, indexInChunk(cc, packet.readShort), packet) } def handleCompressedTileData(packet:PacketCustom, world:World) { - while(packet.more) + var x = packet.readInt + while(x != Int.MaxValue) { - val pos = packet.readCoord + val pos = new BlockCoord(x, packet.readInt, packet.readInt) var i = packet.readUnsignedByte while(i < 255) { TileMultipart.handlePacket(pos, world, i, packet) i = packet.readUnsignedByte } + x = packet.readInt } } } @@ -122,10 +125,13 @@ object MultipartSPH extends IServerPacketHandler { send = true packet.writeByteArray(e._2.getBytes) - packet.writeByte(255) + packet.writeByte(255)//terminator }) if(send) + { + packet.writeInt(Int.MaxValue)//terminator packet.sendToPlayer(p) + } } } updateMap.foreach(_._2.clear()) @@ -134,21 +140,26 @@ object MultipartSPH extends IServerPacketHandler def onChunkWatch(player:EntityPlayer, chunk:Chunk) { val iterator = chunk.chunkTileEntityMap.asInstanceOf[Map[_, TileEntity]].values.iterator - val packet = new PacketCustom(channel, 2).setChunkDataPacket().compressed() - .writeInt(chunk.xPosition).writeInt(chunk.zPosition) + val s = new MCByteStream(new ByteArrayOutputStream) - var empty = true + var num = 0 while(iterator.hasNext) { val tile = iterator.next if(tile.isInstanceOf[TileMultipart]) { - packet.writeShort(indexInChunk(new BlockCoord(tile))) - tile.asInstanceOf[TileMultipart].writeDesc(packet) - empty = false + s.writeShort(indexInChunk(new BlockCoord(tile))) + tile.asInstanceOf[TileMultipart].writeDesc(s) + num+=1 } } - if(!empty) - packet.sendToPlayer(player) + if(num != 0) + { + new PacketCustom(channel, 2).setChunkDataPacket().compressed() + .writeInt(chunk.xPosition).writeInt(chunk.zPosition) + .writeShort(num) + .writeByteArray(s.getBytes) + .sendToPlayer(player) + } } }