Skip to content

Commit

Permalink
Restore bots when disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Sanchez committed Sep 3, 2024
1 parent a649be0 commit 6472de0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Arena.GameSocketHandler do
require Logger
alias Arena.Authentication.GatewaySigner
alias Arena.Authentication.GatewayTokenManager
alias Arena.Utils
alias Arena.Serialization
alias Arena.GameUpdater
alias Arena.Serialization.GameEvent
Expand Down Expand Up @@ -168,6 +169,19 @@ defmodule Arena.GameSocketHandler do
end

@impl true
def terminate(_reason, _req, %{game_finished: false, player_alive: true} = state) do
:telemetry.execute([:arena, :clients], %{count: -1})

if Application.get_env(:arena, :spawn_bots) do
spawn(fn ->
Finch.build(:get, Utils.get_bot_connection_url(state.game_id, state.client_id))
|> Finch.request(Arena.Finch)
end)
end

:ok
end

def terminate(_reason, _req, _state) do
:telemetry.execute([:arena, :clients], %{count: -1})
:ok
Expand Down

0 comments on commit 6472de0

Please sign in to comment.