View Source Teiserver.Connections.ClientLib (Teiserver v0.0.3)

Library of client related functions.

Summary

Functions

Tells us if the client exists right now or not.

Given a user_id, log them in. If the user already exists as a client then the existing client is returned.

Gets a single client.

Returns the list of client ids.

Updates a client with the new data. If changes are made then it will also generate a Teiserver.Connections.Client:{user_id} pubsub message.

Functions

@spec client_exists?(Teiserver.user_id()) :: pid() | boolean()

Tells us if the client exists right now or not.

Given a user_id, log them in. If the user already exists as a client then the existing client is returned.

The calling process will be listed as a connection for the client the client will monitor it for the purposes of tracking if the given client is still connected.

@spec get_client(Teiserver.user_id()) :: Teiserver.Connections.Client.t() | nil

Gets a single client.

Returns nil if the Client does not exist.

Examples

iex> get_client(123)
%Client{}

iex> get_client(456)
nil
@spec list_client_ids() :: [Teiserver.user_id()]

Returns the list of client ids.

Examples

iex> list_client_ids()
[123, ...]
Link to this function

update_client(user_id, data)

View Source
@spec update_client(Teiserver.user_id(), map()) :: :ok | nil

Updates a client with the new data. If changes are made then it will also generate a Teiserver.Connections.Client:{user_id} pubsub message.

Returns nil if the Client does not exist, :ok if the client does.

Examples

iex> update_client(123, %{player_number: 123})
:ok

iex> update_client(456, %{player_number: 123})
nil