Skip to content

Commit

Permalink
Send a LuaUI message to Spads about desyncs so we can get more accura…
Browse files Browse the repository at this point in the history
…te information (#3862)
  • Loading branch information
Beherith authored Oct 20, 2024
1 parent c51a0ee commit 83d62f8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions luaui/Widgets/api_unit_tracker_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,49 @@ function widget:Initialize()
widgetHandler:RegisterGlobal('GadgetCrashingAircraft1', GadgetCrashingAircraft)
end


local iHaveDesynced = false
-- Example console line:
-- [t=00:01:41.862230][f=0011049] Sync error for UnnamedPlayer in frame 11044 (got 5537e3ca, correct is cc130165)
local syncerrorpattern = " Sync error for ([%w%[%]_]+) in frame (%d+) %(got (%x+), correct is (%x+)%)"

function widget:AddConsoleLine(lines, priority)
--Spring.Echo(lines)
if iHaveDesynced then return end
local username, frameNumber, gotChecksum, correctChecksum = lines:match(syncerrorpattern)
if username and frameNumber and gotChecksum and correctChecksum then
local myPlayerName = Spring.GetPlayerInfo(Spring.GetMyPlayerID())
if myPlayerName == username then
-- Yes, we have desynced, time to send a LuaUIMsg to notify the server
-- desyncee, gameID, frame, gameversion, engine version, map, chobby version?
local jsondict = {
eventtype = "syncerror",
username = username, -- desyncee
lobbyName = tostring(Spring.GetMenuName and Spring.GetMenuName()), -- this returns rapid://byar-chobby:test, which is completely useless
gameVersion = tostring(Game.gameVersion), -- this better not be the rapid tag
engineVersion = tostring(Engine.versionFull), -- full complete engine version string
mapName = tostring(Game.mapName), -- full map name
gameID = tostring(Game.gameID and Game.gameID or Spring.GetGameRulesParam("GameID")), -- gameID parameter, not the same as server_match_id, we will match that in teiserver
frame = frameNumber, -- the frame where it happened.
gotChecksum = gotChecksum,
correctChecksum = correctChecksum,
}
--Spring.Echo(jsondict)

local complex_match_event = string.format("complex-match-event:%s", string.base64Encode(Json.encode(jsondict)))

-- We will be forwarding this as a complex event:
-- sayPrivate complex-match-event <Beherith> <desyncreport> <67> <eyJrZXkiOiJ2YWx1ZSJ9>
-- !sendLobby SAYPRIVATE AutohostMonitor 'complex-match-event <[teh]Beherith> <desyncreport> <67> <eyJrZXkiOiJ2YWx1ZSJ9>'
Spring.SendLuaUIMsg(complex_match_event)

-- then remove ourselves, no point to keep running after the first desync is detected
iHaveDesynced = true
end
end
end


function widget:Shutdown()
-- ok this is quite sensitive, in order to prevent taking down the rest of the world with it
-- we need to clear the visible units, and call the respective callins
Expand Down

0 comments on commit 83d62f8

Please sign in to comment.