Archived
0
This commit is contained in:
2018-04-10 22:24:16 +03:00
parent 4da826248e
commit 18663a2432
7 changed files with 107 additions and 0 deletions

View File

@@ -24,6 +24,11 @@ public class ByteArrayOutputNetStream extends NetStream {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public int readInt() {
throw new UnsupportedOperationException();
}
@Override @Override
public void writeByte(int value) { public void writeByte(int value) {
baos.write(value); baos.write(value);
@@ -34,6 +39,14 @@ public class ByteArrayOutputNetStream extends NetStream {
baos.write(buffer, 0, buffer.length); baos.write(buffer, 0, buffer.length);
} }
@Override
public void writeInt(final int value) {
baos.write((byte) value >>> 24);
baos.write((byte) value >>> 16);
baos.write((byte) value >>> 8);
baos.write((byte) value);
}
@Override @Override
public void skipBytes(int count) { public void skipBytes(int count) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@@ -77,9 +77,11 @@ public abstract class NetStream {
public abstract byte readByte(); public abstract byte readByte();
public abstract void readBytes(byte[] buffer); public abstract void readBytes(byte[] buffer);
public abstract int readUnsignedShort(); public abstract int readUnsignedShort();
public abstract int readInt();
public abstract void writeByte(int value); public abstract void writeByte(int value);
public abstract void writeBytes(byte[] buffer); public abstract void writeBytes(byte[] buffer);
public abstract void writeInt(int value);
public abstract void skipBytes(int count); public abstract void skipBytes(int count);
} }

View File

@@ -43,6 +43,11 @@ public class ByteArrayOutputNetStream extends NetStream {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public int readInt() {
throw new UnsupportedOperationException();
}
@Override @Override
public void writeByte(int value) { public void writeByte(int value) {
baos.write(value); baos.write(value);
@@ -53,6 +58,14 @@ public class ByteArrayOutputNetStream extends NetStream {
baos.write(buffer, 0, buffer.length); baos.write(buffer, 0, buffer.length);
} }
@Override
public void writeInt(int value) {
baos.write((byte) value >>> 24);
baos.write((byte) value >>> 16);
baos.write((byte) value >>> 8);
baos.write((byte) value);
}
@Override @Override
public void skipBytes(int count) { public void skipBytes(int count) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@@ -13,6 +13,7 @@ import mc.core.Config;
import mc.core.Main; import mc.core.Main;
import mc.core.netty.proto_125.packets.HandshakePacket; import mc.core.netty.proto_125.packets.HandshakePacket;
import mc.core.netty.proto_125.packets.KickPacket; import mc.core.netty.proto_125.packets.KickPacket;
import mc.core.netty.proto_125.packets.LoginPacket;
import mc.core.netty.proto_125.packets.PingPacket; import mc.core.netty.proto_125.packets.PingPacket;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -49,4 +50,13 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
public void onHandshakePacket(Channel channel, HandshakePacket packet) { public void onHandshakePacket(Channel channel, HandshakePacket packet) {
channel.writeAndFlush(packet); channel.writeAndFlush(packet);
} }
public void onLoginPacket(Channel channel, LoginPacket packet) {
packet.setLevelType("FLAT");
packet.setServerMode(1/*creative*/);
packet.setDimension(0/*Overworld*/);
packet.setDifficulty(0/*Peaceful*/);
packet.setMaxPlayers(config.getMaxPlayers());
channel.writeAndFlush(packet);
}
} }

View File

@@ -10,10 +10,12 @@ import mc.core.CSPacket;
import mc.core.SCPacket; import mc.core.SCPacket;
import mc.core.netty.proto_125.packets.HandshakePacket; import mc.core.netty.proto_125.packets.HandshakePacket;
import mc.core.netty.proto_125.packets.KickPacket; import mc.core.netty.proto_125.packets.KickPacket;
import mc.core.netty.proto_125.packets.LoginPacket;
import mc.core.netty.proto_125.packets.PingPacket; import mc.core.netty.proto_125.packets.PingPacket;
public class PacketManager { public class PacketManager {
private static final BiMap<Integer, Class<?>> packetMap = ImmutableBiMap.of( private static final BiMap<Integer, Class<?>> packetMap = ImmutableBiMap.of(
0x01, LoginPacket.class,
0x02, HandshakePacket.class, 0x02, HandshakePacket.class,
0xFE, PingPacket.class, 0xFE, PingPacket.class,
0xFF, KickPacket.class 0xFF, KickPacket.class

View File

@@ -39,6 +39,11 @@ public class WrapperNetStream extends NetStream {
return byteBuf.readUnsignedShort(); return byteBuf.readUnsignedShort();
} }
@Override
public int readInt() {
return byteBuf.readInt();
}
@Override @Override
public void writeByte(int value) { public void writeByte(int value) {
byteBuf.writeByte(value); byteBuf.writeByte(value);
@@ -49,6 +54,11 @@ public class WrapperNetStream extends NetStream {
byteBuf.writeBytes(buffer); byteBuf.writeBytes(buffer);
} }
@Override
public void writeInt(int value) {
byteBuf.writeInt(value);
}
@Override @Override
public void skipBytes(int count) { public void skipBytes(int count) {
byteBuf.skipBytes(count); byteBuf.skipBytes(count);

View File

@@ -0,0 +1,57 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-04-10
*/
package mc.core.netty.proto_125.packets;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import mc.core.CSPacket;
import mc.core.NetStream;
import mc.core.SCPacket;
import mc.core.netty.proto_125.ByteArrayOutputNetStream;
@ToString
public class LoginPacket implements CSPacket, SCPacket {
@Getter
private int protocol;
@Getter
private String playerName;
@Setter
private int playerId;
@Setter
private String levelType;
@Setter
private int serverMode;
@Setter
private int dimension;
@Setter
private int difficulty;
@Setter
private int maxPlayers;
@Override
public void readSelf(NetStream netStream) {
protocol = netStream.readInt();
netStream.skipBytes(1);
playerName = netStream.readString();
}
@Override
public byte[] toByteArray() {
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
netStream.writeInt(playerId);
netStream.writeString("");
netStream.writeString(levelType);
netStream.writeInt(serverMode);
netStream.writeInt(dimension);
netStream.writeByte(difficulty);
netStream.writeByte(0);
netStream.writeByte(maxPlayers);
return netStream.toByteArray();
}
}