Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ready request and response #96

Merged
merged 6 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ interface LobbyProtocolMessage {
JsonSubTypes.Type(value = AcceptInviteToPartyRequest::class, name = "accept_party_invite"),
JsonSubTypes.Type(value = KickPlayerFromPartyRequest::class, name = "kick_player_from_party"),
JsonSubTypes.Type(value = LeavePartyRequest::class, name = "leave_party"),
JsonSubTypes.Type(value = ReadyPartyRequest::class, name = "ready_party"),
JsonSubTypes.Type(value = UnreadyPartyRequest::class, name = "unready_party"),
JsonSubTypes.Type(value = SelectPartyFactionsRequest::class, name = "set_party_factions"),
JsonSubTypes.Type(value = GameMatchmakingRequest::class, name = "game_matchmaking"),
JsonSubTypes.Type(value = MatchmakerInfoRequest::class, name = "matchmaker_info"),
JsonSubTypes.Type(value = AuthenticateRequest::class, name = "auth"),
JsonSubTypes.Type(value = IsReadyResponse::class, name = "is_ready_response"),
// GPG Client Messages not directly instantiated they are only forwarded from the game so are serialized directly
)
interface ClientMessage : LobbyProtocolMessage
Expand Down Expand Up @@ -82,6 +82,7 @@ interface ClientMessage : LobbyProtocolMessage
JsonSubTypes.Type(value = ConnectToPeerGpgCommand::class, name = "ConnectToPeer"),
JsonSubTypes.Type(value = IceMsgGpgCommand::class, name = "IceMsg"),
JsonSubTypes.Type(value = DisconnectFromPeerGpgCommand::class, name = "DisconnectFromPeer"),
JsonSubTypes.Type(value = IsReadyRequest::class, name = "is_ready"),
)
interface ServerMessage : LobbyProtocolMessage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ class FafLobbyClient(
.flatMapIterable { it.avatarList }
)

override fun sendReady(requestId: String) = send(IsReadyResponse(requestId))

override fun requestMatchmakerInfo() = send(MatchmakerInfoRequest())

override fun gameMatchmaking(queueName: String, state: MatchmakerState) =
Expand All @@ -381,8 +383,6 @@ class FafLobbyClient(

override fun kickPlayerFromParty(playerId: Int) = send(KickPlayerFromPartyRequest(playerId))

override fun readyParty() = send(ReadyPartyRequest())

override fun unreadyParty() = send(UnreadyPartyRequest())

override fun leaveParty() = send(LeavePartyRequest())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ enum class GameType {
@JsonProperty("custom")
CUSTOM,

@JsonProperty("tournament")
TOURNAMENT,

@JsonProperty("matchmaker")
MATCHMAKER,

Expand Down Expand Up @@ -183,7 +186,7 @@ data class GameLaunchResponse(
* Technical name of the leaderboard to select ratings to be shown
*/
@JsonProperty("rating_type")
val leaderboard: String,
val leaderboard: String?,
val args: List<String>,

@JsonProperty("mapname")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ interface MatchmakerApi {

fun kickPlayerFromParty(playerId: Int)

fun readyParty()

fun unreadyParty()

fun leaveParty()

fun setPartyFactions(factions: Set<Faction>)

fun sendReady(requestId: String)

}


Expand Down Expand Up @@ -105,10 +106,35 @@ data class SearchInfo(
) : ServerMessage



/**
* Server asked if the client is ready for a gw or tournament game
*/
data class IsReadyRequest(
@JsonProperty("game_name")
val gameName: String,
@JsonProperty("featured_mod")
val featuredMod: String,
@JsonProperty("response_time_seconds")
val responseTimeSeconds: Int,
@JsonProperty("request_id")
val requestId: String,
) : ServerMessage


// ***********************
// *** CLIENT MESSAGES ***
// ***********************


/**
* Client answers if the client is ready for a gw or tournament game
*/
internal data class IsReadyResponse(
@JsonProperty("request_id")
val requestId: String,
) : ClientMessage

internal data class GameMatchmakingRequest(
@JsonProperty("queue_name")
val queueName: String,
Expand All @@ -130,8 +156,6 @@ internal data class KickPlayerFromPartyRequest(
val playerId: Int
) : ClientMessage

internal class ReadyPartyRequest : ClientMessage

internal class UnreadyPartyRequest : ClientMessage

internal class LeavePartyRequest : ClientMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ class ClientMessageTest {
objectMapper.writeValueAsString(LeavePartyRequest()), true)
}

@Test
fun serializeReadyPartyRequest() {
JSONAssert.assertEquals("""
{"command":"ready_party"}
""",
objectMapper.writeValueAsString(ReadyPartyRequest()), true)
}

@Test
fun serializeUnreadyPartyRequest() {
JSONAssert.assertEquals("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,6 @@ class LobbyClientTest {
stepVerifier.verify(verificationDuration)
}

@Test
fun testReadyParty() {
val stepVerifier = StepVerifier.create(serverMessagesReceived.take(1))
.assertNext { assertCommandMatch(it, ReadyPartyRequest()) }
.expectComplete()
.verifyLater()

instance.readyParty()

stepVerifier.verify(verificationDuration)
}

@Test
fun testUnreadyParty() {
val stepVerifier = StepVerifier.create(serverMessagesReceived.take(1))
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lombokVersion=1.18.18
lombokVersion=1.18.24
junitVersion=5.7.1
mockitoVersion=2.24.0
hamcrestVersion=2.2
Expand Down