Run spotless
This commit is contained in:
1 parent
8c0369be69
commit
f5e18d8540
25 files changed
+117
-162
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,5 @@ enum class LoginState(val id: Int) {
|
||||
WRONG_CODE_2FA(33),
|
||||
CLIENT_OUT_OF_DATE(34),
|
||||
EXTRA_VALIDATION_FAILED(35),
|
||||
REQUIRE_QQ_FOR_ACCOUNT(36);
|
||||
REQUIRE_QQ_FOR_ACCOUNT(36)
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+15
-19
@@ -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,
|
||||
@@ -69,7 +63,9 @@ class JoinPacketSerializer : PacketSerializer<JoinGamePacket> {
|
||||
buffer.writeByte(packet.authData.sessionKey.size)
|
||||
buffer.writeBytes(packet.authData.sessionKey)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unsupported authentication data type: ${packet.authData::class.simpleName}")
|
||||
else ->
|
||||
throw IllegalArgumentException(
|
||||
"Unsupported authentication data type: ${packet.authData::class.simpleName}")
|
||||
}
|
||||
buffer.writeBytes(packet.mac)
|
||||
buffer.writeIntLE(packet.clientRevision)
|
||||
@@ -104,7 +100,8 @@ class JoinPacketSerializer : PacketSerializer<JoinGamePacket> {
|
||||
class JoinPacketDeserializer : PacketDeserializer<JoinGamePacket> {
|
||||
override fun deserialize(buffer: ByteBuf): JoinGamePacket {
|
||||
val authOption = buffer.readByte()
|
||||
val authenticationData = when (authOption) {
|
||||
val authenticationData =
|
||||
when (authOption) {
|
||||
0x00.toByte() -> {
|
||||
val userId = buffer.readIntLE()
|
||||
val sessionKeyLength = buffer.readUnsignedByte().toInt()
|
||||
@@ -171,7 +168,6 @@ class JoinPacketDeserializer : PacketDeserializer<JoinGamePacket> {
|
||||
platform,
|
||||
arch,
|
||||
bitness,
|
||||
unk2
|
||||
)
|
||||
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)
|
||||
|
||||
+3
-3
@@ -4,10 +4,10 @@ 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(
|
||||
|
||||
+1
-3
@@ -14,9 +14,7 @@ data class GameServer(
|
||||
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) {
|
||||
|
||||
+7
-16
@@ -13,10 +13,9 @@ 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(
|
||||
@@ -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)
|
||||
@@ -116,16 +116,7 @@ class GameServerNodesPacketDeserializer : PacketDeserializer<GameServerNodesPack
|
||||
|
||||
return GameServerNodesPacket(
|
||||
LoginState.AUTHED,
|
||||
GameServerData(
|
||||
gameServerId,
|
||||
userId,
|
||||
sessionToken,
|
||||
localAddress,
|
||||
localHostname,
|
||||
port
|
||||
),
|
||||
nodes
|
||||
)
|
||||
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) {
|
||||
|
||||
+6
-7
@@ -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,7 +66,8 @@ class LoginKickPacketDeserializer : PacketDeserializer<LoginKickPacket> {
|
||||
}
|
||||
|
||||
val reasonOrdinal = buffer.readUnsignedByte().toInt()
|
||||
val reason = KickReason.entries.getOrNull(reasonOrdinal)
|
||||
val reason =
|
||||
KickReason.entries.getOrNull(reasonOrdinal)
|
||||
?: throw IllegalArgumentException("Unknown kick reason: $reasonOrdinal")
|
||||
|
||||
when (reason) {
|
||||
|
||||
+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
-14
@@ -23,7 +23,8 @@ class GameServerNodesPacketBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
class AuthedPacketBuilder internal constructor(
|
||||
class AuthedPacketBuilder
|
||||
internal constructor(
|
||||
private val userId: Int,
|
||||
private val sessionToken: ByteArray,
|
||||
private val gameServerId: UByte
|
||||
@@ -33,11 +34,7 @@ class AuthedPacketBuilder internal constructor(
|
||||
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,7 +30,6 @@ dependencies {
|
||||
|
||||
application { mainClass.set("de.fiereu.openmmo.server.game.GameServerKt") }
|
||||
|
||||
|
||||
fun env(key: String): Any {
|
||||
val value =
|
||||
property(key)
|
||||
@@ -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 ->
|
||||
listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc")
|
||||
.forEach { taskName ->
|
||||
tasks.named(taskName) {
|
||||
listOf("copyPublicKeyGame", "copyPrivateKeyGame")
|
||||
.forEach { dependsOn(it) }
|
||||
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 ->
|
||||
listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc")
|
||||
.forEach { taskName ->
|
||||
tasks.named(taskName) {
|
||||
listOf("copyPublicKeyGame", "copyPrivateKeyGame")
|
||||
.forEach { dependsOn(it) }
|
||||
listOf("copyPublicKeyGame", "copyPrivateKeyGame").forEach { dependsOn(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-19
@@ -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 }
|
||||
)
|
||||
event
|
||||
.respondForAuthedUser(userId = 1, sessionToken = ByteArray(16) { 0x42 })
|
||||
.withLocalEndpoint(
|
||||
address = IPAddress.of("127.0.0.1"),
|
||||
hostname = "localhost",
|
||||
port = 7777u
|
||||
)
|
||||
.withNodes(listOf(
|
||||
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)
|
||||
)
|
||||
))
|
||||
weight =
|
||||
0x01u // Always select this node (only one node available in this example)
|
||||
)))
|
||||
.respondTo(event)
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -16,10 +16,7 @@ fun PacketEvent<JoinGameServerPacket>.respondForAuthedUser(
|
||||
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<*>) {
|
||||
|
||||
Reference in new issue
Block a user