Skip to content

Commit

Permalink
Extend battle/start message with engine, game and map
Browse files Browse the repository at this point in the history
  • Loading branch information
L-e-x-o-n committed Feb 10, 2025
1 parent c79ee18 commit 7553169
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
10 changes: 8 additions & 2 deletions lib/teiserver/autohost/tachyon_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ defmodule Teiserver.Autohost.TachyonHandler do

@type start_response :: %{
ips: [String.t()],
port: integer()
port: integer(),
engine: %{String.t() => String.t()},
game: %{String.t() => String.t()},
map: %{String.t() => String.t()}
}

@impl Handler
Expand Down Expand Up @@ -173,7 +176,10 @@ defmodule Teiserver.Autohost.TachyonHandler do
{:ok,
%{
ips: data["ips"],
port: data["port"]
port: data["port"],
engine: %{"version" => data["engine"]},
game: %{"springName" => data["game"]},
map: %{"springName" => data["map"]}
}}}
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/lobby/libs/lobby_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule Teiserver.Lobby.LobbyLib do
cast_lobby(lobby_id, {:update_values, new_values})
end

@spec rename_lobby(T.lobby_id(), String.t(), T.userid()) :: :ok | nil
@spec rename_lobby(T.lobby_id(), String.t(), T.userid() | nil) :: :ok | nil
def rename_lobby(lobby_id, new_base_name, renamer_id) do
cast_lobby(lobby_id, {:rename_lobby, new_base_name, renamer_id})
end
Expand Down
5 changes: 4 additions & 1 deletion lib/teiserver/player/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ defmodule Teiserver.Player.Session do
username: state.user.name,
password: pass,
ip: hd(battle_start_data.ips),
port: battle_start_data.port
port: battle_start_data.port,
engine: battle_start_data.engine,
game: battle_start_data.game,
map: battle_start_data.map
}

state = send_to_player({:battle_start, data}, state)
Expand Down
13 changes: 2 additions & 11 deletions priv/tachyon/schema/battle/start/request.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"$id": "https://schema.beyondallreason.dev/tachyon/battle/start/request.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "BattleStartRequest",
"tachyon": {
"source": "server",
Expand All @@ -13,15 +11,8 @@
"messageId": { "type": "string" },
"commandId": { "const": "battle/start" },
"data": {
"title": "BattleStartRequestData",
"type": "object",
"properties": {
"username": { "type": "string" },
"password": { "type": "string" },
"ip": { "type": "string" },
"port": { "type": "number" }
},
"required": ["username", "password", "ip", "port"]
"$ref": "../definitions/privateBattle.json",
"title": "BattleStartRequestData"
}
},
"required": ["type", "messageId", "commandId", "data"]
Expand Down
28 changes: 28 additions & 0 deletions priv/tachyon/schema/definitions/privateBattle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$id": "https://schema.beyondallreason.dev/tachyon/definitions/privateBattle.json",
"title": "PrivateBattle",
"description": "Battle informations including secrets to pass to spring for joining the game server. Don't expose secrets to other players.",
"type": "object",
"properties": {
"username": { "type": "string" },
"password": { "type": "string" },
"ip": { "type": "string" },
"port": { "type": "number" },
"engine": {
"type": "object",
"properties": { "version": { "type": "string" } },
"required": ["version"]
},
"game": {
"type": "object",
"properties": { "springName": { "type": "string" } },
"required": ["springName"]
},
"map": {
"type": "object",
"properties": { "springName": { "type": "string" } },
"required": ["springName"]
}
},
"required": ["username", "password", "ip", "port", "engine", "game", "map"]
}
5 changes: 4 additions & 1 deletion test/teiserver_web/tachyon/matchmaking_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ defmodule Teiserver.Tachyon.MatchmakingTest do

host_data = %{
ips: ["127.0.0.1"],
port: 48912
port: 48912,
engine: "recoil",
game: "BAR",
map: "Altored Divide"
}

Tachyon.send_response(autohost_client, start_req, data: host_data)
Expand Down

0 comments on commit 7553169

Please sign in to comment.