mirror of https://github.com/hykilpikonna/AquaDX
[O] Hash user ids
parent
146e4bac0f
commit
b17d784d80
|
@ -1,3 +1,5 @@
|
|||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
package ext
|
||||
|
||||
import icu.samnyan.aqua.net.utils.ApiException
|
||||
|
@ -113,7 +115,6 @@ val HTTP = HttpClient(CIO) {
|
|||
}
|
||||
val TIKA = Tika()
|
||||
val MIMES = MimeTypes.getDefaultMimeTypes()
|
||||
val MD5 = MessageDigest.getInstance("MD5")
|
||||
|
||||
// Class resource
|
||||
object Ext { val log = logger() }
|
||||
|
@ -216,11 +217,12 @@ operator fun Str.get(range: IntRange) = substring(range.first, (range.last + 1).
|
|||
operator fun Str.get(start: Int, end: Int) = substring(start, end.coerceAtMost(length))
|
||||
fun Str.center(width: Int, padChar: Char = ' ') = padStart((length + width) / 2, padChar).padEnd(width, padChar)
|
||||
fun Str.splitLines() = replace("\r\n", "\n").split('\n')
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun Str.md5() = MD5.digest(toByteArray(Charsets.UTF_8)).toHexString()
|
||||
fun Str.hash(algo: Str) = MessageDigest.getInstance(algo).digest(toByteArray(StandardCharsets.UTF_8))
|
||||
fun Str.md5() = hash("MD5")
|
||||
fun Str.fromChusanUsername() = String(this.toByteArray(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)
|
||||
fun Str.truncate(len: Int) = if (this.length > len) this.take(len) + "..." else this
|
||||
val Str.some get() = ifBlank { null }
|
||||
val ByteArray.hexStr get() = toHexString()
|
||||
|
||||
// Coroutine
|
||||
suspend fun <T> async(block: suspend kotlinx.coroutines.CoroutineScope.() -> T): T = withContext(Dispatchers.IO) { block() }
|
||||
|
|
|
@ -64,6 +64,7 @@ class FutariLobby(paths: PathProps) {
|
|||
recruits[d.ip] = RecruitRecord(d.RecruitInfo)
|
||||
|
||||
if (!exists) log(d, "StartRecruit")
|
||||
d.RecruitInfo.MechaInfo.UserIDs = d.RecruitInfo.MechaInfo.UserIDs.map { it.str.hashToUInt().toLong() }
|
||||
}
|
||||
|
||||
@API("recruit/finish")
|
||||
|
|
|
@ -11,7 +11,7 @@ data class MechaInfo(
|
|||
val IpAddress: UInt,
|
||||
val MusicID: Int,
|
||||
val Entrys: List<Bool>,
|
||||
val UserIDs: List<Long>,
|
||||
var UserIDs: List<Long>,
|
||||
val UserNames: List<String>,
|
||||
val IconIDs: List<Int>,
|
||||
val FumenDifs: List<Int>,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package icu.samnyan.aqua.sega.maimai2.worldslink
|
||||
|
||||
import ext.logger
|
||||
import ext.md5
|
||||
import ext.millis
|
||||
import ext.thread
|
||||
import java.io.BufferedReader
|
||||
|
@ -10,7 +11,6 @@ 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
|
||||
|
@ -110,14 +110,14 @@ fun ActiveClient.handle(msg: Msg) {
|
|||
}
|
||||
}
|
||||
|
||||
fun hashStringToUInt(input: String) = MessageDigest.getInstance("MD5").digest(input.toByteArray()).let {
|
||||
fun String.hashToUInt() = md5().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)
|
||||
fun keychipToStubIp(keychip: String) = keychip.hashToUInt()
|
||||
|
||||
// Keychip ID to Socket
|
||||
val clients = ConcurrentHashMap<UInt, ActiveClient>()
|
||||
|
|
|
@ -71,7 +71,7 @@ class WaccaServer {
|
|||
""""maintNoticeTime":0,"maintNotPlayableTime":0,"maintStartTime":0,"params":$paramsJson}"""
|
||||
|
||||
return ResponseEntity.ok().headers(
|
||||
"X-Wacca-Hash" to resp.md5(),
|
||||
"X-Wacca-Hash" to resp.md5().hexStr,
|
||||
"Content-Type" to "application/json; charset=utf-8"
|
||||
).body(resp)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue