Protect deflation with a simple semaphore. Should close #336
This commit is contained in:
parent
58dc621fb7
commit
7553f98367
2 changed files with 53 additions and 13 deletions
|
@ -1,6 +1,23 @@
|
|||
--- ../src_base/minecraft/net/minecraft/network/packet/Packet51MapChunk.java
|
||||
+++ ../src_work/minecraft/net/minecraft/network/packet/Packet51MapChunk.java
|
||||
@@ -57,16 +57,19 @@
|
||||
@@ -5,6 +5,7 @@
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
+import java.util.concurrent.Semaphore;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
@@ -45,6 +46,8 @@
|
||||
/** A temporary storage for the compressed chunk data byte array. */
|
||||
private static byte[] temp = new byte[196864];
|
||||
|
||||
+ private Semaphore deflateGate;
|
||||
+
|
||||
public Packet51MapChunk()
|
||||
{
|
||||
this.isChunkDataPacket = true;
|
||||
@@ -57,16 +60,20 @@
|
||||
this.zCh = par1Chunk.zPosition;
|
||||
this.includeInitialize = par2;
|
||||
Packet51MapChunkData var4 = getMapChunkData(par1Chunk, par2, par3);
|
||||
|
@ -9,6 +26,7 @@
|
|||
this.yChMin = var4.field_74580_b;
|
||||
-
|
||||
+ this.field_73596_g = var4.field_74582_a;
|
||||
+ this.deflateGate = new Semaphore(1);
|
||||
+ }
|
||||
+
|
||||
+ private void deflate()
|
||||
|
@ -25,7 +43,7 @@
|
|||
this.tempLength = var5.deflate(this.chunkData);
|
||||
}
|
||||
finally
|
||||
@@ -95,13 +98,16 @@
|
||||
@@ -95,13 +102,16 @@
|
||||
par1DataInputStream.readFully(temp, 0, this.tempLength);
|
||||
int var2 = 0;
|
||||
int var3;
|
||||
|
@ -42,14 +60,19 @@
|
|||
|
||||
if (this.includeInitialize)
|
||||
{
|
||||
@@ -131,6 +137,11 @@
|
||||
@@ -131,6 +141,16 @@
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
||||
{
|
||||
+ if (chunkData == null)
|
||||
+ {
|
||||
+ deflateGate.acquireUninterruptibly();
|
||||
+ if (chunkData == null)
|
||||
+ {
|
||||
+ deflate();
|
||||
+ }
|
||||
+ deflateGate.release();
|
||||
+ }
|
||||
+
|
||||
par1DataOutputStream.writeInt(this.xCh);
|
||||
par1DataOutputStream.writeInt(this.zCh);
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
--- ../src_base/minecraft/net/minecraft/network/packet/Packet56MapChunks.java
|
||||
+++ ../src_work/minecraft/net/minecraft/network/packet/Packet56MapChunks.java
|
||||
@@ -22,6 +22,7 @@
|
||||
@@ -6,6 +6,7 @@
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
+import java.util.concurrent.Semaphore;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
@@ -22,6 +23,9 @@
|
||||
private int field_73585_g;
|
||||
private boolean field_92024_h;
|
||||
private static byte[] field_73591_h = new byte[0];
|
||||
+ private int maxLen = 0;
|
||||
+
|
||||
+ private Semaphore deflateGate;
|
||||
|
||||
public Packet56MapChunks() {}
|
||||
|
||||
@@ -40,15 +41,6 @@
|
||||
@@ -40,30 +44,35 @@
|
||||
{
|
||||
Chunk var5 = (Chunk)par1List.get(var4);
|
||||
Packet51MapChunkData var6 = Packet51MapChunk.getMapChunkData(var5, true, 65535);
|
||||
|
@ -24,10 +34,12 @@
|
|||
var3 += var6.field_74582_a.length;
|
||||
this.field_73589_c[var4] = var5.xPosition;
|
||||
this.field_73586_d[var4] = var5.zPosition;
|
||||
@@ -57,13 +49,26 @@
|
||||
this.field_73590_a[var4] = var6.field_74580_b;
|
||||
this.field_73588_b[var4] = var6.field_74581_c;
|
||||
this.field_73584_f[var4] = var6.field_74582_a;
|
||||
}
|
||||
|
||||
+ deflateGate = new Semaphore(1);
|
||||
+ }
|
||||
+
|
||||
+ maxLen = var3;
|
||||
+ }
|
||||
+
|
||||
|
@ -39,8 +51,8 @@
|
|||
+ {
|
||||
+ System.arraycopy(field_73584_f[x], 0, data, offset, field_73584_f[x].length);
|
||||
+ offset += field_73584_f[x].length;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
Deflater var11 = new Deflater(-1);
|
||||
|
||||
try
|
||||
|
@ -53,14 +65,19 @@
|
|||
this.field_73585_g = var11.deflate(this.field_73587_e);
|
||||
}
|
||||
finally
|
||||
@@ -146,6 +151,11 @@
|
||||
@@ -146,6 +155,16 @@
|
||||
*/
|
||||
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
||||
{
|
||||
+ if (field_73587_e == null)
|
||||
+ {
|
||||
+ deflateGate.acquireUninterruptibly();
|
||||
+ if (field_73587_e == null)
|
||||
+ {
|
||||
+ deflate();
|
||||
+ }
|
||||
+ deflateGate.release();
|
||||
+ }
|
||||
+
|
||||
par1DataOutputStream.writeShort(this.field_73589_c.length);
|
||||
par1DataOutputStream.writeInt(this.field_73585_g);
|
||||
|
|
Loading…
Reference in a new issue