mirror of
https://github.com/kalarina-bit/Matewave.git
synced 2026-11-22 08:06:09 +00:00
Remove the outdated-app check on connect and its messages
- Drop the protocol version gate in the game handshake and its banner - Admit spectators of any version and drop the update-required dialogs - Remove the related strings and tests; reword the unverified warning
This commit is contained in:
@@ -9,8 +9,8 @@ enum class ConnectionState { DISCONNECTED, CONNECTING, CONNECTED, FAILED }
|
||||
/**
|
||||
* Wire protocol shared by all transports: one JSON object per message.
|
||||
* Game messages travel inside [SignedMsg] once the handshake is done; only
|
||||
* [ProfileMsg] and [PingMsg] are sent in the clear. Bump [PROTOCOL_VERSION] on any
|
||||
* incompatible change: peers with an older version are rejected during the handshake.
|
||||
* [ProfileMsg] and [PingMsg] are sent in the clear. [PROTOCOL_VERSION] is sent in the
|
||||
* profile for information only; peers are not rejected by version.
|
||||
*/
|
||||
sealed class GameMessage {
|
||||
data class MoveMsg(
|
||||
|
||||
@@ -27,7 +27,7 @@ class SpectatorClient(
|
||||
) {
|
||||
data class Timing(val connectTimeoutMs: Int = 5_000, val silenceTimeoutMs: Int = 15_000)
|
||||
|
||||
enum class Failure { UNREACHABLE, FULL, NO_GAME, UPDATE_THIS_APP, UPDATE_HOST_APP }
|
||||
enum class Failure { UNREACHABLE, FULL, NO_GAME }
|
||||
|
||||
sealed class Event {
|
||||
data class Joined(val welcome: SpectatorMessage.Welcome) : Event()
|
||||
@@ -97,15 +97,10 @@ class SpectatorClient(
|
||||
val envelope = SpectatorProtocol.decode(read.text) ?: continue
|
||||
val message = envelope.message
|
||||
if (!joined) {
|
||||
// reject keeps its shape across versions, so read it before the version gate.
|
||||
if (message is SpectatorMessage.Reject) {
|
||||
emit(Event.JoinFailed(failureOf(message)))
|
||||
return
|
||||
}
|
||||
if (envelope.version < minVersion) {
|
||||
emit(Event.JoinFailed(Failure.UPDATE_HOST_APP))
|
||||
return
|
||||
}
|
||||
if (message is SpectatorMessage.Welcome) {
|
||||
joined = true
|
||||
emit(Event.Joined(message))
|
||||
@@ -133,8 +128,6 @@ class SpectatorClient(
|
||||
private fun failureOf(reject: SpectatorMessage.Reject): Failure = when (reject.reason) {
|
||||
RejectReason.FULL -> Failure.FULL
|
||||
RejectReason.NO_GAME -> Failure.NO_GAME
|
||||
RejectReason.UPDATE_REQUIRED ->
|
||||
if (version < reject.minVersion) Failure.UPDATE_THIS_APP else Failure.UPDATE_HOST_APP
|
||||
RejectReason.OTHER -> Failure.UNREACHABLE
|
||||
}
|
||||
|
||||
|
||||
@@ -141,14 +141,7 @@ class SpectatorHub(
|
||||
val envelope = (first as? LineResult.Line)?.let { SpectatorProtocol.decode(it.text) }
|
||||
when (envelope?.message) {
|
||||
SpectatorMessage.StatusQuery -> reply(client, status())
|
||||
is SpectatorMessage.Hello -> {
|
||||
if (envelope.version < SpectatorProtocol.MIN_COMPATIBLE_VERSION) {
|
||||
log("Spectator with protocol ${envelope.version} told to update")
|
||||
reply(client, SpectatorMessage.Reject(RejectReason.UPDATE_REQUIRED, SpectatorProtocol.MIN_COMPATIBLE_VERSION))
|
||||
} else {
|
||||
spectator = admit(client)
|
||||
}
|
||||
}
|
||||
is SpectatorMessage.Hello -> { spectator = admit(client) }
|
||||
else -> Unit
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
|
||||
@@ -57,7 +57,6 @@ data class SpectatorSnapshot(
|
||||
|
||||
enum class RejectReason(val wire: String) {
|
||||
FULL("full"),
|
||||
UPDATE_REQUIRED("update"),
|
||||
NO_GAME("no_game"),
|
||||
OTHER("other");
|
||||
|
||||
@@ -94,11 +93,7 @@ data class SpectatorEnvelope(val version: Int, val message: SpectatorMessage?)
|
||||
* the sender's protocol version in "sv". Unknown types are skipped, never fatal.
|
||||
*/
|
||||
object SpectatorProtocol {
|
||||
/**
|
||||
* Bump on incompatible changes and raise [MIN_COMPATIBLE_VERSION] to the oldest version still
|
||||
* understood. hello, status and reject keep their shape so any two versions can still tell
|
||||
* each other that an update is required.
|
||||
*/
|
||||
/** Sent with every message for information only; no version is ever refused. */
|
||||
const val VERSION = 1
|
||||
const val MIN_COMPATIBLE_VERSION = 1
|
||||
|
||||
|
||||
@@ -558,7 +558,6 @@ private fun ConnectionBanner(state: GameUiState) {
|
||||
private fun TrustBanners(state: GameUiState) {
|
||||
val (icon, text, color) = when {
|
||||
state.opponentUntrusted -> Triple(R.drawable.ic_no_encryption, stringResource(R.string.trust_impersonation), Color(0xFFFF6B6B))
|
||||
state.opponentOutdated -> Triple(R.drawable.ic_error, stringResource(R.string.trust_outdated), Color(0xFFFF6B6B))
|
||||
state.opponentUnverified -> Triple(R.drawable.ic_no_encryption, stringResource(R.string.trust_unverified), Color(0xFFFFC46B))
|
||||
else -> Triple(0, null, Color.Unspecified)
|
||||
}
|
||||
|
||||
@@ -182,10 +182,6 @@ fun SpectatorScreen(target: SpectateTarget, onBackToFriends: () -> Unit) {
|
||||
private fun failureTexts(failure: SpectatorClient.Failure?, max: Int): Pair<String, String> = when (failure) {
|
||||
SpectatorClient.Failure.FULL ->
|
||||
stringResource(R.string.spectate_full_title) to stringResource(R.string.spectate_full_text, max)
|
||||
SpectatorClient.Failure.UPDATE_THIS_APP ->
|
||||
stringResource(R.string.spectate_update_title) to stringResource(R.string.spectate_update_this)
|
||||
SpectatorClient.Failure.UPDATE_HOST_APP ->
|
||||
stringResource(R.string.spectate_update_title) to stringResource(R.string.spectate_update_host)
|
||||
SpectatorClient.Failure.NO_GAME ->
|
||||
stringResource(R.string.spectate_failed_title) to stringResource(R.string.spectate_no_game)
|
||||
SpectatorClient.Failure.UNREACHABLE, null ->
|
||||
|
||||
@@ -84,7 +84,6 @@ data class GameUiState(
|
||||
|
||||
val opponentUntrusted: Boolean = false,
|
||||
val opponentUnverified: Boolean = false,
|
||||
val opponentOutdated: Boolean = false,
|
||||
val handshake: HandshakeState = HandshakeState.DISCONNECTED,
|
||||
val newPeerFingerprint: String? = null,
|
||||
|
||||
@@ -1078,13 +1077,6 @@ class GameViewModel : ViewModel() {
|
||||
NetworkLog.log("GAME", "Repeated profile in current session ignored")
|
||||
return
|
||||
}
|
||||
if (msg.protocolVersion < GameMessage.PROTOCOL_VERSION) {
|
||||
NetworkLog.log(
|
||||
"GAME", "Opponent protocol version ${msg.protocolVersion} < ${GameMessage.PROTOCOL_VERSION}, incompatible"
|
||||
)
|
||||
_uiState.value = _uiState.value.copy(opponentOutdated = true)
|
||||
return
|
||||
}
|
||||
val peers = knownPeers
|
||||
if (peers == null) {
|
||||
NetworkLog.log("GAME", "Key store not ready, profile rejected")
|
||||
|
||||
Reference in New Issue
Block a user