diff --git a/luaui/Widgets/api_unit_tracker_gl4.lua b/luaui/Widgets/api_unit_tracker_gl4.lua index 0459ac2236d..185f5872868 100644 --- a/luaui/Widgets/api_unit_tracker_gl4.lua +++ b/luaui/Widgets/api_unit_tracker_gl4.lua @@ -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 <67> + -- !sendLobby SAYPRIVATE AutohostMonitor 'complex-match-event <[teh]Beherith> <67> ' + 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