-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
128 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import io.ktor.client.engine.* | ||
|
||
typealias KtorEngine = HttpClientEngineFactory<HttpClientEngineConfig> | ||
|
||
lateinit var currentUrl: String | ||
lateinit var version: String | ||
lateinit var engine: KtorEngine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import io.ktor.client.call.* | ||
import kotlinx.uuid.UUID | ||
import kotlinx.uuid.generateUUID | ||
import network.LoginRequest | ||
import network.LoginResult | ||
import network.LoginResultType | ||
import network.sendHttp | ||
|
||
var username: String = generateUsername() | ||
lateinit var sessionId: String | ||
lateinit var sessionUUID: UUID | ||
val usernameRegex = Regex("[ㄱ-ㅎ가-힣a-zA-Z0-9._]") | ||
private fun generateUsername() = UUID.generateUUID().toString().substring(0, 4) | ||
|
||
suspend fun login(loginRequest: LoginRequest = LoginRequest(username)): LoginResultType { | ||
val loginResult = runCatching { sendHttp("login", loginRequest, auth = false) } | ||
.apply {println(this.exceptionOrNull()?.stackTraceToString())}.getOrNull()?.body<LoginResult>() ?: return LoginResultType.SERVER_IS_NOT_AVAILABLE | ||
if (loginResult.result == LoginResultType.SUCCESS) { | ||
sessionUUID = loginResult.uuid!! | ||
sessionId = sessionUUID.toString() | ||
} | ||
return loginResult.result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package network | ||
|
||
import currentUrl | ||
import io.ktor.client.call.* | ||
import io.ktor.client.request.* | ||
import kotlinx.uuid.UUID | ||
import sessionId | ||
import username | ||
|
||
suspend fun createRoom(createRoom: CreateRoom) = sendHttp("rooms/create", createRoom).body<CreateRoomResult>() | ||
suspend fun getViewedRooms() = runCatching { | ||
client().post("$currentUrl/rooms") { | ||
basicAuth(username, sessionId) | ||
}.body<List<ViewedRoom>>() | ||
}.apply { this.exceptionOrNull()?.printStackTrace() }.getOrElse { listOf() } | ||
|
||
suspend fun joinRoom(uuid: UUID) = sendHttp("rooms/join", uuid).status | ||
|
||
suspend fun requestLeaveRoom(uuid: UUID) = sendHttp("rooms/leave", uuid).status | ||
|
||
suspend fun getRoomName(uuid: UUID) = sendHttp("rooms/name", uuid).body<String>() | ||
|
||
suspend fun listPlayer() = sendHttp("rooms/players").body<List<ViewedPlayer>>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package util | ||
|
||
import globalCoroutineContext | ||
import korlibs.io.async.launchImmediately | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.koin.mp.KoinPlatform.getKoin | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
fun launchNow(context: CoroutineContext = getKoin().get<CoroutineContext>(), callback: suspend () -> Unit) = CoroutineScope(context).launchImmediately(callback) | ||
@DelicateCoroutinesApi | ||
fun launchNow(context: CoroutineContext = GlobalScope.coroutineContext, callback: suspend () -> Unit) = CoroutineScope(context).launchImmediately(callback) |
Oops, something went wrong.