Automate the stress testing of a Minecraft server network using bots
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Optimisation: Don't use Unpooled

PureGero dadf42a4 3a19ec6f

+23 -10
+22 -6
src/main/java/com/github/puregero/minecraftstresstest/CompressionDecoder.java
··· 1 package com.github.puregero.minecraftstresstest; 2 3 import io.netty.buffer.ByteBuf; 4 - import io.netty.buffer.Unpooled; 5 import io.netty.channel.ChannelHandlerContext; 6 import io.netty.handler.codec.ByteToMessageDecoder; 7 8 import java.util.List; 9 import java.util.zip.Inflater; 10 ··· 23 return; 24 } 25 26 - byte[] bs = new byte[friendlyByteBuf.readableBytes()]; 27 - friendlyByteBuf.readBytes(bs); 28 this.inflater.setInput(bs); 29 - byte[] cs = new byte[length]; 30 - this.inflater.inflate(cs); 31 - list.add(Unpooled.wrappedBuffer(cs)); 32 this.inflater.reset(); 33 } 34 } 35 }
··· 1 package com.github.puregero.minecraftstresstest; 2 3 import io.netty.buffer.ByteBuf; 4 import io.netty.channel.ChannelHandlerContext; 5 import io.netty.handler.codec.ByteToMessageDecoder; 6 7 + import java.nio.ByteBuffer; 8 import java.util.List; 9 import java.util.zip.Inflater; 10 ··· 23 return; 24 } 25 26 + ByteBuffer bs; 27 + if (friendlyByteBuf.nioBufferCount() > 0) { 28 + bs = friendlyByteBuf.nioBuffer(); 29 + friendlyByteBuf.skipBytes(friendlyByteBuf.readableBytes()); 30 + } else { 31 + bs = ByteBuffer.allocateDirect(friendlyByteBuf.readableBytes()); 32 + friendlyByteBuf.readBytes(bs); 33 + bs.flip(); 34 + } 35 this.inflater.setInput(bs); 36 + 37 + ByteBuf cs = channelHandlerContext.alloc().directBuffer(length); 38 + ByteBuffer csInternal = cs.internalNioBuffer(0, length); 39 + int startPos = csInternal.position(); 40 + this.inflater.inflate(csInternal); 41 + int csLength = csInternal.position() - startPos; 42 + if (csLength != length) { 43 + throw new IllegalStateException("Decompressed length " + csLength + " does not match expected length " + length); 44 + } 45 + cs.writerIndex(cs.writerIndex() + csLength); 46 + 47 this.inflater.reset(); 48 + list.add(cs); 49 } 50 } 51 }
+1 -4
src/main/java/com/github/puregero/minecraftstresstest/PacketDecoder.java
··· 1 package com.github.puregero.minecraftstresstest; 2 3 import io.netty.buffer.ByteBuf; 4 - import io.netty.buffer.Unpooled; 5 import io.netty.channel.ChannelHandlerContext; 6 import io.netty.handler.codec.ByteToMessageDecoder; 7 ··· 23 return; 24 } 25 26 - byte[] bs = new byte[length]; 27 - friendlyByteBuf.readBytes(bs); 28 - list.add(Unpooled.wrappedBuffer(bs)); 29 } 30 } 31 }
··· 1 package com.github.puregero.minecraftstresstest; 2 3 import io.netty.buffer.ByteBuf; 4 import io.netty.channel.ChannelHandlerContext; 5 import io.netty.handler.codec.ByteToMessageDecoder; 6 ··· 22 return; 23 } 24 25 + list.add(friendlyByteBuf.readBytes(length)); 26 } 27 } 28 }