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")
|
||||
|
||||
@@ -105,8 +105,7 @@
|
||||
<string name="mesh_permission_text">Um Spieler in der Nähe zu finden und ohne Internet mit ihnen zu spielen, braucht die App Zugriff auf Bluetooth. Die Suche läuft nur, solange der Bildschirm „Spiel in der Nähe“ geöffnet ist.</string>
|
||||
<string name="permissions_card_title">Berechtigungen</string>
|
||||
<string name="trust_impersonation">Dieser Spieler gibt sich als jemand anderes aus – Daten abgelehnt</string>
|
||||
<string name="trust_unverified">Die Identität des Gegners ist nicht bestätigt (er hat eine alte App-Version)</string>
|
||||
<string name="trust_outdated">Die App des Gegners ist veraltet – sicheres Spielen ist nicht möglich. Beide sollten die App aktualisieren.</string>
|
||||
<string name="trust_unverified">Die Identität des Gegners ist nicht bestätigt</string>
|
||||
<string name="perm_grant">Erlauben</string>
|
||||
<string name="perm_nearby_title">Verbindung zu Geräten in der Nähe</string>
|
||||
<string name="perm_nearby_text">Nötig, um Spieler in der Nähe zu finden und ohne Internet zu spielen.</string>
|
||||
@@ -361,9 +360,6 @@
|
||||
<string name="spectate_lost_text">Das Gerät, auf dem die Partie läuft, ist nicht mehr erreichbar.</string>
|
||||
<string name="spectate_full_title">Partie ist voll</string>
|
||||
<string name="spectate_full_text">Diese Partie hat bereits die maximale Zahl von %1$d Zuschauern. Versuch es später noch einmal.</string>
|
||||
<string name="spectate_update_title">Update erforderlich</string>
|
||||
<string name="spectate_update_this">Aktualisiere Matewave, um diese Partie anzusehen.</string>
|
||||
<string name="spectate_update_host">Der Spieler, der diese Partie ausrichtet, muss Matewave aktualisieren, bevor man zuschauen kann.</string>
|
||||
<string name="spectate_failed_title">Zuschauen nicht möglich</string>
|
||||
<string name="spectate_no_game">Diese Partie ist nicht mehr verfügbar.</string>
|
||||
<string name="spectate_unreachable">Das Gerät, auf dem die Partie läuft, ist nicht erreichbar. Achte darauf, dass du im selben WLAN bist.</string>
|
||||
|
||||
@@ -105,8 +105,7 @@
|
||||
<string name="mesh_permission_text">近くのプレイヤーを見つけてインターネットなしで対戦するには、Bluetoothへのアクセスが必要です。検索は「近くで対戦」画面を開いている間だけ行われます。</string>
|
||||
<string name="permissions_card_title">権限</string>
|
||||
<string name="trust_impersonation">このプレイヤーは他人になりすましています — データを拒否しました</string>
|
||||
<string name="trust_unverified">相手の本人確認ができていません(古いバージョンのアプリです)</string>
|
||||
<string name="trust_outdated">相手のアプリが古いため、安全に対局できません。両方のアプリを更新してください。</string>
|
||||
<string name="trust_unverified">相手の本人確認ができていません</string>
|
||||
<string name="perm_grant">許可</string>
|
||||
<string name="perm_nearby_title">近くのデバイスとの通信</string>
|
||||
<string name="perm_nearby_text">近くのプレイヤーを見つけ、インターネットなしで対戦するために必要です。</string>
|
||||
@@ -360,9 +359,6 @@
|
||||
<string name="spectate_lost_text">対局をホストしている端末に接続できなくなりました。</string>
|
||||
<string name="spectate_full_title">満員です</string>
|
||||
<string name="spectate_full_text">この対局の観戦者はすでに上限の%1$d人です。しばらくしてからもう一度お試しください。</string>
|
||||
<string name="spectate_update_title">アップデートが必要です</string>
|
||||
<string name="spectate_update_this">この対局を観戦するには Matewave をアップデートしてください。</string>
|
||||
<string name="spectate_update_host">この対局を観戦するには、対局をホストしているプレイヤーが Matewave をアップデートする必要があります。</string>
|
||||
<string name="spectate_failed_title">観戦できません</string>
|
||||
<string name="spectate_no_game">この対局はもう観戦できません。</string>
|
||||
<string name="spectate_unreachable">対局をホストしている端末に接続できません。同じWi-Fiネットワークに接続しているか確認してください。</string>
|
||||
|
||||
@@ -105,8 +105,7 @@
|
||||
<string name="mesh_permission_text">Kad rastų netoliese esančius žaidėjus ir galėtų su jais žaisti be interneto, programai reikia prieigos prie „Bluetooth“. Paieška vyksta tik kol atidarytas ekranas „Žaidimas netoliese“.</string>
|
||||
<string name="permissions_card_title">Leidimai</string>
|
||||
<string name="trust_impersonation">Šis žaidėjas apsimeta kitu — duomenys atmesti</string>
|
||||
<string name="trust_unverified">Varžovo tapatybė nepatvirtinta (jis turi seną programos versiją)</string>
|
||||
<string name="trust_outdated">Varžovo programa pasenusi – saugus žaidimas neįmanomas. Atnaujinkite programą abiem.</string>
|
||||
<string name="trust_unverified">Varžovo tapatybė nepatvirtinta</string>
|
||||
<string name="perm_grant">Leisti</string>
|
||||
<string name="perm_nearby_title">Ryšys su netoliese esančiais įrenginiais</string>
|
||||
<string name="perm_nearby_text">Reikalinga, kad rastumėte žaidėjų netoliese ir žaistumėte be interneto.</string>
|
||||
@@ -363,9 +362,6 @@
|
||||
<string name="spectate_lost_text">Įrenginio, kuriame vyksta partija, nebepavyksta pasiekti.</string>
|
||||
<string name="spectate_full_title">Vietų nebėra</string>
|
||||
<string name="spectate_full_text">Šią partiją jau stebi didžiausias leidžiamas žiūrovų skaičius (%1$d). Pabandykite vėliau.</string>
|
||||
<string name="spectate_update_title">Reikia atnaujinti</string>
|
||||
<string name="spectate_update_this">Atnaujinkite Matewave, kad galėtumėte stebėti šią partiją.</string>
|
||||
<string name="spectate_update_host">Partiją rengiantis žaidėjas turi atnaujinti Matewave, kad ją būtų galima stebėti.</string>
|
||||
<string name="spectate_failed_title">Šios partijos stebėti negalima</string>
|
||||
<string name="spectate_no_game">Ši partija nebepasiekiama.</string>
|
||||
<string name="spectate_unreachable">Nepavyksta pasiekti įrenginio, kuriame vyksta partija. Įsitikinkite, kad esate prisijungę prie to paties „Wi-Fi“ tinklo.</string>
|
||||
|
||||
@@ -110,8 +110,7 @@
|
||||
<string name="mesh_permission_text">Чтобы находить игроков рядом и играть с ними без интернета, приложению нужен доступ к Bluetooth. Поиск идёт, только пока открыт экран «Игра рядом».</string>
|
||||
<string name="permissions_card_title">Разрешения</string>
|
||||
<string name="trust_impersonation">Этот игрок выдаёт себя за другого — данные не приняты</string>
|
||||
<string name="trust_unverified">Личность соперника не подтверждена (у него старая версия приложения)</string>
|
||||
<string name="trust_outdated">У соперника устаревшая версия приложения — безопасная игра невозможна. Обновите приложение у обоих.</string>
|
||||
<string name="trust_unverified">Личность соперника не подтверждена</string>
|
||||
<string name="perm_grant">Разрешить</string>
|
||||
<string name="perm_nearby_title">Связь с устройствами рядом</string>
|
||||
<string name="perm_nearby_text">Нужна, чтобы находить игроков поблизости и играть без интернета.</string>
|
||||
@@ -369,9 +368,6 @@
|
||||
<string name="spectate_lost_text">Устройство, на котором идёт партия, больше недоступно.</string>
|
||||
<string name="spectate_full_title">Мест нет</string>
|
||||
<string name="spectate_full_text">У этой партии уже максимум зрителей (%1$d). Попробуйте позже.</string>
|
||||
<string name="spectate_update_title">Требуется обновление</string>
|
||||
<string name="spectate_update_this">Обновите Matewave, чтобы смотреть эту партию.</string>
|
||||
<string name="spectate_update_host">Игроку, который проводит эту партию, нужно обновить Matewave, чтобы её можно было смотреть.</string>
|
||||
<string name="spectate_failed_title">Не удаётся посмотреть партию</string>
|
||||
<string name="spectate_no_game">Эта партия больше недоступна.</string>
|
||||
<string name="spectate_unreachable">Устройство, на котором идёт партия, недоступно. Убедитесь, что вы подключены к той же сети Wi-Fi.</string>
|
||||
|
||||
@@ -105,8 +105,7 @@
|
||||
<string name="mesh_permission_text">要查找附近的玩家并在无网络时与他们对战,应用需要蓝牙权限。仅在“附近对战”页面打开时进行搜索。</string>
|
||||
<string name="permissions_card_title">权限</string>
|
||||
<string name="trust_impersonation">该玩家冒充他人 — 数据已拒绝</string>
|
||||
<string name="trust_unverified">对手身份未验证(对方使用的是旧版应用)</string>
|
||||
<string name="trust_outdated">对手的应用版本过旧,无法安全对局。请双方都更新应用。</string>
|
||||
<string name="trust_unverified">对手身份未验证</string>
|
||||
<string name="perm_grant">允许</string>
|
||||
<string name="perm_nearby_title">与附近设备通信</string>
|
||||
<string name="perm_nearby_text">用于发现附近的玩家并在无网络时对战。</string>
|
||||
@@ -360,9 +359,6 @@
|
||||
<string name="spectate_lost_text">无法再连接到主持对局的设备。</string>
|
||||
<string name="spectate_full_title">观战人数已满</string>
|
||||
<string name="spectate_full_text">此对局的观战人数已达上限(%1$d 人),请稍后再试。</string>
|
||||
<string name="spectate_update_title">需要更新</string>
|
||||
<string name="spectate_update_this">请更新 Matewave 以观看此对局。</string>
|
||||
<string name="spectate_update_host">主持此对局的玩家需要更新 Matewave 后才能观战。</string>
|
||||
<string name="spectate_failed_title">无法观看此对局</string>
|
||||
<string name="spectate_no_game">此对局已不可观看。</string>
|
||||
<string name="spectate_unreachable">无法连接到主持对局的设备。请确认你们连接的是同一个 Wi-Fi 网络。</string>
|
||||
|
||||
@@ -105,8 +105,7 @@
|
||||
<string name="mesh_permission_text">To find players nearby and play with them without the internet, the app needs Bluetooth access. Searching runs only while the nearby play screen is open.</string>
|
||||
<string name="permissions_card_title">Permissions</string>
|
||||
<string name="trust_impersonation">This player is impersonating someone else — data rejected</string>
|
||||
<string name="trust_unverified">The opponent\'s identity isn\'t verified (they have an old version of the app)</string>
|
||||
<string name="trust_outdated">The opponent\'s app is outdated and can\'t play securely with yours. Both players need to update.</string>
|
||||
<string name="trust_unverified">The opponent\'s identity isn\'t verified</string>
|
||||
<string name="perm_grant">Allow</string>
|
||||
<string name="perm_nearby_title">Nearby device connection</string>
|
||||
<string name="perm_nearby_text">Needed to find players nearby and play without the internet.</string>
|
||||
@@ -361,9 +360,6 @@
|
||||
<string name="spectate_lost_text">The host\'s device can no longer be reached.</string>
|
||||
<string name="spectate_full_title">Game is full</string>
|
||||
<string name="spectate_full_text">This game already has the maximum of %1$d spectators. Try again later.</string>
|
||||
<string name="spectate_update_title">Update required</string>
|
||||
<string name="spectate_update_this">Update Matewave to watch this game.</string>
|
||||
<string name="spectate_update_host">The player hosting this game needs to update Matewave before it can be watched.</string>
|
||||
<string name="spectate_failed_title">Can\'t watch this game</string>
|
||||
<string name="spectate_no_game">This game is no longer available.</string>
|
||||
<string name="spectate_unreachable">The host\'s device can\'t be reached. Make sure you\'re on the same Wi-Fi network.</string>
|
||||
|
||||
@@ -2,7 +2,6 @@ package cc.skysparkle.matewave
|
||||
|
||||
import cc.skysparkle.matewave.engine.PieceColor
|
||||
import cc.skysparkle.matewave.spectate.MAX_SPECTATORS
|
||||
import cc.skysparkle.matewave.spectate.RejectReason
|
||||
import cc.skysparkle.matewave.spectate.SpectatorBroadcaster
|
||||
import cc.skysparkle.matewave.spectate.SpectatorClient
|
||||
import cc.skysparkle.matewave.spectate.SpectatorClient.Event
|
||||
@@ -24,10 +23,8 @@ import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.Test
|
||||
import java.io.BufferedReader
|
||||
import java.io.Closeable
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.net.InetAddress
|
||||
import java.net.ServerSocket
|
||||
import java.net.Socket
|
||||
@@ -271,35 +268,6 @@ class SpectatorHubTest {
|
||||
assertTrue("publish took $elapsedMs ms", elapsedMs < 1_000)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun outdatedSpectatorIsToldToUpdate() {
|
||||
val hub = hub()
|
||||
val (_, recorder) = watch(hub.port, version = 0, minVersion = 0)
|
||||
assertEquals(Event.JoinFailed(Failure.UPDATE_THIS_APP), recorder.next())
|
||||
assertEquals(0, hub.count.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun outdatedHostIsReported() {
|
||||
val hub = hub()
|
||||
val newer = SpectatorProtocol.VERSION + 1
|
||||
val (_, recorder) = watch(hub.port, version = newer, minVersion = newer)
|
||||
assertEquals(Event.JoinFailed(Failure.UPDATE_HOST_APP), recorder.next())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rawOldClientGetsAClearRejectInsteadOfACrash() {
|
||||
val hub = hub()
|
||||
Socket(loopback, hub.port).use { s ->
|
||||
s.soTimeout = 2_000
|
||||
s.getOutputStream().write("{\"type\":\"hello\",\"sv\":0}\n".toByteArray())
|
||||
val reply = BufferedReader(InputStreamReader(s.getInputStream())).readLine()
|
||||
val reject = SpectatorProtocol.decode(reply)!!.message as SpectatorMessage.Reject
|
||||
assertEquals(RejectReason.UPDATE_REQUIRED, reject.reason)
|
||||
assertEquals(SpectatorProtocol.MIN_COMPATIBLE_VERSION, reject.minVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun garbageAndOversizedInputCloseOnlyThatConnection() {
|
||||
val hub = hub()
|
||||
|
||||
Reference in New Issue
Block a user