send hello from minosoft chat message, refactor protocol (release name, etc)

This commit is contained in:
Bixilon 2020-07-04 17:43:07 +02:00
parent 7bb3353ad1
commit f47b88d319
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
20 changed files with 82 additions and 38 deletions

View File

@ -98,7 +98,7 @@ public class Connection {
network.startPacketThread();
startHandlingThread();
ConnectionState next = ((reason == ConnectionReason.CONNECT) ? ConnectionState.LOGIN : ConnectionState.STATUS);
network.sendPacket(new PacketHandshake(getHost(), getPort(), next, (next == ConnectionState.STATUS) ? -1 : getVersion().getVersion()));
network.sendPacket(new PacketHandshake(getHost(), getPort(), next, (next == ConnectionState.STATUS) ? -1 : getVersion().getVersionNumber()));
// after sending it, switch to next state
setConnectionState(next);
break;
@ -209,7 +209,7 @@ public class Connection {
serverVersion = buffer.readString();
toSend.writeString(clientVersion);
}
Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, getVersion().getName()));
Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, getVersion().getVersionString()));
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getIdentifier().get(version), toSend);
});

View File

@ -36,7 +36,7 @@ public class PacketBlockAction implements ClientboundPacket {
case VERSION_1_9_4:
case VERSION_1_10:
// that's the only difference here
if (buffer.getVersion().getVersion() >= ProtocolVersion.VERSION_1_8.getVersion()) {
if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_8.getVersionNumber()) {
position = buffer.readPosition();
} else {
position = buffer.readBlockPositionShort();

View File

@ -77,7 +77,7 @@ public class PacketMapData implements ClientboundPacket {
case VERSION_1_10: {
mapId = buffer.readVarInt();
scale = buffer.readByte();
if (buffer.getVersion().getVersion() >= ProtocolVersion.VERSION_1_9_4.getVersion()) {
if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_9_4.getVersionNumber()) {
boolean trackPosition = buffer.readBoolean();
}
int pinCount = buffer.readVarInt();

View File

@ -67,7 +67,7 @@ public class PacketSpawnObject implements ClientboundPacket {
int data = buffer.readInt();
try {
if (buffer.getVersion().getVersion() >= ProtocolVersion.VERSION_1_8.getVersion()) {
if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_8.getVersionNumber()) {
// velocity present AND metadata
Velocity velocity = null;

View File

@ -44,7 +44,7 @@ public class PacketHandshake implements ServerboundPacket {
public OutPacketBuffer write(ProtocolVersion version) {
// no version checking, is the same in all versions (1.7.x - 1.15.2)
OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.HANDSHAKING_HANDSHAKE));
buffer.writeVarInt((nextState == ConnectionState.STATUS ? -1 : version.getVersion())); // get best protocol version
buffer.writeVarInt((nextState == ConnectionState.STATUS ? -1 : version.getVersionNumber())); // get best protocol version
buffer.writeString(address);
buffer.writeShort((short) port);
buffer.writeVarInt(nextState.getId());

View File

@ -175,7 +175,7 @@ public class InByteBuffer {
}
public BlockPosition readPosition() {
if (version.getVersion() >= ProtocolVersion.VERSION_1_14_4.getVersion()) {
if (version.getVersionNumber() >= ProtocolVersion.VERSION_1_14_4.getVersionNumber()) {
// changed in 1.14, thanks for the explanation @Sainan
Long raw = readLong();
int x = (int) (raw >> 38);

View File

@ -153,7 +153,7 @@ public class OutByteBuffer {
}
public void writePosition(BlockPosition location) {
if (version.getVersion() >= ProtocolVersion.VERSION_1_14_4.getVersion()) {
if (version.getVersionNumber() >= ProtocolVersion.VERSION_1_14_4.getVersionNumber()) {
writeLong((((long) (location.getX() & 0x3FFFFFF) << 38) | ((long) (location.getZ() & 0x3FFFFFF) << 12) | (long) (location.getY() & 0xFFF)));
} else {
writeLong((((long) location.getX() & 0x3FFFFFF) << 38) | (((long) location.getZ() & 0x3FFFFFF)) | ((long) location.getY() & 0xFFF) << 26);

View File

@ -67,7 +67,7 @@ public class PacketHandler {
case GET_VERSION:
// reconnect...
connection.disconnect();
Log.info(String.format("Server is running on version %s, reconnecting...", connection.getVersion().getName()));
Log.info(String.format("Server is running on version %s, reconnecting...", connection.getVersion().getVersionString()));
break;
case CONNECT:
// do nothing
@ -95,6 +95,7 @@ public class PacketHandler {
connection.getPlayer().setPlayer(new OtherPlayer(pkg.getEntityId(), connection.getPlayer().getPlayerName(), connection.getPlayer().getPlayerUUID(), null, null, null, (short) 0, (short) 0, (short) 0, null));
connection.getPlayer().getWorld().setHardcore(pkg.isHardcore());
connection.getPlayer().getWorld().setDimension(pkg.getDimension());
connection.getSender().sendChatMessage("I am alive! ~ Minosoft");
}
public void handle(PacketLoginDisconnect pkg) {

View File

@ -164,6 +164,6 @@ public abstract class Protocol implements ProtocolInterface {
@Override
public int hashCode() {
return getProtocolVersion();
return getProtocolVersionNumber();
}
}

View File

@ -14,7 +14,9 @@
package de.bixilon.minosoft.protocol.protocol;
public interface ProtocolInterface {
String getName();
String getVersionString();
int getProtocolVersion();
int getProtocolVersionNumber();
String getReleaseName(); // Minecraft + getReleaseName() + Update
}

View File

@ -32,7 +32,7 @@ public enum ProtocolVersion {
static {
for (ProtocolVersion v : values()) {
versionMapping.put(v.getVersion(), v);
versionMapping.put(v.getVersionNumber(), v);
}
versionMappingArray = new ProtocolVersion[values().length];
int counter = 0;
@ -43,25 +43,23 @@ public enum ProtocolVersion {
}
final int version;
final Protocol protocol;
ProtocolVersion(Protocol protocol) {
this.protocol = protocol;
this.version = protocol.getProtocolVersion();
}
public static ProtocolVersion byId(int protocolNumber) {
for (ProtocolVersion v : values()) {
if (v.getVersion() == protocolNumber) {
if (v.getVersionNumber() == protocolNumber) {
return v;
}
}
return null;
}
public int getVersion() {
return version;
public int getVersionNumber() {
return protocol.getProtocolVersionNumber();
}
public Protocol getProtocol() {
@ -72,8 +70,12 @@ public enum ProtocolVersion {
return protocol.getPacketCommand(p);
}
public String getName() {
return protocol.getName();
public String getVersionString() {
return protocol.getVersionString();
}
public String getReleaseName() {
return protocol.getReleaseName();
}
}

View File

@ -130,13 +130,17 @@ public class Protocol_1_10 extends Protocol {
serverboundPacketMapping.put(Packets.Serverbound.PLAY_USE_ITEM, 0x1D);
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 210;
}
@Override
public String getName() {
public String getVersionString() {
return "1.10.x";
}
@Override
public String getReleaseName() {
return "Frostburn";
}
}

View File

@ -21,13 +21,17 @@ public class Protocol_1_11_2 extends Protocol {
//ToDo
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 316;
}
@Override
public String getName() {
public String getVersionString() {
return "1.11.2";
}
@Override
public String getReleaseName() {
return "Exploration";
}
}

View File

@ -21,13 +21,18 @@ public class Protocol_1_12_2 extends Protocol {
//ToDo
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 340;
}
@Override
public String getName() {
public String getVersionString() {
return "1.12.2";
}
@Override
public String getReleaseName() {
return "World of Color";
}
}

View File

@ -21,13 +21,17 @@ public class Protocol_1_13_2 extends Protocol {
//ToDo
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 404;
}
@Override
public String getName() {
public String getVersionString() {
return "1.13.2";
}
@Override
public String getReleaseName() {
return "Aquatic";
}
}

View File

@ -21,13 +21,17 @@ public class Protocol_1_14_4 extends Protocol {
//ToDo
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 498;
}
@Override
public String getName() {
public String getVersionString() {
return "1.14.4";
}
@Override
public String getReleaseName() {
return "Village and Pillage";
}
}

View File

@ -21,13 +21,17 @@ public class Protocol_1_15_2 extends Protocol {
//ToDo
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 578;
}
@Override
public String getName() {
public String getVersionString() {
return "1.15.2";
}
@Override
public String getReleaseName() {
return "Buzzy Bees";
}
}

View File

@ -113,12 +113,18 @@ public class Protocol_1_7_10 extends Protocol {
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 5;
}
@Override
public String getName() {
public String getVersionString() {
return "1.7.10";
}
@Override
public String getReleaseName() {
return "Realms";
}
}

View File

@ -125,13 +125,17 @@ public class Protocol_1_8 extends Protocol {
clientboundPacketMapping.put(Packets.Clientbound.PLAY_NBT_QUERY_RESPONSE, 0x49);
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 47;
}
@Override
public String getName() {
public String getVersionString() {
return "1.8.x";
}
@Override
public String getReleaseName() {
return "Bountiful";
}
}

View File

@ -136,13 +136,17 @@ public class Protocol_1_9_4 extends Protocol {
}
public int getProtocolVersion() {
public int getProtocolVersionNumber() {
return 110;
}
@Override
public String getName() {
public String getVersionString() {
return "1.9.4";
}
@Override
public String getReleaseName() {
return "Combat";
}
}