From f5ea8792b27ec355898a729df69b4341c42c927c Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 11 Apr 2024 23:57:37 +0300 Subject: [PATCH] feat: logout packets --- .../outgoing/codec/logout/LogoutEncoder.kt | 21 ++++ .../codec/logout/LogoutTransferEncoder.kt | 24 +++++ .../codec/logout/LogoutWithReasonEncoder.kt | 22 +++++ .../protocol/game/outgoing/logout/Logout.kt | 10 ++ .../game/outgoing/logout/LogoutTransfer.kt | 96 +++++++++++++++++++ .../game/outgoing/logout/LogoutWithReason.kt | 40 ++++++++ 6 files changed, 213 insertions(+) create mode 100644 protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutEncoder.kt create mode 100644 protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutTransferEncoder.kt create mode 100644 protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutWithReasonEncoder.kt create mode 100644 protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/Logout.kt create mode 100644 protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutTransfer.kt create mode 100644 protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutWithReason.kt diff --git a/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutEncoder.kt b/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutEncoder.kt new file mode 100644 index 000000000..c0f03c16c --- /dev/null +++ b/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutEncoder.kt @@ -0,0 +1,21 @@ +package net.rsprot.protocol.game.outgoing.codec.logout + +import io.netty.channel.ChannelHandlerContext +import net.rsprot.buffer.JagByteBuf +import net.rsprot.protocol.ServerProt +import net.rsprot.protocol.game.outgoing.logout.Logout +import net.rsprot.protocol.game.outgoing.prot.GameServerProt +import net.rsprot.protocol.message.codec.MessageEncoder +import net.rsprot.protocol.metadata.Consistent + +@Consistent +public class LogoutEncoder : MessageEncoder { + override val prot: ServerProt = GameServerProt.LOGOUT + + override fun encode( + ctx: ChannelHandlerContext, + buffer: JagByteBuf, + message: Logout, + ) { + } +} diff --git a/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutTransferEncoder.kt b/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutTransferEncoder.kt new file mode 100644 index 000000000..7a64855d1 --- /dev/null +++ b/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutTransferEncoder.kt @@ -0,0 +1,24 @@ +package net.rsprot.protocol.game.outgoing.codec.logout + +import io.netty.channel.ChannelHandlerContext +import net.rsprot.buffer.JagByteBuf +import net.rsprot.protocol.ServerProt +import net.rsprot.protocol.game.outgoing.logout.LogoutTransfer +import net.rsprot.protocol.game.outgoing.prot.GameServerProt +import net.rsprot.protocol.message.codec.MessageEncoder +import net.rsprot.protocol.metadata.Consistent + +@Consistent +public class LogoutTransferEncoder : MessageEncoder { + override val prot: ServerProt = GameServerProt.LOGOUT_TRANSFER + + override fun encode( + ctx: ChannelHandlerContext, + buffer: JagByteBuf, + message: LogoutTransfer, + ) { + buffer.pjstr(message.host) + buffer.p2(message.id) + buffer.p4(message.properties) + } +} diff --git a/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutWithReasonEncoder.kt b/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutWithReasonEncoder.kt new file mode 100644 index 000000000..04eb2f233 --- /dev/null +++ b/protocol/osrs-221-desktop/src/main/kotlin/net/rsprot/protocol/game/outgoing/codec/logout/LogoutWithReasonEncoder.kt @@ -0,0 +1,22 @@ +package net.rsprot.protocol.game.outgoing.codec.logout + +import io.netty.channel.ChannelHandlerContext +import net.rsprot.buffer.JagByteBuf +import net.rsprot.protocol.ServerProt +import net.rsprot.protocol.game.outgoing.logout.LogoutWithReason +import net.rsprot.protocol.game.outgoing.prot.GameServerProt +import net.rsprot.protocol.message.codec.MessageEncoder +import net.rsprot.protocol.metadata.Consistent + +@Consistent +public class LogoutWithReasonEncoder : MessageEncoder { + override val prot: ServerProt = GameServerProt.LOGOUT_WITHREASON + + override fun encode( + ctx: ChannelHandlerContext, + buffer: JagByteBuf, + message: LogoutWithReason, + ) { + buffer.p1(message.reason) + } +} diff --git a/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/Logout.kt b/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/Logout.kt new file mode 100644 index 000000000..c13ffbeba --- /dev/null +++ b/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/Logout.kt @@ -0,0 +1,10 @@ +package net.rsprot.protocol.game.outgoing.logout + +import net.rsprot.protocol.message.OutgoingMessage + +/** + * Log out messages are used to tell the client the player + * has finished playing, which then causes the client to close + * the socket, and reset a lot of properties as a result. + */ +public data object Logout : OutgoingMessage diff --git a/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutTransfer.kt b/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutTransfer.kt new file mode 100644 index 000000000..e6f1f126b --- /dev/null +++ b/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutTransfer.kt @@ -0,0 +1,96 @@ +package net.rsprot.protocol.game.outgoing.logout + +import net.rsprot.protocol.message.OutgoingMessage + +/** + * Logout transfer packet is used for world-hopping purposes, + * making the client connect to a different world instead. + * + * World properties table: + * ``` + * | Flag | Type | + * |------------|:-----------------------:| + * | 0x1 | Members | + * | 0x2 | Quick chat | + * | 0x4 | PvP world | + * | 0x8 | Lootshare | + * | 0x10 | Dedicated activity | + * | 0x20 | Bounty world | + * | 0x40 | PvP Arena | + * | 0x80 | High level only - 1500+ | + * | 0x100 | Speedrun | + * | 0x200 | Existing players only | + * | 0x400 | Extra-hard wilderness | + * | 0x800 | Dungeoneering | + * | 0x1000 | Instance shard | + * | 0x2000 | Rentable | + * | 0x4000 | Last man standing | + * | 0x8000 | New players | + * | 0x10000 | Beta world | + * | 0x20000 | Staff IP only | + * | 0x40000 | High level only - 2000+ | + * | 0x80000 | High level only - 2400+ | + * | 0x100000 | VIPs only | + * | 0x200000 | Hidden world | + * | 0x400000 | Legacy only | + * | 0x800000 | EoC only | + * | 0x1000000 | Behind proxy | + * | 0x2000000 | No save mode | + * | 0x4000000 | Tournament world | + * | 0x8000000 | Fresh start world | + * | 0x10000000 | High level only - 1750+ | + * | 0x20000000 | Deadman world | + * | 0x40000000 | Seasonal world | + * | 0x80000000 | External partner only | + * ``` + * + * @property host the ip address of the new world + * @property id the id of the new world + * @property properties the flags of the new world + */ +public class LogoutTransfer private constructor( + public val host: String, + private val _id: UShort, + public val properties: Int, +) : OutgoingMessage { + public constructor( + host: String, + id: Int, + properties: Int, + ) : this( + host, + id.toUShort(), + properties, + ) + + public val id: Int + get() = _id.toInt() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as LogoutTransfer + + if (host != other.host) return false + if (_id != other._id) return false + if (properties != other.properties) return false + + return true + } + + override fun hashCode(): Int { + var result = host.hashCode() + result = 31 * result + _id.hashCode() + result = 31 * result + properties + return result + } + + override fun toString(): String { + return "LogoutTransfer(" + + "host='$host', " + + "id=$id, " + + "properties=$properties" + + ")" + } +} diff --git a/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutWithReason.kt b/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutWithReason.kt new file mode 100644 index 000000000..239802f36 --- /dev/null +++ b/protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/outgoing/logout/LogoutWithReason.kt @@ -0,0 +1,40 @@ +package net.rsprot.protocol.game.outgoing.logout + +import net.rsprot.protocol.message.OutgoingMessage + +/** + * Logout with reason, much like [Logout], is used to + * log the player out of the game. The only difference here + * is that the user will be given a reason for why they were + * logged out of the game, e.g. inactive for too long. + * + * Logout reasons table: + * ``` + * | Id | Type | + * |----|:--------:| + * | 1 | Kicked | + * | 2 | Updating | + * ``` + * + * @property reason the id of the reason to display (see table above) + */ +public class LogoutWithReason( + public val reason: Int, +) : OutgoingMessage { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as LogoutWithReason + + return reason == other.reason + } + + override fun hashCode(): Int { + return reason + } + + override fun toString(): String { + return "LogoutWithReason(reason=$reason)" + } +}