apologiesserver.event

Event handlers.

All event handlers operate in terms of passed-in state, encapsulated in the StateManager object. The caller must ensure that 1) the state manager is locked before calling any handler methods other than execute() and 2) that the execute() method is called once at the end of processing but outside of the manager lock. The goal is to ensure that state-related operations are fast and non-blocking, and happen behind a clear transaction boundary. Any tasks that might block (such as network requests) should be added to the task queue, to be executed by the execute() method once state updates have been completed.

Module Contents

apologiesserver.event.log
class apologiesserver.event.RequestContext

Context provided to a request handler method.

message :apologiesserver.interface.Message
websocket :websockets.legacy.server.WebSocketServerProtocol
player :apologiesserver.manager.TrackedPlayer
game :apologiesserver.interface.Optional[apologiesserver.manager.TrackedGame]
class apologiesserver.event.TaskQueue

A queue of asynchronous tasks to be executed.

messages :apologiesserver.interface.List[Tuple[str, websockets.legacy.server.WebSocketServerProtocol]]
disconnects :Set[websockets.legacy.server.WebSocketServerProtocol]
is_empty() bool
clear() None
message(message: apologiesserver.interface.Message, websockets: apologiesserver.interface.Optional[apologiesserver.interface.List[websockets.legacy.server.WebSocketServerProtocol]] = None, players: apologiesserver.interface.Optional[apologiesserver.interface.List[apologiesserver.manager.TrackedPlayer]] = None) None

Enqueue a task to send a message to one or more destination websockets.

disconnect(websocket: apologiesserver.interface.Optional[websockets.legacy.server.WebSocketServerProtocol]) None

Enqueue a task to disconnect a websocket.

async execute() None

Execute all tasks in the queue, sending messages first and then disconnecting websockets.

class apologiesserver.event.EventHandler
manager :apologiesserver.manager.StateManager
queue :TaskQueue
__enter__() EventHandler
__exit__(_type, _value, _tb) None
async execute_tasks() None

Send all enqueued tasks.

handle_idle_websocket_check_task() Tuple[int, int]

Execute the Idle Websocket Check task, returning tuple of (idle, inactive).

handle_idle_player_check_task() Tuple[int, int]

Execute the Idle Player Check task, returning tuple of (idle, inactive).

handle_idle_game_check_task() Tuple[int, int]

Execute the Idle Game Check task, returning tuple of (idle, inactive).

handle_obsolete_game_check_task() int

Execute the Obsolete Game Check task returning obsolete games.

handle_register_player_request(message: apologiesserver.interface.Message, websocket: websockets.legacy.server.WebSocketServerProtocol) None

Handle the Register Player request.

handle_reregister_player_request(request: RequestContext) None

Handle the Reregister Player request.

handle_unregister_player_request(request: RequestContext) None

Handle the Unregister Player request.

handle_list_players_request(request: RequestContext) None

Handle the List Players request.

handle_advertise_game_request(request: RequestContext) None

Handle the Advertise Game request.

handle_list_available_games_request(request: RequestContext) None

Handle the List Available Games request.

handle_join_game_request(request: RequestContext) None

Handle the Join Game request.

handle_quit_game_request(request: RequestContext) None

Handle the Quit Game request.

handle_start_game_request(request: RequestContext) None

Handle the Start Game request.

handle_cancel_game_request(request: RequestContext) None

Handle the Cancel Game request.

handle_execute_move_request(request: RequestContext) None

Handle the Execute Move request.

handle_optimal_move_request(request: RequestContext) None

Handle the Optimal Move request.

handle_retrieve_game_state_request(request: RequestContext) None

Handle the Retrieve Game State request.

handle_send_message_request(request: RequestContext) None

Handle the Send Message request.

handle_server_shutdown_event() None

Handle the Server Shutdown event.

handle_websocket_connected_event(websocket: websockets.legacy.server.WebSocketServerProtocol) None

Handle the Websocket Connected event.

handle_websocket_disconnected_event(websocket: websockets.legacy.server.WebSocketServerProtocol) None

Handle the Websocket Disconnected event.

handle_websocket_idle_event(websocket: apologiesserver.manager.TrackedWebsocket) None

Handle the Websocket Idle event.

handle_websocket_inactive_event(websocket: apologiesserver.manager.TrackedWebsocket) None

Handle the Websocket Inactive event.

handle_registered_players_event(player: apologiesserver.manager.TrackedPlayer) None

Handle the Registered Players event.

handle_available_games_event(player: apologiesserver.manager.TrackedPlayer) None

Handle the Available Games event.

handle_player_registered_event(websocket: websockets.legacy.server.WebSocketServerProtocol, handle: str) None

Handle the Player Registered event.

handle_player_reregistered_event(player: apologiesserver.manager.TrackedPlayer, websocket: websockets.legacy.server.WebSocketServerProtocol) None

Handle the Player Registered event.

handle_player_unregistered_event(player: apologiesserver.manager.TrackedPlayer, game: apologiesserver.interface.Optional[apologiesserver.manager.TrackedGame] = None) None

Handle the Player Unregistered event.

handle_player_disconnected_event(player: apologiesserver.manager.TrackedPlayer) None

Handle the Player Disconnected event.

handle_player_idle_event(player: apologiesserver.manager.TrackedPlayer) None

Handle the Player Idle event.

handle_player_inactive_event(player: apologiesserver.manager.TrackedPlayer) None

Handle the Player Inactive event.

handle_player_message_received_event(sender_handle: str, recipient_handles: apologiesserver.interface.List[str], sender_message: str) None

Handle the Player Message Received event.

handle_game_advertised_event(player: apologiesserver.manager.TrackedPlayer, advertised: apologiesserver.interface.AdvertiseGameContext) None

Handle the Game Advertised event.

handle_game_invitation_event(game: apologiesserver.manager.TrackedGame) None

Handle the Game Invitation event.

handle_game_joined_event(player: apologiesserver.manager.TrackedPlayer, game_id: apologiesserver.interface.Optional[str] = None, game: apologiesserver.interface.Optional[apologiesserver.manager.TrackedGame] = None) None

Handle the Game Joined event.

handle_game_started_event(game: apologiesserver.manager.TrackedGame) None

Handle the Game Started event.

handle_game_cancelled_event(game: apologiesserver.manager.TrackedGame, reason: apologiesserver.interface.CancelledReason, comment: apologiesserver.interface.Optional[str] = None, notify: bool = True) None

Handle the Game Cancelled event.

handle_game_completed_event(game: apologiesserver.manager.TrackedGame, winner: str, comment: str) None

Handle the Game Completed event.

handle_game_idle_event(game: apologiesserver.manager.TrackedGame) None

Handle the Game Idle event.

handle_game_inactive_event(game: apologiesserver.manager.TrackedGame) None

Handle the Game Inactive event.

handle_game_obsolete_event(game: apologiesserver.manager.TrackedGame) None

Handle the Game Obsolete event.

handle_game_player_quit_event(player: apologiesserver.manager.TrackedPlayer, game: apologiesserver.manager.TrackedGame) None

Handle the Game Player Quit event.

handle_game_player_left_event(player: apologiesserver.manager.TrackedPlayer, game: apologiesserver.manager.TrackedGame, comment: str) None

Handle the Game Player Left event.

handle_game_player_move_event(player: apologiesserver.manager.TrackedPlayer, game: apologiesserver.manager.TrackedGame, move_id: str) None

Handle the Game Player Move event.

handle_game_programmatic_move_event(handle: str, game: apologiesserver.manager.TrackedGame) None

Handle the Game Programmatic Move event.

handle_game_move_event(handle: str, game: apologiesserver.manager.TrackedGame, move_id: str) None

Handle the Game Move event.

handle_game_next_turn_event(game: apologiesserver.manager.TrackedGame) None

Handle the Game Next Turn event.

handle_game_player_change_event(game: apologiesserver.manager.TrackedGame, comment: str) None

Handle the Game Player Change event.

handle_game_state_change_event(game: apologiesserver.manager.TrackedGame, player: apologiesserver.interface.Optional[apologiesserver.manager.TrackedPlayer] = None) None

Handle the Game State Change event.

handle_game_player_turn_event(player: apologiesserver.manager.TrackedPlayer, moves: apologiesserver.interface.List[apologiesserver.interface.Move]) None

Handle the Game Player Turn event.