Fix: prevent desync after clan team assignment for profane username (#2511)

## Description:

Clan tag was removed when overwriting profane username. The local player
still sees the name they put in though, and are assigned to a team based
on the clan tag. Other player's browsers don't assign them to their team
because the clan tag isn't visible to them.

**Fixes:**
- GameRunner.ts > username.ts: fetch clan tag before potentially
overwriting bad username. Prepend non-profane clan tag back to the name
string afterwards.

- Util.ts: added getClanTagOriginalCase; we can't use getClanTag in
censorNameWithClanTag because it returns all caps and we needed to
retain the orginal capitalization. Explained in code comment.

- Game.ts: no changes. By keeping the getClanTag in PlayerInfo
contructor, TeamAssignment still gets clan param to correctly assign
clan teams, other players get to see the clan tag of the "BeNicer"
player, and GameServer archivegame() and LocalServer endGame() can still
do getClanTag to have the same data at the end of the game, and test
files keep working.

**Screencap after fix:**

https://github.com/user-attachments/assets/564c0ffd-577e-4653-ba33-155d2135a9f0

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

tryout33
This commit is contained in:
VariableVince
2025-11-25 20:08:30 -08:00
committed by GitHub
parent 1255f197a9
commit 7d8c1c2822
3 changed files with 72 additions and 15 deletions
+11 -2
View File
@@ -339,9 +339,18 @@ export function sigmoid(
// Compute clan from name
export function getClanTag(name: string): string | null {
const clanTag = clanMatch(name);
return clanTag ? clanTag[1].toUpperCase() : null;
}
export function getClanTagOriginalCase(name: string): string | null {
const clanTag = clanMatch(name);
return clanTag ? clanTag[1] : null;
}
function clanMatch(name: string): RegExpMatchArray | null {
if (!name.includes("[") || !name.includes("]")) {
return null;
}
const clanMatch = name.match(/\[([a-zA-Z0-9]{2,5})\]/);
return clanMatch ? clanMatch[1].toUpperCase() : null;
return name.match(/\[([a-zA-Z0-9]{2,5})\]/);
}