Skip to content

Commit

Permalink
feat: logout packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Kris committed Apr 11, 2024
1 parent 0c3e30e commit f5ea879
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Logout> {
override val prot: ServerProt = GameServerProt.LOGOUT

override fun encode(
ctx: ChannelHandlerContext,
buffer: JagByteBuf,
message: Logout,
) {
}
}
Original file line number Diff line number Diff line change
@@ -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<LogoutTransfer> {
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)
}
}
Original file line number Diff line number Diff line change
@@ -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<LogoutWithReason> {
override val prot: ServerProt = GameServerProt.LOGOUT_WITHREASON

override fun encode(
ctx: ChannelHandlerContext,
buffer: JagByteBuf,
message: LogoutWithReason,
) {
buffer.p1(message.reason)
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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" +
")"
}
}
Original file line number Diff line number Diff line change
@@ -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)"
}
}

0 comments on commit f5ea879

Please sign in to comment.