Skip to content

Commit

Permalink
Move broadcast to coordinator commands
Browse files Browse the repository at this point in the history
  • Loading branch information
L-e-x-o-n committed Sep 30, 2024
1 parent b01d9c5 commit 11fad26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
12 changes: 0 additions & 12 deletions lib/teiserver/coordinator/consul_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2071,18 +2071,6 @@ defmodule Teiserver.Coordinator.ConsulCommands do
end
end

def handle_command(
%{command: "broadcast", remaining: message, senderid: senderid} = cmd,
state
) do
Lobby.list_lobby_ids()
|> Enum.each(fn lobby_id ->
Lobby.say(senderid, message, lobby_id)
end)

state
end

#################### Internal commands
# Would need to be sent by internal since battlestatus isn't part of the command queue
def handle_command(
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/coordinator/consul_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Teiserver.Coordinator.ConsulServer do
@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 forceplay lock unlock makebalance set-config-teaser)
@admin_commands ~w(playerlimit broadcast)
@admin_commands ~w(playerlimit)

# @handled_by_lobby ~w(explain)
@splitter "########################################"
Expand Down
24 changes: 23 additions & 1 deletion lib/teiserver/coordinator/coordinator_commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Teiserver.Coordinator.CoordinatorCommands do
# These commands are handled by coordinator commands, but are not on the always allow list
@mod_allow ~w(check modparty unparty)
@forward_to_consul ~w(s status players follow joinq leaveq splitlobby y yes n no explain)
@admin_commands ~w(broadcast)

def is_coordinator_command?(command) do
# The list of allowed commands are now defined in this file
Expand All @@ -21,6 +22,9 @@ defmodule Teiserver.Coordinator.CoordinatorCommands do
@spec allow_command?(map(), map()) :: boolean()
defp allow_command?(%{senderid: senderid} = cmd, state) do
client = Client.get_client_by_id(senderid)
user = Account.get_user_by_id(senderid)

is_admin = Enum.member?(user.roles, "Admin")

cond do
client == nil ->
Expand All @@ -32,7 +36,12 @@ defmodule Teiserver.Coordinator.CoordinatorCommands do
Enum.member?(@always_allow, cmd.command) ->
true

client.moderator == true ->
# Allow all commands for Admins
is_admin ->
true

# Allow all except Admin only commands for moderators
client.moderator and not Enum.member?(@admin_commands, cmd.command) ->
true

not Enum.member?(@always_allow ++ @forward_to_consul, cmd.command) ->
Expand Down Expand Up @@ -545,6 +554,19 @@ defmodule Teiserver.Coordinator.CoordinatorCommands do
state
end

# Admin commands
defp do_handle(
%{command: "broadcast", senderid: senderid, remaining: message} = cmd,
state
) do
Lobby.list_lobby_ids()
|> Enum.each(fn lobby_id ->
Lobby.say(senderid, message, lobby_id)
end)

state
end

# Moderator commands
defp do_handle(%{command: command, senderid: senderid} = _cmd, state) do
CacheUser.send_direct_message(
Expand Down

0 comments on commit 11fad26

Please sign in to comment.