Skip to content

Commit

Permalink
Remove obsolete functionality and revamp syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Oct 16, 2024
1 parent 01e50ee commit 6c2f590
Show file tree
Hide file tree
Showing 61 changed files with 423 additions and 2,130 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val sharedGroup = "com.projectcitybuild.pcbridge"
val sharedVersion = "6.0.0"
val sharedVersion = "6.1.0"

group = sharedGroup
version = sharedVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import com.projectcitybuild.pcbridge.http.clients.MojangClient
import com.projectcitybuild.pcbridge.http.clients.PCBClientFactory
import com.projectcitybuild.pcbridge.http.parsing.ResponseParser
import com.projectcitybuild.pcbridge.http.services.mojang.PlayerUUIDHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.AccountLinkHTTPService
import com.projectcitybuild.pcbridge.http.services.pcb.AggregateHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.IPBanHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.PlayerGroupHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.PlayerWarningHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.RegisterHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.PlayerHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.TelemetryHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.UUIDBanHttpService

class HttpService(
private val authToken: String,
Expand All @@ -37,24 +33,12 @@ class HttpService(
val playerUuid
get() = PlayerUUIDHttpService(mojangClient, responseParser)

val playerGroup
get() = PlayerGroupHttpService(pcbClient, responseParser)

val playerWarning
get() = PlayerWarningHttpService(pcbClient, responseParser)

val uuidBan
get() = UUIDBanHttpService(pcbClient, responseParser)

val ipBan
get() = IPBanHttpService(pcbClient, responseParser)

val aggregate
get() = AggregateHttpService(pcbClient, responseParser)
val player
get() = PlayerHttpService(pcbClient, responseParser)

val telemetry
get() = TelemetryHttpService(pcbClient, responseParser)

val verificationURL
get() = AccountLinkHTTPService(pcbClient, responseParser)
val register
get() = RegisterHttpService(pcbClient, responseParser)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ internal class PCBClientFactory(
private val baseUrl: String,
private val withLogging: Boolean,
) {
fun build(): Retrofit {
val authenticatedClient = makeAuthenticatedClient()
return Retrofit.Builder()
.baseUrl(baseUrl)
.client(authenticatedClient)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
fun build(): Retrofit = Retrofit.Builder()
.baseUrl(baseUrl)
.client(makeAuthenticatedClient())
.addConverterFactory(GsonConverterFactory.create())
.build()

private fun makeAuthenticatedClient(): OkHttpClient {
var clientFactory =
OkHttpClient().newBuilder()
.addInterceptor { chain ->
// Add access token as header to each API request
val request = chain.request()
val requestBuilder = request.newBuilder().header("Authorization", "Bearer $authToken")
val nextRequest = requestBuilder.build()
.newBuilder()
.header("Authorization", "Bearer $authToken")
.build()

chain.proceed(nextRequest)
chain.proceed(request)
}

if (withLogging) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,152 +1,52 @@
package com.projectcitybuild.pcbridge.http.requests

import com.projectcitybuild.pcbridge.http.parsing.ApiResponse
import com.projectcitybuild.pcbridge.http.responses.Account
import com.projectcitybuild.pcbridge.http.responses.Aggregate
import com.projectcitybuild.pcbridge.http.responses.AuthURL
import com.projectcitybuild.pcbridge.http.responses.DonationPerk
import com.projectcitybuild.pcbridge.http.responses.IPBan
import com.projectcitybuild.pcbridge.http.responses.PlayerBan
import com.projectcitybuild.pcbridge.http.responses.PlayerWarning
import com.projectcitybuild.pcbridge.http.responses.PlayerData
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

internal interface PCBRequest {
/**
* Begins the authentication flow by exchanging a player's UUID
* for a URL that they can click and login with
* Fetches all data for the given UUID, such as ban status,
* user groups and badges
*/
@POST("auth/minecraft")
@FormUrlEncoded
suspend fun getVerificationUrl(
@Field("minecraft_uuid") uuid: String,
): ApiResponse<AuthURL>
@GET("v2/minecraft/player/{uuid}")
suspend fun getPlayer(
@Path(value = "uuid") uuid: String,
@Query("ip") ip: String,
): ApiResponse<PlayerData>

/**
* Fetches the groups that the given UUID belongs to
* Begins registration of a PCB account linked to the current
* Minecraft player
*/
@GET("auth/minecraft/{uuid}")
suspend fun getUserGroups(
@POST("v2/minecraft/player/{uuid}/register")
@FormUrlEncoded
suspend fun sendRegisterCode(
@Path(value = "uuid") uuid: String,
): ApiResponse<Account>
@Field(value = "alias") playerName: String,
@Field(value = "email") email: String,
): ApiResponse<Unit>

/**
* Fetches various data for the given uuid, such as ban status
* and user groups. This is to make the login more efficient by
* combining everything into one request
* Finishes registration by verifying the code sent to them
* over email
*/
@GET("v2/minecraft/{uuid}/aggregate")
suspend fun getAggregate(
@Path(value = "uuid") uuid: String,
@Query("ip") ip: String,
): ApiResponse<Aggregate>

@GET("v2/minecraft/{uuid}/donation-tiers")
suspend fun getDonationTier(
@Path(value = "uuid") uuid: String,
): ApiResponse<Array<DonationPerk>>

@POST("v2/bans/ip/ban")
@FormUrlEncoded
suspend fun banIP(
@Field("ip_address") ip: String,
@Field("banner_player_id") bannerPlayerId: String?,
@Field("banner_player_type") bannerPlayerType: String = "minecraft_uuid",
@Field("banner_player_alias") bannerPlayerAlias: String,
@Field("reason") reason: String,
): ApiResponse<IPBan>

@POST("v2/bans/ip/unban")
@FormUrlEncoded
suspend fun unbanIP(
@Field("ip_address") ip: String,
@Field("unbanner_player_id") unbannerPlayerId: String?,
@Field("unbanner_player_type") unbannerPlayerType: String = "minecraft_uuid",
@Field("unbanner_player_alias") unbannerPlayerAlias: String,
): ApiResponse<IPBan>

@POST("v2/bans/ip/status")
@FormUrlEncoded
suspend fun getIPStatus(
@Field("ip_address") ip: String,
): ApiResponse<IPBan>

@POST("v2/bans/player/ban")
@PUT("v2/minecraft/player/{uuid}/register")
@FormUrlEncoded
suspend fun banUUID(
@Field("banned_player_id") bannedPlayerId: String,
@Field("banned_player_type") bannedPlayerType: String = "minecraft_uuid",
@Field("banned_player_alias") bannedPlayerAlias: String,
@Field("banner_player_id") bannerPlayerId: String?,
@Field("banner_player_type") bannerPlayerType: String = "minecraft_uuid",
@Field("banner_player_alias") bannerPlayerAlias: String,
@Field("reason") reason: String? = null,
@Field("expires_at") expiresAt: Long?,
): ApiResponse<PlayerBan>

@POST("v2/bans/player/unban")
@FormUrlEncoded
suspend fun unbanUUID(
@Field("banned_player_id") bannedPlayerId: String,
@Field("banned_player_type") bannedPlayerType: String = "minecraft_uuid",
@Field("unbanner_player_id") unbannerPlayerId: String?,
@Field("unbanner_player_type") unbannerPlayerType: String = "minecraft_uuid",
): ApiResponse<PlayerBan>

@POST("v2/bans/player/status")
@FormUrlEncoded
suspend fun getUuidBanStatus(
@Field("player_id") playerId: String,
@Field("player_type") playerType: String = "minecraft_uuid",
): ApiResponse<PlayerBan>

@POST("v2/bans/player/all")
@FormUrlEncoded
suspend fun getUUIDBans(
@Field("player_id") playerId: String,
@Field("player_id_type") playerType: String = "minecraft_uuid",
): ApiResponse<List<PlayerBan>>

@POST("v2/bans/player/ban")
@FormUrlEncoded
suspend fun convertToPermanentBan(
@Field("ban_id") bannedPlayerId: String,
@Field("banner_player_id") bannerPlayerId: String,
@Field("banner_player_type") bannerPlayerType: String = "minecraft_uuid",
@Field("banner_player_alias") bannerPlayerAlias: String,
@Field("reason") reason: String? = null,
): ApiResponse<PlayerBan>

@GET("v2/warnings")
suspend fun getWarnings(
@Query("player_id") playerId: String,
@Query("player_type") playerType: String = "minecraft_uuid",
@Query("player_alias") playerAlias: String,
): ApiResponse<List<PlayerWarning>>

@POST("v2/warnings")
@FormUrlEncoded
suspend fun createWarning(
@Field("warned_player_id") warnedPlayerId: String,
@Field("warned_player_type") warnedPlayerType: String = "minecraft_uuid",
@Field("warned_player_alias") warnedPlayerAlias: String,
@Field("warner_player_id") warnerPlayerId: String,
@Field("warner_player_type") warnerPlayerType: String = "minecraft_uuid",
@Field("warner_player_alias") warnerPlayerAlias: String,
@Field("reason") reason: String,
@Field("weight") weight: Int = 1,
): ApiResponse<PlayerWarning>

@POST("v2/warnings/acknowledge")
@FormUrlEncoded
suspend fun acknowledgeWarning(
@Field("warning_id") warningId: Int,
): ApiResponse<PlayerWarning>
suspend fun verifyRegisterCode(
@Path(value = "uuid") uuid: String,
@Field(value = "code") code: String,
): ApiResponse<Unit>

/**
* Updates the last seen date of the player
*/
@POST("v2/minecraft/telemetry/seen")
@FormUrlEncoded
suspend fun telemetrySeen(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.projectcitybuild.pcbridge.http.responses

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
import java.util.UUID

@Serializable
data class Account(
@SerializedName("account_id")
val id: String = UUID.randomUUID().toString(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.projectcitybuild.pcbridge.http.responses

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
import java.time.LocalDate
import java.time.ZoneId

@Serializable
data class DonationPerk(
@SerializedName("donation_perks_id")
val id: Int = Math.random().toInt(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.projectcitybuild.pcbridge.http.responses

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable

@Serializable
data class DonationTier(
@SerializedName("donation_tier_id")
val id: Int = Math.random().toInt(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.projectcitybuild.pcbridge.http.responses

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable

@Serializable
data class Group(
@SerializedName("group_id")
val id: Int = Math.random().toInt(),
Expand All @@ -11,10 +13,4 @@ data class Group(
val alias: String? = null,
@SerializedName("minecraft_name")
val minecraftName: String?,
@SerializedName("is_default")
private val _isDefault: Boolean = false,
@SerializedName("is_staff")
private val _isStaff: Boolean = false,
@SerializedName("is_admin")
private val _isAdmin: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.projectcitybuild.pcbridge.http.responses

import com.google.gson.annotations.SerializedName

data class Aggregate(
data class PlayerData(
@SerializedName("account")
val account: Account? = null,
@SerializedName("ban")
Expand Down

This file was deleted.

Loading

0 comments on commit 6c2f590

Please sign in to comment.