From 3114a9b8c66d69c8cfd892360fa76cc4d2b2e6c8 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 15 Jan 2025 19:27:20 -0500 Subject: [PATCH] [O] No leaks --- .../aqua/sega/maimai2/worldslink/FutariServer.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariServer.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariServer.kt index bc1dfb7b..57124e2e 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariServer.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariServer.kt @@ -10,6 +10,7 @@ import java.io.OutputStreamWriter import java.net.ServerSocket import java.net.Socket import java.net.SocketTimeoutException +import java.security.MessageDigest import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.locks.ReentrantLock import kotlin.collections.set @@ -109,7 +110,14 @@ fun ActiveClient.handle(msg: Msg) { } } -fun keychipToStubIp(keychip: String) = "1${keychip.substring(2)}".toUInt() +fun hashStringToUInt(input: String) = MessageDigest.getInstance("MD5").digest(input.toByteArray()).let { + ((it[0].toUInt() and 0xFFu) shl 24) or + ((it[1].toUInt() and 0xFFu) shl 16) or + ((it[2].toUInt() and 0xFFu) shl 8) or + (it[3].toUInt() and 0xFFu) +} + +fun keychipToStubIp(keychip: String) = hashStringToUInt(keychip) // Keychip ID to Socket val clients = ConcurrentHashMap()