Merge NIO into master. I would not recommend this on a production server at all. Its 1.5 anyway.
This commit is contained in:
@@ -17,4 +17,14 @@
|
||||
|
||||
<name>BungeeCord-Protocol</name>
|
||||
<description>Minimal implementation of the Minecraft protocol for use in BungeeCord</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<!-- TODO: Fix this -->
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.0.Beta3-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -1,14 +1,13 @@
|
||||
package net.md_5.mendax;
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import static net.md_5.mendax.PacketDefinitions.OpCode.*;
|
||||
import static net.md_5.bungee.protocol.PacketDefinitions.OpCode.*;
|
||||
|
||||
public class PacketDefinitions
|
||||
{
|
||||
|
||||
private static final int MAX_PACKET = 256;
|
||||
public static final OpCode[][] opCodes = new OpCode[ MAX_PACKET * 2 ][];
|
||||
public static final OpCode[][] opCodes = new OpCode[ 512 ][];
|
||||
public static final int VANILLA_PROTOCOL = 0;
|
||||
public static final int FORGE_PROTOCOL = MAX_PACKET;
|
||||
public static final int FORGE_PROTOCOL = 256;
|
||||
|
||||
public enum OpCode
|
||||
{
|
||||
@@ -332,7 +331,8 @@ public class PacketDefinitions
|
||||
};
|
||||
opCodes[0xFE] = new OpCode[]
|
||||
{
|
||||
}; // Should be byte, screw you too bitchy server admins!
|
||||
BYTE
|
||||
};
|
||||
opCodes[0xFF] = new OpCode[]
|
||||
{
|
||||
STRING
|
@@ -1,17 +1,17 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BulkChunk extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
short count = in.readShort();
|
||||
int size = in.readInt();
|
||||
in.readBoolean();
|
||||
skip( in, buffer, size + count * 12 );
|
||||
in.skipBytes( size + count * 12 );
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class ByteHeader extends Instruction
|
||||
@@ -14,12 +14,12 @@ class ByteHeader extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
byte size = in.readByte();
|
||||
for ( byte b = 0; b < size; b++ )
|
||||
{
|
||||
child.read( in, buffer );
|
||||
child.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
abstract class Instruction
|
||||
@@ -30,10 +30,5 @@ abstract class Instruction
|
||||
// Custom instructions
|
||||
static final Instruction STRING_ARRAY = new ShortHeader( STRING );
|
||||
|
||||
abstract void read(DataInput in, byte[] buffer) throws IOException;
|
||||
|
||||
final void skip(DataInput in, byte[] buffer, int len) throws IOException
|
||||
{
|
||||
in.readFully( buffer, 0, len );
|
||||
}
|
||||
abstract void read(ByteBuf in) throws IOException;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class IntHeader extends Instruction
|
||||
@@ -14,12 +14,12 @@ class IntHeader extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
int size = in.readInt();
|
||||
for ( int i = 0; i < size; i++ )
|
||||
{
|
||||
child.read( in, buffer );
|
||||
child.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class Item extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
short type = in.readShort();
|
||||
if ( type >= 0 )
|
||||
{
|
||||
in.skipBytes( 3 );
|
||||
SHORT_BYTE.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class Jump extends Instruction
|
||||
@@ -18,8 +18,8 @@ class Jump extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
skip( in, buffer, len );
|
||||
in.skipBytes( len );
|
||||
}
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class MetaData extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
int x = in.readUnsignedByte();
|
||||
while ( x != 127 )
|
||||
@@ -16,25 +16,25 @@ class MetaData extends Instruction
|
||||
switch ( type )
|
||||
{
|
||||
case 0:
|
||||
BYTE.read( in, buffer );
|
||||
BYTE.read( in );
|
||||
break;
|
||||
case 1:
|
||||
SHORT.read( in, buffer );
|
||||
SHORT.read( in );
|
||||
break;
|
||||
case 2:
|
||||
INT.read( in, buffer );
|
||||
INT.read( in );
|
||||
break;
|
||||
case 3:
|
||||
FLOAT.read( in, buffer );
|
||||
FLOAT.read( in );
|
||||
break;
|
||||
case 4:
|
||||
STRING.read( in, buffer );
|
||||
STRING.read( in );
|
||||
break;
|
||||
case 5:
|
||||
ITEM.read( in, buffer );
|
||||
ITEM.read( in );
|
||||
break;
|
||||
case 6:
|
||||
skip( in, buffer, 12 ); // int, int, int
|
||||
in.skipBytes( 12 ); // int, int, int
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown metadata type " + type );
|
@@ -0,0 +1,18 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class OptionalMotion extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
int data = in.readInt();
|
||||
if ( data > 0 )
|
||||
{
|
||||
in.skipBytes( 6 );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,16 +1,16 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.md_5.mendax.PacketDefinitions;
|
||||
import net.md_5.mendax.PacketDefinitions.OpCode;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions.OpCode;
|
||||
|
||||
public class DataInputPacketReader
|
||||
public class PacketReader
|
||||
{
|
||||
|
||||
private static final Instruction[][] instructions = new Instruction[ 256 ][];
|
||||
private static final Instruction[][] instructions = new Instruction[ PacketDefinitions.opCodes.length ][];
|
||||
|
||||
static
|
||||
{
|
||||
@@ -59,7 +59,7 @@ public class DataInputPacketReader
|
||||
}
|
||||
}
|
||||
|
||||
private static void readPacket(int packetId, DataInput in, byte[] buffer, int protocol) throws IOException
|
||||
private static void readPacket(int packetId, ByteBuf in, int protocol) throws IOException
|
||||
{
|
||||
Instruction[] packetDef = null;
|
||||
if ( packetId + protocol < instructions.length )
|
||||
@@ -74,20 +74,20 @@ public class DataInputPacketReader
|
||||
throw new IOException( "Unknown packet id " + packetId );
|
||||
} else
|
||||
{
|
||||
readPacket( packetId, in, buffer, PacketDefinitions.VANILLA_PROTOCOL );
|
||||
readPacket( packetId, in, PacketDefinitions.VANILLA_PROTOCOL );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for ( Instruction instruction : packetDef )
|
||||
{
|
||||
instruction.read( in, buffer );
|
||||
instruction.read( in );
|
||||
}
|
||||
}
|
||||
|
||||
public static void readPacket(DataInput in, byte[] buffer, int protocol) throws IOException
|
||||
public static void readPacket(ByteBuf in, int protocol) throws IOException
|
||||
{
|
||||
int packetId = in.readUnsignedByte();
|
||||
readPacket( packetId, in, buffer, protocol );
|
||||
readPacket( packetId, in, protocol );
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import java.io.DataInput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class ShortHeader extends Instruction
|
||||
@@ -14,12 +14,12 @@ class ShortHeader extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
short size = in.readShort();
|
||||
for ( short s = 0; s < size; s++ )
|
||||
{
|
||||
child.read( in, buffer );
|
||||
child.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class Team extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
STRING.read( in );
|
||||
byte mode = in.readByte();
|
||||
if ( mode == 0 || mode == 2 )
|
||||
{
|
||||
STRING.read( in );
|
||||
STRING.read( in );
|
||||
STRING.read( in );
|
||||
BYTE.read( in );
|
||||
}
|
||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||
{
|
||||
STRING_ARRAY.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class UnsignedShortByte extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
{
|
||||
int size = in.readUnsignedShort();
|
||||
in.skipBytes( size );
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
class Item extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
{
|
||||
short type = in.readShort();
|
||||
if ( type >= 0 )
|
||||
{
|
||||
skip( in, buffer, 3 );
|
||||
SHORT_BYTE.read( in, buffer );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class OptionalMotion extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
{
|
||||
int data = in.readInt();
|
||||
if ( data > 0 )
|
||||
{
|
||||
skip( in, buffer, 6 );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
class Team extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
{
|
||||
STRING.read( in, buffer );
|
||||
byte mode = in.readByte();
|
||||
if ( mode == 0 || mode == 2 )
|
||||
{
|
||||
STRING.read( in, buffer );
|
||||
STRING.read( in, buffer );
|
||||
STRING.read( in, buffer );
|
||||
BYTE.read( in, buffer );
|
||||
}
|
||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||
{
|
||||
STRING_ARRAY.read( in, buffer );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package net.md_5.mendax.datainput;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnsignedShortByte extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(DataInput in, byte[] buffer) throws IOException
|
||||
{
|
||||
int size = in.readUnsignedShort();
|
||||
skip( in, buffer, size );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user