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
Takes a name and password, tries to authenticate the user.
Takes a name, email and password. Creates a user with them.
Clients
Makes use of Teiserver.Connections.ClientLib.connect_user/1
to connect
and then also subscribes you to the following pubsubs
Users
@spec get_user_by_id(Teiserver.user_id()) :: User.t() | nil
@spec get_user_by_name(String.t()) :: User.t() | nil
@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}
@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
@spec connect_user(Teiserver.user_id()) :: Teiserver.Connections.Client.t()
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
@spec update_client(Teiserver.user_id(), map(), String.t()) :: Client.t() | nil
@spec update_client_full(Teiserver.user_id(), map(), String.t()) :: Client.t() | nil
@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
Lobby
@spec add_client_to_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.id()) :: :ok | {:error, String.t()}
@spec can_add_client_to_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.id()) :: {boolean(), String.t() | nil}
@spec can_add_client_to_lobby( Teiserver.user_id(), Teiserver.Game.Lobby.id(), String.t() ) :: {boolean(), String.t() | nil}
@spec close_lobby(Teiserver.Game.Lobby.id()) :: :ok
@spec cycle_lobby(Teiserver.Game.Lobby.id()) :: :ok
@spec get_lobby(Teiserver.Game.Lobby.id()) :: Teiserver.Game.Lobby.t() | nil
@spec get_lobby_summary(Teiserver.Game.Lobby.id()) :: LobbySummary.t() | nil
@spec list_lobby_ids() :: [Teiserver.Game.Lobby.id()]
@spec lobby_exists?(Teiserver.Game.Lobby.id()) :: boolean()
See Teiserver.Game.LobbyLib.lobby_exists?/1
.
@spec open_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.name()) :: {:ok, Teiserver.Game.Lobby.id()} | {:error, String.t()}
@spec remove_client_from_lobby(Teiserver.user_id(), Teiserver.Game.Lobby.id()) :: :ok | nil
@spec stream_lobby_summaries() :: Enumerable.t(LobbySummary.t())
@spec stream_lobby_summaries(map()) :: Enumerable.t(LobbySummary.t())
@spec subscribe_to_lobby(Teiserver.Game.Lobby.id() | Teiserver.Game.Lobby.t()) :: :ok
@spec unsubscribe_from_lobby(Teiserver.Game.Lobby.id() | Teiserver.Game.Lobby.t()) :: :ok
@spec update_lobby(Teiserver.Game.Lobby.id(), map()) :: :ok | nil
Match
@spec end_match(Teiserver.Game.Match.id(), map()) :: Teiserver.Game.Match.t()
@spec start_match(Teiserver.Game.Lobby.t()) :: Teiserver.Game.Match.t()