add ineter
This commit is contained in:
1 parent
3d170f9277
commit
f2ea538c7d
3 files changed
+32
No files matched your search
@@ -19,6 +19,7 @@ netty = "4.2.4.Final"
|
||||
typesafe-config = "1.4.4"
|
||||
dagger = "2.57"
|
||||
ksp = "2.2.10-2.0.2"
|
||||
ineter = "0.3.1"
|
||||
|
||||
[libraries]
|
||||
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
@@ -50,6 +51,7 @@ typesafe-config = { module = "com.typesafe:config", version.ref = "typesafe-conf
|
||||
dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" }
|
||||
dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" }
|
||||
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
|
||||
ineter = { module = "com.github.maltalex:ineter", version.ref = "ineter" }
|
||||
|
||||
[bundles]
|
||||
crypto = ["bouncycastle-pkix", "bouncycastle-provider"]
|
||||
|
||||
@@ -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,29 @@ 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())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user