Keep an EUD's team colour current for the whole connection - #349
Open
texaskst wants to merge 1 commit into
Open
Conversation
eud.team_id is only ever written by EudHandler.parse_device_info, which is called behind `if event and not self.uid` - so it runs once, on the first CoT of a TCP connection. If an operator changes their team colour while connected, the database keeps the old colour until they reconnect, however many SA updates arrive in between. The web UI map reads team_color from that row, so it shows the stale colour and refreshing the browser doesn't help, since the staleness is in the database rather than the page. I ran into this using team colour to carry live state during airsoft games (marking a player out of the game), where the map is what everyone watches. Peers were never affected - EudHandler relays the original CoT verbatim, so other ATAK/iTAK clients parse __group themselves and always saw the real colour. It's only the server's own view that goes stale. cot_parser already sees every position update and owns both the EUD rows and the socketio emits, so the refresh goes there. It compares against a per-uid cache and only touches the database when the colour actually changed, so the common case is one dict lookup per position update. On a change it also emits the 'eud' event, which is what makes an already open map recolour without a reload. Team creation mirrors what parse_device_info does, including the IntegrityError fallback for when another cot_parser process creates the same team first. The cache is only written after a successful update, so a failure retries on the next position update instead of being swallowed until the EUD reconnects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
eud.team_idis only written inEudHandler.parse_device_info, whichhandle_cotcalls behind:So it runs once, on the first CoT of a TCP connection. If an operator changes their team colour while connected, the database keeps the old value until they reconnect, however many SA updates arrive in between.
The web UI map reads
team_coloroff that row, so the marker keeps the old colour, and refreshing the browser doesn't help — the stale value is in the database, not the page.How I ran into it
I use team colour to carry live state during airsoft games: a player who's out switches to a reserved colour so everyone can see they're out. The web map is what the game master watches, and it kept showing the pre-change colour for the rest of the session.
Measured on 1.7.11 — the device was broadcasting
<__group name="Cyan" role="Team Member"/>whileeuds.team_idstill pointed at the colour it had when it connected, the last connect being 9 seconds before the change.Other clients were never affected.
EudHandler.on_messagerelays the original CoT verbatim, so ATAK/iTAK parse__groupthemselves and always saw the right colour. It's only the server's own view that goes stale.Fix
cot_parseralready sees every position update and owns both the EUD rows and the socketio emits, so the refresh goes there.eudevent on change, which is what makes an already open map recolour without a reload.parse_device_info, including theIntegrityErrorfallback for when anothercot_parserprocess creates the same team first.Testing
Running this on my own server against ATAK-CIV 5.7.0.10.
euds.team_idfollows within one position update (measured about a second), and an already open map recolours without a reload. Before the change the same test left the row stale indefinitely.Note
Callsign, ATAK version and
team_roleare set in the same connect-only block and go stale the same way. I left those alone to keep this focused, but happy to extend it if you'd like the same treatment.