Thread Tools Display Modes
11-10-14, 05:16 AM   #1
blackytemp
A Murloc Raider
Join Date: Feb 2012
Posts: 4
Weird result from string operations on BNet friends

Hello,

I was trying to make a quick addon but stumbled upon this which I can just assume is me doing something really wrong. The plan was to filter BNet friend requests by name etc. I have a function

Code:
	function self:GetFriendInviteName(i)
		local _, r = BNGetFriendInviteInfo(i)
		return r
	end
(this could be done inline but I made it into a separate function in an effort to debug this issue). I now have the Friend invite name and want to match it (looking for the spammy GM0000 type requests). I considered my expression of (GM)([0-9])+ to be at least somewhat correct and wondered why it wasn't matching so I dug a little deeper and these are the results of a macro I used to check:

Macro:

Code:
/run local w = nx_Talents:GetFriendInviteName(1); print(w); print(string.find(w,".......")); print(string.match(w,"......."));
Result:

Code:
|Kb5|kGM6767|k
1 7
|Kb5|k0
Ingame the first result shows as just GM6767 , I assume the rest is coloring? I used a catchall on the macro because previous investigations showed weird results and I wanted to see what's really happening. I have no Idea how to go about matching it correctly and why it doesn't give me the actual name as a string. Thanks in advance for your help.
  Reply With Quote
11-10-14, 05:39 AM   #2
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Most Battle.net functions return |K escape sequences instead of actual real names. These are translated to real names by the client outside of the UI, so AddOns and scripts can't see anything more than the escape sequence.

Presumably the b character represents a BattleTag name instead of a given name, surname or full name.
  Reply With Quote
11-10-14, 06:45 AM   #3
blackytemp
A Murloc Raider
Join Date: Feb 2012
Posts: 4
Thank you! That explains the weird output. However, I am still having serious issues with the string matching. Even running

Code:
/run local _,w = BNGetFriendInviteInfo(1); print(w); print(string.match(w,"GM"));
Results in:

Code:
|Kb5|kGM6767|k
nil
Even though the output of the variable shows that GM is clearly even in the escaped string. Again using the dots as a catchall (one short of the total string length so I can actually see it in ingame chat) reveals it is somehow using 0's instead when under the string operation (tested with both match and find):

Code:
/run local _,w = BNGetFriendInviteInfo(1); print(w); print(string.match(w,"............."));
Results in:

Code:
|Kb5|kGM6767|k
|Kb5|k000000|
However, if I extend the . wildcards by one for the full length, it suddenly gives back the correct escaped string again. I'm having serious troubles wrapping my head around this, I assume I'm misunderstanding something about the string operations maybe?
  Reply With Quote
11-10-14, 11:01 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The "|k000000|k" sequence is replaced with the real text internally. You can print it or SetText with it and get the expected text shown on the screen, but you can't actually see it in Lua code or manipulate with the Lua string functions. This is intentional, and there is no way around it. Addon code cannot tell what the contents of the "|k" sequence are, period.

It's also worth noting that you can trim the sequence by removing some of the 0 characters (so if "|k00000|k" is "Phanx" then "|k00|k" is just "Ph") but extra 0s are just ignored ("|k00000000000000|k" is still just "Phanx").
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Weird result from string operations on BNet friends


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off