Merge branch 'dev_protocol_login'
# Conflicts: # common/src/main/kotlin/de/fiereu/openmmo/common/enums/LoginState.kt # protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt
This commit is contained in:
commit
9fabe28642
21 files changed
+819
-9
No files matched your search
@@ -6,6 +6,7 @@ plugins {
|
||||
dependencies {
|
||||
api(libs.kotlinx.serialization.core)
|
||||
api(libs.netty)
|
||||
api(libs.ineter)
|
||||
|
||||
implementation(libs.slf4j)
|
||||
implementation(libs.kotlin.logging)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package de.fiereu.openmmo.protocols
|
||||
|
||||
import com.github.maltalex.ineter.base.IPAddress
|
||||
import com.github.maltalex.ineter.base.IPv4Address
|
||||
import com.github.maltalex.ineter.base.IPv6Address
|
||||
import io.netty.buffer.ByteBuf
|
||||
|
||||
fun ByteBuf.readCharLE(): Char {
|
||||
@@ -26,3 +29,40 @@ fun ByteBuf.writeUtf16LE(value: String) {
|
||||
}
|
||||
writeCharLE(0.toChar()) // Null-terminator
|
||||
}
|
||||
|
||||
fun ByteBuf.readIpLE(): IPAddress {
|
||||
val type = readUnsignedByte().toInt()
|
||||
return when (type) {
|
||||
4 -> {
|
||||
val intValue = readIntLE()
|
||||
IPv4Address.of(intValue)
|
||||
}
|
||||
6 -> {
|
||||
val upper = readLongLE()
|
||||
val lower = readLongLE()
|
||||
IPv6Address.of(upper, lower)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unknown IP address type: $type")
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteBuf.writeIpLE(ipAddress: IPAddress) {
|
||||
if (ipAddress is IPv4Address) {
|
||||
writeByte(4)
|
||||
writeIntLE(ipAddress.toInt())
|
||||
} else {
|
||||
writeByte(6)
|
||||
writeBytes(ipAddress.toArray())
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteBuf.readIpRangeLE(): Pair<IPAddress, IPAddress> {
|
||||
val start = readIpLE()
|
||||
val end = readIpLE()
|
||||
return Pair(start, end)
|
||||
}
|
||||
|
||||
fun ByteBuf.writeIpRangeLE(start: IPAddress, end: IPAddress) {
|
||||
writeIpLE(start)
|
||||
writeIpLE(end)
|
||||
}
|
||||
Reference in new issue
Block a user