View Source Teiserver.Api (Teiserver v0.0.4)

A set of functions for a basic usage of Teiserver. The purpose is to allow you to start with importing only this module and then import others as your needs grow more complex.

Summary

Users

@spec get_user_by_id(Teiserver.user_id()) :: User.t() | nil

See Teiserver.Account.UserLib.get_user_by_id/1.

@spec get_user_by_name(String.t()) :: User.t() | nil

See Teiserver.Account.UserLib.get_user_by_name/1.

Link to this function

maybe_authenticate_user(name, password)

View Source
@spec maybe_authenticate_user(String.t(), String.t()) ::
  {:ok, Teiserver.Account.User.t()} | {:error, :no_user | :bad_password}

Takes a name and password, tries to authenticate the user.

Examples

iex> maybe_authenticate_user("Alice", "password1")
{:ok, %User{}}

iex> maybe_authenticate_user("Bob", "bad password")
{:error, :bad_password}

iex> maybe_authenticate_user("Chris", "password1")
{:error, :no_user}
Link to this function

register_user(name, email, password)

View Source
@spec register_user(String.t(), String.t(), String.t()) ::
  {:ok, User.t()} | {:error, Ecto.Changeset.t()}

Takes a name, email and password. Creates a user with them.

Examples

iex> register_user("Alice", "alice@alice", "password1")
{:ok, %User{}}

iex> register_user("Bob", "bob@bob", "1")
{:error, %Ecto.Changeset{}}

Clients

Makes use of Teiserver.Connections.ClientLib.connect_user/1 to connect and then also subscribes you to the following pubsubs:

Always returns :ok

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

See Teiserver.Connections.ClientLib.get_client/1.

Link to this function

update_client(user_id, updates, reason)

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

See Teiserver.Connections.ClientLib.update_client/3.

Link to this function

update_client_full(user_id, updates, reason)

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

See Teiserver.Connections.ClientLib.update_client_full/3.

Link to this function

update_client_in_lobby(user_id, updates, reason)

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

See Teiserver.Connections.ClientLib.update_client_in_lobby/3.

Room messages

Match messages

Direct messages

Link to this function

send_direct_message(sender_id, to_id, content)

View Source
@spec send_direct_message(Teiserver.user_id(), Teiserver.user_id(), String.t()) ::
  {:ok, Teiserver.Communication.DirectMessage.t()}
  | {:error, Ecto.Changeset.t()}

See Teiserver.Communication.DirectMessageLib.send_direct_message/3.

Link to this function

subscribe_to_user_messaging(user_or_user_id)

View Source
@spec subscribe_to_user_messaging(User.id() | User.t()) :: :ok

See Teiserver.Communication.DirectMessageLib.subscribe_to_user_messaging/1.

Link to this function

unsubscribe_from_user_messaging(user_or_user_id)

View Source
@spec unsubscribe_from_user_messaging(User.id() | User.t()) :: :ok

See Teiserver.Communication.DirectMessageLib.unsubscribe_from_user_messaging/1.

Lobby

Link to this function

add_client_to_lobby(user_id, lobby_id)

View Source
@spec add_client_to_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.id()) ::
  :ok | {:error, String.t()}

See Teiserver.Game.LobbyLib.add_client_to_lobby/2.

Link to this function

can_add_client_to_lobby(user_id, lobby_id)

View Source
@spec can_add_client_to_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.id()) ::
  {boolean(), String.t() | nil}

See Teiserver.Game.LobbyLib.can_add_client_to_lobby/2.

Link to this function

can_add_client_to_lobby(user_id, lobby_id, password)

View Source
@spec can_add_client_to_lobby(
  Teiserver.user_id(),
  Teiserver.Game.Lobby.id(),
  String.t()
) ::
  {boolean(), String.t() | nil}

See Teiserver.Game.LobbyLib.can_add_client_to_lobby/3.

@spec close_lobby(Teiserver.Game.Lobby.id()) :: :ok

See Teiserver.Game.LobbyLib.close_lobby/1.

@spec cycle_lobby(Teiserver.Game.Lobby.id()) :: :ok

See Teiserver.Game.LobbyLib.cycle_lobby/1.

@spec get_lobby(Teiserver.Game.Lobby.id()) :: Teiserver.Game.Lobby.t() | nil

See Teiserver.Game.LobbyLib.get_lobby/1.

Link to this function

get_lobby_summary(lobby_id)

View Source
@spec get_lobby_summary(Teiserver.Game.Lobby.id()) :: LobbySummary.t() | nil

See Teiserver.Game.LobbyLib.get_lobby_summary/1.

@spec list_lobby_ids() :: [Teiserver.Game.Lobby.id()]

See Teiserver.Game.LobbyLib.list_lobby_ids/0.

@spec lobby_exists?(Teiserver.Game.Lobby.id()) :: boolean()

See Teiserver.Game.LobbyLib.lobby_exists?/1.

Link to this function

open_lobby(host_id, name)

View Source
@spec open_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.name()) ::
  {:ok, Teiserver.Game.Lobby.id()} | {:error, String.t()}

See Teiserver.Game.LobbyLib.open_lobby/2.

Link to this function

remove_client_from_lobby(user_id, lobby_id)

View Source
@spec remove_client_from_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.id()) ::
  :ok | nil

See Teiserver.Game.LobbyLib.remove_client_from_lobby/2.

Link to this function

stream_lobby_summaries()

View Source
@spec stream_lobby_summaries() :: Enumerable.t(LobbySummary.t())

See Teiserver.Game.LobbyLib.stream_lobby_summaries/0.

Link to this function

stream_lobby_summaries(filters)

View Source
@spec stream_lobby_summaries(map()) :: Enumerable.t(LobbySummary.t())

See Teiserver.Game.LobbyLib.stream_lobby_summaries/1.

Link to this function

subscribe_to_lobby(lobby_or_lobby_id)

View Source
@spec subscribe_to_lobby(Teiserver.Game.Lobby.id() | Teiserver.Game.Lobby.t()) :: :ok

See Teiserver.Game.LobbyLib.subscribe_to_lobby/1.

Link to this function

unsubscribe_from_lobby(lobby_or_lobby_id)

View Source
@spec unsubscribe_from_lobby(Teiserver.Game.Lobby.id() | Teiserver.Game.Lobby.t()) ::
  :ok

See Teiserver.Game.LobbyLib.unsubscribe_from_lobby/1.

Link to this function

update_lobby(lobby_id, value_map)

View Source
@spec update_lobby(Teiserver.Game.Lobby.id(), map()) :: :ok | nil

See Teiserver.Game.LobbyLib.update_lobby/2.

Match