Rename project
This commit is contained in:
37 files changed
+105
-91
No files matched your search
+2
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public expect class _Buffer {
|
||||
@@ -24,6 +24,7 @@ public expect class _Buffer {
|
||||
public fun readLong(endian: ByteOrder = ByteOrder.BIG_ENDIAN): Long
|
||||
public fun readBytes(length: Int): ByteArray
|
||||
public fun toByteArray(): ByteArray
|
||||
public fun hasRemaining(): Boolean
|
||||
public fun close()
|
||||
public val size: Int
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
public enum class ByteOrder {
|
||||
BIG_ENDIAN, LITTLE_ENDIAN
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public expect class _ReadChannel {
|
||||
+2
-2
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
/**
|
||||
* An object class used to pass some parameters
|
||||
* that exists only on native targets
|
||||
*/
|
||||
public expect class MCPingContext()
|
||||
public expect class LibMCContext()
|
||||
+3
-3
@@ -5,17 +5,17 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public expect class _Socket public constructor(host: String, port: Int, context: MCPingContext) {
|
||||
public expect class _Socket public constructor(host: String, port: Int, context: LibMCContext) {
|
||||
public fun openReadChannel(): _ReadChannel
|
||||
public fun openWriteChannel(): _WriteChannel
|
||||
public fun close()
|
||||
}
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public expect class _UdpSocket public constructor(host: String, port: Int, context: MCPingContext) {
|
||||
public expect class _UdpSocket public constructor(host: String, port: Int, context: LibMCContext) {
|
||||
public fun sendAndReceive(data: ByteArray): ByteArray
|
||||
public fun close()
|
||||
}
|
||||
+4
-1
@@ -4,7 +4,7 @@
|
||||
* Date: 2026/9/3
|
||||
*/
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
@@ -21,6 +21,7 @@ public actual class _Buffer {
|
||||
}
|
||||
|
||||
public actual fun writeByte(value: Byte) {
|
||||
readBuffer = null
|
||||
outStream.write(value.toInt())
|
||||
}
|
||||
|
||||
@@ -58,6 +59,7 @@ public actual class _Buffer {
|
||||
}
|
||||
|
||||
public actual fun writeBytes(bytes: ByteArray) {
|
||||
readBuffer = null
|
||||
outStream.write(bytes)
|
||||
}
|
||||
|
||||
@@ -88,6 +90,7 @@ public actual class _Buffer {
|
||||
}
|
||||
|
||||
public actual fun toByteArray(): ByteArray = outStream.toByteArray()
|
||||
public actual fun hasRemaining(): Boolean = readOffset < ensureReadArray().size
|
||||
|
||||
public actual fun close(): Unit = outStream.close()
|
||||
public actual val size: Int get() = outStream.size()
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import java.io.EOFException
|
||||
import java.io.InputStream
|
||||
+2
-2
@@ -4,9 +4,9 @@
|
||||
* Date: 2026/9/3
|
||||
*/
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
/**
|
||||
* No Context for jvm targets
|
||||
*/
|
||||
public actual class MCPingContext
|
||||
public actual class LibMCContext
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
internal fun ByteArray.toShort(endian: ByteOrder = ByteOrder.BIG_ENDIAN): Short {
|
||||
val b1 = this[0].toInt() and 0xFF
|
||||
+3
-3
@@ -4,7 +4,7 @@
|
||||
* Date: 2026/9/3
|
||||
*/
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import java.net.DatagramPacket
|
||||
import java.net.DatagramSocket
|
||||
@@ -12,7 +12,7 @@ import java.net.InetSocketAddress
|
||||
import java.net.Socket as JvmSocket
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public actual class _Socket public actual constructor(host: String, port: Int, context: MCPingContext) {
|
||||
public actual class _Socket public actual constructor(host: String, port: Int, context: LibMCContext) {
|
||||
private val socket = JvmSocket(host, port)
|
||||
|
||||
public actual fun openReadChannel(): _ReadChannel = _ReadChannel(socket.getInputStream())
|
||||
@@ -21,7 +21,7 @@ public actual class _Socket public actual constructor(host: String, port: Int, c
|
||||
}
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public actual class _UdpSocket public actual constructor(host: String, port: Int, context: MCPingContext) {
|
||||
public actual class _UdpSocket public actual constructor(host: String, port: Int, context: LibMCContext) {
|
||||
private val socket = DatagramSocket().apply {
|
||||
soTimeout = 3000
|
||||
connect(InetSocketAddress(host, port))
|
||||
+11
-2
@@ -4,7 +4,7 @@
|
||||
* Date: 2026/9/3
|
||||
*/
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import io.ktor.utils.io.bits.*
|
||||
import kotlinx.io.Buffer
|
||||
@@ -56,7 +56,16 @@ public actual class _Buffer {
|
||||
}
|
||||
|
||||
public actual fun readBytes(length: Int): ByteArray = _delegateBuf.readByteArray(length)
|
||||
public actual fun toByteArray(): ByteArray = _delegateBuf.peek().readByteArray()
|
||||
public actual fun toByteArray(): ByteArray {
|
||||
val copy = _delegateBuf.peek()
|
||||
return try {
|
||||
copy.readByteArray()
|
||||
} finally {
|
||||
copy.close()
|
||||
}
|
||||
}
|
||||
|
||||
public actual fun hasRemaining(): Boolean = !_delegateBuf.exhausted()
|
||||
public actual fun close(): Unit = _delegateBuf.close()
|
||||
|
||||
public actual val size: Int
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
* Date: 2026/9/3
|
||||
*/
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import io.ktor.utils.io.*
|
||||
import io.ktor.utils.io.bits.reverseByteOrder
|
||||
+2
-2
@@ -6,13 +6,13 @@
|
||||
|
||||
@file:Suppress("PropertyName")
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import io.ktor.network.selector.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
|
||||
public actual class MCPingContext actual constructor() {
|
||||
public actual class LibMCContext actual constructor() {
|
||||
internal var _selectorManager: SelectorManager = SelectorManager(Dispatchers.IO)
|
||||
internal var _autoCloseSelectorManager: Boolean = false
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@
|
||||
* Date: 2026/9/3
|
||||
*/
|
||||
|
||||
package cn.rtast.mcping.platform
|
||||
package cn.rtast.libmc.common
|
||||
|
||||
import io.ktor.network.sockets.*
|
||||
import io.ktor.utils.io.core.*
|
||||
@@ -12,7 +12,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.io.readByteArray
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public actual class _Socket public actual constructor(host: String, port: Int, context: MCPingContext) {
|
||||
public actual class _Socket public actual constructor(host: String, port: Int, context: LibMCContext) {
|
||||
private val ctx = context
|
||||
private val socket = runBlocking { aSocket(ctx._selectorManager).tcp().connect(host, port) }
|
||||
|
||||
@@ -27,7 +27,7 @@ public actual class _Socket public actual constructor(host: String, port: Int, c
|
||||
}
|
||||
|
||||
@Suppress("CLASSNAME")
|
||||
public actual class _UdpSocket public actual constructor(host: String, port: Int, context: MCPingContext) {
|
||||
public actual class _UdpSocket public actual constructor(host: String, port: Int, context: LibMCContext) {
|
||||
private val ctx = context
|
||||
|
||||
// use bind to create an unconnected socket
|
||||
Reference in New Issue
Block a user