From 209bdfa9633780798886d35e75863bfac4b60fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Villegas?= <67444519+tvillegas98@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:39:37 -0300 Subject: [PATCH] [HOTFIX] - Bug Fix Team Mode (#1052) * chore: modify if to check if the current amount of players is less than the max capacity * Add team attribute to GameJoined proto * chore: send the team id to the client * feat: rename team_id to team * chore: restore wrongly pushed file * chore: increase arena version --------- Co-authored-by: Nicolas Sanchez --- apps/arena/lib/arena/game_socket_handler.ex | 6 ++-- apps/arena/lib/arena/game_updater.ex | 3 ++ apps/arena/lib/arena/matchmaking/pair_mode.ex | 2 +- .../lib/arena/serialization/messages.pb.ex | 1 + .../serialization/messages.pb.ex | 1 + apps/bot_manager/lib/protobuf/messages.pb.ex | 1 + .../assets/js/protobuf/messages_pb.js | 32 ++++++++++++++++++- .../lib/game_client/protobuf/messages.pb.ex | 1 + apps/serialization/messages.proto | 1 + 9 files changed, 44 insertions(+), 4 deletions(-) diff --git a/apps/arena/lib/arena/game_socket_handler.ex b/apps/arena/lib/arena/game_socket_handler.ex index d7d22d2ef..dc228a761 100644 --- a/apps/arena/lib/arena/game_socket_handler.ex +++ b/apps/arena/lib/arena/game_socket_handler.ex @@ -41,7 +41,7 @@ defmodule Arena.GameSocketHandler do Logger.info("Websocket INIT called") Phoenix.PubSub.subscribe(Arena.PubSub, state.game_id) - {:ok, %{player_id: player_id, game_config: config, game_status: game_status, bounties: bounties}} = + {:ok, %{player_id: player_id, team: team, game_config: config, game_status: game_status, bounties: bounties}} = GameUpdater.join(state.game_pid, state.client_id) state = @@ -54,7 +54,9 @@ defmodule Arena.GameSocketHandler do encoded_msg = GameEvent.encode(%GameEvent{ - event: {:joined, %GameJoined{player_id: player_id, config: to_broadcast_config(config), bounties: bounties}} + event: + {:joined, + %GameJoined{player_id: player_id, team: team, config: to_broadcast_config(config), bounties: bounties}} }) :telemetry.execute([:arena, :clients], %{count: 1}) diff --git a/apps/arena/lib/arena/game_updater.ex b/apps/arena/lib/arena/game_updater.ex index 2dd0b2168..e4c2dc2ea 100644 --- a/apps/arena/lib/arena/game_updater.ex +++ b/apps/arena/lib/arena/game_updater.ex @@ -122,8 +122,11 @@ defmodule Arena.GameUpdater do |> Enum.shuffle() |> Enum.take(state.game_config.game.bounties_options_amount) + player = Map.get(state.game_state.players, player_id) + response = %{ player_id: player_id, + team: player.aditional_info.team, game_config: state.game_config, game_status: state.game_state.status, bounties: bounties diff --git a/apps/arena/lib/arena/matchmaking/pair_mode.ex b/apps/arena/lib/arena/matchmaking/pair_mode.ex index c4d096441..130ec2b85 100644 --- a/apps/arena/lib/arena/matchmaking/pair_mode.ex +++ b/apps/arena/lib/arena/matchmaking/pair_mode.ex @@ -114,7 +114,7 @@ defmodule Arena.Matchmaking.PairMode do game_params = Map.put(game_params, :game_mode, :PAIR) bot_clients = - if Application.get_env(:arena, :spawn_bots) do + if Enum.count(clients) < Application.get_env(:arena, :players_needed_in_match) do get_bot_clients(Application.get_env(:arena, :players_needed_in_match) - Enum.count(clients)) else [] diff --git a/apps/arena/lib/arena/serialization/messages.pb.ex b/apps/arena/lib/arena/serialization/messages.pb.ex index 9f004ff56..abc46785b 100644 --- a/apps/arena/lib/arena/serialization/messages.pb.ex +++ b/apps/arena/lib/arena/serialization/messages.pb.ex @@ -224,6 +224,7 @@ defmodule Arena.Serialization.GameJoined do field(:player_id, 1, type: :uint64, json_name: "playerId") field(:config, 2, type: Arena.Serialization.Configuration) field(:bounties, 3, repeated: true, type: Arena.Serialization.BountyInfo) + field(:team, 4, type: :uint32) end defmodule Arena.Serialization.Configuration do diff --git a/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex b/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex index 756fd1cd2..5b22462fc 100644 --- a/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex +++ b/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex @@ -229,6 +229,7 @@ defmodule ArenaLoadTest.Serialization.GameJoined do field(:player_id, 1, type: :uint64, json_name: "playerId") field(:config, 2, type: ArenaLoadTest.Serialization.Configuration) field(:bounties, 3, repeated: true, type: ArenaLoadTest.Serialization.BountyInfo) + field(:team, 4, type: :uint32) end defmodule ArenaLoadTest.Serialization.Configuration do diff --git a/apps/bot_manager/lib/protobuf/messages.pb.ex b/apps/bot_manager/lib/protobuf/messages.pb.ex index 7f0858657..455514049 100644 --- a/apps/bot_manager/lib/protobuf/messages.pb.ex +++ b/apps/bot_manager/lib/protobuf/messages.pb.ex @@ -224,6 +224,7 @@ defmodule BotManager.Protobuf.GameJoined do field(:player_id, 1, type: :uint64, json_name: "playerId") field(:config, 2, type: BotManager.Protobuf.Configuration) field(:bounties, 3, repeated: true, type: BotManager.Protobuf.BountyInfo) + field(:team, 4, type: :uint32) end defmodule BotManager.Protobuf.Configuration do diff --git a/apps/game_client/assets/js/protobuf/messages_pb.js b/apps/game_client/assets/js/protobuf/messages_pb.js index 31da0b583..ff180f07f 100644 --- a/apps/game_client/assets/js/protobuf/messages_pb.js +++ b/apps/game_client/assets/js/protobuf/messages_pb.js @@ -2934,7 +2934,8 @@ proto.GameJoined.toObject = function(includeInstance, msg) { playerId: jspb.Message.getFieldWithDefault(msg, 1, 0), config: (f = msg.getConfig()) && proto.Configuration.toObject(includeInstance, f), bountiesList: jspb.Message.toObjectList(msg.getBountiesList(), - proto.BountyInfo.toObject, includeInstance) + proto.BountyInfo.toObject, includeInstance), +team: jspb.Message.getFieldWithDefault(msg, 4, 0) }; if (includeInstance) { @@ -2985,6 +2986,10 @@ proto.GameJoined.deserializeBinaryFromReader = function(msg, reader) { reader.readMessage(value,proto.BountyInfo.deserializeBinaryFromReader); msg.addBounties(value); break; + case 4: + var value = /** @type {number} */ (reader.readUint32()); + msg.setTeam(value); + break; default: reader.skipField(); break; @@ -3037,6 +3042,13 @@ proto.GameJoined.serializeBinaryToWriter = function(message, writer) { proto.BountyInfo.serializeBinaryToWriter ); } + f = message.getTeam(); + if (f !== 0) { + writer.writeUint32( + 4, + f + ); + } }; @@ -3133,6 +3145,24 @@ proto.GameJoined.prototype.clearBountiesList = function() { }; +/** + * optional uint32 team = 4; + * @return {number} + */ +proto.GameJoined.prototype.getTeam = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); +}; + + +/** + * @param {number} value + * @return {!proto.GameJoined} returns this + */ +proto.GameJoined.prototype.setTeam = function(value) { + return jspb.Message.setProto3IntField(this, 4, value); +}; + + /** * List of repeated fields within this message type. diff --git a/apps/game_client/lib/game_client/protobuf/messages.pb.ex b/apps/game_client/lib/game_client/protobuf/messages.pb.ex index 009a49bf5..599153d5a 100644 --- a/apps/game_client/lib/game_client/protobuf/messages.pb.ex +++ b/apps/game_client/lib/game_client/protobuf/messages.pb.ex @@ -224,6 +224,7 @@ defmodule GameClient.Protobuf.GameJoined do field(:player_id, 1, type: :uint64, json_name: "playerId") field(:config, 2, type: GameClient.Protobuf.Configuration) field(:bounties, 3, repeated: true, type: GameClient.Protobuf.BountyInfo) + field(:team, 4, type: :uint32) end defmodule GameClient.Protobuf.Configuration do diff --git a/apps/serialization/messages.proto b/apps/serialization/messages.proto index 437f4724c..972f7f53e 100644 --- a/apps/serialization/messages.proto +++ b/apps/serialization/messages.proto @@ -60,6 +60,7 @@ message GameJoined { uint64 player_id = 1; Configuration config = 2; repeated BountyInfo bounties = 3; + uint32 team = 4; } message Configuration {