Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
caelumlux committed Jan 27, 2024
1 parent dc8ddfc commit 4f0e8c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 60 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/moe/fuqiuluo/api/session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ fun findSession(uin: Long): Session {

internal inline fun <T> Session.withRuntime(crossinline action: () -> T): T? {
val t = action()
pool.release(this)
return t
}
9 changes: 1 addition & 8 deletions src/main/kotlin/moe/fuqiuluo/unidbg/session/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import kotlinx.coroutines.sync.Mutex
import moe.fuqiuluo.comm.EnvData
import moe.fuqiuluo.unidbg.QSecVM

class Session(
envData: EnvData,
val pool: WorkerPool
): Worker(pool) {
class Session(envData: EnvData){
internal val vm: QSecVM =
QSecVM(BASE_PATH, envData, CONFIG.unidbg.dynarmic, CONFIG.unidbg.unicorn, CONFIG.unidbg.kvm)

Expand All @@ -25,8 +22,4 @@ class Session(
vm.init()
FEKit.init(vm, envData.uin.toString())
}

override fun destroy() {
vm.destroy()
}
}
59 changes: 8 additions & 51 deletions src/main/kotlin/moe/fuqiuluo/unidbg/session/SessionManager.kt
Original file line number Diff line number Diff line change
@@ -1,74 +1,31 @@
package moe.fuqiuluo.unidbg.session

import CONFIG
import com.github.unidbg.worker.WorkerPool
import com.github.unidbg.worker.WorkerPoolFactory
import moe.fuqiuluo.api.BlackListError
import moe.fuqiuluo.comm.EnvData
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit
import kotlin.concurrent.timer

object SessionManager {
private var workerPoolMap = hashMapOf<String, WorkerPool>()
private val envDataByUin = ConcurrentHashMap<Long, EnvData>()
private val uin0 ="0";
init {
if (CONFIG.shareToken) {
timer("reload", false, 1000L * 60 * 40, 1000L * 60 * 40) {
workerPoolMap[uin0]?.close()
}
}
}

fun get(uin: Long): Session? {
if (uin !in this) {
return null
}
private val sessionMap = ConcurrentHashMap<Long, Session>()

if (CONFIG.shareToken) {
val envData = envDataByUin[uin]!!
return workerPoolMap[uin.toString()]?.borrow<Session?>(3 * 1000L, TimeUnit.MILLISECONDS).also {
val env = it?.vm?.envData
if (env != null && env.uin != uin) {
env.uin = uin
env.androidId = envData.androidId
env.code = envData.code
env.guid = envData.guid
env.packageName = envData.packageName
env.qua = envData.qua
env.version = envData.version
env.qimei36 = envData.qimei36
}
}
} else {
return workerPoolMap[uin.toString()]?.borrow(3 * 1000L, TimeUnit.MILLISECONDS)
}
operator fun get(uin: Long): Session? {
return sessionMap[uin]
}

operator fun contains(uin: Long) = envDataByUin.containsKey(uin)
operator fun contains(uin: Long) = sessionMap.containsKey(uin)

fun register(envData: EnvData) {
if (CONFIG.blackList?.contains(envData.uin) == true) {
throw BlackListError
}
if (envData.uin in this && !CONFIG.shareToken) {
if (envData.uin in this) {
close(envData.uin)
}

envDataByUin[envData.uin] = envData
if(workerPoolMap.containsKey(uin0) && CONFIG.shareToken) {
return
}
workerPoolMap[if (CONFIG.shareToken) uin0 else envData.uin.toString()] = WorkerPoolFactory.create({ pool ->
Session(envData, pool)
}, CONFIG.count)
sessionMap[envData.uin] = Session(envData)
}

fun close(uin: Long) {
envDataByUin.remove(uin)
if (!CONFIG.shareToken) {
workerPoolMap[uin.toString()]?.close()
}
sessionMap[uin]?.vm?.destroy()
sessionMap.remove(uin)
}
}

0 comments on commit 4f0e8c0

Please sign in to comment.