Add ToSPacket
This commit is contained in:
1 parent
dd01b4fefe
commit
fc550ace27
2 files changed
+57
No files matched your search
@@ -18,6 +18,9 @@ import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketSerializer
|
||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket
|
||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketDeserializer
|
||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketSerializer
|
||||
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacket
|
||||
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketDeserializer
|
||||
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketSerializer
|
||||
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacket
|
||||
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketDeserializer
|
||||
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketSerializer
|
||||
@@ -55,6 +58,7 @@ class LoginServerProtocol() : LoginProtocol() {
|
||||
outgoingPacket(0x08u, MfaChallengePacket::class, MfaChallengePacketSerializer())
|
||||
incomingPacket(0x08u, MfaResponsePacketDeserializer())
|
||||
incomingPacket(0x11u, LoginRequestPacketDeserializer())
|
||||
outgoingPacket(0x14u, ToSPacket::class, ToSPacketSerializer())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +74,7 @@ class LoginClientProtocol() : LoginProtocol() {
|
||||
incomingPacket(0x08u, MfaChallengePacketDeserializer())
|
||||
outgoingPacket(0x08u, MfaResponsePacket::class, MfaResponsePacketSerializer())
|
||||
outgoingPacket(0x11u, LoginRequestPacket::class, LoginRequestPacketSerializer())
|
||||
incomingPacket(0x14u, ToSPacketDeserializer())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package de.fiereu.openmmo.protocols.tls.packets
|
||||
|
||||
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||
import io.netty.buffer.ByteBuf
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
data class ToSPacket(
|
||||
val confirmationKey: Byte,
|
||||
val tosText: String
|
||||
)
|
||||
|
||||
class ToSPacketSerializer : PacketSerializer<ToSPacket> {
|
||||
override fun serialize(packet: ToSPacket, buffer: ByteBuf) {
|
||||
buffer.writeByte(packet.confirmationKey.toInt())
|
||||
|
||||
val compressedText = compressString(packet.tosText)
|
||||
buffer.writeShortLE(compressedText.size)
|
||||
buffer.writeBytes(compressedText)
|
||||
}
|
||||
|
||||
private fun compressString(text: String): ByteArray {
|
||||
val baos = ByteArrayOutputStream()
|
||||
GZIPOutputStream(baos).use { gzipOut ->
|
||||
gzipOut.write(text.toByteArray(StandardCharsets.UTF_8))
|
||||
}
|
||||
return baos.toByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
class ToSPacketDeserializer : PacketDeserializer<ToSPacket> {
|
||||
override fun deserialize(buffer: ByteBuf): ToSPacket {
|
||||
val confirmationKey = buffer.readByte()
|
||||
val tosLength = buffer.readUnsignedShortLE()
|
||||
val compressedTosText = ByteArray(tosLength)
|
||||
buffer.readBytes(compressedTosText)
|
||||
|
||||
val decompressedText = decompressBytes(compressedTosText)
|
||||
return ToSPacket(confirmationKey, decompressedText)
|
||||
}
|
||||
|
||||
private fun decompressBytes(compressed: ByteArray): String {
|
||||
val bais = ByteArrayInputStream(compressed)
|
||||
return GZIPInputStream(bais).use { gzipIn ->
|
||||
String(gzipIn.readAllBytes(), StandardCharsets.UTF_8)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user