fix joinGame() error message

This commit is contained in:
creeper123123321 2021-06-06 11:59:59 -03:00
parent b0e09bee90
commit e034831b66
3 changed files with 33 additions and 31 deletions

View File

@ -168,11 +168,12 @@ fun readRemainingBytes(byteBuf: ByteBuf) = Type.REMAINING_BYTES.read(byteBuf)!!
fun ByteBuf.readByteArray(length: Int) = ByteArray(length).also { readBytes(it) } fun ByteBuf.readByteArray(length: Int) = ByteArray(length).also { readBytes(it) }
suspend fun hasJoined(username: String, hash: String): JsonObject { suspend fun hasJoined(username: String, hash: String): JsonObject {
return httpClient.get( return try {
"https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + httpClient.get("https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" +
UrlEscapers.urlFormParameterEscaper().escape(username) + UrlEscapers.urlFormParameterEscaper().escape(username) + "&serverId=$hash")
"&serverId=$hash" } catch (e: Exception) {
) ?: throw StacklessException("Couldn't authenticate with session servers") throw StacklessException("Couldn't authenticate with session servers", e)
}
} }
fun generate128Bits() = ByteArray(16).also { secureRandom.nextBytes(it) } fun generate128Bits() = ByteArray(16).also { secureRandom.nextBytes(it) }

View File

@ -98,7 +98,7 @@ class LoginState : MinecraftConnectionState {
val frontHandler = handler.data.frontHandler val frontHandler = handler.data.frontHandler
val backChan = handler.data.backChannel!! val backChan = handler.data.backChannel!!
handler.coroutineScope.launch(Dispatchers.IO) { handler.coroutineScope.launch {
try { try {
val playerId = callbackPlayerId.await() val playerId = callbackPlayerId.await()

View File

@ -14,6 +14,7 @@ import com.viaversion.aas.parseUndashedId
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.aas.webLogger import com.viaversion.aas.webLogger
import io.ipinfo.api.IPInfo import io.ipinfo.api.IPInfo
import io.ipinfo.api.model.IPResponse
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.http.cio.websocket.* import io.ktor.http.cio.websocket.*
import io.ktor.websocket.* import io.ktor.websocket.*
@ -65,7 +66,7 @@ class WebDashboardServer {
val usernameIdCache = CacheBuilder.newBuilder() val usernameIdCache = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.HOURS) .expireAfterWrite(1, TimeUnit.HOURS)
.build<String, CompletableFuture<UUID?>>(CacheLoader.from { name -> .build<String, CompletableFuture<UUID?>>(CacheLoader.from { name ->
GlobalScope.async(Dispatchers.IO) { CoroutineScope(Dispatchers.IO).async {
httpClient.get<JsonObject?>("https://api.mojang.com/users/profiles/minecraft/$name") httpClient.get<JsonObject?>("https://api.mojang.com/users/profiles/minecraft/$name")
?.get("id")?.asString?.let { parseUndashedId(it) } ?.get("id")?.asString?.let { parseUndashedId(it) }
}.asCompletableFuture() }.asCompletableFuture()
@ -83,34 +84,34 @@ class WebDashboardServer {
if (!listeners.containsKey(id)) { if (!listeners.containsKey(id)) {
future.completeExceptionally(StacklessException("No browser listening")) future.completeExceptionally(StacklessException("No browser listening"))
} else { } else {
val info = withContext(Dispatchers.IO) { coroutineScope {
(address as? InetSocketAddress)?.let { launch(Dispatchers.IO) {
try { var info: IPResponse? = null
it.address?.hostName // resolve it (address as? InetSocketAddress)?.let {
ipInfo.lookupIP(it.address?.hostAddress?.substringBefore("%")) try {
} catch (ignored: Exception) { val ipLookup = async(Dispatchers.IO) {
null ipInfo.lookupIP(it.address?.hostAddress?.substringBefore("%"))
}
val reverseLookup = async(Dispatchers.IO) {
it.address?.hostName
}
info = ipLookup.await()
reverseLookup.await()
} catch (ignored: Exception) {
}
} }
} val msg = "Requester: $id $address (${info?.org}, ${info?.city}, ${info?.region}, " +
} "${info?.countryCode})\nBackend: $backAddress"
val msg = """Requester: $id $address (${info?.org}, ${info?.city}, ${info?.region}, ${info?.countryCode}) listeners[id]?.forEach {
Backend: $backAddress""" it.ws.send(JsonObject().also {
listeners[id]?.forEach { it.addProperty("action", "session_hash_request")
coroutineScope { it.addProperty("user", name)
launch { it.addProperty("session_hash", hash)
it.ws.send( it.addProperty("message", msg)
JsonObject().also { }.toString())
it.addProperty("action", "session_hash_request")
it.addProperty("user", name)
it.addProperty("session_hash", hash)
it.addProperty("message", msg)
}.toString()
)
it.ws.flush() it.ws.flush()
} }
} }
}
coroutineScope {
launch { launch {
delay(20_000) delay(20_000)
future.completeExceptionally(StacklessException("No response from browser")) future.completeExceptionally(StacklessException("No response from browser"))