diff --git a/lib/teiserver/account/libs/role_lib.ex b/lib/teiserver/account/libs/role_lib.ex index 957065333..9426db9cc 100644 --- a/lib/teiserver/account/libs/role_lib.ex +++ b/lib/teiserver/account/libs/role_lib.ex @@ -95,7 +95,7 @@ defmodule Teiserver.Account.RoleLib do }, # Privileged - %{name: "VIP", colour: "#AA8833", icon: "fa-solid fa-sparkles", contains: ["BAR+"]}, + %{name: "VIP", colour: "#AA8833", icon: "fa-solid fa-sparkles", contains: ~w()}, %{name: "Streamer", colour: "#660066", icon: "fa-brands fa-twitch", contains: ~w()}, %{name: "Tournament", colour: "#0000AA", icon: "fa-solid fa-trophy", contains: ~w()}, %{ diff --git a/lib/teiserver/coordinator/consul_server.ex b/lib/teiserver/coordinator/consul_server.ex index 7602349fc..f36a6f33d 100644 --- a/lib/teiserver/coordinator/consul_server.ex +++ b/lib/teiserver/coordinator/consul_server.ex @@ -27,9 +27,8 @@ defmodule Teiserver.Coordinator.ConsulServer do @always_allow ~w(status s y n follow joinq leaveq splitlobby afks roll password? tournament) @boss_commands ~w(balancealgorithm gatekeeper welcome-message meme reset-approval rename minchevlevel maxchevlevel resetchevlevels resetratinglevels minratinglevel maxratinglevel setratinglevels) - @vip_boss_commands ~w(shuffle) @host_commands ~w(specunready makeready settag speclock forceplay lobbyban lobbybanmult unban forcespec lock unlock makebalance set-config-teaser) - @admin_commands ~w(playerlimit broadcast) + @admin_commands ~w(playerlimit broadcast shuffle) # @handled_by_lobby ~w(explain) @splitter "########################################" @@ -970,7 +969,6 @@ defmodule Teiserver.Coordinator.ConsulServer do is_host = senderid == state.host_id is_boss = Enum.member?(state.host_bosses, senderid) - is_vip = Enum.member?(user.roles, "VIP") is_admin = Enum.member?(user.roles, "Admin") cond do @@ -997,26 +995,6 @@ defmodule Teiserver.Coordinator.ConsulServer do Enum.member?(@boss_commands, cmd.command) and (is_host or is_boss) -> true - Enum.member?(@vip_boss_commands, cmd.command) and (is_vip and is_boss) -> - true - - Enum.member?(@vip_boss_commands, cmd.command) and not (is_vip and is_boss) -> - msg = - if is_vip do - "You also need to be boss to call '#{cmd.command}'" - else - "No listed command of '#{cmd.command}'" - end - - ChatLib.sayprivateex( - state.coordinator_id, - cmd.senderid, - msg, - state.lobby_id - ) - - false - Enum.member?(@host_commands, cmd.command) and not is_host -> ChatLib.sayprivateex( state.coordinator_id, diff --git a/lib/teiserver/data/cache_user.ex b/lib/teiserver/data/cache_user.ex index 5caa97fb1..735b4722a 100644 --- a/lib/teiserver/data/cache_user.ex +++ b/lib/teiserver/data/cache_user.ex @@ -406,16 +406,7 @@ defmodule Teiserver.CacheUser do @spec rename_user(T.userid(), String.t(), boolean) :: :success | {:error, String.t()} def rename_user(userid, new_name, admin_action \\ false) do - rename_log = - Account.get_user_stat_data(userid) - |> Map.get("rename_log", []) - new_name = String.trim(new_name) - - now = System.system_time(:second) - # since_most_recent_rename = now - (Enum.slice(rename_log, 0..0) ++ [0] |> hd) - since_rename_two = now - ((Enum.slice(rename_log, 1..1) ++ [0, 0, 0]) |> hd) - since_rename_three = now - ((Enum.slice(rename_log, 2..2) ++ [0, 0, 0]) |> hd) max_username_length = Config.get_site_config_cache("teiserver.Username max length") cond do @@ -428,15 +419,8 @@ defmodule Teiserver.CacheUser do admin_action == false and WordLib.acceptable_name?(new_name) == false -> {:error, "Not an acceptable name, please see section 1.4 of the code of conduct"} - # Can't rename more than 2 times in 5 days - admin_action == false and since_rename_two < 60 * 60 * 24 * 5 -> - {:error, - "If you keep changing your name people won't know who you are; give it a bit of time (5 days)"} - - # Can't rename more than 3 times in 30 days - admin_action == false and since_rename_three < 60 * 60 * 24 * 30 -> - {:error, - "If you keep changing your name people won't know who you are; give it a bit of time (30 days)"} + admin_action == false and renamed_recently(userid) -> + {:error, "Rename limit reached (2 times in 5 days or 3 times in 30 days)"} admin_action == false and is_restricted?(userid, ["All chat", "Renaming"]) -> {:error, "Muted"} @@ -460,6 +444,27 @@ defmodule Teiserver.CacheUser do end end + @spec renamed_recently(T.userid()) :: boolean() + defp renamed_recently(user_id) do + rename_log = + Account.get_user_stat_data(user_id) + |> Map.get("rename_log", []) + + now = System.system_time(:second) + since_rename_two = now - ((Enum.slice(rename_log, 1..1) ++ [0, 0, 0]) |> hd) + since_rename_three = now - ((Enum.slice(rename_log, 2..2) ++ [0, 0, 0]) |> hd) + + cond do + # VIPs ignore time based rename restrictions + is_vip?(user_id) -> false + # Can't rename more than 2 times in 5 days + since_rename_two < 60 * 60 * 24 * 5 -> true + # Can't rename more than 3 times in 30 days + since_rename_three < 60 * 60 * 24 * 30 -> true + true -> false + end + end + @spec do_rename_user(T.userid(), String.t()) :: :ok defp do_rename_user(userid, new_name) do client = Account.get_client_by_id(userid) @@ -1241,6 +1246,12 @@ defmodule Teiserver.CacheUser do def is_admin?(%{roles: roles}), do: Enum.member?(roles, "Admin") def is_admin?(_), do: false + @spec is_vip?(T.userid() | T.user()) :: boolean() + def is_vip?(nil), do: false + def is_vip?(userid) when is_integer(userid), do: is_vip?(get_user_by_id(userid)) + def is_vip?(%{roles: roles}), do: Enum.member?(roles, "VIP") + def is_vip?(_), do: false + @spec rank_time(T.userid()) :: non_neg_integer() def rank_time(userid) do stats = Account.get_user_stat(userid) || %{data: %{}}