diff --git a/lib/teiserver/battle/schemas/match.ex b/lib/teiserver/battle/schemas/match.ex index f32d64d68..290b65012 100644 --- a/lib/teiserver/battle/schemas/match.ex +++ b/lib/teiserver/battle/schemas/match.ex @@ -4,6 +4,7 @@ defmodule Teiserver.Battle.Match do schema "teiserver_battle_matches" do field :server_uuid, :string field :uuid, :string + field :game_id, :string field :map, :string # The end of match data to be provided by clients field :data, :map, default: %{} @@ -45,7 +46,7 @@ defmodule Teiserver.Battle.Match do struct |> cast( params, - ~w(server_uuid uuid map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id rating_type_id lobby_policy_id game_duration)a + ~w(server_uuid uuid game_id map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id rating_type_id lobby_policy_id game_duration)a ) |> validate_required( ~w(server_uuid uuid map tags team_count team_size passworded game_type founder_id bots started)a @@ -57,7 +58,7 @@ defmodule Teiserver.Battle.Match do struct |> cast( params, - ~w(server_uuid uuid map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id game_duration)a + ~w(server_uuid uuid game_id map data tags team_count team_size passworded game_type founder_id bots started winning_team finished processed queue_id game_duration)a ) |> validate_required(~w(founder_id)a) end diff --git a/lib/teiserver/battle/tasks/post_match_process_task.ex b/lib/teiserver/battle/tasks/post_match_process_task.ex index 3a2a72785..9c27f2656 100644 --- a/lib/teiserver/battle/tasks/post_match_process_task.ex +++ b/lib/teiserver/battle/tasks/post_match_process_task.ex @@ -151,7 +151,11 @@ defmodule Teiserver.Battle.Tasks.PostMatchProcessTask do |> hd_or_x({nil, nil}) |> elem(0) - Battle.update_match(match, %{winning_team: winning_team, game_duration: host_game_duration}) + Battle.update_match(match, %{ + winning_team: winning_team, + game_duration: host_game_duration, + game_id: export_data["gameId"] + }) memberships |> Enum.map(fn m -> diff --git a/lib/teiserver/coordinator/spads_parser.ex b/lib/teiserver/coordinator/spads_parser.ex index ba61b9206..72385ad5c 100644 --- a/lib/teiserver/coordinator/spads_parser.ex +++ b/lib/teiserver/coordinator/spads_parser.ex @@ -43,6 +43,13 @@ defmodule Teiserver.Coordinator.SpadsParser do _match = Regex.run(~r/Boss mode disabled by \S+/, msg) -> {:host_update, %{host_bosses: []}} + # Remove an individual boss + match = Regex.run(~r/Boss mode disabled for (\S+) \(by \S+\)/, msg) -> + [_, player_name] = match + player_id = CacheUser.get_userid(player_name) + + {:host_update, %{host_bosses: List.delete(state.host_bosses, player_id)}} + # Not handling it, return nil true -> nil diff --git a/lib/teiserver/helpers/styling_helpers.ex b/lib/teiserver/helpers/styling_helpers.ex index 90684ef41..6fe5cc928 100644 --- a/lib/teiserver/helpers/styling_helpers.ex +++ b/lib/teiserver/helpers/styling_helpers.ex @@ -92,6 +92,8 @@ defmodule Teiserver.Helper.StylingHelper do def icon(:quarter, _fa_type), do: "" def icon(:year, _fa_type), do: "" + def icon(:replay, _fa_type), do: "fa-solid fa-arrow-rotate-left" + # defp split_colour(c) do # {r, _} = c |> String.slice(1, 2) |> Integer.parse(16) # {g, _} = c |> String.slice(3, 2) |> Integer.parse(16) diff --git a/lib/teiserver_web/live/battles/match/match_components.ex b/lib/teiserver_web/live/battles/match/match_components.ex index 45910b47e..9ed0a8d6b 100644 --- a/lib/teiserver_web/live/battles/match/match_components.ex +++ b/lib/teiserver_web/live/battles/match/match_components.ex @@ -10,6 +10,7 @@ defmodule TeiserverWeb.Battle.MatchComponents do attr :active, :string, required: true attr :current_user, :map, required: true attr :match_id, :integer, default: nil + attr :replay, :string, default: nil def section_menu(assigns) do ~H""" @@ -63,13 +64,13 @@ defmodule TeiserverWeb.Battle.MatchComponents do
<.section_menu_button - :if={@match_id != nil and allow?(@current_user, "Moderator")} + :if={@replay != nil} bsname={@view_colour} - icon={StylingHelper.icon(:admin)} + icon={StylingHelper.icon(:replay)} active={false} - url={~p"/battle/#{@match_id}"} + url={@replay} > - Admin view + Replay
""" diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index f63fa3c1c..2e5c35267 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -185,6 +185,19 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do end) |> Enum.sort_by(fn v -> v end, &<=/2) + game_id = + cond do + match.game_id -> match.game_id + match.data -> match.data["export_data"]["gameId"] + true -> nil + end + + replay = + if game_id do + Application.get_env(:teiserver, Teiserver)[:main_website] <> + "/replays?gameId=" <> game_id + end + socket |> assign(:match, match) |> assign(:match_name, match_name) @@ -195,6 +208,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do |> assign(:new_balance, new_balance) |> assign(:events_by_type, events_by_type) |> assign(:events_by_team_and_type, events_by_team_and_type) + |> assign(:replay, replay) else socket |> assign(:match, nil) @@ -206,6 +220,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do |> assign(:new_balance, %{}) |> assign(:events_by_type, %{}) |> assign(:events_by_team_and_type, %{}) + |> assign(:replay, nil) end end diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index 30009a8a5..7543d7f62 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -11,6 +11,7 @@ view_colour={@view_colour} current_user={@current_user} match_id={@match.id} + replay={@replay} />
diff --git a/priv/repo/migrations/20241013105515_add_game_id.exs b/priv/repo/migrations/20241013105515_add_game_id.exs new file mode 100644 index 000000000..36b2d470c --- /dev/null +++ b/priv/repo/migrations/20241013105515_add_game_id.exs @@ -0,0 +1,9 @@ +defmodule Teiserver.Repo.Migrations.AddGameId do + use Ecto.Migration + + def change do + alter table(:teiserver_battle_matches) do + add :game_id, :string + end + end +end