Run spotless
This commit is contained in:
1 parent
8c0369be69
commit
f5e18d8540
28 files changed
+317
-362
No files matched your search
@@ -8,7 +8,8 @@ enum class Arch {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(ordinal: Int): Arch {
|
fun from(ordinal: Int): Arch {
|
||||||
return entries.firstOrNull { it.ordinal == ordinal } ?: throw IllegalArgumentException("Unknown arch: $ordinal")
|
return entries.firstOrNull { it.ordinal == ordinal }
|
||||||
|
?: throw IllegalArgumentException("Unknown arch: $ordinal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,8 @@ enum class Bitness {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(ordinal: Int): Bitness {
|
fun from(ordinal: Int): Bitness {
|
||||||
return entries.firstOrNull { it.ordinal == ordinal } ?: throw IllegalArgumentException("Unknown bitness: $ordinal")
|
return entries.firstOrNull { it.ordinal == ordinal }
|
||||||
|
?: throw IllegalArgumentException("Unknown bitness: $ordinal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
package de.fiereu.openmmo.common.enums
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
enum class LoginState(val id: Int) {
|
enum class LoginState(val id: Int) {
|
||||||
AUTHED(0),
|
AUTHED(0),
|
||||||
SYSTEM_ERROR(1),
|
SYSTEM_ERROR(1),
|
||||||
INVALID_PASSWORD(2),
|
INVALID_PASSWORD(2),
|
||||||
AUTHED_HALF(3),
|
AUTHED_HALF(3),
|
||||||
NO_GS_AVAILABLE(6),
|
NO_GS_AVAILABLE(6),
|
||||||
ALREADY_LOGGED_IN(7),
|
ALREADY_LOGGED_IN(7),
|
||||||
SERVER_DOWN(8),
|
SERVER_DOWN(8),
|
||||||
ACCOUNT_ISSUE(9),
|
ACCOUNT_ISSUE(9),
|
||||||
GM_ONLY(16),
|
GM_ONLY(16),
|
||||||
BAN_IP(22),
|
BAN_IP(22),
|
||||||
RATE_LIMITED(23),
|
RATE_LIMITED(23),
|
||||||
ERROR_CONNECTING_AUTH_SERVER(24),
|
ERROR_CONNECTING_AUTH_SERVER(24),
|
||||||
INVALID_TOS_REVSION(25),
|
INVALID_TOS_REVSION(25),
|
||||||
BLOCKLIST_IP(26),
|
BLOCKLIST_IP(26),
|
||||||
ANDROID_ALPHA_PERMISSION(27),
|
ANDROID_ALPHA_PERMISSION(27),
|
||||||
BLOCKLIST_IP_RANGE(28),
|
BLOCKLIST_IP_RANGE(28),
|
||||||
ERROR_CONNECTING_GAME_SERVER(29),
|
ERROR_CONNECTING_GAME_SERVER(29),
|
||||||
INVALID_SAVED_CREDENTIALS(30),
|
INVALID_SAVED_CREDENTIALS(30),
|
||||||
ERROR_CONNECTING_FIREWALL(31),
|
ERROR_CONNECTING_FIREWALL(31),
|
||||||
RATE_LIMITED_2FA(32),
|
RATE_LIMITED_2FA(32),
|
||||||
WRONG_CODE_2FA(33),
|
WRONG_CODE_2FA(33),
|
||||||
CLIENT_OUT_OF_DATE(34),
|
CLIENT_OUT_OF_DATE(34),
|
||||||
EXTRA_VALIDATION_FAILED(35),
|
EXTRA_VALIDATION_FAILED(35),
|
||||||
REQUIRE_QQ_FOR_ACCOUNT(36);
|
REQUIRE_QQ_FOR_ACCOUNT(36)
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
package de.fiereu.openmmo.common.enums
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
enum class Platform {
|
enum class Platform {
|
||||||
WINDOWS,
|
WINDOWS,
|
||||||
LINUX,
|
LINUX,
|
||||||
MACOS,
|
MACOS,
|
||||||
ANDROID,
|
ANDROID,
|
||||||
IOS,
|
IOS,
|
||||||
UNKNOWN;
|
UNKNOWN;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(value: Int): Platform {
|
fun from(value: Int): Platform {
|
||||||
return when (value) {
|
return when (value) {
|
||||||
0x00 -> WINDOWS
|
0x00 -> WINDOWS
|
||||||
0x01 -> LINUX
|
0x01 -> LINUX
|
||||||
0x02 -> MACOS
|
0x02 -> MACOS
|
||||||
0x03 -> IOS
|
0x03 -> IOS
|
||||||
0x04 -> ANDROID
|
0x04 -> ANDROID
|
||||||
else -> UNKNOWN
|
else -> UNKNOWN
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package de.fiereu.openmmo.protocols.game
|
package de.fiereu.openmmo.protocols.game
|
||||||
|
|
||||||
import de.fiereu.openmmo.protocols.Protocol
|
import de.fiereu.openmmo.protocols.Protocol
|
||||||
import de.fiereu.openmmo.protocols.incomingPacket
|
|
||||||
import de.fiereu.openmmo.protocols.outgoingPacket
|
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket
|
import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinPacketDeserializer
|
import de.fiereu.openmmo.protocols.game.packets.JoinPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinPacketSerializer
|
import de.fiereu.openmmo.protocols.game.packets.JoinPacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.incomingPacket
|
||||||
|
import de.fiereu.openmmo.protocols.outgoingPacket
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game Protocol implementation. This protocol handles in-game communication after the TLS handshake is
|
* Game Protocol implementation. This protocol handles in-game communication after the TLS handshake
|
||||||
* complete.
|
* is complete.
|
||||||
*/
|
*/
|
||||||
abstract class GameProtocol : Protocol() {
|
abstract class GameProtocol : Protocol() {
|
||||||
override val async: Boolean
|
override val async: Boolean
|
||||||
|
|||||||
+121
-125
@@ -9,28 +9,22 @@ import de.fiereu.openmmo.protocols.readUtf16LE
|
|||||||
import de.fiereu.openmmo.protocols.writeUtf16LE
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class RomInfo(
|
data class RomInfo(val code: String, val id: Byte, val type: Byte)
|
||||||
val code: String,
|
|
||||||
val id: Byte,
|
|
||||||
val type: Byte
|
|
||||||
)
|
|
||||||
|
|
||||||
abstract class GameAuthenticationData
|
abstract class GameAuthenticationData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when a player reconnects to the game server after a disconnection.
|
* Used when a player reconnects to the game server after a disconnection. This data typically
|
||||||
* This data typically includes the player's unique identifier and a session key
|
* includes the player's unique identifier and a session key that was issued by the login server to
|
||||||
* that was issued by the login server to re-establish the session.
|
* re-establish the session.
|
||||||
*/
|
*/
|
||||||
data class ReconnectAuthData(
|
data class ReconnectAuthData(val playerId: Long, val sessionKey: ByteArray) :
|
||||||
val playerId: Long,
|
GameAuthenticationData()
|
||||||
val sessionKey: ByteArray
|
|
||||||
) : GameAuthenticationData()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when a player is joining the game server for the first time after logging in.
|
* Used when a player is joining the game server for the first time after logging in. This data
|
||||||
* This data typically includes the user's unique identifier and a session key
|
* typically includes the user's unique identifier and a session key that was issued by the login
|
||||||
* that was issued by the login server to authenticate the session.
|
* server to authenticate the session.
|
||||||
*/
|
*/
|
||||||
data class NewAuthData(
|
data class NewAuthData(
|
||||||
val userId: Int,
|
val userId: Int,
|
||||||
@@ -55,123 +49,125 @@ data class JoinGamePacket(
|
|||||||
)
|
)
|
||||||
|
|
||||||
class JoinPacketSerializer : PacketSerializer<JoinGamePacket> {
|
class JoinPacketSerializer : PacketSerializer<JoinGamePacket> {
|
||||||
override fun serialize(packet: JoinGamePacket, buffer: ByteBuf) {
|
override fun serialize(packet: JoinGamePacket, buffer: ByteBuf) {
|
||||||
when (packet.authData) {
|
when (packet.authData) {
|
||||||
is NewAuthData -> {
|
is NewAuthData -> {
|
||||||
buffer.writeByte(0x00)
|
buffer.writeByte(0x00)
|
||||||
buffer.writeIntLE(packet.authData.userId)
|
buffer.writeIntLE(packet.authData.userId)
|
||||||
buffer.writeByte(packet.authData.sessionKey.size)
|
buffer.writeByte(packet.authData.sessionKey.size)
|
||||||
buffer.writeBytes(packet.authData.sessionKey)
|
buffer.writeBytes(packet.authData.sessionKey)
|
||||||
}
|
}
|
||||||
is ReconnectAuthData -> {
|
is ReconnectAuthData -> {
|
||||||
buffer.writeByte(0x01)
|
buffer.writeByte(0x01)
|
||||||
buffer.writeLongLE(packet.authData.playerId)
|
buffer.writeLongLE(packet.authData.playerId)
|
||||||
buffer.writeByte(packet.authData.sessionKey.size)
|
buffer.writeByte(packet.authData.sessionKey.size)
|
||||||
buffer.writeBytes(packet.authData.sessionKey)
|
buffer.writeBytes(packet.authData.sessionKey)
|
||||||
}
|
}
|
||||||
else -> throw IllegalArgumentException("Unsupported authentication data type: ${packet.authData::class.simpleName}")
|
else ->
|
||||||
}
|
throw IllegalArgumentException(
|
||||||
buffer.writeBytes(packet.mac)
|
"Unsupported authentication data type: ${packet.authData::class.simpleName}")
|
||||||
buffer.writeIntLE(packet.clientRevision)
|
|
||||||
buffer.writeIntLE(packet.installationRevision)
|
|
||||||
buffer.writeByte(packet.currentChatLanguage.toInt())
|
|
||||||
buffer.writeShortLE(packet.chatLanguages.toInt())
|
|
||||||
buffer.writeShortLE(packet.matchmakingLanguages.toInt())
|
|
||||||
buffer.writeByte(packet.romMask.toInt())
|
|
||||||
|
|
||||||
buffer.writeByte(packet.roms.size)
|
|
||||||
for (rom in packet.roms) {
|
|
||||||
buffer.writeUtf16LE(rom.code)
|
|
||||||
buffer.writeByte(rom.id.toInt())
|
|
||||||
buffer.writeByte(rom.type.toInt())
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.writeByte(packet.clientInfo.size)
|
|
||||||
for ((key, value) in packet.clientInfo) {
|
|
||||||
buffer.writeByte(key.toInt())
|
|
||||||
buffer.writeUtf16LE(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.writeByte(packet.platform.ordinal)
|
|
||||||
buffer.writeByte(packet.arch.ordinal)
|
|
||||||
buffer.writeByte(packet.bitness.ordinal)
|
|
||||||
|
|
||||||
buffer.writeByte(packet.unk1.size)
|
|
||||||
buffer.writeBytes(packet.unk1)
|
|
||||||
}
|
}
|
||||||
|
buffer.writeBytes(packet.mac)
|
||||||
|
buffer.writeIntLE(packet.clientRevision)
|
||||||
|
buffer.writeIntLE(packet.installationRevision)
|
||||||
|
buffer.writeByte(packet.currentChatLanguage.toInt())
|
||||||
|
buffer.writeShortLE(packet.chatLanguages.toInt())
|
||||||
|
buffer.writeShortLE(packet.matchmakingLanguages.toInt())
|
||||||
|
buffer.writeByte(packet.romMask.toInt())
|
||||||
|
|
||||||
|
buffer.writeByte(packet.roms.size)
|
||||||
|
for (rom in packet.roms) {
|
||||||
|
buffer.writeUtf16LE(rom.code)
|
||||||
|
buffer.writeByte(rom.id.toInt())
|
||||||
|
buffer.writeByte(rom.type.toInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeByte(packet.clientInfo.size)
|
||||||
|
for ((key, value) in packet.clientInfo) {
|
||||||
|
buffer.writeByte(key.toInt())
|
||||||
|
buffer.writeUtf16LE(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeByte(packet.platform.ordinal)
|
||||||
|
buffer.writeByte(packet.arch.ordinal)
|
||||||
|
buffer.writeByte(packet.bitness.ordinal)
|
||||||
|
|
||||||
|
buffer.writeByte(packet.unk1.size)
|
||||||
|
buffer.writeBytes(packet.unk1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JoinPacketDeserializer : PacketDeserializer<JoinGamePacket> {
|
class JoinPacketDeserializer : PacketDeserializer<JoinGamePacket> {
|
||||||
override fun deserialize(buffer: ByteBuf): JoinGamePacket {
|
override fun deserialize(buffer: ByteBuf): JoinGamePacket {
|
||||||
val authOption = buffer.readByte()
|
val authOption = buffer.readByte()
|
||||||
val authenticationData = when (authOption) {
|
val authenticationData =
|
||||||
0x00.toByte() -> {
|
when (authOption) {
|
||||||
val userId = buffer.readIntLE()
|
0x00.toByte() -> {
|
||||||
val sessionKeyLength = buffer.readUnsignedByte().toInt()
|
val userId = buffer.readIntLE()
|
||||||
val sessionKey = ByteArray(sessionKeyLength)
|
val sessionKeyLength = buffer.readUnsignedByte().toInt()
|
||||||
buffer.readBytes(sessionKey)
|
val sessionKey = ByteArray(sessionKeyLength)
|
||||||
NewAuthData(userId, sessionKey)
|
buffer.readBytes(sessionKey)
|
||||||
}
|
NewAuthData(userId, sessionKey)
|
||||||
0x01.toByte() -> {
|
}
|
||||||
val playerId = buffer.readLongLE()
|
0x01.toByte() -> {
|
||||||
val sessionKeyLength = buffer.readUnsignedByte().toInt()
|
val playerId = buffer.readLongLE()
|
||||||
val sessionKey = ByteArray(sessionKeyLength)
|
val sessionKeyLength = buffer.readUnsignedByte().toInt()
|
||||||
buffer.readBytes(sessionKey)
|
val sessionKey = ByteArray(sessionKeyLength)
|
||||||
ReconnectAuthData(playerId, sessionKey)
|
buffer.readBytes(sessionKey)
|
||||||
}
|
ReconnectAuthData(playerId, sessionKey)
|
||||||
else -> throw IllegalArgumentException("Unsupported authentication option: $authOption")
|
}
|
||||||
|
else -> throw IllegalArgumentException("Unsupported authentication option: $authOption")
|
||||||
}
|
}
|
||||||
|
|
||||||
val mac = ByteArray(6)
|
val mac = ByteArray(6)
|
||||||
buffer.readBytes(mac)
|
buffer.readBytes(mac)
|
||||||
|
|
||||||
val clientRevision = buffer.readIntLE()
|
val clientRevision = buffer.readIntLE()
|
||||||
val installationRevision = buffer.readIntLE()
|
val installationRevision = buffer.readIntLE()
|
||||||
val currentChatLanguage = buffer.readByte()
|
val currentChatLanguage = buffer.readByte()
|
||||||
val chatLanguages = buffer.readShortLE()
|
val chatLanguages = buffer.readShortLE()
|
||||||
val ignoreLanguages = buffer.readShortLE()
|
val ignoreLanguages = buffer.readShortLE()
|
||||||
val romMask = buffer.readByte()
|
val romMask = buffer.readByte()
|
||||||
|
|
||||||
val romCount = buffer.readUnsignedByte().toInt()
|
val romCount = buffer.readUnsignedByte().toInt()
|
||||||
val roms = mutableListOf<RomInfo>()
|
val roms = mutableListOf<RomInfo>()
|
||||||
for (i in 0 until romCount) {
|
for (i in 0 until romCount) {
|
||||||
val code = buffer.readUtf16LE()
|
val code = buffer.readUtf16LE()
|
||||||
val id = buffer.readByte()
|
val id = buffer.readByte()
|
||||||
val type = buffer.readByte()
|
val type = buffer.readByte()
|
||||||
roms.add(RomInfo(code, id, type))
|
roms.add(RomInfo(code, id, type))
|
||||||
}
|
|
||||||
|
|
||||||
val clientInfoCount = buffer.readUnsignedByte().toInt()
|
|
||||||
val clientInfo = mutableMapOf<Byte, String>()
|
|
||||||
for (i in 0 until clientInfoCount) {
|
|
||||||
val key = buffer.readByte()
|
|
||||||
val value = buffer.readUtf16LE()
|
|
||||||
clientInfo[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
val platform = Platform.from(buffer.readByte().toInt())
|
|
||||||
val arch = Arch.from(buffer.readByte().toInt())
|
|
||||||
val bitness = Bitness.from(buffer.readByte().toInt())
|
|
||||||
|
|
||||||
val unk1 = buffer.readByte().toInt()
|
|
||||||
val unk2 = ByteArray(unk1)
|
|
||||||
buffer.readBytes(unk2)
|
|
||||||
|
|
||||||
return JoinGamePacket(
|
|
||||||
authenticationData,
|
|
||||||
mac,
|
|
||||||
clientRevision,
|
|
||||||
installationRevision,
|
|
||||||
currentChatLanguage,
|
|
||||||
chatLanguages,
|
|
||||||
ignoreLanguages,
|
|
||||||
romMask,
|
|
||||||
roms,
|
|
||||||
clientInfo,
|
|
||||||
platform,
|
|
||||||
arch,
|
|
||||||
bitness,
|
|
||||||
unk2
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val clientInfoCount = buffer.readUnsignedByte().toInt()
|
||||||
|
val clientInfo = mutableMapOf<Byte, String>()
|
||||||
|
for (i in 0 until clientInfoCount) {
|
||||||
|
val key = buffer.readByte()
|
||||||
|
val value = buffer.readUtf16LE()
|
||||||
|
clientInfo[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
val platform = Platform.from(buffer.readByte().toInt())
|
||||||
|
val arch = Arch.from(buffer.readByte().toInt())
|
||||||
|
val bitness = Bitness.from(buffer.readByte().toInt())
|
||||||
|
|
||||||
|
val unk1 = buffer.readByte().toInt()
|
||||||
|
val unk2 = ByteArray(unk1)
|
||||||
|
buffer.readBytes(unk2)
|
||||||
|
|
||||||
|
return JoinGamePacket(
|
||||||
|
authenticationData,
|
||||||
|
mac,
|
||||||
|
clientRevision,
|
||||||
|
installationRevision,
|
||||||
|
currentChatLanguage,
|
||||||
|
chatLanguages,
|
||||||
|
ignoreLanguages,
|
||||||
|
romMask,
|
||||||
|
roms,
|
||||||
|
clientInfo,
|
||||||
|
platform,
|
||||||
|
arch,
|
||||||
|
bitness,
|
||||||
|
unk2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,45 +3,45 @@ package de.fiereu.openmmo.protocols.tls
|
|||||||
import de.fiereu.openmmo.protocols.Protocol
|
import de.fiereu.openmmo.protocols.Protocol
|
||||||
import de.fiereu.openmmo.protocols.incomingPacket
|
import de.fiereu.openmmo.protocols.incomingPacket
|
||||||
import de.fiereu.openmmo.protocols.outgoingPacket
|
import de.fiereu.openmmo.protocols.outgoingPacket
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.ExistingSessionPacket
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacket
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacket
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket
|
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacket
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket
|
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacket
|
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketSerializer
|
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.GameServerListPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketDeserializer
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketSerializer
|
|
||||||
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
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketDeserializer
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketSerializer
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacket
|
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacket
|
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketSerializer
|
||||||
|
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.SentCredentialsPacket
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketSerializer
|
||||||
|
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.ToSPacket
|
import de.fiereu.openmmo.protocols.tls.packets.ToSPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ExistingSessionPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketDeserializer
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketSerializer
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login Protocol implementation. This protocol handles the login process after the TLS handshake is
|
* Login Protocol implementation. This protocol handles the login process after the TLS handshake is
|
||||||
@@ -73,7 +73,8 @@ class LoginServerProtocol() : LoginProtocol() {
|
|||||||
class LoginClientProtocol() : LoginProtocol() {
|
class LoginClientProtocol() : LoginProtocol() {
|
||||||
init {
|
init {
|
||||||
incomingPacket(0x01u, LoginResponsePacketDeserializer())
|
incomingPacket(0x01u, LoginResponsePacketDeserializer())
|
||||||
outgoingPacket(0x02u, RequestGameServerListPacketSerializer(), RequestGameServerListPacket::class)
|
outgoingPacket(
|
||||||
|
0x02u, RequestGameServerListPacketSerializer(), RequestGameServerListPacket::class)
|
||||||
outgoingPacket(0x03u, JoinGameServerPacketSerializer(), JoinGameServerPacket::class)
|
outgoingPacket(0x03u, JoinGameServerPacketSerializer(), JoinGameServerPacket::class)
|
||||||
incomingPacket(0x03u, GameServerNodesPacketDeserializer())
|
incomingPacket(0x03u, GameServerNodesPacketDeserializer())
|
||||||
outgoingPacket(0x04u, ToSConfirmationPacketSerializer(), ToSConfirmationPacket::class)
|
outgoingPacket(0x04u, ToSConfirmationPacketSerializer(), ToSConfirmationPacket::class)
|
||||||
|
|||||||
+6
-6
@@ -4,16 +4,16 @@ import com.github.maltalex.ineter.base.IPv4Address
|
|||||||
import com.github.maltalex.ineter.base.IPv6Address
|
import com.github.maltalex.ineter.base.IPv6Address
|
||||||
import de.fiereu.openmmo.protocols.PacketDeserializer
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.PacketSerializer
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.readUtf16LE
|
|
||||||
import de.fiereu.openmmo.protocols.writeUtf16LE
|
|
||||||
import de.fiereu.openmmo.protocols.writeIpLE
|
|
||||||
import de.fiereu.openmmo.protocols.readIpLE
|
import de.fiereu.openmmo.protocols.readIpLE
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeIpLE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class ExistingSessionPacket(
|
data class ExistingSessionPacket(
|
||||||
val sessionId: Long,
|
val sessionId: Long,
|
||||||
val sessionKey: ByteArray,
|
val sessionKey: ByteArray,
|
||||||
val serverName: String
|
val serverName: String
|
||||||
) {
|
) {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
|
|||||||
+6
-8
@@ -7,16 +7,14 @@ import de.fiereu.openmmo.protocols.writeUtf16LE
|
|||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class GameServer(
|
data class GameServer(
|
||||||
val id: UByte,
|
val id: UByte,
|
||||||
val name: String,
|
val name: String,
|
||||||
val currentPlayers: UShort = 0u,
|
val currentPlayers: UShort = 0u,
|
||||||
val maxPlayers: UShort = 0u,
|
val maxPlayers: UShort = 0u,
|
||||||
val joinable: Boolean
|
val joinable: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
data class GameServerListPacket(
|
data class GameServerListPacket(val gameServers: List<GameServer>)
|
||||||
val gameServers: List<GameServer>
|
|
||||||
)
|
|
||||||
|
|
||||||
class GameServerListPacketSerializer : PacketSerializer<GameServerListPacket> {
|
class GameServerListPacketSerializer : PacketSerializer<GameServerListPacket> {
|
||||||
override fun serialize(packet: GameServerListPacket, buffer: ByteBuf) {
|
override fun serialize(packet: GameServerListPacket, buffer: ByteBuf) {
|
||||||
|
|||||||
+21
-30
@@ -13,32 +13,31 @@ import de.fiereu.openmmo.protocols.writeUtf16LE
|
|||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nodes are address entries for game servers that the client can connect to.
|
* Nodes are address entries for game servers that the client can connect to. The nodes are selected
|
||||||
* The nodes are selected by a weighted random algorithm on the client side.
|
* by a weighted random algorithm on the client side. The weight is a value between 0 and 255, where
|
||||||
* The weight is a value between 0 and 255, where 0 means the node
|
* 0 means the node will never be selected and 255 means the node will always be selected.
|
||||||
* will never be selected and 255 means the node will always be selected.
|
|
||||||
* Typically, nodes are assigned weights based on their capacity or priority.
|
* Typically, nodes are assigned weights based on their capacity or priority.
|
||||||
*/
|
*/
|
||||||
data class GameServerNode(
|
data class GameServerNode(
|
||||||
val iPv4Address: IPv4Address,
|
val iPv4Address: IPv4Address,
|
||||||
val iPv6Address: IPv6Address,
|
val iPv6Address: IPv6Address,
|
||||||
val port: UShort = 7777u,
|
val port: UShort = 7777u,
|
||||||
val weight: UByte
|
val weight: UByte
|
||||||
)
|
)
|
||||||
|
|
||||||
data class GameServerData(
|
data class GameServerData(
|
||||||
val gameServerId: UByte,
|
val gameServerId: UByte,
|
||||||
val userId: Int,
|
val userId: Int,
|
||||||
val sessionToken: ByteArray,
|
val sessionToken: ByteArray,
|
||||||
val localAddress: IPAddress,
|
val localAddress: IPAddress,
|
||||||
val localHostname: String,
|
val localHostname: String,
|
||||||
val port: UShort,
|
val port: UShort,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class GameServerNodesPacket(
|
data class GameServerNodesPacket(
|
||||||
val loginState: LoginState,
|
val loginState: LoginState,
|
||||||
val gameServerData: GameServerData? = null,
|
val gameServerData: GameServerData? = null,
|
||||||
val nodes: List<GameServerNode> = emptyList()
|
val nodes: List<GameServerNode> = emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
class GameServerNodesPacketSerializer : PacketSerializer<GameServerNodesPacket> {
|
class GameServerNodesPacketSerializer : PacketSerializer<GameServerNodesPacket> {
|
||||||
@@ -48,7 +47,8 @@ class GameServerNodesPacketSerializer : PacketSerializer<GameServerNodesPacket>
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val gsd = requireNotNull(packet.gameServerData) { "GameServerData must be provided for AUTHED state" }
|
val gsd =
|
||||||
|
requireNotNull(packet.gameServerData) { "GameServerData must be provided for AUTHED state" }
|
||||||
|
|
||||||
buffer.writeIntLE(gsd.userId)
|
buffer.writeIntLE(gsd.userId)
|
||||||
buffer.writeByte(gsd.sessionToken.size)
|
buffer.writeByte(gsd.sessionToken.size)
|
||||||
@@ -115,17 +115,8 @@ class GameServerNodesPacketDeserializer : PacketDeserializer<GameServerNodesPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
return GameServerNodesPacket(
|
return GameServerNodesPacket(
|
||||||
LoginState.AUTHED,
|
LoginState.AUTHED,
|
||||||
GameServerData(
|
GameServerData(gameServerId, userId, sessionToken, localAddress, localHostname, port),
|
||||||
gameServerId,
|
nodes)
|
||||||
userId,
|
|
||||||
sessionToken,
|
|
||||||
localAddress,
|
|
||||||
localHostname,
|
|
||||||
port
|
|
||||||
),
|
|
||||||
nodes
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-3
@@ -4,9 +4,7 @@ import de.fiereu.openmmo.protocols.PacketDeserializer
|
|||||||
import de.fiereu.openmmo.protocols.PacketSerializer
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class JoinGameServerPacket(
|
data class JoinGameServerPacket(val gameServerId: UByte)
|
||||||
val gameServerId: UByte
|
|
||||||
)
|
|
||||||
|
|
||||||
class JoinGameServerPacketSerializer : PacketSerializer<JoinGameServerPacket> {
|
class JoinGameServerPacketSerializer : PacketSerializer<JoinGameServerPacket> {
|
||||||
override fun serialize(packet: JoinGameServerPacket, buffer: ByteBuf) {
|
override fun serialize(packet: JoinGameServerPacket, buffer: ByteBuf) {
|
||||||
|
|||||||
+7
-8
@@ -3,10 +3,10 @@ package de.fiereu.openmmo.protocols.tls.packets
|
|||||||
import com.github.maltalex.ineter.base.IPv4Address
|
import com.github.maltalex.ineter.base.IPv4Address
|
||||||
import de.fiereu.openmmo.protocols.PacketDeserializer
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.PacketSerializer
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.readUtf16LE
|
|
||||||
import de.fiereu.openmmo.protocols.writeUtf16LE
|
|
||||||
import de.fiereu.openmmo.protocols.writeIpRangeLE
|
|
||||||
import de.fiereu.openmmo.protocols.readIpRangeLE
|
import de.fiereu.openmmo.protocols.readIpRangeLE
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeIpRangeLE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
// TODO needs proper investigation and implementation
|
// TODO needs proper investigation and implementation
|
||||||
@@ -17,9 +17,7 @@ enum class KickReason {
|
|||||||
C
|
C
|
||||||
}
|
}
|
||||||
|
|
||||||
data class LoginKickPacket(
|
data class LoginKickPacket(val reason: KickReason?)
|
||||||
val reason: KickReason?
|
|
||||||
)
|
|
||||||
|
|
||||||
class LoginKickPacketSerializer : PacketSerializer<LoginKickPacket> {
|
class LoginKickPacketSerializer : PacketSerializer<LoginKickPacket> {
|
||||||
override fun serialize(packet: LoginKickPacket, buffer: ByteBuf) {
|
override fun serialize(packet: LoginKickPacket, buffer: ByteBuf) {
|
||||||
@@ -68,8 +66,9 @@ class LoginKickPacketDeserializer : PacketDeserializer<LoginKickPacket> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val reasonOrdinal = buffer.readUnsignedByte().toInt()
|
val reasonOrdinal = buffer.readUnsignedByte().toInt()
|
||||||
val reason = KickReason.entries.getOrNull(reasonOrdinal)
|
val reason =
|
||||||
?: throw IllegalArgumentException("Unknown kick reason: $reasonOrdinal")
|
KickReason.entries.getOrNull(reasonOrdinal)
|
||||||
|
?: throw IllegalArgumentException("Unknown kick reason: $reasonOrdinal")
|
||||||
|
|
||||||
when (reason) {
|
when (reason) {
|
||||||
KickReason.A -> {
|
KickReason.A -> {
|
||||||
|
|||||||
+5
-6
@@ -8,10 +8,7 @@ import de.fiereu.openmmo.protocols.writeUtf16LE
|
|||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
data class LoginResponsePacket(
|
data class LoginResponsePacket(val state: LoginState, val ratelimitEnd: LocalDateTime?) {
|
||||||
val state: LoginState,
|
|
||||||
val ratelimitEnd: LocalDateTime?
|
|
||||||
) {
|
|
||||||
constructor(state: LoginState) : this(state, null)
|
constructor(state: LoginState) : this(state, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,8 +16,10 @@ class LoginResponsePacketSerializer : PacketSerializer<LoginResponsePacket> {
|
|||||||
override fun serialize(packet: LoginResponsePacket, buffer: ByteBuf) {
|
override fun serialize(packet: LoginResponsePacket, buffer: ByteBuf) {
|
||||||
buffer.writeByte(packet.state.id)
|
buffer.writeByte(packet.state.id)
|
||||||
if (packet.state == LoginState.RATE_LIMITED || packet.state == LoginState.RATE_LIMITED_2FA) {
|
if (packet.state == LoginState.RATE_LIMITED || packet.state == LoginState.RATE_LIMITED_2FA) {
|
||||||
val epochSeconds = packet.ratelimitEnd?.toEpochSecond(java.time.ZoneOffset.UTC)
|
val epochSeconds =
|
||||||
?: throw IllegalArgumentException("ratelimitEnd must be provided for RATE_LIMITED states")
|
packet.ratelimitEnd?.toEpochSecond(java.time.ZoneOffset.UTC)
|
||||||
|
?: throw IllegalArgumentException(
|
||||||
|
"ratelimitEnd must be provided for RATE_LIMITED states")
|
||||||
buffer.writeLongLE(epochSeconds)
|
buffer.writeLongLE(epochSeconds)
|
||||||
}
|
}
|
||||||
if (packet.state == LoginState.AUTHED) {
|
if (packet.state == LoginState.AUTHED) {
|
||||||
|
|||||||
+1
-4
@@ -6,10 +6,7 @@ import de.fiereu.openmmo.protocols.readUtf16LE
|
|||||||
import de.fiereu.openmmo.protocols.writeUtf16LE
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class MfaChallengePacket(
|
data class MfaChallengePacket(val unk: Byte, val email: String)
|
||||||
val unk: Byte,
|
|
||||||
val email: String
|
|
||||||
)
|
|
||||||
|
|
||||||
class MfaChallengePacketSerializer : PacketSerializer<MfaChallengePacket> {
|
class MfaChallengePacketSerializer : PacketSerializer<MfaChallengePacket> {
|
||||||
override fun serialize(packet: MfaChallengePacket, buffer: ByteBuf) {
|
override fun serialize(packet: MfaChallengePacket, buffer: ByteBuf) {
|
||||||
|
|||||||
+1
-3
@@ -6,9 +6,7 @@ import de.fiereu.openmmo.protocols.readUtf16LE
|
|||||||
import de.fiereu.openmmo.protocols.writeUtf16LE
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class MfaResponsePacket(
|
data class MfaResponsePacket(val mfaCode: String)
|
||||||
val mfaCode: String
|
|
||||||
)
|
|
||||||
|
|
||||||
class MfaResponsePacketSerializer : PacketSerializer<MfaResponsePacket> {
|
class MfaResponsePacketSerializer : PacketSerializer<MfaResponsePacket> {
|
||||||
override fun serialize(packet: MfaResponsePacket, buffer: ByteBuf) {
|
override fun serialize(packet: MfaResponsePacket, buffer: ByteBuf) {
|
||||||
|
|||||||
+12
-13
@@ -8,27 +8,26 @@ import io.netty.buffer.ByteBuf
|
|||||||
import java.util.Base64
|
import java.util.Base64
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This packet is sent to the Client to give it the credentials for a user.
|
* This packet is sent to the Client to give it the credentials for a user. These credentials are
|
||||||
* These credentials are used so no password is stored on the User PC and the Client can
|
* used so no password is stored on the User PC and the Client can automatically log in the user
|
||||||
* automatically log in the user without asking for a password.
|
* without asking for a password.
|
||||||
*/
|
*/
|
||||||
data class SentCredentialsPacket(
|
data class SentCredentialsPacket(val username: String, val key: String) {
|
||||||
val username: String,
|
|
||||||
val key: String
|
|
||||||
) {
|
|
||||||
/**
|
/**
|
||||||
* Constructor for when a key is provided.
|
* Constructor for when a key is provided.
|
||||||
|
*
|
||||||
* @param username the username of the user whose credentials we want to send.
|
* @param username the username of the user whose credentials we want to send.
|
||||||
* @param keyBytes the key for the user as a byte array.
|
* @param keyBytes the key for the user as a byte array.
|
||||||
*/
|
*/
|
||||||
constructor(username: String, keyBytes: ByteArray?) : this(
|
constructor(
|
||||||
username,
|
username: String,
|
||||||
keyBytes?.let { Base64.getEncoder().encodeToString(it) } ?: ""
|
keyBytes: ByteArray?
|
||||||
)
|
) : this(username, keyBytes?.let { Base64.getEncoder().encodeToString(it) } ?: "")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for when no key is provided.
|
* Constructor for when no key is provided. The Client will remove the credentials for this user
|
||||||
* The Client will remove the credentials for this user from its credential list.
|
* from its credential list.
|
||||||
|
*
|
||||||
* @param username the username of the user whose credentials we want to remove.
|
* @param username the username of the user whose credentials we want to remove.
|
||||||
*/
|
*/
|
||||||
constructor(username: String) : this(username, "")
|
constructor(username: String) : this(username, "")
|
||||||
|
|||||||
+1
-3
@@ -4,9 +4,7 @@ import de.fiereu.openmmo.protocols.PacketDeserializer
|
|||||||
import de.fiereu.openmmo.protocols.PacketSerializer
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
data class ToSConfirmationPacket(
|
data class ToSConfirmationPacket(val confirmationKey: Byte)
|
||||||
val confirmationKey: Byte
|
|
||||||
)
|
|
||||||
|
|
||||||
class ToSConfirmationPacketSerializer : PacketSerializer<ToSConfirmationPacket> {
|
class ToSConfirmationPacketSerializer : PacketSerializer<ToSConfirmationPacket> {
|
||||||
override fun serialize(packet: ToSConfirmationPacket, buffer: ByteBuf) {
|
override fun serialize(packet: ToSConfirmationPacket, buffer: ByteBuf) {
|
||||||
|
|||||||
@@ -3,16 +3,13 @@ package de.fiereu.openmmo.protocols.tls.packets
|
|||||||
import de.fiereu.openmmo.protocols.PacketDeserializer
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.PacketSerializer
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
import java.util.zip.GZIPOutputStream
|
import java.util.zip.GZIPOutputStream
|
||||||
|
|
||||||
data class ToSPacket(
|
data class ToSPacket(val confirmationKey: Byte, val tosText: String)
|
||||||
val confirmationKey: Byte,
|
|
||||||
val tosText: String
|
|
||||||
)
|
|
||||||
|
|
||||||
class ToSPacketSerializer : PacketSerializer<ToSPacket> {
|
class ToSPacketSerializer : PacketSerializer<ToSPacket> {
|
||||||
override fun serialize(packet: ToSPacket, buffer: ByteBuf) {
|
override fun serialize(packet: ToSPacket, buffer: ByteBuf) {
|
||||||
|
|||||||
+5
-5
@@ -17,11 +17,11 @@ class GameServerListPacketBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addServer(
|
fun addServer(
|
||||||
id: UByte,
|
id: UByte,
|
||||||
name: String,
|
name: String,
|
||||||
currentPlayers: UShort = 0u,
|
currentPlayers: UShort = 0u,
|
||||||
maxPlayers: UShort = 0u,
|
maxPlayers: UShort = 0u,
|
||||||
joinable: Boolean = true
|
joinable: Boolean = true
|
||||||
): GameServerListPacketBuilder {
|
): GameServerListPacketBuilder {
|
||||||
servers.add(GameServer(id, name, currentPlayers, maxPlayers, joinable))
|
servers.add(GameServer(id, name, currentPlayers, maxPlayers, joinable))
|
||||||
return this
|
return this
|
||||||
|
|||||||
+11
-20
@@ -14,30 +14,27 @@ class GameServerNodesPacketBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun forAuthedUser(
|
fun forAuthedUser(
|
||||||
userId: Int,
|
userId: Int,
|
||||||
sessionToken: ByteArray,
|
sessionToken: ByteArray,
|
||||||
gameServerId: UByte
|
gameServerId: UByte
|
||||||
): AuthedPacketBuilder {
|
): AuthedPacketBuilder {
|
||||||
return AuthedPacketBuilder(userId, sessionToken, gameServerId)
|
return AuthedPacketBuilder(userId, sessionToken, gameServerId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthedPacketBuilder internal constructor(
|
class AuthedPacketBuilder
|
||||||
private val userId: Int,
|
internal constructor(
|
||||||
private val sessionToken: ByteArray,
|
private val userId: Int,
|
||||||
private val gameServerId: UByte
|
private val sessionToken: ByteArray,
|
||||||
|
private val gameServerId: UByte
|
||||||
) {
|
) {
|
||||||
private var localAddress: IPAddress? = null
|
private var localAddress: IPAddress? = null
|
||||||
private var localHostname: String? = null
|
private var localHostname: String? = null
|
||||||
private var port: UShort? = null
|
private var port: UShort? = null
|
||||||
private var nodes: List<GameServerNode> = emptyList()
|
private var nodes: List<GameServerNode> = emptyList()
|
||||||
|
|
||||||
fun withLocalEndpoint(
|
fun withLocalEndpoint(address: IPAddress, hostname: String, port: UShort): AuthedPacketBuilder {
|
||||||
address: IPAddress,
|
|
||||||
hostname: String,
|
|
||||||
port: UShort
|
|
||||||
): AuthedPacketBuilder {
|
|
||||||
this.localAddress = address
|
this.localAddress = address
|
||||||
this.localHostname = hostname
|
this.localHostname = hostname
|
||||||
this.port = port
|
this.port = port
|
||||||
@@ -54,14 +51,8 @@ class AuthedPacketBuilder internal constructor(
|
|||||||
requireNotNull(localHostname) { "Local hostname must be set for AUTHED packets" }
|
requireNotNull(localHostname) { "Local hostname must be set for AUTHED packets" }
|
||||||
requireNotNull(port) { "Port must be set for AUTHED packets" }
|
requireNotNull(port) { "Port must be set for AUTHED packets" }
|
||||||
|
|
||||||
val gameServerData = GameServerData(
|
val gameServerData =
|
||||||
gameServerId,
|
GameServerData(gameServerId, userId, sessionToken, localAddress!!, localHostname!!, port!!)
|
||||||
userId,
|
|
||||||
sessionToken,
|
|
||||||
localAddress!!,
|
|
||||||
localHostname!!,
|
|
||||||
port!!
|
|
||||||
)
|
|
||||||
|
|
||||||
return GameServerNodesPacket(LoginState.AUTHED, gameServerData, nodes)
|
return GameServerNodesPacket(LoginState.AUTHED, gameServerData, nodes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ class TlsServerProtocol(serverKeyPair: Pair<ECPrivateKey, ECPublicKey>) : TlsPro
|
|||||||
init {
|
init {
|
||||||
incomingPacket(0x00u, ClientHelloPacketDeserializer())
|
incomingPacket(0x00u, ClientHelloPacketDeserializer())
|
||||||
outgoingPacket(
|
outgoingPacket(
|
||||||
0x01u, ServerHelloPacketSerializer(serverKeyPair.first), ServerHelloPacket::class
|
0x01u, ServerHelloPacketSerializer(serverKeyPair.first), ServerHelloPacket::class)
|
||||||
)
|
|
||||||
incomingPacket(0x02u, ClientReadyPacketDeserializer())
|
incomingPacket(0x02u, ClientReadyPacketDeserializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package de.fiereu.openmmo.protocols
|
|||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.jvm.jvmErasure
|
|
||||||
|
|
||||||
/** Value class wrapping a UByte to represent an opcode. */
|
/** Value class wrapping a UByte to represent an opcode. */
|
||||||
@JvmInline
|
@JvmInline
|
||||||
|
|||||||
@@ -30,13 +30,12 @@ dependencies {
|
|||||||
|
|
||||||
application { mainClass.set("de.fiereu.openmmo.server.game.GameServerKt") }
|
application { mainClass.set("de.fiereu.openmmo.server.game.GameServerKt") }
|
||||||
|
|
||||||
|
|
||||||
fun env(key: String): Any {
|
fun env(key: String): Any {
|
||||||
val value =
|
val value =
|
||||||
property(key)
|
property(key)
|
||||||
?: System.getenv(key)
|
?: System.getenv(key)
|
||||||
?: throw IllegalArgumentException(
|
?: throw IllegalArgumentException(
|
||||||
"Environment variable or system property '$key' is not set.")
|
"Environment variable or system property '$key' is not set.")
|
||||||
fun interpolate(value: String): Any {
|
fun interpolate(value: String): Any {
|
||||||
val PATTERN_WORD = Regex("\\$([a-zA-Z0-9_]+)")
|
val PATTERN_WORD = Regex("\\$([a-zA-Z0-9_]+)")
|
||||||
val PATTERN_MULTI = Regex("\\$\\{([a-zA-Z0-9_]+)\\}")
|
val PATTERN_MULTI = Regex("\\$\\{([a-zA-Z0-9_]+)\\}")
|
||||||
@@ -47,7 +46,7 @@ fun env(key: String): Any {
|
|||||||
val envValue = System.getProperty(envName) ?: System.getProperty(envName)
|
val envValue = System.getProperty(envName) ?: System.getProperty(envName)
|
||||||
if (envValue == null) {
|
if (envValue == null) {
|
||||||
throw IllegalArgumentException(
|
throw IllegalArgumentException(
|
||||||
"Environment variable or system property '$envName' is not set.")
|
"Environment variable or system property '$envName' is not set.")
|
||||||
}
|
}
|
||||||
acc.replace(match.value, envValue)
|
acc.replace(match.value, envValue)
|
||||||
}
|
}
|
||||||
@@ -75,7 +74,7 @@ jooq {
|
|||||||
name = "org.jooq.meta.postgres.PostgresDatabase"
|
name = "org.jooq.meta.postgres.PostgresDatabase"
|
||||||
includes = ".*"
|
includes = ".*"
|
||||||
excludes =
|
excludes =
|
||||||
"""
|
"""
|
||||||
flyway_schema_history |
|
flyway_schema_history |
|
||||||
pgp_armor_headers
|
pgp_armor_headers
|
||||||
"""
|
"""
|
||||||
@@ -116,9 +115,9 @@ tasks.register("cleanMigrateAndGenerate") {
|
|||||||
spotless { kotlin { targetExclude("src/main/jooq/**") } }
|
spotless { kotlin { targetExclude("src/main/jooq/**") } }
|
||||||
|
|
||||||
// If someone knows a better way then this please please please help me :(
|
// If someone knows a better way then this please please please help me :(
|
||||||
listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc").forEach { taskName ->
|
listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc")
|
||||||
tasks.named(taskName) {
|
.forEach { taskName ->
|
||||||
listOf("copyPublicKeyGame", "copyPrivateKeyGame")
|
tasks.named(taskName) {
|
||||||
.forEach { dependsOn(it) }
|
listOf("copyPublicKeyGame", "copyPrivateKeyGame").forEach { dependsOn(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-1
@@ -32,7 +32,9 @@ class GameProtocolHandler(
|
|||||||
|
|
||||||
fun onJoinGame(event: PacketEvent<JoinGamePacket>) {
|
fun onJoinGame(event: PacketEvent<JoinGamePacket>) {
|
||||||
log.info { "Player joined the game." }
|
log.info { "Player joined the game." }
|
||||||
log.debug { "This is what the Game knows about you:\n${event.packet.clientInfo.values.joinToString("\n")}" }
|
log.debug {
|
||||||
|
"This is what the Game knows about you:\n${event.packet.clientInfo.values.joinToString("\n")}"
|
||||||
|
}
|
||||||
// TODO handle player joining the game
|
// TODO handle player joining the game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,10 +123,9 @@ tasks.register("cleanMigrateAndGenerate") {
|
|||||||
spotless { kotlin { targetExclude("src/main/jooq/**") } }
|
spotless { kotlin { targetExclude("src/main/jooq/**") } }
|
||||||
|
|
||||||
// If someone knows a better way then this please please please help me :(
|
// If someone knows a better way then this please please please help me :(
|
||||||
listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc").forEach { taskName ->
|
listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc")
|
||||||
tasks.named(taskName) {
|
.forEach { taskName ->
|
||||||
listOf("copyPublicKeyGame", "copyPrivateKeyGame")
|
tasks.named(taskName) {
|
||||||
.forEach { dependsOn(it) }
|
listOf("copyPublicKeyGame", "copyPrivateKeyGame").forEach { dependsOn(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+21
-25
@@ -10,10 +10,10 @@ import de.fiereu.openmmo.protocols.tls.packets.GameServerNode
|
|||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket
|
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket
|
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket
|
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket
|
||||||
import de.fiereu.openmmo.server.login.protocol.login.ext.respondTo
|
|
||||||
import de.fiereu.openmmo.server.login.protocol.login.ext.respondForAuthedUser
|
import de.fiereu.openmmo.server.login.protocol.login.ext.respondForAuthedUser
|
||||||
import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithState
|
import de.fiereu.openmmo.server.login.protocol.login.ext.respondTo
|
||||||
import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithServers
|
import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithServers
|
||||||
|
import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithState
|
||||||
import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler
|
import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler
|
||||||
import de.fiereu.openmmo.server.protocol.PacketEvent
|
import de.fiereu.openmmo.server.protocol.PacketEvent
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
@@ -37,7 +37,8 @@ class LoginProtocolHandler(
|
|||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
when (event.packet) {
|
when (event.packet) {
|
||||||
is LoginRequestPacket -> onLoginRequest(event as PacketEvent<LoginRequestPacket>)
|
is LoginRequestPacket -> onLoginRequest(event as PacketEvent<LoginRequestPacket>)
|
||||||
is RequestGameServerListPacket -> onGameServerListRequest(event as PacketEvent<RequestGameServerListPacket>)
|
is RequestGameServerListPacket ->
|
||||||
|
onGameServerListRequest(event as PacketEvent<RequestGameServerListPacket>)
|
||||||
is JoinGameServerPacket -> onServerSelection(event as PacketEvent<JoinGameServerPacket>)
|
is JoinGameServerPacket -> onServerSelection(event as PacketEvent<JoinGameServerPacket>)
|
||||||
else -> log.warn { "Unhandled login packet type: ${event.packet::class.simpleName}" }
|
else -> log.warn { "Unhandled login packet type: ${event.packet::class.simpleName}" }
|
||||||
}
|
}
|
||||||
@@ -53,32 +54,27 @@ class LoginProtocolHandler(
|
|||||||
fun onGameServerListRequest(event: PacketEvent<RequestGameServerListPacket>) {
|
fun onGameServerListRequest(event: PacketEvent<RequestGameServerListPacket>) {
|
||||||
log.info { "Received game server list request" }
|
log.info { "Received game server list request" }
|
||||||
// TODO replace hardcoded server list with actual server list from database or config
|
// TODO replace hardcoded server list with actual server list from database or config
|
||||||
event.respondWithServers(listOf(
|
event.respondWithServers(listOf(GameServer(0x00u, "OpenMMO", 0u, 1u, true)))
|
||||||
GameServer(0x00u, "OpenMMO", 0u, 1u, true)
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onServerSelection(event: PacketEvent<JoinGameServerPacket>) {
|
fun onServerSelection(event: PacketEvent<JoinGameServerPacket>) {
|
||||||
log.info { "Received server selection for server id ${event.packet.gameServerId}" }
|
log.info { "Received server selection for server id ${event.packet.gameServerId}" }
|
||||||
// TODO proper server node selection handling (depends on onGameServerListRequest implementation)
|
// TODO proper server node selection handling (depends on onGameServerListRequest
|
||||||
|
// implementation)
|
||||||
// Example refuse connection: event.respondWithState(LoginState.INVALID_PASSWORD)
|
// Example refuse connection: event.respondWithState(LoginState.INVALID_PASSWORD)
|
||||||
event.respondForAuthedUser(
|
event
|
||||||
userId = 1,
|
.respondForAuthedUser(userId = 1, sessionToken = ByteArray(16) { 0x42 })
|
||||||
sessionToken = ByteArray(16) { 0x42 }
|
.withLocalEndpoint(
|
||||||
)
|
address = IPAddress.of("127.0.0.1"), hostname = "localhost", port = 7777u)
|
||||||
.withLocalEndpoint(
|
.withNodes(
|
||||||
address = IPAddress.of("127.0.0.1"),
|
listOf(
|
||||||
hostname = "localhost",
|
GameServerNode(
|
||||||
port = 7777u
|
iPv4Address = IPv4Address.of("127.0.0.1"),
|
||||||
)
|
iPv6Address = IPv6Address.of("::1"),
|
||||||
.withNodes(listOf(
|
port = 7777u,
|
||||||
GameServerNode(
|
weight =
|
||||||
iPv4Address = IPv4Address.of("127.0.0.1"),
|
0x01u // Always select this node (only one node available in this example)
|
||||||
iPv6Address = IPv6Address.of("::1"),
|
)))
|
||||||
port = 7777u,
|
.respondTo(event)
|
||||||
weight = 0x01u // Always select this node (only one node available in this example)
|
|
||||||
)
|
|
||||||
))
|
|
||||||
.respondTo(event)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-6
@@ -12,14 +12,11 @@ fun PacketEvent<JoinGameServerPacket>.respondWithErrorState(state: LoginState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PacketEvent<JoinGameServerPacket>.respondForAuthedUser(
|
fun PacketEvent<JoinGameServerPacket>.respondForAuthedUser(
|
||||||
userId: Int,
|
userId: Int,
|
||||||
sessionToken: ByteArray
|
sessionToken: ByteArray
|
||||||
): AuthedPacketBuilder {
|
): AuthedPacketBuilder {
|
||||||
return GameServerNodesPacketBuilder.forAuthedUser(
|
return GameServerNodesPacketBuilder.forAuthedUser(
|
||||||
userId = userId,
|
userId = userId, sessionToken = sessionToken, gameServerId = this.packet.gameServerId)
|
||||||
sessionToken = sessionToken,
|
|
||||||
gameServerId = this.packet.gameServerId
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun AuthedPacketBuilder.respondTo(event: PacketEvent<*>) {
|
fun AuthedPacketBuilder.respondTo(event: PacketEvent<*>) {
|
||||||
|
|||||||
+2
-2
@@ -12,8 +12,8 @@ fun PacketEvent<LoginRequestPacket>.respondWithState(state: LoginState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PacketEvent<LoginRequestPacket>.respondWithRateLimit(
|
fun PacketEvent<LoginRequestPacket>.respondWithRateLimit(
|
||||||
state: LoginState,
|
state: LoginState,
|
||||||
ratelimitEnd: LocalDateTime
|
ratelimitEnd: LocalDateTime
|
||||||
) {
|
) {
|
||||||
this.respond(LoginResponsePacketBuilder.withRateLimit(state, ratelimitEnd))
|
this.respond(LoginResponsePacketBuilder.withRateLimit(state, ratelimitEnd))
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user