Efficient character exists check

100 Human Paladin
11995
I'm working with PHP and I want to be able to efficiently check if a character exists within Battle.net's armory. (Meaning, the armory data is available, isn't level sub-10, etc.)

Currently, this is how my quick-n-dirty check works:

$url = 'http://'.$region.'.battle.net/api/wow/character/'.$realm.'/'.$member['name'].'?fields= ';
$json = file_get_contents($url);
if ($json !== FALSE){
$decoded = json_decode($json);
if ($decoded !== FALSE || $decoded !== NULL){
/* Add player to Database */
return TRUE;
}


Is there a better way? I really hate pulling all that data needlessly.
Reply Quote
MVP
90 Tauren Druid
10125
It appears the API doesn't do well with HEAD requests, so this is probably as good as you can do. Luckily, the data payload with no extra fields is fairly small; you can squeeze a few more bytes out if you use gzip (my character profile goes from 220 bytes to 192 bytes, and a 404 goes from 70 bytes to 50 bytes). Of course, the requests do go toward your limit.
________________________________________________
MVP, Web and API
WoW Libraries for the Community Platform API: http://us.battle.net/wow/en/forum/topic/2369882588
D3 Libraries for the Community Platform API: http://us.battle.net/d3/en/forum/topic/6307731317
Reply Quote
100 Human Paladin
11995
Thanks for the reply Cyaga, I did some more research in the php platform, and found this little gem: get_headers($url) and wrote a function to share.


/**
* Checks Blizzard's Battle.net API server is a character exists in the specified region and realm.
* @param string $region US,EU, etc. Anything that uses the battle.net TLD.
* @param string $realm Name of the realm/server the character exists on.
* @param string $character Name of the player character.
* @return boolean Returns true if the player was found (HTTP 200) and false on any other HTTP code.
*/
function characterExists($region, $realm, $character){
if (empty($region) || empty($realm) || empty($character)){
return FALSE;
}
else {
$url = 'http://'.$region.'.battle.net/api/wow/character/'.$realm.'/'.$character;
$headers = get_headers($url);
$status = $headers[0];
$tok = strtok($status, ' '); // Grabbing that status code.
$tok = strtok($tok);
$status = strtok($tok, ' ');
if ($status == 200){
return TRUE;
}
else {
return FALSE;
}
}
}
Reply Quote
Battle.net Developer
The possibility that we could do (no promises on timeline) is get a new character resource api that basically returns the same data you get as part of the guild?fields=members api. It's heavily cached character data that just gives spec / class / level info etc. It would be cheaper than the full profile API on your limits and might provide slightly out of date info but might be better for many uses.

Of course for guild websites that only need this data fields=members is the cheapest way to get it already.
Reply Quote
100 Human Paladin
11995
The possibility that we could do (no promises on timeline) is get a new character resource api that basically returns the same data you get as part of the guild?fields=members api. It's heavily cached character data that just gives spec / class / level info etc. It would be cheaper than the full profile API on your limits and might provide slightly out of date info but might be better for many uses.

Of course for guild websites that only need this data fields=members is the cheapest way to get it already.


That would be interesting, but I'm writing an application that is guild agnostic. Is there was a resource that could be called like player?fields=exists and returns some indication that the character exists before other fields get calls. Maybe it returns only character's name, or some other arbitrary data, just so long as it'd be differentiable from a DNE.
Reply Quote
Battle.net Developer
The possibility that we could do (no promises on timeline) is get a new character resource api that basically returns the same data you get as part of the guild?fields=members api. It's heavily cached character data that just gives spec / class / level info etc. It would be cheaper than the full profile API on your limits and might provide slightly out of date info but might be better for many uses.

Of course for guild websites that only need this data fields=members is the cheapest way to get it already.


That would be interesting, but I'm writing an application that is guild agnostic. Is there was a resource that could be called like player?fields=exists and returns some indication that the character exists before other fields get calls. Maybe it returns only character's name, or some other arbitrary data, just so long as it'd be differentiable from a DNE.


Sorry for any confusion, that's exactly what I meant. The new resource wouldn't be in the context of a guild, it would be the same DATA as you get as part of fields=members.

That being said, the api isn't supposed to be used to check this. Checking if a character you know about exists is ok, randomly checking names to find what characters exist is not. We do keep an eye out for apps that scan for profiles (on wow and d3).
Reply Quote
100 Human Paladin
11995
11/28/2012 02:24 PMPosted by Peratryn
That being said, the api isn't supposed to be used to check this. Checking if a character you know about exists is ok, randomly checking names to find what characters exist is not. We do keep an eye out for apps that scan for profiles (on wow and d3).


Oh, no no! It's a raid roster. The name checks are designed to keep data entries clean, and doesn't log which names are taken and which are available. Being that many Raid Leader's rosters can be very large, I'm very interested in scripts that make data requests measured in bytes or kilobytes. By my tests, the function I posted runs on around 900 bytes.

That resource sounds great. If it's efficient for the both of us, I won't complain. :)
Reply Quote
2 Gnome Warlock
0
How about a search facility (across realms/regions?)

It could be used for this and for other uses. I am looking to add a search facility to my Wow Activity site, so that people can find their guilds/characters and will have to do something like this too.

For example a json/api version of this page: http://us.battle.net/wow/en/community/

Thanks,
Chris

http://wafbeta.kimptoc.net/
Reply Quote
100 Human Paladin
11995
11/29/2012 12:54 PMPosted by Kimptoc
How about a search facility (across realms/regions?)


This is something I'm asked to feature on my web app a lot too. In short it's a bad idea, but here's the whole story:

You can definitely do that with either of the functions I presented here. The first one (that uses json) can be expensive against your query count -- especially when used against all the realms at once. The http header one, probably not so much, however I noticed it likes to hand up a little on names that don't exist.

As far as data control is concerned, it's a bad idea. Searching per region and realm is a better idea. In both our cases, (having looked at your app) the user should have a good idea of what they're looking for and be prepared to know the answer to "Are you US, EU, etc.", "What server are you on", and "Whats your toon's name?" Really, it's not asking much of your users. Even big players like wowhead make sure you know what you're looking for.

Furthermore, it's unrealistic for a 3rd party app to copy Blizzard's search functions because they have an efficient path to their data: it's (semi) local. The only way to replicate it would be to brute-force cache it -- and that's bandwidth and processing expensive for both Blizzard and you.
Reply Quote
2 Gnome Warlock
0
Thanks for the tips - will get them to specify region/realm :)
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)

Reported!

[Close]