Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bots url protocol + bot process dying when attacking #956

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/arena/lib/arena/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ defmodule Arena.Utils do

def get_bot_connection_url(game_id, bot_client) do
server_url = System.get_env("PHX_HOST") || "localhost"
bot_manager_host = System.get_env("BOT_MANAGER_HOST", "localhost")
bot_manager_port = System.get_env("BOT_MANAGER_PORT", "4003")
bot_manager_host = System.get_env("BOT_MANAGER_HOST", "localhost:4003")
protocol = get_correct_protocol(bot_manager_host)

"http://#{bot_manager_host}:#{bot_manager_port}/join/#{server_url}/#{game_id}/#{bot_client}"
"#{protocol}#{bot_manager_host}/join/#{server_url}/#{game_id}/#{bot_client}"
end

defp get_correct_protocol("localhost" <> _host), do: "http://"
defp get_correct_protocol(_host), do: "https://"
end
19 changes: 7 additions & 12 deletions apps/bot_manager/lib/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,17 @@ defmodule BotManager.GameSocketHandler do

def handle_info(:perform_action, state) do
Process.send_after(self(), :perform_action, @action_delay_ms)

send_current_action(state)
{:ok, update_block_attack_state(state)}
end

state =
case state.current_action do
{:attack, _} ->
Map.put(state, :attack_blocked, true)
Process.send_after(self(), :unblock_attack, Enum.random(2000..4000))

_ ->
state
end

{:ok, state}
defp update_block_attack_state(%{current_action: {:attack, _}} = state) do
Process.send_after(self(), :unblock_attack, Enum.random(2000..4000))
Map.put(state, :attack_blocked, true)
end

defp update_block_attack_state(state), do: state

def handle_cast({:send, {_type, _msg} = frame}, state) do
{:reply, frame, state}
end
Expand Down
Loading