-
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
1 parent
421e996
commit b6867d1
Showing
5 changed files
with
61 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package http | ||
|
||
import http.dto.BeginSessionResponse | ||
import http.dto.DevCommandRequest | ||
import javax.swing.JOptionPane | ||
import kong.unirest.HttpMethod | ||
import util.DialogUtilNew | ||
import util.OnlineConstants | ||
import util.UpdateManager.checkForUpdates | ||
|
||
class SessionApi(private val httpClient: HttpClient) { | ||
fun beginSession(name: String) { | ||
val response = | ||
httpClient.doCall<BeginSessionResponse>( | ||
HttpMethod.POST, | ||
Routes.DEV_COMMAND, | ||
DevCommandRequest(name) | ||
) | ||
|
||
when (response) { | ||
is FailureResponse -> handleBeginSessionFailure(response) | ||
is CommunicationError -> | ||
DialogUtilNew.showError( | ||
"Error communicating with server: ${response.unirestException.message}" | ||
) | ||
is SuccessResponse<BeginSessionResponse> -> { | ||
// Errr, store the sessionId someplace, then hook back into legacy code somehow to | ||
// launch the lobby etc | ||
val sessionResponse = response.body | ||
} | ||
} | ||
} | ||
|
||
private fun handleBeginSessionFailure(response: FailureResponse<*>) { | ||
when (response.errorCode) { | ||
UPDATE_REQUIRED -> { | ||
val response = | ||
DialogUtilNew.showQuestion( | ||
"Your client must be updated to connect. Check for updates now?" | ||
) | ||
|
||
if (response == JOptionPane.YES_OPTION) { | ||
checkForUpdates(OnlineConstants.ENTROPY_VERSION_NUMBER) | ||
} | ||
} | ||
else -> DialogUtilNew.showError("An error occurred: ${response.errorMessage}") | ||
} | ||
} | ||
} |
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