Skip to content

Commit

Permalink
Add game version guard to the regular lobby (#6406)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas authored Aug 13, 2024
1 parent beee3d5 commit 6208f25
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog/snippets/other.6406.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- (#6406) Automatically eject people from a lobby when there is a missmatch in the game version

Players often mention how it is annoying that games desync as a game release happens. This happens even more frequently on the FAF Develop and FAF Beta Balance game types. With this change we introduce a guard to prevent players from joining a lobby when their game version does not match the game version of the host. If there is a missmatch, the host is informed in the chat and is encouraged to re-create the lobby.
2 changes: 2 additions & 0 deletions loc/RU/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5341,6 +5341,8 @@ lobui_CAUDesc="У каждого игрока есть своя армия и с
lobui_CACommon="Единая армия, союзный контроль"
lobui_CACDesc="Каждая команда - это одна армия. Все юниты и ресурсы общие, все члены команды могут отдавать команды."

lobui_666="Замечено несовпадение версии игры с %s. \r\n - хост: %s (@%s)\r\n - %s: %s (@%s). \r\n\r\nДля предотвращения рассинхронизации, %s был исключен автоматически. Возможно была опубликована новая версия игры. Если это продолжает происходить, то следует создать новое лобби."

AutoLobbyHeaderText="Состояние соединения"
AutoLobbyConnectionsTextPlural="%s из %s подключено"

Expand Down
2 changes: 2 additions & 0 deletions loc/US/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4709,6 +4709,8 @@ lobui_CAUDesc="Each player has their own army and their own resources. Allied pl
lobui_CACommon="Single army, union control"
lobui_CACDesc="Each team is one army. All units and resources are shared, all team members can issue commands."

lobui_666="Game version missmatch detected with %s. \r\n - host: %s (@%s)\r\n - %s: %s (@%s). \r\n\r\nTo prevent desyncs, %s is ejected automatically. It is possible that a new game version is released. If this keeps happening then it is better to rehost."

AutoLobbyHeaderText="Connection status"
AutoLobbyConnectionsTextSingular="%s / %s players are connected"
AutoLobbyConnectionsTextPlural="%s / %s players are connected"
Expand Down
2 changes: 1 addition & 1 deletion lua/ui/game/score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ function SetupPlayerLines()
"\r\n\r\n" .. LOC("<LOC map_version>Map version") .. ": " .. tostring(sessionInfo.map_version) ..
"\r\n" .. LOC("<LOC replay_id>Replay ID") .. ": " .. tostring(UIUtil.GetReplayId()) ..
"\r\n" ..
"\r\n" .. "Game version: " .. version .. "\r\n" .. "Game type: " .. gametype .. "\r\n" .. "Commit: " .. commit
"\r\n" .. "Game version: " .. version .. "\r\n" .. "Game type: " .. gametype .. "\r\n" .. "Commit: " .. commit:sub(1, 8)

-- add ladder icon
mapData.Ranked = sessionInfo.Options.Ranked or false
Expand Down
3 changes: 3 additions & 0 deletions lua/ui/lobby/data/playerdata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
---@field StartSpot number
---@field Team number
---@field AILobbyProperties? AILobbyProperties
---@field Version VERSION # Related to game version
---@field GameType string # Related to game version
---@field Commit string # Related to game version


local WatchedValueTable = import("/lua/ui/lobby/data/watchedvalue/watchedvaluetable.lua").WatchedValueTable
Expand Down
24 changes: 20 additions & 4 deletions lua/ui/lobby/lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ end

--- Get a PlayerData object for the local player, configured using data from their profile.
function GetLocalPlayerData()

local version, gametype, commit = import("/lua/version.lua").GetVersionData()

return PlayerData(
{
PlayerName = localPlayerName,
Expand All @@ -452,6 +455,11 @@ function GetLocalPlayerData()
MEAN = argv.playerMean,
DEV = argv.playerDeviation,
Country = argv.PrefLanguage,

Version = version,
GameType = gametype,
Commit = commit,

}
)
end
Expand Down Expand Up @@ -3152,7 +3160,7 @@ function CreateUI(maxPlayers)
GUI.gameVersionText:SetDropShadow(true)

Tooltip.AddControlTooltipManual(GUI.gameVersionText, 'Version control', string.format(
'Game version: %s\nGame type: %s\nCommit hash: %s', version, gametype, commit
'Game version: %s\nGame type: %s\nCommit hash: %s', version, gametype, commit:sub(1, 8)
))

LayoutHelpers.AtLeftTopIn(GUI.gameVersionText, GUI.panel, 70, 3)
Expand Down Expand Up @@ -5263,7 +5271,6 @@ local MessageHandlers = {
end
end


if not data.PlayerOptions.OwnerID then
return false
end
Expand All @@ -5275,11 +5282,20 @@ local MessageHandlers = {
if FindNameForID(data.SenderID) then
return false
end


-- check game version and reject if there is a missmatch
local hostVersion, hostGametype, hostCommit = import("/lua/version.lua").GetVersionData()
local playerVersion, playerGameType, playerCommit = tostring(data.PlayerOptions.Version), tostring(data.PlayerOptions.GameType), tostring(data.PlayerOptions.Commit)
if hostVersion ~= playerVersion or hostGametype ~= playerGameType or hostCommit ~= playerCommit then
local playerName = data.PlayerOptions.PlayerName
AddChatText(LOCF("<LOC lobui_666>Game version missmatch detected with %s. \r\n - host: %s (@%s)\r\n - %s: %s (@%s). \r\n\r\nTo prevent desyncs, %s is ejected automatically. It is possible that a new game version is released. If this keeps happening then it is better to rehost.", playerName, hostVersion, hostCommit:sub(1, 8), playerName, playerVersion, playerCommit:sub(1, 8), playerName))
return false
end

return lobbyComm:IsHost()
end,
Reject = function(data)
lobbyComm:EjectPeer(data.SenderID, "Invalid player data.")
lobbyComm:EjectPeer(data.SenderID, "Game version missmatch or invalid player data.")
end,
Handle = function(data)
-- try to reassign the same slot as in the last game if it's a rehosted game, otherwise give it an empty
Expand Down

0 comments on commit 6208f25

Please sign in to comment.