apologiesserver.interface¶
Definition of the public interface for the server.
Both requests (message sent from a client to the server) and events (published from the server to one or more clients) can be serialized and deserialized to and from JSON. However, we apply much tighter validation rules on the context associated with requests, since the input is untrusted. We assume that the unit tests and the Python type validations imposed by MyPy give us everything we need for events that are only built internally.
The file docs/design.rst includes a detailed discussion of each request and event.
Module Contents¶
- class apologiesserver.interface.Visibility(*args, **kwds)¶
Bases:
enum.EnumVisibility for advertised games.
- PUBLIC = 'Public'¶
- PRIVATE = 'Private'¶
- class apologiesserver.interface.CancelledReason(*args, **kwds)¶
Bases:
enum.EnumReasons a game can be cancelled.
- CANCELLED = 'Game was cancelled by advertiser'¶
- NOT_VIABLE = 'Game is no longer viable.'¶
- INACTIVE = 'The game was idle too long and was marked inactive'¶
- SHUTDOWN = 'Game was cancelled due to system shutdown'¶
- class apologiesserver.interface.PlayerType(*args, **kwds)¶
Bases:
enum.EnumTypes of players.
- HUMAN = 'Human'¶
- PROGRAMMATIC = 'Programmatic'¶
- class apologiesserver.interface.PlayerState(*args, **kwds)¶
Bases:
enum.EnumA player’s game state.
- WAITING = 'Waiting'¶
- JOINED = 'Joined'¶
- PLAYING = 'Playing'¶
- FINISHED = 'Finished'¶
- QUIT = 'Quit'¶
- DISCONNECTED = 'Disconnected'¶
- class apologiesserver.interface.ConnectionState(*args, **kwds)¶
Bases:
enum.EnumA player’s connection state.
- CONNECTED = 'Connected'¶
- DISCONNECTED = 'Disconnected'¶
- class apologiesserver.interface.ActivityState(*args, **kwds)¶
Bases:
enum.EnumA player’s activity state.
- ACTIVE = 'Active'¶
- IDLE = 'Idle'¶
- INACTIVE = 'Inactive'¶
- class apologiesserver.interface.GameState(*args, **kwds)¶
Bases:
enum.EnumA game’s state.
- ADVERTISED = 'Advertised'¶
- PLAYING = 'Playing'¶
- COMPLETED = 'Completed'¶
- CANCELLED = 'Cancelled'¶
- class apologiesserver.interface.FailureReason(*args, **kwds)¶
Bases:
enum.EnumFailure reasons advertised to clients.
- INVALID_REQUEST = 'Invalid request'¶
- DUPLICATE_USER = 'Handle is already in use'¶
- INVALID_AUTH = 'Missing or invalid authorization header'¶
- WEBSOCKET_LIMIT = 'Connection limit reached; try again later'¶
- USER_LIMIT = 'System user limit reached; try again later'¶
- GAME_LIMIT = 'System game limit reached; try again later'¶
- INVALID_PLAYER = 'Unknown or invalid player'¶
- INVALID_GAME = 'Unknown or invalid game'¶
- NOT_PLAYING = 'Player is not playing a game'¶
- NOT_ADVERTISER = 'Player did not advertise this game'¶
- ALREADY_PLAYING = 'Player is already playing a game'¶
- NO_MOVE_PENDING = 'No move is pending for this player'¶
- ILLEGAL_MOVE = 'The chosen move is not legal'¶
- ADVERTISER_MAY_NOT_QUIT = 'Advertiser may not quit a game (cancel instead)'¶
- INTERNAL_ERROR = 'Internal error'¶
- class apologiesserver.interface.MessageType(*args, **kwds)¶
Bases:
enum.EnumEnumeration of all message types, including received events and published requests.
- REGISTER_PLAYER = 'Register Player'¶
- REREGISTER_PLAYER = 'Reregister Player'¶
- UNREGISTER_PLAYER = 'Unregister Player'¶
- LIST_PLAYERS = 'List Players'¶
- ADVERTISE_GAME = 'Advertise Game'¶
- LIST_AVAILABLE_GAMES = 'List Available'¶
- JOIN_GAME = 'Join Game'¶
- QUIT_GAME = 'Quit Game'¶
- START_GAME = 'Start Game'¶
- CANCEL_GAME = 'Cancel Game'¶
- EXECUTE_MOVE = 'Execute Move'¶
- OPTIMAL_MOVE = 'Optimal Move'¶
- RETRIEVE_GAME_STATE = 'Retrieve Game State'¶
- SEND_MESSAGE = 'Send Message'¶
- SERVER_SHUTDOWN = 'Server Shutdown'¶
- REQUEST_FAILED = 'Request Failed'¶
- REGISTERED_PLAYERS = 'Registered Players'¶
- AVAILABLE_GAMES = 'Available Games'¶
- PLAYER_REGISTERED = 'Player Registered'¶
- PLAYER_UNREGISTERED = 'Player Unregistered'¶
- WEBSOCKET_IDLE = 'Connection Idle'¶
- WEBSOCKET_INACTIVE = 'Connection Inactive'¶
- PLAYER_IDLE = 'Player Idle'¶
- PLAYER_INACTIVE = 'Player Inactive'¶
- PLAYER_MESSAGE_RECEIVED = 'Player Message Received'¶
- GAME_ADVERTISED = 'Game Advertise'¶
- GAME_INVITATION = 'Game Invitation'¶
- GAME_JOINED = 'Game Joined'¶
- GAME_STARTED = 'Game Started'¶
- GAME_CANCELLED = 'Game Cancelled'¶
- GAME_COMPLETED = 'Game Completed'¶
- GAME_IDLE = 'Game Idle'¶
- GAME_INACTIVE = 'Game Inactive'¶
- GAME_PLAYER_QUIT = 'Game Player Quit'¶
- GAME_PLAYER_CHANGE = 'Game Player Change'¶
- GAME_STATE_CHANGE = 'Game State Change'¶
- GAME_PLAYER_TURN = 'Game Player Turn'¶
- exception apologiesserver.interface.ProcessingError¶
Bases:
RuntimeErrorException thrown when there is a general processing error.
- reason: FailureReason¶
- class apologiesserver.interface.GamePlayer¶
The public definition of a player within a game.
- player_type: PlayerType¶
- player_state: PlayerState¶
- class apologiesserver.interface.RegisteredPlayer¶
The public definition of a player registered with the system.
- registration_date: arrow.Arrow¶
- last_active_date: arrow.Arrow¶
- connection_state: ConnectionState¶
- activity_state: ActivityState¶
- player_state: PlayerState¶
- class apologiesserver.interface.AdvertisedGame¶
A game that has been advertised in the system.
- mode: apologies.GameMode¶
- visibility: Visibility¶
- class apologiesserver.interface.GameStatePawn¶
State of a pawn in a game.
- color: apologies.PlayerColor¶
- static for_pawn(pawn: apologies.Pawn) GameStatePawn¶
Create a GameStatePawn based on apologies.game.Pawn.
- static for_position(pawn: apologies.Pawn, position: apologies.Position) GameStatePawn¶
Create a GameStatePawn based on apologies.game.Pawn and apologies.gamePosition.
- class apologiesserver.interface.GameStatePlayer¶
Player in a game, when describing the state of the board.
- color: apologies.PlayerColor¶
- pawns: list[GameStatePawn]¶
- static for_player(player: apologies.Player) GameStatePlayer¶
Create a GameStatePlayer based on apologies.game.Player.
- class apologiesserver.interface.GameStateHistory¶
History for a game.
- timestamp: arrow.Arrow¶
- static for_history(history: apologies.History) GameStateHistory¶
- class apologiesserver.interface.GameAction¶
An action applied to a pawn in a game.
- start: GameStatePawn¶
- end: GameStatePawn¶
- static for_action(action: apologies.Action) GameAction¶
Create a GamePlayerAction based on apologies.rules.Action.
- class apologiesserver.interface.GameMove¶
A move that may be executed as a result of a player’s turn.
- card: apologies.CardType¶
- actions: list[GameAction]¶
- side_effects: list[GameAction]¶
- class apologiesserver.interface.RegisterPlayerContext¶
Bases:
ContextContext for a REGISTER_PLAYER request.
- class apologiesserver.interface.ReregisterPlayerContext¶
Bases:
ContextContext for a REREGISTER_PLAYER request.
- class apologiesserver.interface.AdvertiseGameContext¶
Bases:
ContextContext for an ADVERTISE_GAME request.
- mode: apologies.GameMode¶
- visibility: Visibility¶
- class apologiesserver.interface.JoinGameContext¶
Bases:
ContextContext for a JOIN_GAME request.
- class apologiesserver.interface.ExecuteMoveContext¶
Bases:
ContextContext for an EXECUTE_MOVE request.
- class apologiesserver.interface.SendMessageContext¶
Bases:
ContextContext for an SEND_MESSAGE request.
- class apologiesserver.interface.RequestFailedContext¶
Bases:
ContextContext for a REQUEST_FAILED event.
- reason: FailureReason¶
- class apologiesserver.interface.RegisteredPlayersContext¶
Bases:
ContextContext for a REGISTERED_PLAYERS event.
- players: list[RegisteredPlayer]¶
- class apologiesserver.interface.AvailableGamesContext¶
Bases:
ContextContext for an AVAILABLE_GAMES event.
- games: list[AdvertisedGame]¶
- class apologiesserver.interface.PlayerRegisteredContext¶
Bases:
ContextContext for a PLAYER_REGISTERED event.
- class apologiesserver.interface.PlayerUnregisteredContext¶
Bases:
ContextContext for a PLAYER_UNREGISTERED event.
- class apologiesserver.interface.PlayerIdleContext¶
Bases:
ContextContext for a PLAYER_IDLE event.
- class apologiesserver.interface.PlayerInactiveContext¶
Bases:
ContextContext for a PLAYER_INACTIVE event.
- class apologiesserver.interface.PlayerMessageReceivedContext¶
Bases:
ContextContext for a PLAYER_MESSAGE_RECEIVED event.
- class apologiesserver.interface.GameAdvertisedContext¶
Bases:
ContextContext for a GAME_ADVERTISED event.
- game: AdvertisedGame¶
- class apologiesserver.interface.GameInvitationContext¶
Bases:
ContextContext for a GAME_INVITATION event.
- game: AdvertisedGame¶
- class apologiesserver.interface.GameJoinedContext¶
Bases:
ContextContext for a GAME_JOINED event.
- mode: apologies.GameMode¶
- class apologiesserver.interface.GameStartedContext¶
Bases:
ContextContext for a GAME_STARTED event.
- class apologiesserver.interface.GameCancelledContext¶
Bases:
ContextContext for a GAME_CANCELLED event.
- reason: CancelledReason¶
- class apologiesserver.interface.GameCompletedContext¶
Bases:
ContextContext for a GAME_COMPLETED event.
- class apologiesserver.interface.GameIdleContext¶
Bases:
ContextContext for a GAME_IDLE event.
- class apologiesserver.interface.GameInactiveContext¶
Bases:
ContextContext for a GAME_INACTIVE event.
- class apologiesserver.interface.GamePlayerQuitContext¶
Bases:
ContextContext for a GAME_PLAYER_LEFT event.
- class apologiesserver.interface.GamePlayerChangeContext¶
Bases:
ContextContext for a GAME_PLAYER_CHANGE event.
- players: list[GamePlayer]¶
- class apologiesserver.interface.GameStateChangeContext¶
Bases:
ContextContext for a GAME_STATE_CHANGE event.
- recent_history: list[GameStateHistory]¶
- player: GameStatePlayer¶
- opponents: list[GameStatePlayer]¶
- static for_context(game_id: str, view: apologies.PlayerView, history: list[apologies.History]) GameStateChangeContext¶
Create a GameStateChangeContext based on apologies.game.PlayerView.
- class apologiesserver.interface.GamePlayerTurnContext¶
Bases:
ContextContext for a GAME_PLAYER_TURN event.
- static for_moves(handle: str, game_id: str, moves: list[apologies.Move]) GamePlayerTurnContext¶
Create a GamePlayerTurnContext based on a sequence of apologies.rules.Move.
- class apologiesserver.interface.Message¶
A message that is part of the public interface, either a client request or a published event.
- message: MessageType¶
- context: Any¶