Make custom lobby leave idempotent for stale lobby IDs
This commit is contained in:
@@ -168,7 +168,12 @@ func leave(on_done: Callable = Callable()) -> void:
|
|||||||
lobby_left.emit()
|
lobby_left.emit()
|
||||||
if on_done.is_valid(): on_done.call(),
|
if on_done.is_valid(): on_done.call(),
|
||||||
func(code: String, msg: String) -> void:
|
func(code: String, msg: String) -> void:
|
||||||
print("[CustomLobby] ERR leave ", code, " ", msg))
|
print("[CustomLobby] ERR leave ", code, " ", msg)
|
||||||
|
if code == "LOBBY_NOT_FOUND":
|
||||||
|
# Treat as stale local lobby state and recover UX.
|
||||||
|
clear_state()
|
||||||
|
lobby_left.emit()
|
||||||
|
if on_done.is_valid(): on_done.call())
|
||||||
|
|
||||||
|
|
||||||
## Mark the caller as ready with their final deck and first-turn preference.
|
## Mark the caller as ready with their final deck and first-turn preference.
|
||||||
|
|||||||
@@ -45,8 +45,13 @@ internal sealed class GameLeaveCustomLobbyHandler : GameHandlerBase, IMessageHan
|
|||||||
var req = _serializer.DeserializePayload<LeaveCustomLobbyRequest>(message.Payload);
|
var req = _serializer.DeserializePayload<LeaveCustomLobbyRequest>(message.Payload);
|
||||||
var accountId = Guid.Parse(connection.UserId);
|
var accountId = Guid.Parse(connection.UserId);
|
||||||
|
|
||||||
var lobby = await _gameDb.CustomLobbies.FindAsync([req.LobbyId], ct)
|
var lobby = await _gameDb.CustomLobbies.FindAsync([req.LobbyId], ct);
|
||||||
?? throw new GameException("LOBBY_NOT_FOUND");
|
if (lobby is null)
|
||||||
|
{
|
||||||
|
// Idempotent leave: stale client lobby IDs should not hard-fail.
|
||||||
|
return ServerMessage.Reply("game.custom.leave.ack", message.Seq,
|
||||||
|
new LeaveCustomLobbyResponse(LobbyId: req.LobbyId));
|
||||||
|
}
|
||||||
|
|
||||||
// If already resolved (game started or lobby cancelled), return success silently.
|
// If already resolved (game started or lobby cancelled), return success silently.
|
||||||
// Player should use game.concede for an in-progress game.
|
// Player should use game.concede for an in-progress game.
|
||||||
|
|||||||
Reference in New Issue
Block a user