PDA

View Full Version : World of Warcraft Roster Generator



freyyr
08-19-2007, 05:45 PM
I wrote this for my guild because I didn't relish the prospect of manually typing out a 180 row table and updating it every time somebody dinged.

See it in action (http://armyofdestiny.freehostia.com/roster.php).

roster.php (my form on this is terrible, I was too lazy to bother with any error reporting or even success checks):

<?php
/* Dynamic roster creator by <redacted>.
Thanks to <redacted> for writing the WoW
signature generator from which the author
borrowed and modifed the XML aquiry code.
For this reason, the project is licensed
under the BSD License. */


// Use CURL to aquire XML file.
$pageurl = "http://armory.worldofwarcraft.com/guild-info.xml?r=Boulderfist&n=Army+Of+Destiny"; //Edit this line to match your guild
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_URL, $pageurl);
$remote = curl_exec($ch) or die('Error: Unable to access the the XML datafiles. Please contact the webmaster.');
curl_close($ch);

$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

xml_parse_into_struct($parser, $remote, &$data_array, &$index_array);

$numberArrayValues = count($index_array['character']);

echo '<br /><strong>Current Number of Members: </strong>'.$numberArrayValues.'<br /><br /></p></div>';

echo '<table border="1" id="table"><tr><td><strong>Name</strong></td><td><strong>Class</strong></td><td><strong>Race</strong></td><td><strong>Level</strong></td><td><strong>Rank</strong></td></tr>';

$ranksArray[0] = 'Guild Leader';
$ranksArray[1] = 'Assistant';
$ranksArray[2] = 'Masters Council';
$ranksArray[3] = 'Class Officer';
$ranksArray[4] = 'Captain';
$ranksArray[5] = 'Sergeant';
$ranksArray[6] = 'Private';
$ranksArray[7] = 'Officer Alt';
$ranksArray[8] = '<font color="red" /><b>Little Bitch</b></font>';

$timesLooped = 0;

while ($timesLooped<$numberArrayValues) {
echo '<tr><td width="30%"><a href="http://armyofdestiny.freehostia.com/charstats.php?name='.$data_array[$index_array['character'][$timesLooped]]['attributes']['name'].'">'.$data_array[$index_array['character'][$timesLooped]]['attributes']['name']."</a></td>";
echo '<td width="20%">'.$data_array[$index_array['character'][$timesLooped]]['attributes']['class']."</td>";
echo '<td width="20%">'.$data_array[$index_array['character'][$timesLooped]]['attributes']['race']."</td>";
echo '<td width="10%">'.$data_array[$index_array['character'][$timesLooped]]['attributes']['level']."</td>";
echo '<td width="20%">'.$ranksArray[$data_array[$index_array['character'][$timesLooped]]['attributes']['rank']]."</td></tr>";
$timesLooped++;
}

echo "</table>"

?>

charstats.php (better form here, with configuration options, error handling, and function use rather than linear coding):

<?php
/* Dynamic character stat viewer by <redacted>.
Thanks to <redacted> for writing the WoW
signature generator from which the author
borrowed and modifed the XML aquiry code.
For this reason, the project is licensed
under the BSD License. */

// Set your realm and contact email here.
$realm = '<redacted>';
$contact = '<redacted>@gmail.com';

// Get name
$name = $_GET['name'];

// Use CURL to aquire XML file.
function aquire_xml_character($r,$n){
$pageurl = "http://armory.worldofwarcraft.com/character-sheet.xml?r=".$r."&n=".$n;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_URL, $pageurl);
$remote = curl_exec($ch) or die('Error: Unable to access the the XML datafiles. Please contact the webmaster.');
curl_close($ch);
return $remote;
}

if ($name == '') {
echo '<strong>No Input Specified!</strong>';
}
else {

$characterxml = aquire_xml_character($realm,$name);

$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser, $characterxml, &$data_array, &$index_array);

if ($data_array[$index_array['character'][0]]['attributes']['name'] == '' or $data_array[$index_array['character'][0]]['attributes']['name'] == NULL) {
echo '<strong>Array Read Error</strong><br />';
echo 'We recieved an XML file from the server and successfully parsed it, but the name field was null. ';
echo 'This usually means that the character does not exist. If you have just created the character, please try again later.<br />';
echo 'This script is currently configured for the '.$realm.' realm. If this is incorrect and you are the webmaster, please set your ';
echo '$realm variable to the correct value.<br />';
echo 'If you are a user and are seeing this message after following a valid link, please notify the webmaster at ';
echo '<a href="mailto:'.$contact.'">'.$contact.'</a>.<br /><br /><br />';
}
elseif ($data_array[$index_array['strength'][0]]['attributes']['effective'] == NULL) {
echo '<strong>No Data Avaliable</strong><br />';
echo 'We got a response from the server, parsed it, and verified the character existed, but no stats beyond that were avaliable. ';
echo "This usually means that the Blizzard armory hasn't updated your character yet. If this is a newly created character, this is ";
echo "normal and no cause for concern. Please check back within a day or so. If you believe this to be another issue, please contact the webmaster at ";
echo '<a href="mailto:'.$contact.'">'.$contact.'</a>.<br /><br /><br />';
}
else {
echo '<font size="+3"><strong>'.$data_array[$index_array['character'][0]]['attributes']['name'].'</strong></font><br />';
echo '<font size="+2"><i>Level '.$data_array[$index_array['character'][0]]['attributes']['level'].' '.$data_array[$index_array['character'][0]]['attributes']['race'].' '.$data_array[$index_array['character'][0]]['attributes']['class'].'</i></font><br /><br />';
echo '<strong>Total Horde Pwn3d:</strong> '.$data_array[$index_array['pvp'][0]+1]['attributes']['value'].'<br /><br />';


echo '<font size="+1"><strong>Professions</strong></font><br />';

$timesLooped = $index_array['professions'][0]+1;
$timesToLoop = $index_array['professions'][1];

if($data_array[$timesLooped-1]['type']=='complete') {
echo '<strong>This character has not learned any professions.</strong><br /><br />';
}
else {
//Generate Professions Table
echo '<table border="1"><tr><td><strong>Profession</strong></td><td><strong>Level</strong></td></tr>';

while($timesLooped<$timesToLoop) {
echo '<tr><td>'.$data_array[$timesLooped]['attributes']['name'].'</td>';
echo '<td>'.$data_array[$timesLooped]['attributes']['value'].'/'.$data_array[$timesLooped]['attributes']['max'].'</td></tr>';
$timesLooped++;
}
echo '</table><br />';

}

echo '<font size="+1"><strong>Combat - General Attributes & Stats, Including Bonuses</strong></font><br />';
echo '<table border="1"><tr><td><strong>Attribute/Stat</strong></td><td><strong>Value</strong></td></tr>';
echo '<tr><td>Strength</td><td>'.$data_array[$index_array['strength'][0]]['attributes']['effective'].'</td>';
echo '<tr><td>Agility</td><td>'.$data_array[$index_array['agility'][0]]['attributes']['effective'].'</td>';
echo '<tr><td>Stamina</td><td>'.$data_array[$index_array['stamina'][0]]['attributes']['effective'].'</td>';
echo '<tr><td>Intellect</td><td>'.$data_array[$index_array['intellect'][0]]['attributes']['effective'].'</td>';
echo '<tr><td>Spirit</td><td>'.$data_array[$index_array['spirit'][0]]['attributes']['effective'].'</td>';
echo '<tr><td>Damage Per Second [Main Hand]</td><td>'.$data_array[$index_array['mainHandDamage'][0]]['attributes']['dps'].'</td>';
echo '<tr><td>Damage Per Second [Off Hand]</td><td>'.$data_array[$index_array['offHandDamage'][0]]['attributes']['dps'].'</td>';
echo '<tr><td>Damage Per Second [Ranged]</td><td>'.$data_array[$index_array['damage'][0]]['attributes']['dps'].'</td>';
echo '<tr><td>Crit Chance</td><td>'.$data_array[$index_array['critChance'][0]]['attributes']['percent'].'%</td>';
echo '<tr><td>Mana Regeneration [Casting]</td><td>'.$data_array[$index_array['manaRegen'][0]]['attributes']['casting'].'</td>';
echo '<tr><td>Mana Regeneration [Not Casting]</td><td>'.$data_array[$index_array['manaRegen'][0]]['attributes']['notCasting'].'</td>';

echo '</table><br />';

echo '<font size="+1"><strong>Resistances/Defensive</strong></font><br />';
echo '<table border="1"><tr><td><strong>Attribute/Stat</strong></td><td><strong>Value</strong></td></tr>';
echo '<tr><td>Armor</td><td>'.$data_array[$index_array['armor'][0]]['attributes']['effective'].'</td>';
echo '<tr><td>Arcane</td><td>'.$data_array[$index_array['arcane'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Fire</td><td>'.$data_array[$index_array['fire'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Frost</td><td>'.$data_array[$index_array['frost'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Holy</td><td>'.$data_array[$index_array['holy'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Nature</td><td>'.$data_array[$index_array['nature'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Shadow</td><td>'.$data_array[$index_array['shadow'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Defense</td><td>'.$data_array[$index_array['defense'][0]]['attributes']['value'].'</td>';
echo '<tr><td>Dodge</td><td>'.$data_array[$index_array['dodge'][0]]['attributes']['percent'].'%</td>';
echo '<tr><td>Parry</td><td>'.$data_array[$index_array['parry'][0]]['attributes']['percent'].'%</td>';
echo '<tr><td>Block</td><td>'.$data_array[$index_array['block'][0]]['attributes']['percent'].'%</td>';
echo '<tr><td>Resilience</td><td>'.$data_array[$index_array['resilience'][0]]['attributes']['value'].'%</td>';

echo '</table><br />';
}
}
?>


Maybe I'll update roster.php for configuration one day. I figured this might be useful to some people in the meantime, though.

Drunkenoldma
08-20-2007, 12:30 PM
and why make this, when you can freely use wowroster (http://www.wowroster.net/)?

freyyr
08-20-2007, 06:39 PM
and why make this, when you can freely use wowroster (http://www.wowroster.net/)?

I wish someone would have told me about that earlier. That could've saved me a lot of time.

Drunkenoldma
08-21-2007, 08:53 PM
or you could have used google