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