Thread Tools Display Modes
04-23-09, 08:34 PM   #1
Mud
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 8
Determining if a user is online?

What's the simplest way to determine if a player is online?

I'm using SendAddonMessage to send data to a named player. This chokes if that user is not online. Is there a simpler way to determine a whisper target is valid than sending a who request and iterating through the results?

Last edited by Mud : 04-23-09 at 08:39 PM.
  Reply With Quote
04-23-09, 08:45 PM   #2
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
In short, aside from targets which you can directly reference with a unit ID (such as raid1, etc), no, you can't really check for online status without some form of a server request.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
04-23-09, 09:16 PM   #3
Mud
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 8
Originally Posted by Shirik View Post
In short, aside from targets which you can directly reference with a unit ID (such as raid1, etc), no, you can't really check for online status without some form of a server request.
Alrighty then.

I'm calling SendAddonMessage multiple times (sending arbitrarily sized data in ~240-byte chunks), so if the target doesn't exist my addon user's chat window is spammed with:

No player named 'foobar' is currently playing.
No player named 'foobar' is currently playing.
No player named 'foobar' is currently playing.
...

I guess I could check for this message and abort my send attempt. Unless y'all can think of a more clever solution...
  Reply With Quote
04-23-09, 09:33 PM   #4
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
EDIT: Didn't read the post right, and ended up posting code to iterate through a /who (which is what I did in my AddOn).

Last edited by Exawatt : 04-23-09 at 09:37 PM.
  Reply With Quote
04-23-09, 09:38 PM   #5
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Mud, your solution can work, however you are going to run into an issue of hitting chat rate limits if you do it too quickly. If you're only doing this rarely, though, this should be OK.

If you want to get rid of that spam, look into ChatFrame_AddMessageFilter() or whatever it's called.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
04-23-09, 09:57 PM   #6
Mud
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 8
Originally Posted by Shirik View Post
Mud, your solution can work, however you are going to run into an issue of hitting chat rate limits if you do it too quickly. If you're only doing this rarely, though, this should be OK.
It's a notepad addon, so I'm just sending relatively small text blocks. I was prepared to use a timer to meter out the send, but blasting even the largest of my notes has not been a problem so far.

Originally Posted by Shirik View Post
If you want to get rid of that spam, look into ChatFrame_AddMessageFilter() or whatever it's called.
It's actually appropriate (given my addon) for the user to see that error once, but I'd like to abort the send at that point. Do you know what event I should be watching to catch that error message?
  Reply With Quote
04-23-09, 10:29 PM   #7
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
If I remember correctly, that message comes through via CHAT_MSG_SYSTEM
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
04-23-09, 11:13 PM   #8
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
Couldn't you use GetNetStats() to estimate how long it'll take maximum for the server to let you know the player isn't online?

Code:
_, _, latency = GetNetStats()
then wait about (latency) milliseconds for a server response?
  Reply With Quote
04-23-09, 11:15 PM   #9
Tuhljin
A Flamescale Wyrmkin
 
Tuhljin's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 106
My addon ZoneDefense uses a library I wrote called TjChanShare. I'm not suggesting using the library, since it sounds like it doesn't handle what you want to do exactly, but it does have a working example of detecting offline players that you're sending addon whispers to.

For starters, see the function detectOfflinePlayers_filter() in the file.

Last edited by Tuhljin : 04-23-09 at 11:21 PM.
  Reply With Quote
04-24-09, 02:07 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Exawatt View Post
Couldn't you use GetNetStats() to estimate how long it'll take maximum for the server to let you know the player isn't online?
Not really, since your actual latency can fluctuate wildly, and GetNetStats() will only return a new value every 5-10 seconds. This is why even if you have a huge lag spike, GetNetStats() and latency meters may not show it, or may show that you have a 12473ms ping time even after the spike passes.
  Reply With Quote
04-24-09, 08:34 PM   #11
tsadok
An Aku'mai Servant
 
tsadok's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 32
You could hook DEFAULT_CHAT_FRAME:AddMessage() and not send it on if it detects that message. It's annoying that that's the only response to SendAddonMessage() is in the chat frame- SendAddonMessage() is for hidden communication.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Determining if a user is online?

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