mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 15:29:20 -04:00
support for other login packet ids (1.13-pre3-1.13-pre8)
This commit is contained in:
parent
5cef35471f
commit
5aa94801ea
@ -14,16 +14,19 @@
|
|||||||
package de.bixilon.minosoft.game.datatypes.objectLoader.versions;
|
package de.bixilon.minosoft.game.datatypes.objectLoader.versions;
|
||||||
|
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ConnectionState;
|
||||||
import de.bixilon.minosoft.protocol.protocol.Packets;
|
import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Version {
|
public class Version {
|
||||||
final String versionName;
|
final String versionName;
|
||||||
final int protocolVersion;
|
final int protocolVersion;
|
||||||
final HashBiMap<Packets.Serverbound, Integer> serverboundPacketMapping;
|
final HashMap<ConnectionState, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping;
|
||||||
final HashBiMap<Packets.Clientbound, Integer> clientboundPacketMapping;
|
final HashMap<ConnectionState, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping;
|
||||||
VersionMapping mapping;
|
VersionMapping mapping;
|
||||||
|
|
||||||
public Version(String versionName, int protocolVersion, HashBiMap<Packets.Serverbound, Integer> serverboundPacketMapping, HashBiMap<Packets.Clientbound, Integer> clientboundPacketMapping) {
|
public Version(String versionName, int protocolVersion, HashMap<ConnectionState, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping, HashMap<ConnectionState, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping) {
|
||||||
this.versionName = versionName;
|
this.versionName = versionName;
|
||||||
this.protocolVersion = protocolVersion;
|
this.protocolVersion = protocolVersion;
|
||||||
this.serverboundPacketMapping = serverboundPacketMapping;
|
this.serverboundPacketMapping = serverboundPacketMapping;
|
||||||
@ -38,23 +41,25 @@ public class Version {
|
|||||||
return protocolVersion;
|
return protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Packets.Clientbound getPacketByCommand(int command) { // state must be play!
|
public Packets.Clientbound getPacketByCommand(ConnectionState state, int command) {
|
||||||
return clientboundPacketMapping.inverse().get(command);
|
if (clientboundPacketMapping.containsKey(state) && clientboundPacketMapping.get(state).containsValue(command)) {
|
||||||
|
return clientboundPacketMapping.get(state).inverse().get(command);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCommandByPacket(Packets.Serverbound packet) {
|
public Integer getCommandByPacket(Packets.Serverbound packet) {
|
||||||
return serverboundPacketMapping.get(packet);
|
if (serverboundPacketMapping.containsKey(packet.getState()) && serverboundPacketMapping.get(packet.getState()).containsKey(packet)) {
|
||||||
|
return serverboundPacketMapping.get(packet.getState()).get(packet);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCommandByPacket(Packets.Clientbound packet) {
|
public HashMap<ConnectionState, HashBiMap<Packets.Clientbound, Integer>> getClientboundPacketMapping() {
|
||||||
return clientboundPacketMapping.get(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashBiMap<Packets.Clientbound, Integer> getClientboundPacketMapping() {
|
|
||||||
return clientboundPacketMapping;
|
return clientboundPacketMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashBiMap<Packets.Serverbound, Integer> getServerboundPacketMapping() {
|
public HashMap<ConnectionState, HashBiMap<Packets.Serverbound, Integer>> getServerboundPacketMapping() {
|
||||||
return serverboundPacketMapping;
|
return serverboundPacketMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import com.google.gson.JsonObject;
|
|||||||
import de.bixilon.minosoft.Config;
|
import de.bixilon.minosoft.Config;
|
||||||
import de.bixilon.minosoft.game.datatypes.Mappings;
|
import de.bixilon.minosoft.game.datatypes.Mappings;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ConnectionState;
|
||||||
import de.bixilon.minosoft.protocol.protocol.Packets;
|
import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||||
import de.bixilon.minosoft.util.Util;
|
import de.bixilon.minosoft.util.Util;
|
||||||
@ -60,8 +61,8 @@ public class Versions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashBiMap<Packets.Serverbound, Integer> serverboundPacketMapping;
|
HashMap<ConnectionState, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping;
|
||||||
HashBiMap<Packets.Clientbound, Integer> clientboundPacketMapping;
|
HashMap<ConnectionState, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping;
|
||||||
if (versionJson.get("mapping").isJsonPrimitive()) {
|
if (versionJson.get("mapping").isJsonPrimitive()) {
|
||||||
// inherits or copies mapping from an other version
|
// inherits or copies mapping from an other version
|
||||||
if (!versionMap.containsKey(protocolId)) {
|
if (!versionMap.containsKey(protocolId)) {
|
||||||
@ -72,16 +73,24 @@ public class Versions {
|
|||||||
clientboundPacketMapping = parent.getClientboundPacketMapping();
|
clientboundPacketMapping = parent.getClientboundPacketMapping();
|
||||||
} else {
|
} else {
|
||||||
JsonObject mappingJson = versionJson.getAsJsonObject("mapping");
|
JsonObject mappingJson = versionJson.getAsJsonObject("mapping");
|
||||||
serverboundPacketMapping = HashBiMap.create();
|
serverboundPacketMapping = new HashMap<>();
|
||||||
|
|
||||||
for (JsonElement packetElement : mappingJson.getAsJsonArray("serverbound")) {
|
for (JsonElement packetElement : mappingJson.getAsJsonArray("serverbound")) {
|
||||||
String packetName = packetElement.getAsString();
|
String packetName = packetElement.getAsString();
|
||||||
serverboundPacketMapping.put(Packets.Serverbound.valueOf(packetName), serverboundPacketMapping.size());
|
Packets.Serverbound packet = Packets.Serverbound.valueOf(packetName);
|
||||||
|
if (!serverboundPacketMapping.containsKey(packet.getState())) {
|
||||||
|
serverboundPacketMapping.put(packet.getState(), HashBiMap.create());
|
||||||
|
}
|
||||||
|
serverboundPacketMapping.get(packet.getState()).put(packet, serverboundPacketMapping.get(packet.getState()).size());
|
||||||
}
|
}
|
||||||
clientboundPacketMapping = HashBiMap.create();
|
clientboundPacketMapping = new HashMap<>();
|
||||||
for (JsonElement packetElement : mappingJson.getAsJsonArray("clientbound")) {
|
for (JsonElement packetElement : mappingJson.getAsJsonArray("clientbound")) {
|
||||||
String packetName = packetElement.getAsString();
|
String packetName = packetElement.getAsString();
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.valueOf(packetName), clientboundPacketMapping.size());
|
Packets.Clientbound packet = Packets.Clientbound.valueOf(packetName);
|
||||||
|
if (!clientboundPacketMapping.containsKey(packet.getState())) {
|
||||||
|
clientboundPacketMapping.put(packet.getState(), HashBiMap.create());
|
||||||
|
}
|
||||||
|
clientboundPacketMapping.get(packet.getState()).put(packet, clientboundPacketMapping.get(packet.getState()).size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Version version = new Version(versionName, protocolId, serverboundPacketMapping, clientboundPacketMapping);
|
Version version = new Version(versionName, protocolId, serverboundPacketMapping, clientboundPacketMapping);
|
||||||
|
@ -257,17 +257,25 @@ public class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPacketCommand(Packets.Serverbound packet) {
|
public int getPacketCommand(Packets.Serverbound packet) {
|
||||||
if (packet.getState() == ConnectionState.PLAY) {
|
Integer command = null;
|
||||||
return version.getCommandByPacket(packet);
|
if (getReason() != ConnectionReason.GET_VERSION) {
|
||||||
|
command = version.getCommandByPacket(packet);
|
||||||
}
|
}
|
||||||
return Protocol.getPacketCommand(packet);
|
if (command == null) {
|
||||||
|
return Protocol.getPacketCommand(packet);
|
||||||
|
}
|
||||||
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Packets.Clientbound getPacketByCommand(ConnectionState state, int command) {
|
public Packets.Clientbound getPacketByCommand(ConnectionState state, int command) {
|
||||||
if (state == ConnectionState.PLAY) {
|
Packets.Clientbound packet = null;
|
||||||
return version.getPacketByCommand(command);
|
if (getReason() != ConnectionReason.GET_VERSION) {
|
||||||
|
packet = version.getPacketByCommand(state, command);
|
||||||
}
|
}
|
||||||
return Protocol.getPacketByCommand(state, command);
|
if (packet == null) {
|
||||||
|
return Protocol.getPacketByCommand(state, command);
|
||||||
|
}
|
||||||
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VelocityHandler getVelocityHandler() {
|
public VelocityHandler getVelocityHandler() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user