Expand streams a little bit
This commit is contained in:
parent
9424bdedca
commit
db4abfe486
@ -0,0 +1,38 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MinecraftInput
|
||||
{
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public byte readByte()
|
||||
{
|
||||
return buf.readByte();
|
||||
}
|
||||
|
||||
public short readUnisgnedByte()
|
||||
{
|
||||
return buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
public int readInt()
|
||||
{
|
||||
return buf.readInt();
|
||||
}
|
||||
|
||||
public String readString()
|
||||
{
|
||||
short len = buf.readShort();
|
||||
char[] c = new char[ len ];
|
||||
for ( int i = 0; i < c.length; i++ )
|
||||
{
|
||||
c[i] = buf.readChar();
|
||||
}
|
||||
|
||||
return new String( c );
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MinecraftOutput
|
||||
{
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public MinecraftOutput()
|
||||
{
|
||||
buf = Unpooled.buffer();
|
||||
}
|
||||
|
||||
public byte[] toArray()
|
||||
{
|
||||
if ( buf.hasArray() )
|
||||
{
|
||||
return Arrays.copyOfRange( buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.writerIndex() );
|
||||
} else
|
||||
{
|
||||
byte[] b = new byte[ buf.writerIndex() ];
|
||||
buf.readBytes( b );
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public MinecraftOutput writeByte(byte b)
|
||||
{
|
||||
buf.writeByte( b );
|
||||
return this;
|
||||
}
|
||||
|
||||
public void writeInt(int i)
|
||||
{
|
||||
buf.writeInt( i );
|
||||
}
|
||||
|
||||
public void writeString(String s)
|
||||
{
|
||||
char[] cc = s.toCharArray();
|
||||
buf.writeShort( cc.length );
|
||||
for ( char c : cc )
|
||||
{
|
||||
buf.writeChar( c );
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MinecraftStream
|
||||
{
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public byte readByte()
|
||||
{
|
||||
return buf.readByte();
|
||||
}
|
||||
|
||||
public MinecraftStream writeByte(byte b)
|
||||
{
|
||||
buf.writeByte( b );
|
||||
return this;
|
||||
}
|
||||
/*========================================================================*/
|
||||
|
||||
public short readUnisgnedByte()
|
||||
{
|
||||
return buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
/*========================================================================*/
|
||||
public int readInt()
|
||||
{
|
||||
return buf.readInt();
|
||||
}
|
||||
|
||||
public void writeInt(int i)
|
||||
{
|
||||
buf.writeInt( i );
|
||||
}
|
||||
/*========================================================================*/
|
||||
|
||||
public String readString()
|
||||
{
|
||||
short len = buf.readShort();
|
||||
char[] c = new char[ len ];
|
||||
for ( int i = 0; i < c.length; i++ )
|
||||
{
|
||||
c[i] = buf.readChar();
|
||||
}
|
||||
|
||||
return new String( c );
|
||||
}
|
||||
|
||||
public void writeString(String s)
|
||||
{
|
||||
char[] cc = s.toCharArray();
|
||||
buf.writeShort( cc.length );
|
||||
for ( char c : cc )
|
||||
{
|
||||
buf.writeChar( c );
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,8 @@ import java.io.DataInputStream;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.protocol.MinecraftStream;
|
||||
import net.md_5.bungee.protocol.MinecraftInput;
|
||||
import net.md_5.bungee.protocol.MinecraftOutput;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@ -56,8 +57,8 @@ public class PacketFAPluginMessage extends DefinedPacket
|
||||
return new DataInputStream( new ByteArrayInputStream( data ) );
|
||||
}
|
||||
|
||||
public MinecraftStream getMCStream()
|
||||
public MinecraftInput getMCStream()
|
||||
{
|
||||
return new MinecraftStream( Unpooled.wrappedBuffer( data ) );
|
||||
return new MinecraftInput( Unpooled.wrappedBuffer( data ) );
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package net.md_5.bungee.connection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.util.concurrent.ScheduledFuture;
|
||||
import java.io.DataInput;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URLEncoder;
|
||||
@ -39,7 +38,7 @@ import net.md_5.bungee.netty.PacketDecoder;
|
||||
import net.md_5.bungee.netty.PacketHandler;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.protocol.Forge;
|
||||
import net.md_5.bungee.protocol.MinecraftStream;
|
||||
import net.md_5.bungee.protocol.MinecraftInput;
|
||||
import net.md_5.bungee.protocol.Vanilla;
|
||||
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.packet.Packet1Login;
|
||||
@ -109,7 +108,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
if ( pingFuture.cancel( false ) )
|
||||
{
|
||||
MinecraftStream in = pluginMessage.getMCStream();
|
||||
MinecraftInput in = pluginMessage.getMCStream();
|
||||
version = in.readByte();
|
||||
String connectHost = in.readString();
|
||||
int connectPort = in.readInt();
|
||||
|
Loading…
Reference in New Issue
Block a user