Harden chess against forged packets and lost moves
- Chain values count once and in order; moves need a fresh value - Game info carries the inviter's chain value; colours come from the invite - Accepters keep their seed; unconfirmed sends keep the move and resend it - Check draw accept and timeout claim preconditions; drop unused minutes - Notify in the background, keep own games under the cap, 16-bit ply - Sanitise adopted castling rights, guard incoming handling - Localised square labels and translations for the new strings - Restore two Korean strings changed by mistake
This commit is contained in:
1 parent
adead644c7
commit
c2877f6875
53 files changed
+1977
-306
No files matched your search
@@ -197,6 +197,22 @@ class _ChessBoardViewState extends State<ChessBoardView> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Screen reader label of an occupied square, e.g. "e4: Pawn, white".
|
||||
static String _pieceLabel(BuildContext context, String square, String piece) {
|
||||
final l10n = context.l10n;
|
||||
final name = switch (piece.toLowerCase()) {
|
||||
'k' => l10n.chess_pieceKing,
|
||||
'q' => l10n.chess_pieceQueen,
|
||||
'r' => l10n.chess_pieceRook,
|
||||
'b' => l10n.chess_pieceBishop,
|
||||
'n' => l10n.chess_pieceKnight,
|
||||
_ => l10n.chess_piecePawn,
|
||||
};
|
||||
return piece == piece.toUpperCase()
|
||||
? l10n.chess_squareWhitePiece(square, name)
|
||||
: l10n.chess_squareBlackPiece(square, name);
|
||||
}
|
||||
|
||||
Widget _square(
|
||||
BuildContext context, {
|
||||
required ColorScheme scheme,
|
||||
@@ -225,7 +241,7 @@ class _ChessBoardViewState extends State<ChessBoardView> {
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => _onTap(square),
|
||||
child: Semantics(
|
||||
label: piece == null ? square : '$square $piece',
|
||||
label: piece == null ? square : _pieceLabel(context, square, piece),
|
||||
button: isTarget || (_interactive && piece != null),
|
||||
selected: isSelected,
|
||||
child: SizedBox(
|
||||
|
||||
@@ -267,7 +267,12 @@ class _StatusCard extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!game.hasPlayers) lines.add(l10n.chess_statusUnverified);
|
||||
if (game.moveUnconfirmed) lines.add(l10n.chess_statusMoveUnconfirmed);
|
||||
if (!game.hasPlayers) {
|
||||
lines.add(l10n.chess_statusUnverified);
|
||||
} else if (!game.playersConfirmed) {
|
||||
lines.add(l10n.chess_statusPlayersUnchecked);
|
||||
}
|
||||
}
|
||||
return MeshCard(
|
||||
child: Column(
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../helpers/snack_bar_builder.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import '../../../l10n/l10n.dart';
|
||||
import '../../../models/channel.dart';
|
||||
import '../../../utils/radio_guard.dart';
|
||||
@@ -96,8 +97,7 @@ class _ChessGamesSheetBody extends StatelessWidget {
|
||||
(g) =>
|
||||
g.status == ChessGameStatus.invite &&
|
||||
!g.iAmInviter &&
|
||||
(g.targetName == null ||
|
||||
_sameName(g.targetName!, service.selfName)),
|
||||
service.isListed(g),
|
||||
)
|
||||
.toList();
|
||||
final live = games
|
||||
@@ -170,9 +170,6 @@ class _ChessGamesSheetBody extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
bool _sameName(String a, String b) =>
|
||||
a.trim().toLowerCase() == b.trim().toLowerCase();
|
||||
|
||||
class _ActionCard extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
@@ -251,7 +248,9 @@ class _GameCard extends StatelessWidget {
|
||||
: l10n.chess_statusToMove(toMove);
|
||||
subtitle = l10n.chess_rowMoveTurn((game.ply ~/ 2) + 1, turn);
|
||||
case ChessGameStatus.finished:
|
||||
title = l10n.chessPlayers(game);
|
||||
title = game.hasPlayers || game.inviter == null
|
||||
? l10n.chessPlayers(game)
|
||||
: _inviteTitle(l10n, service);
|
||||
subtitle = l10n.chessResult(game);
|
||||
}
|
||||
return MeshCard(
|
||||
@@ -302,6 +301,21 @@ class _GameCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// An invite that never became a game: who invited whom.
|
||||
String _inviteTitle(AppLocalizations l10n, ChessService service) {
|
||||
final target = game.targetName;
|
||||
if (game.iAmInviter) {
|
||||
return target == null
|
||||
? l10n.chess_rowYourOpenInvite
|
||||
: l10n.chess_rowYourChallenge(target);
|
||||
}
|
||||
final inviter = game.inviter?.name ?? l10n.chess_unknownPlayer;
|
||||
if (target == null) return l10n.chess_rowOpenInvite(inviter);
|
||||
return service.isSelf(target)
|
||||
? l10n.chess_rowChallengedYou(inviter)
|
||||
: l10n.chess_rowChallenge(inviter, target);
|
||||
}
|
||||
|
||||
Future<void> _confirmCancel(
|
||||
BuildContext context,
|
||||
ChessService service,
|
||||
|
||||
Reference in new issue
Block a user