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

Library of client related functions.

Summary

Functions

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 from a user_id.

Given a list of ids, return a list of client states.

Returns the list of client ids.

Subscribes the process to client updates for this user

Unsubscribes the process to client updates for this user

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

Updates a client with the new data for any and all keys (so be careful not to break things like lobby memberships).

Updates a client with the new data for their lobby presence. If changes are made then it will also generate a Teiserver.Connections.Client:{user_id} pubsub message and a Teiserver.Game.Lobby:{lobby_id} pubsub message.

Functions

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.

Link to this function

disconnect_user(user_id)

View Source
@spec disconnect_user(Teiserver.user_id()) :: :ok
@spec get_client(Teiserver.user_id()) :: Teiserver.Connections.Client.t() | nil

Gets a single client from a user_id.

Returns nil if the Client does not exist.

Examples

iex> get_client(123)
%Client{}

iex> get_client(456)
nil
Link to this function

get_client_list(user_ids)

View Source
@spec get_client_list([Teiserver.user_id()]) :: [
  Teiserver.Connections.Client.t() | nil
]

Given a list of ids, return a list of client states.

Returns nil if the Client does not exist.

Examples

iex> get_client_list([123, 124])
[%Client{}, %Client{}]

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

Returns the list of client ids.

Examples

iex> list_client_ids()
[123, ...]
@spec list_local_client_ids() :: [Teiserver.user_id()]
Link to this function

subscribe_to_client(client_or_client_id)

View Source

Subscribes the process to client updates for this user

Link to this function

unsubscribe_from_client(client_or_client_id)

View Source
@spec unsubscribe_from_client(
  Teiserver.Account.User.id()
  | Teiserver.Account.User.t()
  | Teiserver.Connections.Client.t()
) :: :ok

Unsubscribes the process to client updates for this user

Link to this function

update_client(user_id, data, reason)

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

Updates a client with the new data (excluding lobby related details). 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, %{afk?: false})
:ok

iex> update_client(456, %{afk?: false})
nil
Link to this function

update_client_full(user_id, data, reason)

View Source
@spec update_client_full(Teiserver.user_id(), map(), String.t()) :: :ok | nil

Updates a client with the new data for any and all keys (so be careful not to break things like lobby memberships).

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

Examples

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

iex> update_client_full(456, %{player_number: 123})
nil
Link to this function

update_client_in_lobby(user_id, data, reason)

View Source
@spec update_client_in_lobby(Teiserver.user_id(), map(), String.t()) :: :ok | nil

Updates a client with the new data for their lobby presence. If changes are made then it will also generate a Teiserver.Connections.Client:{user_id} pubsub message and a Teiserver.Game.Lobby:{lobby_id} pubsub message.

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

Examples

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

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