Skip to content

Commit

Permalink
Merge branch 'remove-ping-message' into last-playtest-13-09
Browse files Browse the repository at this point in the history
  • Loading branch information
manucamejo committed Sep 13, 2024
2 parents 0bd8281 + bf76802 commit 77f1e2f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 820 deletions.
13 changes: 0 additions & 13 deletions apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,6 @@ defmodule Arena.GameSocketHandler do
{:ok, Map.put(state, :enable, true)}
end

@impl true
def websocket_info({:ping, game_state}, state) do
{:reply, {:binary, game_state}, state}
end

@impl true
def websocket_info({:ping_update, game_state}, state) do
{:reply, {:binary, game_state}, state}
end

@impl true
def websocket_info({:game_update, game_state}, state) do
# Logger.info("Websocket info, Message: GAME UPDATE")
Expand Down Expand Up @@ -214,9 +204,6 @@ defmodule Arena.GameSocketHandler do
defp handle_decoded_message(%{action_type: {:select_bounty, bounty_params}}, state),
do: GameUpdater.select_bounty(state.game_pid, state.player_id, bounty_params.bounty_quest_id)

defp handle_decoded_message(%{action_type: {:pong, pong_params}}, state),
do: GameUpdater.pong(state.game_pid, self(), pong_params.ping_timestamp)

defp handle_decoded_message(%{action_type: {:toggle_zone, _zone_params}}, state),
do: GameUpdater.toggle_zone(state.game_pid)

Expand Down
38 changes: 0 additions & 38 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ defmodule Arena.GameUpdater do
alias Arena.Serialization.GameState
alias Arena.Serialization.GameFinished
alias Arena.Serialization.ToggleBots
alias Arena.Serialization.PingUpdate
alias Arena.Serialization.Ping
alias Phoenix.PubSub
alias Arena.Game.Trap

Expand Down Expand Up @@ -57,10 +55,6 @@ defmodule Arena.GameUpdater do
GenServer.cast(game_pid, {:change_tickrate, tickrate})
end

def pong(game_pid, client_pid, ping_timestamp) do
GenServer.cast(game_pid, {:pong, client_pid, ping_timestamp})
end

##########################
# END API
##########################
Expand All @@ -74,7 +68,6 @@ defmodule Arena.GameUpdater do
match_id = Ecto.UUID.generate()

send(self(), :update_game)
send(self(), :send_ping)

bounties_enabled? = game_config.game.bounty_pick_time_ms > 0

Expand Down Expand Up @@ -220,20 +213,6 @@ defmodule Arena.GameUpdater do
{:noreply, put_in(state, [:game_config, :game, :tick_rate_ms], tickrate)}
end

def handle_cast({:pong, client_pid, ping_timestamp}, state) do
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond)
latency = now - ping_timestamp

encoded_msg =
GameEvent.encode(%GameEvent{
event: {:ping_update, %PingUpdate{latency: latency}}
})

send(client_pid, {:ping_update, encoded_msg})

{:noreply, state}
end

##########################
# END API Callbacks
##########################
Expand Down Expand Up @@ -313,12 +292,6 @@ defmodule Arena.GameUpdater do
{:noreply, %{state | game_state: game_state, last_broadcasted_game_state: last_broadcasted_game_state}}
end

def handle_info(:send_ping, state) do
Process.send_after(self(), :send_ping, 500)
broadcast_ping(state.game_state)
{:noreply, state}
end

def handle_info(:selecting_bounty, state) do
Process.send_after(self(), :game_start, state.game_config.game.start_game_time_ms)
Process.send_after(self(), :pick_default_bounty_for_missing_players, state.game_config.game.start_game_time_ms)
Expand Down Expand Up @@ -758,17 +731,6 @@ defmodule Arena.GameUpdater do
PubSub.broadcast(Arena.PubSub, game_id, {:game_update, encoded_state})
end

defp broadcast_ping(state) do
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond)

encoded_state =
GameEvent.encode(%GameEvent{
event: {:ping, %Ping{timestamp_now: now}}
})

PubSub.broadcast(Arena.PubSub, state.game_id, {:ping, encoded_state})
end

defp broadcast_game_ended(winner, state) do
game_state = %GameFinished{
winner: complete_entity(winner, :player),
Expand Down
31 changes: 2 additions & 29 deletions apps/arena/lib/arena/serialization/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,15 @@ defmodule Arena.Serialization.GameEvent do
field(:joined, 1, type: Arena.Serialization.GameJoined, oneof: 0)
field(:update, 2, type: Arena.Serialization.GameState, oneof: 0)
field(:finished, 3, type: Arena.Serialization.GameFinished, oneof: 0)
field(:ping_update, 4, type: Arena.Serialization.PingUpdate, json_name: "pingUpdate", oneof: 0)
field(:toggle_bots, 5, type: Arena.Serialization.ToggleBots, json_name: "toggleBots", oneof: 0)
field(:ping, 6, type: Arena.Serialization.Ping, oneof: 0)
field(:toggle_bots, 4, type: Arena.Serialization.ToggleBots, json_name: "toggleBots", oneof: 0)

field(:bounty_selected, 7,
field(:bounty_selected, 5,
type: Arena.Serialization.BountySelected,
json_name: "bountySelected",
oneof: 0
)
end

defmodule Arena.Serialization.Ping do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:timestamp_now, 1, type: :int64, json_name: "timestampNow")
end

defmodule Arena.Serialization.PingUpdate do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:latency, 1, type: :uint64)
end

defmodule Arena.Serialization.BountySelected do
@moduledoc false

Expand Down Expand Up @@ -749,18 +731,9 @@ defmodule Arena.Serialization.GameAction do
oneof: 0
)

field(:pong, 9, type: Arena.Serialization.Pong, oneof: 0)
field(:timestamp, 3, type: :int64)
end

defmodule Arena.Serialization.Pong do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:ping_timestamp, 1, type: :int64, json_name: "pingTimestamp")
end

defmodule Arena.Serialization.Zone do
@moduledoc false

Expand Down
2 changes: 1 addition & 1 deletion apps/arena/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Arena.MixProject do
def project do
[
app: :arena,
version: "0.7.1",
version: "0.8.1",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,43 +141,19 @@ defmodule ArenaLoadTest.Serialization.GameEvent do
field(:update, 2, type: ArenaLoadTest.Serialization.GameState, oneof: 0)
field(:finished, 3, type: ArenaLoadTest.Serialization.GameFinished, oneof: 0)

field(:ping_update, 4,
type: ArenaLoadTest.Serialization.PingUpdate,
json_name: "pingUpdate",
oneof: 0
)

field(:toggle_bots, 5,
field(:toggle_bots, 4,
type: ArenaLoadTest.Serialization.ToggleBots,
json_name: "toggleBots",
oneof: 0
)

field(:ping, 6, type: ArenaLoadTest.Serialization.Ping, oneof: 0)

field(:bounty_selected, 7,
field(:bounty_selected, 5,
type: ArenaLoadTest.Serialization.BountySelected,
json_name: "bountySelected",
oneof: 0
)
end

defmodule ArenaLoadTest.Serialization.Ping do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:timestamp_now, 1, type: :int64, json_name: "timestampNow")
end

defmodule ArenaLoadTest.Serialization.PingUpdate do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:latency, 1, type: :uint64)
end

defmodule ArenaLoadTest.Serialization.BountySelected do
@moduledoc false

Expand Down Expand Up @@ -812,18 +788,9 @@ defmodule ArenaLoadTest.Serialization.GameAction do
oneof: 0
)

field(:pong, 9, type: ArenaLoadTest.Serialization.Pong, oneof: 0)
field(:timestamp, 3, type: :int64)
end

defmodule ArenaLoadTest.Serialization.Pong do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:ping_timestamp, 1, type: :int64, json_name: "pingTimestamp")
end

defmodule ArenaLoadTest.Serialization.Zone do
@moduledoc false

Expand Down
31 changes: 2 additions & 29 deletions apps/bot_manager/lib/protobuf/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,15 @@ defmodule BotManager.Protobuf.GameEvent do
field(:joined, 1, type: BotManager.Protobuf.GameJoined, oneof: 0)
field(:update, 2, type: BotManager.Protobuf.GameState, oneof: 0)
field(:finished, 3, type: BotManager.Protobuf.GameFinished, oneof: 0)
field(:ping_update, 4, type: BotManager.Protobuf.PingUpdate, json_name: "pingUpdate", oneof: 0)
field(:toggle_bots, 5, type: BotManager.Protobuf.ToggleBots, json_name: "toggleBots", oneof: 0)
field(:ping, 6, type: BotManager.Protobuf.Ping, oneof: 0)
field(:toggle_bots, 4, type: BotManager.Protobuf.ToggleBots, json_name: "toggleBots", oneof: 0)

field(:bounty_selected, 7,
field(:bounty_selected, 5,
type: BotManager.Protobuf.BountySelected,
json_name: "bountySelected",
oneof: 0
)
end

defmodule BotManager.Protobuf.Ping do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:timestamp_now, 1, type: :int64, json_name: "timestampNow")
end

defmodule BotManager.Protobuf.PingUpdate do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:latency, 1, type: :uint64)
end

defmodule BotManager.Protobuf.BountySelected do
@moduledoc false

Expand Down Expand Up @@ -749,18 +731,9 @@ defmodule BotManager.Protobuf.GameAction do
oneof: 0
)

field(:pong, 9, type: BotManager.Protobuf.Pong, oneof: 0)
field(:timestamp, 3, type: :int64)
end

defmodule BotManager.Protobuf.Pong do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:ping_timestamp, 1, type: :int64, json_name: "pingTimestamp")
end

defmodule BotManager.Protobuf.Zone do
@moduledoc false

Expand Down
Loading

0 comments on commit 77f1e2f

Please sign in to comment.