Skip to content

Commit

Permalink
Client server autodetection (#864)
Browse files Browse the repository at this point in the history
* Change servers encoding

* Add current servers to seeds

* Filter servers by status

* Allow to create servers without ip
  • Loading branch information
agustinesco authored Aug 22, 2024
1 parent d43025e commit e6f6b4a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ defmodule GameBackend.ArenaServers.ArenaServer do
def changeset(arena_server, attrs) do
arena_server
|> cast(attrs, [:name, :ip, :url, :status, :environment])
|> validate_required([:name, :ip, :url, :status, :environment])
|> validate_required([:name, :url, :status, :environment])
end
end
18 changes: 18 additions & 0 deletions apps/game_backend/lib/game_backend/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ defmodule GameBackend.Configuration do
Repo.all(ArenaServer)
end

@doc """
Returns the list of arena_servers that has the field "status" with a value of "active".
## Examples
iex> list_active_arena_servers()
[%ArenaServer{status: "active"}, ...]
"""
def list_active_arena_servers do
q =
from(as in ArenaServer,
where: as.status == ^"active"
)

Repo.all(q)
end

@doc """
Gets a single arena_server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ defmodule Gateway.Controllers.ArenaServersController do

def list_arena_servers(conn, _params) do
arena_servers =
Configuration.list_arena_servers()
Configuration.list_active_arena_servers()

conn
|> send_resp(200, Jason.encode!(arena_servers))
|> send_resp(200, Jason.encode!(%{servers: arena_servers}))
end
end
22 changes: 22 additions & 0 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2920,4 +2920,26 @@ map_config = %{

GameBackend.CurseOfMirra.Config.import_quest_descriptions_config()

brazil_arena_server =
%{
name: "BRAZIL",
ip: "",
url: "arena-brazil-staging.championsofmirra.com",
status: "active",
environment: "production"
}

GameBackend.Configuration.create_arena_server(brazil_arena_server)

europe_arena_server =
%{
name: "EUROPE",
ip: "",
url: "arena-europe-testing.championsofmirra.com",
status: "active",
environment: "production"
}

GameBackend.Configuration.create_arena_server(europe_arena_server)

################### END CURSE OF MIRRA ###################

0 comments on commit e6f6b4a

Please sign in to comment.