|
|
|
@ -8,6 +8,7 @@ import com.google.gson.reflect.TypeToken
|
|
|
|
|
import okhttp3.MultipartBody
|
|
|
|
|
import okhttp3.OkHttpClient
|
|
|
|
|
import okhttp3.Request
|
|
|
|
|
import okhttp3.Response
|
|
|
|
|
import org.json.JSONObject
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
|
|
|
|
@ -71,5 +72,87 @@ class ControllerLobby {
|
|
|
|
|
}
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun PlayerCreatorIdPresentInLobby(idPlayer: Int, lobbyId: Int): Boolean {
|
|
|
|
|
|
|
|
|
|
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
|
|
|
|
|
StrictMode.setThreadPolicy(policy)
|
|
|
|
|
|
|
|
|
|
// Client HTTP API
|
|
|
|
|
val client = OkHttpClient()
|
|
|
|
|
|
|
|
|
|
// API Access
|
|
|
|
|
val request = Request.Builder()
|
|
|
|
|
.url("https://trusting-panini.87-106-126-109.plesk.page/api/lobbies/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
// API Response
|
|
|
|
|
client.newCall(request).execute().use { response ->
|
|
|
|
|
if (!response.isSuccessful) throw IOException("Unexpected code $response")
|
|
|
|
|
|
|
|
|
|
// Gson deserialization
|
|
|
|
|
val gson = Gson()
|
|
|
|
|
val typeTokenProduct = object : TypeToken<ArrayList<Lobby>>() {}.type
|
|
|
|
|
|
|
|
|
|
val lobby: ArrayList<Lobby> = gson.fromJson(response.body!!.string(), typeTokenProduct)
|
|
|
|
|
return lobby[0].idplayercreator == idPlayer
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun deleteLobby(lobbyId: Int) {
|
|
|
|
|
try {
|
|
|
|
|
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
|
|
|
|
|
StrictMode.setThreadPolicy(policy)
|
|
|
|
|
|
|
|
|
|
// Client HTTP API
|
|
|
|
|
val client = OkHttpClient()
|
|
|
|
|
|
|
|
|
|
// API Access - Suppression du lobby
|
|
|
|
|
val deleteRequest = Request.Builder()
|
|
|
|
|
.url("https://trusting-panini.87-106-126-109.plesk.page/api/lobbies/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
|
|
|
|
|
.delete()
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
// API Response
|
|
|
|
|
val deleteResponse: Response = client.newCall(deleteRequest).execute()
|
|
|
|
|
|
|
|
|
|
// Vérifier si la suppression a réussi
|
|
|
|
|
if (!deleteResponse.isSuccessful) {
|
|
|
|
|
Log.e("deleteLobby", "Error deleting lobby")
|
|
|
|
|
}
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
// Log en cas d'erreur
|
|
|
|
|
Log.e("deleteLobby", "Error deleting lobby", e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun updateLobbyIdCreatorLobby(lobbyId: Int,lobbyData: MultipartBody.Builder) {
|
|
|
|
|
try {
|
|
|
|
|
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
|
|
|
|
|
StrictMode.setThreadPolicy(policy)
|
|
|
|
|
|
|
|
|
|
// Client HTTP API
|
|
|
|
|
val client = OkHttpClient()
|
|
|
|
|
|
|
|
|
|
// API Access - Mise à jour du lobby
|
|
|
|
|
val updateRequest = Request.Builder()
|
|
|
|
|
.url("https://trusting-panini.87-106-126-109.plesk.page/api/update/lobbies/idcreatorlobby/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
|
|
|
|
|
// Ajoutez d'autres paramètres ou données pour la mise à jour si nécessaire
|
|
|
|
|
.post(lobbyData.build()) //TODO attention api pb
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
// API Response
|
|
|
|
|
val updateResponse: Response = client.newCall(updateRequest).execute()
|
|
|
|
|
|
|
|
|
|
// Vérifier si la mise à jour a réussi
|
|
|
|
|
if (!updateResponse.isSuccessful) {
|
|
|
|
|
Log.e("updateLobby", "Error updating lobby")
|
|
|
|
|
}
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
// Log en cas d'erreur
|
|
|
|
|
Log.e("updateLobby", "Error updating lobby", e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|