Skip to content

Commit

Permalink
Apply mix format
Browse files Browse the repository at this point in the history
  • Loading branch information
StanczakDominik committed Jun 3, 2024
1 parent e66bae6 commit 9bb669e
Show file tree
Hide file tree
Showing 33 changed files with 983 additions and 905 deletions.
1,155 changes: 588 additions & 567 deletions .dialyzer_ignore.exs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ if config_env() == :prod do
config :teiserver, Teiserver.Setup,
key: Teiserver.ConfigHelpers.get_env("TEI_SETUP_ROOT_KEY", nil)

enable_discord_bridge = Teiserver.ConfigHelpers.get_env("TEI_ENABLE_DISCORD_BRIDGE", true, :bool)
enable_discord_bridge =
Teiserver.ConfigHelpers.get_env("TEI_ENABLE_DISCORD_BRIDGE", true, :bool)

config :teiserver, Teiserver,
game_name: "Beyond All Reason",
Expand Down
3 changes: 2 additions & 1 deletion lib/teiserver/account/libs/role_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ defmodule Teiserver.Account.RoleLib do
end

def allowed_role_management("Admin") do
staff_roles() ++ community_roles() ++ privileged_roles() ++ allowed_role_management("Moderator")
staff_roles() ++
community_roles() ++ privileged_roles() ++ allowed_role_management("Moderator")
end

def allowed_role_management("Moderator") do
Expand Down
6 changes: 4 additions & 2 deletions lib/teiserver/account/libs/user_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,12 @@ defmodule Teiserver.Account.UserLib do
defp can_login(user) do
cond do
Teiserver.CacheUser.is_restricted?(user.id, ["Login"]) ->
{:error, "Your account is currently suspended. Check the suspension's status at https://discord.gg/beyond-all-reason -> #moderation-bot"}
{:error,
"Your account is currently suspended. Check the suspension's status at https://discord.gg/beyond-all-reason -> #moderation-bot"}

user.smurf_of_id != nil ->
{:error, "Alt account detected. Please log in using your original account instead. If you're not sure what that account is or have trouble accessing it, please contact the moderation team at https://discord.gg/beyond-all-reason -> #open-ticket"}
{:error,
"Alt account detected. Please log in using your original account instead. If you're not sure what that account is or have trouble accessing it, please contact the moderation team at https://discord.gg/beyond-all-reason -> #open-ticket"}

true ->
:ok
Expand Down
10 changes: 5 additions & 5 deletions lib/teiserver/battle/balance/balance_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ defmodule Teiserver.Battle.Balance.BalanceTypes do
}

@type group() :: %{
members: [T.userid()],
ratings: [rating_value()],
group_rating: rating_value(),
count: non_neg_integer()
}
members: [T.userid()],
ratings: [rating_value()],
group_rating: rating_value(),
count: non_neg_integer()
}
@type expanded_group_or_pair() :: expanded_group() | {expanded_group(), expanded_group()}

@type algorithm_result :: map()
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/battle/balance/cheeky_switcher_smart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Teiserver.Battle.Balance.CheekySwitcherSmart do

@spec perform([BT.expanded_group_or_pair()], non_neg_integer(), list()) :: BT.algorithm_result()
def perform(raw_groups, team_count, opts) do
groups_with_names = Enum.map(raw_groups, fn x-> Map.drop(x,[:ranks]) end)
groups_with_names = Enum.map(raw_groups, fn x -> Map.drop(x, [:ranks]) end)

{teams, logs} = do_cheeky_switcher(groups_with_names, team_count, opts, [])

Expand Down
6 changes: 3 additions & 3 deletions lib/teiserver/battle/balance/split_one_chevs_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Teiserver.Battle.Balance.SplitOneChevsTypes do
member_id: any()
}
@type team :: %{
members: [member],
team_id: integer()
}
members: [member],
team_id: integer()
}
end
6 changes: 3 additions & 3 deletions lib/teiserver/battle/libs/balance_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ defmodule Teiserver.Battle.BalanceLib do

# Only take keys we need
defp clean_groups(groups) do
groups |> Enum.map(fn x->
groups
|> Enum.map(fn x ->
Map.take(x, ~w(members count group_rating ratings)a)
end)
end
Expand All @@ -179,7 +180,7 @@ defmodule Teiserver.Battle.BalanceLib do
true ->
balance_result.teams
|> Map.new(fn {team_id, groups} ->
{team_id, Enum.reverse(clean_groups((groups)))}
{team_id, Enum.reverse(clean_groups(groups))}
end)
end

Expand Down Expand Up @@ -541,7 +542,6 @@ defmodule Teiserver.Battle.BalanceLib do
get_user_rating_value(userid, rating_type_id)
end


# Used to get the rating value of the user for internal balance purposes which might be
# different from public/reporting
@spec get_user_balance_rating_value(T.userid(), String.t() | non_neg_integer()) ::
Expand Down
13 changes: 10 additions & 3 deletions lib/teiserver/battle/servers/match_monitor_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ defmodule Teiserver.Battle.MatchMonitorServer do
if match_id do
game_time = int_parse(game_time)
Telemetry.log_simple_match_event(userid, match_id, event_type_name, game_time)
Logger.info("match-event: Stored <#{username}> <#{event_type_name}> <#{game_time}> userid #{userid} match_id #{match_id}")

Logger.info(
"match-event: Stored <#{username}> <#{event_type_name}> <#{game_time}> userid #{userid} match_id #{match_id}"
)
else
Logger.warning("match-event: Cannot get match_id of userid of #{username}")
end
Expand Down Expand Up @@ -253,13 +256,14 @@ defmodule Teiserver.Battle.MatchMonitorServer do
[_all, username, _user_num, to, msg] ->
host = Client.get_client_by_id(from_id)
user = CacheUser.get_user_by_name(username)

if host == nil do
Logger.error("No host found for from_id: #{from_id} for message #{to}:#{msg}")

# Optionally, handle the case here, such as by sending a message back to the user or taking other corrective actions.
# Just returning {:noreply, state} for now.
{:noreply, state}
else

case to do
"d" ->
# We don't persist this as it's already persisted elsewhere
Expand All @@ -284,6 +288,7 @@ defmodule Teiserver.Battle.MatchMonitorServer do
{:liveview_lobby_chat, :say, user.id, "s: #{msg}"}
)
end

{:noreply, state}
end

Expand Down Expand Up @@ -337,7 +342,9 @@ defmodule Teiserver.Battle.MatchMonitorServer do
defp handle_json_msg(%{"username" => username, "GPU" => _} = contents, from_id) do
case CacheUser.get_user_by_name(username) do
nil ->
Logger.warning("No username on handle_json_msg: #{username} - #{Kernel.inspect(contents)}")
Logger.warning(
"No username on handle_json_msg: #{username} - #{Kernel.inspect(contents)}"
)

:ok

Expand Down
66 changes: 33 additions & 33 deletions lib/teiserver/battle/tasks/seasonal_uncertainty_reset_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,37 @@ defmodule Teiserver.Battle.SeasonalUncertaintyResetTask do
end

defp reset_rating(existing, _new_uncertainty, new_last_updated) do
# Use the greater of the existing uncertainty or the minimum value (5.0)
new_uncertainty = max(existing.uncertainty, 5.0)

new_rating_value = BalanceLib.calculate_rating_value(existing.skill, new_uncertainty)

new_leaderboard_rating =
BalanceLib.calculate_leaderboard_rating(existing.skill, new_uncertainty)

Account.update_rating(existing, %{
rating_value: new_rating_value,
uncertainty: new_uncertainty,
leaderboard_rating: new_leaderboard_rating,
last_updated: new_last_updated
})

log_params = %{
user_id: existing.user_id,
rating_type_id: existing.rating_type_id,
match_id: nil,
inserted_at: new_last_updated,
value: %{
reason: "Seasonal reset",
rating_value: new_rating_value,
skill: existing.skill,
uncertainty: new_uncertainty,
rating_value_change: new_rating_value - existing.rating_value,
skill_change: 0,
uncertainty_change: new_uncertainty - existing.uncertainty
}
}

{:ok, _} = Game.create_rating_log(log_params)
end
# Use the greater of the existing uncertainty or the minimum value (5.0)
new_uncertainty = max(existing.uncertainty, 5.0)

new_rating_value = BalanceLib.calculate_rating_value(existing.skill, new_uncertainty)

new_leaderboard_rating =
BalanceLib.calculate_leaderboard_rating(existing.skill, new_uncertainty)

Account.update_rating(existing, %{
rating_value: new_rating_value,
uncertainty: new_uncertainty,
leaderboard_rating: new_leaderboard_rating,
last_updated: new_last_updated
})

log_params = %{
user_id: existing.user_id,
rating_type_id: existing.rating_type_id,
match_id: nil,
inserted_at: new_last_updated,
value: %{
reason: "Seasonal reset",
rating_value: new_rating_value,
skill: existing.skill,
uncertainty: new_uncertainty,
rating_value_change: new_rating_value - existing.rating_value,
skill_change: 0,
uncertainty_change: new_uncertainty - existing.uncertainty
}
}

{:ok, _} = Game.create_rating_log(log_params)
end
end
11 changes: 6 additions & 5 deletions lib/teiserver/coordinator/consul_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ defmodule Teiserver.Coordinator.ConsulServer do
{:noreply, state}
end

@doc"""
@doc """
This method handles state when all players have left the lobby
"""
def handle_info(
Expand All @@ -387,10 +387,11 @@ defmodule Teiserver.Coordinator.ConsulServer do
# Everyone left the lobby
# Restore some settings to default
if new_player_count == 0 do
new_state = %{state |
minimum_rating_to_play: 0,
maximum_rating_to_play: 1000,
balance_algorithm: @default_balance_algorithm
new_state = %{
state
| minimum_rating_to_play: 0,
maximum_rating_to_play: 1000,
balance_algorithm: @default_balance_algorithm
}

{:noreply, new_state}
Expand Down
5 changes: 3 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, Config, 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,8 @@ defmodule Teiserver.Game.MatchRatingLib do
match.team_count < 2 ->
{:error, :not_enough_teams}

match.game_duration < Config.get_site_config_cache("matchmaking.Time to treat game as ranked") ->
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
3 changes: 1 addition & 2 deletions lib/teiserver/game/servers/balancer_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ defmodule Teiserver.Game.BalancerServer do
players
|> Enum.map(fn %{userid: userid} ->
%{
userid =>
BalanceLib.get_user_rating_rank(userid, rating_type, opts[:fuzz_multiplier])
userid => BalanceLib.get_user_rating_rank(userid, rating_type, opts[:fuzz_multiplier])
}
end)

Expand Down
4 changes: 3 additions & 1 deletion lib/teiserver/helpers/oban_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ defmodule Teiserver.Helper.ObanLogger do
end

def handle_event([:oban, :job, event], measure, meta, _) do
Logger.info("[Oban] #{event} #{meta.worker} ran in #{System.convert_time_unit(measure.duration, :native, :milliseconds)}ms")
Logger.info(
"[Oban] #{event} #{meta.worker} ran in #{System.convert_time_unit(measure.duration, :native, :milliseconds)}ms"
)
end
end
6 changes: 4 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,10 @@ 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) |> Enum.to_list()
end) |> Enum.to_list()
end)
|> Enum.to_list()
end)
|> Enum.to_list()
|> List.flatten()

Ecto.Multi.new()
Expand Down
22 changes: 18 additions & 4 deletions lib/teiserver/protocols/spring/spring_telemetry_in.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule Teiserver.Protocols.Spring.TelemetryIn do
case Spring.unzip(compressed_contents) do
{:ok, contents} ->
if String.valid?(contents) do

params = %{
user_hash: user_hash,
user_id: state.userid,
Expand All @@ -35,14 +34,29 @@ defmodule Teiserver.Protocols.Spring.TelemetryIn do
DiscordBridgeBot.new_infolog(infolog)
end

reply(:spring, :okay, "upload_infolog - id:#{infolog.id}", msg_id, state)
reply(
:spring,
:okay,
"upload_infolog - id:#{infolog.id}",
msg_id,
state
)

{:error, _changeset} ->
reply(:spring, :no, "upload_infolog - db error", msg_id, state)
end
else
Logger.error("#{state.userid} #{log_type} upload_infolog - contents contain invalid characters")
reply(:spring, :no, "upload_infolog - contents contain invalid characters", msg_id, state)
Logger.error(
"#{state.userid} #{log_type} upload_infolog - contents contain invalid characters"
)

reply(
:spring,
:no,
"upload_infolog - contents contain invalid characters",
msg_id,
state
)
end

{:error, _} ->
Expand Down
2 changes: 2 additions & 0 deletions lib/teiserver_web/controllers/admin/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ defmodule TeiserverWeb.Admin.UserController do
) ++
Account.list_users(search: [id_in: id_list]))
|> Enum.uniq()

user_stats = for user <- users, do: Account.get_user_stat_data(user.id)

conn
Expand Down Expand Up @@ -127,6 +128,7 @@ defmodule TeiserverWeb.Admin.UserController do

Account.list_users(search: [id_in: id_list])
end

user_stats = for user <- users, do: Account.get_user_stat_data(user.id)

conn
Expand Down
10 changes: 5 additions & 5 deletions lib/teiserver_web/live/account/profile/contributor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do
Account.recache_user(assigns.user.id)

{:noreply,
socket
|> assign(:country_code, assigns.temp_country_code)
|> assign(:error_message, nil)}
socket
|> assign(:country_code, assigns.temp_country_code)
|> assign(:error_message, nil)}
else
{:noreply,
socket
|> assign(:error_message, "Country code must not contain space")}
socket
|> assign(:error_message, "Country code must not contain space")}
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/teiserver_web/live/battles/lobbies/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ spectators =
<ul>
<li>Max players: <%= @lobby.max_players %></li>
<li>Locked: <%= @lobby.locked %></li>
<li>Rated Game: <%= if @modoptions["game/modoptions/ranked_game"] == "1", do: "Yes", else: "No" %></li>
<li>
Rated Game: <%= if @modoptions["game/modoptions/ranked_game"] == "1",
do: "Yes",
else: "No" %>
</li>
<%= if @lobby.password != nil do %>
<li>Password: <%= @lobby.password %></li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
The more information you can provide the better, some useful items include:
<ul>
<li>A description of what was done or specific words said</li>
<li>Links to the replay itself from <a href="https://bar-rts.com/replays" target="_blank">BAR Replays</a></li>
<li>
Links to the replay itself from
<a href="https://bar-rts.com/replays" target="_blank">BAR Replays</a>
</li>
<li>Timestamps (even if approximate) of in-game events</li>
</ul>
<br /><br />
Expand Down
Loading

0 comments on commit 9bb669e

Please sign in to comment.