Thread Tools Display Modes
03-05-14, 10:40 AM   #1
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Player and server name from received whisper

Hello,

Sender's name from event CHAT_MSG_WHISPER now looks like "John-KirinTor" (without any space) if a whisp is received from John from Kirin Tor server (with a space) and even if you also play on Kirin Tor server.
So, as we cann't perform a test on the server name because in this case the builtin function GetRealmName() will return "Kirin Tor", how could I do to know if John is on the same server as me ?

If John is on the same server as me, and only in this case, I would like to split the server name, the easy part.

Thanks.
  Reply With Quote
03-05-14, 11:11 AM   #2
GnomTEC
A Defias Bandit
 
GnomTEC's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3
I remove the Space from the name i got from GetRealmName(), this seems to be the same what Blizzard does.
Ofcourse nobody can say what funny ideas they have next, perhaps changing case unpredictable.

At the moment i use following in my code (which you have then to concatenate with the player's name):

Lua Code:
  1. string.gsub(GetRealmName(), "%s+", "")

PS: to get player and realm from sender i use following:

Lua Code:
  1. player, realm = strsplit( "-", sender, 2 )
__________________
GnomTEC - Gnomische Technologie für ein freies Gnomeregan
(GnomTEC - Gnomish technology for a free Gnomeregan)

Last edited by GnomTEC : 03-05-14 at 11:14 AM.
  Reply With Quote
03-05-14, 11:13 AM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
For any unit with a valid unitID UnitRealmRelationship(unitID) will return a constant among LE_REALM_RELATION_SAME|LE_REALM_RELATION_COALESCED|LE_REALM_RELATION_VIRTUAL

For chat you might be able to use name, realm = UnitFullName("player") and compare the realm return (I'm not sure if the realm return here is normalized and can be used for a direct comparison, no access to wow to test atm)

You can also try passing the full name through Ambiguate("name","none") it should strip off the realm if it's same realm as you so you have an indirect way to test.

Edit:Saw GnomeTEC's response, that should work for most cases but it also needs to strip out apostrophes and I'm not sure for the realms with special characters in their name (some French, Italian and Portuguese/Brazilian)
The armory at least does Unicode normalization converting the accented chars to their base equivalent.

Last edited by Dridzt : 03-05-14 at 11:20 AM.
  Reply With Quote
03-06-14, 08:33 AM   #4
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Thanks for your replies

Is it interesting to know that the "shortened" server name can be found with

Code:
local player, serverShortName = UnitFullName("player")
  Reply With Quote
03-06-14, 09:19 AM   #5
GnomTEC
A Defias Bandit
 
GnomTEC's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3
Ah, i didn't know this thing with UnitFullName("player").

But if this "shortens" the realm name corectly it's surely the better solution to get the own realm name. I will also have a look at this and propably change my own code.
__________________
GnomTEC - Gnomische Technologie für ein freies Gnomeregan
(GnomTEC - Gnomish technology for a free Gnomeregan)
  Reply With Quote
03-06-14, 04:48 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Dridzt View Post
... it also needs to strip out apostrophes and I'm not sure for the realms with special characters in their name (some French, Italian and Portuguese/Brazilian)
This is incorrect. At least on EU realms, apostrophes are included in the realm names as passed with CHAT_MSG_* events and returned by UnitFullName.

I couldn't find anyone with a non-ASCII character, and didn't feel like going and making a character on a FR/IT/PT realm to check, but I suspect they are also used as-is in-game.
__________________
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
03-06-14, 05:14 PM   #7
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Originally Posted by Phanx View Post
This is incorrect. At least on EU realms, apostrophes are included in the realm names as passed with CHAT_MSG_* events and returned by UnitFullName.

I couldn't find anyone with a non-ASCII character, and didn't feel like going and making a character on a FR/IT/PT realm to check, but I suspect they are also used as-is in-game.
I specifically noted the apostrophe part and unicode normalization as an aside relevant to the armory, not in-game.
You can safely ignore my edit and use the first part of the post that's relevant to the question and apparently provides a suitable method.

Edit: I also (with regard to armory) wasn't referring to the player name but the realm name.
As an example this is what happens to the url for "Pozzo dell'Eternità" (an Italian realm)

Last edited by Dridzt : 03-06-14 at 05:19 PM.
  Reply With Quote
03-07-14, 09:15 AM   #8
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
I don't know why but UnitFullName("player") sometimes returns NIL if called just after the VARIABLES_LOADED event, so I finally use GnomeTEC function :

Code:
shortenedSeverName = string.gsub(GetRealmName(), "%s+", "")

Originally Posted by Phanx View Post
I couldn't find anyone with a non-ASCII character, and didn't feel like going and making a character on a FR/IT/PT realm to check, but I suspect they are also used as-is in-game.
Realm "Confrérie du Thorium" is shortened in "ConfrérieduThorium" (which means Thorium brotherhood )
  Reply With Quote
03-07-14, 09:52 AM   #9
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Originally Posted by Zax View Post
I don't know why but UnitFullName("player") sometimes returns NIL if called just after the VARIABLES_LOADED event, <snip>
Realm "Confrérie du Thorium" is shortened in "ConfrérieduThorium" (which means Thorium brotherhood )
That's because VARIABLES_LOADED is a bad event to use for addon initialization and has been bad since WoW 3.1 or something like that

You either want ADDON_LOADED with arg1 == 'YourAddonName' which guarantees saved variables initialization but not much else or even better PLAYER_LOGIN which ensures player information (including name / realm) are available.

Last edited by Dridzt : 03-07-14 at 06:50 PM.
  Reply With Quote
03-07-14, 11:05 AM   #10
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Originally Posted by Dridzt View Post
That's because VARIABLES_LOADED is a bad event to use for addon initialization and has been bad since WoW 3.1 or something like that

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Player and server name from received whisper

Thread Tools
Display Modes

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