Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into jauggy/add-rankicons
Browse files Browse the repository at this point in the history
  • Loading branch information
jauggy committed May 14, 2024
2 parents 1cee1d2 + 25b83e3 commit 45772b3
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 30 deletions.
3 changes: 1 addition & 2 deletions lib/teiserver/account/libs/role_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ defmodule Teiserver.Account.RoleLib do
end

def allowed_role_management("Admin") do
# Remove this code later; it has been fixed in another PR
staff_roles() ++ privileged_roles() ++ allowed_role_management("Moderator") ++ community_roles()
staff_roles() ++ community_roles() ++ privileged_roles() ++ allowed_role_management("Moderator")
end

def allowed_role_management("Moderator") do
Expand Down
4 changes: 2 additions & 2 deletions lib/teiserver/game/libs/match_rating_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Teiserver.Game.MatchRatingLib do
to balance matches. For that use Teiserver.Battle.BalanceLib.
"""

alias Teiserver.{Account, Coordinator, Game, Battle}
alias Teiserver.{Account, Coordinator, Config, Game, Battle,}
alias Teiserver.Data.Types, as: T
alias Teiserver.Repo
alias Teiserver.Battle.{BalanceLib, MatchLib}
Expand Down Expand Up @@ -71,7 +71,7 @@ defmodule Teiserver.Game.MatchRatingLib do
match.team_count < 2 ->
{:error, :not_enough_teams}

match.game_duration < 180 ->
match.game_duration < Config.get_site_config_cache("matchmaking.Time to treat game as ranked") ->
{:error, :too_short}

Map.get(match.tags, "game/modoptions/ranked_game", "1") == "0" ->
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/helpers/oban_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ defmodule Teiserver.Helper.ObanLogger do
end

def handle_event([:oban, :job, event], measure, meta, _) do
Logger.info("[Oban] #{event} #{meta.worker} ran in #{measure.duration}")
Logger.info("[Oban] #{event} #{meta.worker} ran in #{System.convert_time_unit(measure.duration, :native, :milliseconds)}ms")
end
end
10 changes: 10 additions & 0 deletions lib/teiserver/libs/teiserver_configs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ defmodule Teiserver.TeiserverConfigs do
value_label: "Require ready check"
})

add_site_config_type(%{
key: "matchmaking.Time to treat game as ranked",
section: "Matchmaking",
type: "integer",
permissions: ["Server"],
description: "Games shorter than this time in seconds will not be treated as ranked.",
default: 90,
value_label: "Require ready check"
})

add_site_config_type(%{
key: "bots.Flag",
section: "Bots",
Expand Down
4 changes: 2 additions & 2 deletions lib/teiserver/mix_tasks/fake_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ defmodule Mix.Tasks.Teiserver.Fakedata do
inserted_at: Timex.shift(Timex.now(), days: -day, minutes: -minutes) |> time_convert,
updated_at: Timex.shift(Timex.now(), days: -day, minutes: -minutes) |> time_convert
}
end)
end)
end) |> Enum.to_list()
end) |> Enum.to_list()
|> List.flatten()

Ecto.Multi.new()
Expand Down
7 changes: 6 additions & 1 deletion lib/teiserver_web/controllers/admin/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ defmodule TeiserverWeb.Admin.UserController do
end

users = (exact_match ++ users) |> Enum.reject(&(&1 == nil))
user_stats = for user <- users, do: Account.get_user_stat_data(user.id)

if Enum.count(users) == 1 do
conn
|> redirect(to: Routes.ts_admin_user_path(conn, :show, hd(users).id))
else
conn
|> add_breadcrumb(name: "List users", url: conn.request_path)
|> assign(:users, users)
|> assign(:users, Enum.zip(users, user_stats))
|> assign(:params, search_defaults(conn))
|> render("index.html")
end
Expand Down Expand Up @@ -1066,8 +1067,12 @@ defmodule TeiserverWeb.Admin.UserController do

case Teiserver.Account.UserLib.has_access(user, conn) do
{true, _} ->

new_user =
Map.merge(user, %{
name: Ecto.UUID.generate(),
email: "#{user.id}@#{user.id}",
password: UserLib.make_bot_password(),
country: "??"
})

Expand Down
1 change: 1 addition & 0 deletions lib/teiserver_web/live/battles/lobbies/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ spectators =
<ul>
<li>Max players: <%= @lobby.max_players %></li>
<li>Locked: <%= @lobby.locked %></li>
<li>Rated Game: <%= if @modoptions.rated_game == 1, do: "Yes", else: "No" %></li>
<%= if @lobby.password != nil do %>
<li>Password: <%= @lobby.password %></li>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions lib/teiserver_web/live/queues/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ defmodule TeiserverWeb.Matchmaking.QueueLive.Index do
true
end
end)
|> Enum.to_list()

is_admin = allow?(socket.assigns[:current_user], "Admin")

Expand Down
30 changes: 9 additions & 21 deletions lib/teiserver_web/templates/admin/user/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ is_moderator = allow?(@conn, "Moderator") %>
<th>Status</th>
<%= if is_moderator do %>
<th>HW</th>
<th>CHB</th>
<% end %>
<th>Trusted</th>
<th>Contributor</th>
<th>Moderator</th>
<th>Roles</th>
<th>Registered</th>

<%= if is_moderator do %>
Expand All @@ -77,7 +74,7 @@ is_moderator = allow?(@conn, "Moderator") %>
</tr>
</thead>
<tbody>
<%= for user <- @users do %>
<%= for {user, user_stats} <- @users do %>
<tr>
<td style={"background-color: #{user.colour}; color: #FFF;"} width="22">
<%= central_component("icon", icon: user.icon) %>
Expand All @@ -86,37 +83,28 @@ is_moderator = allow?(@conn, "Moderator") %>
<%= if is_moderator do %>
<td><%= user.email %></td>
<% end %>
<td><%= user.data["lobby_client"] %></td>
<td><%= user_stats["lobby_client"] %></td>

<td>
<TeiserverWeb.UserComponents.status_icon user={user} />
</td>

<%= if is_moderator do %>
<td>
<%= if user.data["hw_hash"] != "" and user.data["hw_hash"] != nil do %>
<i class="fa-fw far fa-check"></i>
<%= if user_stats["hardware:cpuinfo"] != "" and user_stats["hardware:cpuinfo"] != nil do %>
<%= user_stats["hardware:cpuinfo"] %>
<br/>
<%= user_stats["hardware:gpuinfo"] %>
<% else %>
&nbsp;
<% end %>
</td>

<td>
<%= if user.data["lobby_hash"] != "" and user.data["lobby_hash"] != nil do %>
<i class="fa-fw far fa-check"></i>
<% else %>
&nbsp;
<% end %>
</td>
<% end %>

<td>
<%= if Enum.member?(user.roles || [], "Trusted"), do: "Trusted" %>
</td>
<td>
<%= if Enum.member?(user.roles || [], "Contributor"), do: "Contributor" %>
</td>
<td>
<%= if Enum.member?(user.roles || [], "Trusted"), do: "Trusted " %>
<%= if Enum.member?(user.roles || [], "Contributor"), do: "Contributor " %>
<%= if Enum.member?(user.roles || [], "Moderator"), do: "Moderator" %>
</td>

Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/views/api/spads_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule TeiserverWeb.API.SpadsView do

def render("rating.json", assigns) do
%{
rating_value: assigns.rating_value |> round(2) |> max(1),
rating_value: assigns.rating_value |> round(2),
uncertainty: assigns.uncertainty |> round(2)
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Teiserver.Repo.Migrations.AddFkBattleMatchesLobbyMessages do
use Ecto.Migration
# This change is being done to reduce the CPU load of the hourly Teiserver.Battle.Tasks.CleanupTask
# As deleting rows from tables with non-indexed foreign keys is probably expensive
# This migration adds indexes on the columns used as foreign key on the battle_matches table

def change do
create index(:teiserver_battle_match_memberships, [:match_id])
create index(:teiserver_lobby_messages, [:match_id])
create index(:moderation_reports, [:match_id])
create index(:telemetry_simple_match_events, [:match_id])
create index(:telemetry_complex_match_events, [:match_id])
create index(:telemetry_simple_lobby_events, [:match_id])
create index(:telemetry_complex_lobby_events, [:match_id])
create index(:moderation_report_groups, [:match_id])
end
end

0 comments on commit 45772b3

Please sign in to comment.