try to fix tablist uuid for player, cleanup

This commit is contained in:
creeper123123321 2021-04-02 14:29:15 -03:00
parent c51aaf0510
commit 88dbbb9ad2
3 changed files with 27 additions and 33 deletions

View File

@ -3,7 +3,6 @@ package com.github.creeper123123321.viaaas.protocol.id47toid5.packets
import com.github.creeper123123321.viaaas.protocol.id47toid5.Protocol1_8To1_7_6 import com.github.creeper123123321.viaaas.protocol.id47toid5.Protocol1_8To1_7_6
import us.myles.ViaVersion.api.remapper.PacketRemapper import us.myles.ViaVersion.api.remapper.PacketRemapper
import us.myles.ViaVersion.api.type.Type import us.myles.ViaVersion.api.type.Type
import us.myles.ViaVersion.api.type.types.CustomByteType
import us.myles.ViaVersion.packets.State import us.myles.ViaVersion.packets.State
fun Protocol1_8To1_7_6.registerLoginPackets() { fun Protocol1_8To1_7_6.registerLoginPackets() {
@ -11,28 +10,16 @@ fun Protocol1_8To1_7_6.registerLoginPackets() {
this.registerOutgoing(State.LOGIN, 0x01, 0x01, object : PacketRemapper() { this.registerOutgoing(State.LOGIN, 0x01, 0x01, object : PacketRemapper() {
override fun registerMap() { override fun registerMap() {
map(Type.STRING) //Server ID map(Type.STRING) //Server ID
handler { packetWrapper -> map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE)
val publicKeyLength = packetWrapper.read(Type.SHORT).toInt() map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE)
packetWrapper.write(Type.VAR_INT, publicKeyLength)
packetWrapper.passthrough(CustomByteType(publicKeyLength))
val verifyTokenLength = packetWrapper.read(Type.SHORT).toInt()
packetWrapper.write(Type.VAR_INT, verifyTokenLength)
packetWrapper.passthrough(CustomByteType(verifyTokenLength))
}
} }
}) })
//Encryption Response //Encryption Response
this.registerIncoming(State.LOGIN, 0x01, 0x01, object : PacketRemapper() { this.registerIncoming(State.LOGIN, 0x01, 0x01, object : PacketRemapper() {
override fun registerMap() { override fun registerMap() {
handler { packetWrapper -> map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE)
val sharedSecretLength: Int = packetWrapper.read(Type.VAR_INT) map(Type.SHORT_BYTE_ARRAY, Type.BYTE_ARRAY_PRIMITIVE)
packetWrapper.write(Type.SHORT, sharedSecretLength.toShort())
packetWrapper.passthrough(CustomByteType(sharedSecretLength))
val verifyTokenLength: Int = packetWrapper.read(Type.VAR_INT)
packetWrapper.write(Type.SHORT, verifyTokenLength.toShort())
packetWrapper.passthrough(CustomByteType(verifyTokenLength))
}
} }
}) })
} }

View File

@ -1,5 +1,6 @@
package com.github.creeper123123321.viaaas.protocol.id47toid5.packets package com.github.creeper123123321.viaaas.protocol.id47toid5.packets
import com.github.creeper123123321.viaaas.generateOfflinePlayerUuid
import com.github.creeper123123321.viaaas.protocol.id47toid5.Protocol1_8To1_7_6 import com.github.creeper123123321.viaaas.protocol.id47toid5.Protocol1_8To1_7_6
import com.github.creeper123123321.viaaas.protocol.id47toid5.metadata.MetadataRewriter import com.github.creeper123123321.viaaas.protocol.id47toid5.metadata.MetadataRewriter
import com.github.creeper123123321.viaaas.protocol.id47toid5.storage.EntityTracker import com.github.creeper123123321.viaaas.protocol.id47toid5.storage.EntityTracker
@ -110,11 +111,11 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
this.registerOutgoing(State.PLAY, 0x0C, 0x0C, object : PacketRemapper() { this.registerOutgoing(State.PLAY, 0x0C, 0x0C, object : PacketRemapper() {
override fun registerMap() { override fun registerMap() {
handler { packetWrapper -> handler { packetWrapper ->
val entityId: Int = packetWrapper.passthrough(Type.VAR_INT) //Entity Id val entityId = packetWrapper.passthrough(Type.VAR_INT) //Entity Id
val uuid = UUID.fromString(packetWrapper.read(Type.STRING)) //UUID val uuid = UUID.fromString(packetWrapper.read(Type.STRING)) //UUID
packetWrapper.write(Type.UUID, uuid) packetWrapper.write(Type.UUID, uuid)
val name: String = ChatColorUtil.stripColor(packetWrapper.read(Type.STRING)) //Name val name = ChatColorUtil.stripColor(packetWrapper.read(Type.STRING)) //Name
val dataCount: Int = packetWrapper.read(Type.VAR_INT) //DataCunt val dataCount = packetWrapper.read(Type.VAR_INT) //DataCunt
val properties = ArrayList<Tablist.Property>() val properties = ArrayList<Tablist.Property>()
for (i in 0 until dataCount) { for (i in 0 until dataCount) {
val key: String = packetWrapper.read(Type.STRING) //Name val key: String = packetWrapper.read(Type.STRING) //Name
@ -122,15 +123,15 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
val signature: String = packetWrapper.read(Type.STRING) //Signature val signature: String = packetWrapper.read(Type.STRING) //Signature
properties.add(Tablist.Property(key, value, signature)) properties.add(Tablist.Property(key, value, signature))
} }
val x: Int = packetWrapper.passthrough(Type.INT) //x val x = packetWrapper.passthrough(Type.INT) //x
val y: Int = packetWrapper.passthrough(Type.INT) //y val y = packetWrapper.passthrough(Type.INT) //y
val z: Int = packetWrapper.passthrough(Type.INT) //z val z = packetWrapper.passthrough(Type.INT) //z
val yaw: Byte = packetWrapper.passthrough(Type.BYTE) //yaw val yaw = packetWrapper.passthrough(Type.BYTE) //yaw
val pitch: Byte = packetWrapper.passthrough(Type.BYTE) //pitch val pitch = packetWrapper.passthrough(Type.BYTE) //pitch
val item: Short = packetWrapper.passthrough(Type.SHORT) //Item in hand val item = packetWrapper.passthrough(Type.SHORT) //Item in hand
val metadata = packetWrapper.read(Types1_7_6_10.METADATA_LIST) //Metadata val metadata = packetWrapper.read(Types1_7_6_10.METADATA_LIST) //Metadata
MetadataRewriter.transform(Entity1_10Types.EntityType.PLAYER, metadata) MetadataRewriter.transform(Entity1_10Types.EntityType.PLAYER, metadata)
packetWrapper.write<List<Metadata>>(Types1_8.METADATA_LIST, metadata) packetWrapper.write(Types1_8.METADATA_LIST, metadata)
val tablist = packetWrapper.user().get(Tablist::class.java)!! val tablist = packetWrapper.user().get(Tablist::class.java)!!
var entryByName = tablist.getTabListEntry(name) var entryByName = tablist.getTabListEntry(name)
if (entryByName == null && name.length > 14) entryByName = tablist.getTabListEntry(name.substring(0, 14)) if (entryByName == null && name.length > 14) entryByName = tablist.getTabListEntry(name.substring(0, 14))
@ -215,11 +216,11 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
this.registerOutgoing(State.PLAY, 0x38, 0x38, object : PacketRemapper() { this.registerOutgoing(State.PLAY, 0x38, 0x38, object : PacketRemapper() {
override fun registerMap() { override fun registerMap() {
handler { packetWrapper -> handler { packetWrapper ->
val name: String = packetWrapper.read(Type.STRING) val name = packetWrapper.read(Type.STRING)
val displayName: String? = null val displayName: String? = null
val online: Boolean = packetWrapper.read(Type.BOOLEAN) val online = packetWrapper.read(Type.BOOLEAN)
val ping: Short = packetWrapper.read(Type.SHORT) val ping = packetWrapper.read(Type.SHORT)
val tablist: Tablist = packetWrapper.user().get(Tablist::class.java)!! val tablist = packetWrapper.user().get(Tablist::class.java)!!
var entry = tablist.getTabListEntry(name) var entry = tablist.getTabListEntry(name)
if (!online && entry != null) { if (!online && entry != null) {
packetWrapper.write(Type.VAR_INT, 4) packetWrapper.write(Type.VAR_INT, 4)
@ -227,7 +228,13 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
packetWrapper.write(Type.UUID, entry.uuid) packetWrapper.write(Type.UUID, entry.uuid)
tablist.remove(entry) tablist.remove(entry)
} else if (online && entry == null) { } else if (online && entry == null) {
entry = Tablist.TabListEntry(name, UUID.nameUUIDFromBytes("OfflinePlayer:$name".toByteArray(Charsets.UTF_8))) val uuid = if (name == packetWrapper.user().protocolInfo?.username) {
packetWrapper.user().protocolInfo!!.uuid!!
} else {
generateOfflinePlayerUuid(name)
}
entry = Tablist.TabListEntry(name, uuid)
entry.displayName = displayName entry.displayName = displayName
tablist.add(entry) tablist.add(entry)
packetWrapper.write(Type.VAR_INT, 0) // Add packetWrapper.write(Type.VAR_INT, 0) // Add

View File

@ -27,7 +27,7 @@ class Tablist(user: UserConnection?) : StoredObject(user) {
class TabListEntry(var name: String, var uuid: UUID) { class TabListEntry(var name: String, var uuid: UUID) {
var displayName: String? = null var displayName: String? = null
var ping = 0 var ping = 0
var properties: List<Property> = ArrayList() var properties = mutableListOf<Property>()
} }
class Property(var name: String?, var value: String?, var signature: String?) class Property(var name: String?, var value: String?, var signature: String?)