Opened 9 years ago

Closed 9 years ago

Last modified 5 years ago

#3281 closed defect (fixed)

[PATCH] Lobby - Some playernames not highlighted in the chat

Reported by: elexis Owned by: Stan
Priority: Should Have Milestone: Alpha 19
Component: Multiplayer lobby Keywords: patch
Cc: Patch:

Description (last modified by elexis)

If someone types your name in the chat, that occurance will be replaced with a colored version of your name.

However this doesn't work for some people like ffm.

The code that deals with this function is in lobby.js:

function addChatMessage(msg)
...
// Highlight local user's nick
if (msg.text.indexOf(g_Name) != -1 && g_Name != msg.from)
	msg.text = msg.text.replace(new RegExp('\\b' + '\\' + g_Name + '\\b', "g"), colorPlayerName(g_Name));

Here a doc about the RegExp that fails: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

As far as I can tell the '\\' shouldn't be added, since the regex looks for form feed characters, if the name starts with f then.

Attachments (4)

t3281_fix_highlighted_playername_regex.patch (756 bytes ) - added by elexis 9 years ago.
t3281_highlighted_playername_almost_without_regex.patch (1.9 KB ) - added by elexis 9 years ago.
Replaces the RegExp with a function with less side effects. Still uses a RegExp to check if a single character is alphanumerical.
t3281_highlighted_playername_almost_without_regex_v1.1.patch (1.9 KB ) - added by elexis 9 years ago.
Cleaned line 875.
3281.diff (665 bytes ) - added by Stan 9 years ago.
Working version that just replace the name ​http://imgur.com/FvE7rTm Proof.

Download all attachments as: .zip

Change History (12)

comment:1 by elexis, 9 years ago

Description: modified (diff)
Summary: [PATCH] Lobby - Some playernames not colored in the chat[PATCH] Lobby - Some playernames not highlighted in the chat

by elexis, 9 years ago

Replaces the RegExp with a function with less side effects. Still uses a RegExp to check if a single character is alphanumerical.

by elexis, 9 years ago

Cleaned line 875.

comment:2 by leper, 9 years ago

Why not just skip the work needed to decide if the nick is not in a word (which might or might not give strange results with some non-latin chars at some point), and just highlight it stupidly? Does not really fix the issue of possibly splitting some chars, but that would be the fault of indexOf returning that as a match.

Which would result in being able to use a simple replace. Short nicks that are common in some words are not really that common.

comment:3 by Stan, 9 years ago

Owner: set to Stan

by Stan, 9 years ago

Attachment: 3281.diff added

Working version that just replace the name ​http://imgur.com/FvE7rTm Proof.

comment:4 by Stan, 9 years ago

Keywords: review patch added

comment:5 by Itms, 9 years ago

Resolution: fixed
Status: newclosed

In 17041:

Highlight all player names in the lobby chat. Patch by stanislas69, fixes #3281.

comment:6 by Itms, 9 years ago

Keywords: review removed

Thanks for the patch! :D

comment:7 by elexis, 7 years ago

Told you so #4343

in reply to:  2 comment:8 by elexis, 5 years ago

Description: modified (diff)

Replying to leper:

Why not just skip the work needed to decide if the nick is not in a word (which might or might not give strange results with some non-latin chars at some point), and just highlight it stupidly? Does not really fix the issue of possibly splitting some chars, but that would be the fault of indexOf returning that as a match.

Which would result in being able to use a simple replace. Short nicks that are common in some words are not really that common.

There's a difference between changing code style because one finds it nicer one way over the other, and deciding a function to knowingly return wrong values that was already written to account for that case.

This issue is reported by players multiple times per year, and those that are affected are pinged very often (acoustically as r18545).

(09:01:09 PM) T: I receive a notification in the chat if it says "t" in a sentence.. Triumvir, elexis

2017-09/2017-09-24-QuakeNet-#0ad-dev.log:13:05 < bb1> so lobby rubbish bbl etc pings me 2017-12/2017-12-14-QuakeNet-#0ad-dev.log:13:00 < bb1> y so I don't get pingen on "lobby"

(It's not only people with 1-3 letters in the nick. Players with 4 letters in the nick and some vowels aren't so rarely affected either that one could neglect that. We also have multiple hannibals online sometimes.)

Which doesn't mean that attachment:t3281_highlighted_playername_almost_without_regex_v1.1.patch

was the cleanest or correct code either.

Note: See TracTickets for help on using tickets.