From e6f6b4a905239294b9139cdc8b3d0b1c28fa915c Mon Sep 17 00:00:00 2001 From: Agustin Escobar <106101218+agustinesco@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:55:59 -0300 Subject: [PATCH] Client server autodetection (#864) * Change servers encoding * Add current servers to seeds * Filter servers by status * Allow to create servers without ip --- .../arena_servers/arena_server.ex | 2 +- .../lib/game_backend/configuration.ex | 18 +++++++++++++++ .../controllers/arena_servers_controller.ex | 4 ++-- priv/repo/seeds.exs | 22 +++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/apps/game_backend/lib/game_backend/arena_servers/arena_server.ex b/apps/game_backend/lib/game_backend/arena_servers/arena_server.ex index 686871b0b..b4226c71e 100644 --- a/apps/game_backend/lib/game_backend/arena_servers/arena_server.ex +++ b/apps/game_backend/lib/game_backend/arena_servers/arena_server.ex @@ -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 diff --git a/apps/game_backend/lib/game_backend/configuration.ex b/apps/game_backend/lib/game_backend/configuration.ex index 32e9a3693..420286bf7 100644 --- a/apps/game_backend/lib/game_backend/configuration.ex +++ b/apps/game_backend/lib/game_backend/configuration.ex @@ -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. diff --git a/apps/gateway/lib/gateway/controllers/arena_servers_controller.ex b/apps/gateway/lib/gateway/controllers/arena_servers_controller.ex index bee20e613..ae9987545 100644 --- a/apps/gateway/lib/gateway/controllers/arena_servers_controller.ex +++ b/apps/gateway/lib/gateway/controllers/arena_servers_controller.ex @@ -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 diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 6a97d9af0..5e509b756 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -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 ###################