svn[1314] Bug in armory.class.php

Posts from previous Beta sessions

svn[1314] Bug in armory.class.php

Postby poetter » Sat Sep 08, 2007 9:18 am

Hi,

theres a bug in the cache system of armory.class.php.

The cache tag is always given as $character.$locale.$realm.$is_XML;
So every second fetch of a character would give the same content, whatever function you call fetchCharacter or fetchCharacterTalents.

BTW: After Blizzard splitting the character infos to diffrent xml sheets it would be nice to implement fetching of character-skills.xml and character-reputation.xml

Here is a patch to do so:
Code: Select all
--- D:/xampp/roster.com/htdocs/lib/armory.class.php.org   Sat Sep 08 03:02:58 2007
+++ D:/xampp/roster.com/htdocs/lib/armory.class.php   Sat Sep 08 03:10:42 2007
@@ -285,7 +285,7 @@
       global $roster;
       
       $locale = substr($locale, 0, 2);
-      $cache_tag = $character.$locale.$realm.$is_XML;
+      $cache_tag = $character.$locale.$realm.'talents'.$is_XML;
       
       if( $roster->cache->check($cache_tag) )
       {
@@ -325,6 +325,118 @@
    }
    
    /**
+    * Fetch skills of $character from the Armory
+    * $realm is required
+    * $locale is reqired
+    *
+    * @param string $character
+    * @param string $locale
+    * @param string $realm
+    * @param bool $is_XML
+    * @return array
+    */
+   function fetchCharacterSkills( $character, $locale, $realm, $is_XML=false )
+   {
+      global $roster;
+      
+      $locale = substr($locale, 0, 2);
+      $cache_tag = $character.$locale.$realm.'skills'.$is_XML;
+      
+      if( $roster->cache->check($cache_tag) )
+      {
+         return $roster->cache->get($cache_tag);
+      }
+      else
+      {
+         $url = $this->_makeUrl( 5, $locale, false, $character, $realm );
+         if( $this->_requestXml($url) )
+         {
+            if( $is_XML )
+            {
+               $roster->cache->put($cache_tag);
+               return $this->xml;
+            }
+            $this->xmlParser->Parse($this->xml);
+            $char = $this->xmlParser->getParsedData();
+            $roster->cache->put($char, $cache_tag);
+            return $char;
+         }
+      }
+   }
+   
+   /**
+    * Fetch skills of $character from the Armory
+    * $realm is required
+    * $locale is reqired
+    * Returns XML string
+    *
+    * @param string $character
+    * @param string $locale
+    * @param string $realm
+    * @return string | xml string
+    */   
+   function fetchCharacterSkillsXML( $character, $locale, $realm )
+   {
+      return $this->fetchCharacterSkills($character, $locale, $realm, true);
+   }
+
+   /**
+    * Fetch reputation of $character from the Armory
+    * $realm is required
+    * $locale is reqired
+    *
+    * @param string $character
+    * @param string $locale
+    * @param string $realm
+    * @param bool $is_XML
+    * @return array
+    */
+   function fetchCharacterReputation( $character, $locale, $realm, $is_XML=false )
+   {
+      global $roster;
+      
+      $locale = substr($locale, 0, 2);
+      $cache_tag = $character.$locale.$realm.'reputation'.$is_XML;
+      
+      if( $roster->cache->check($cache_tag) )
+      {
+         return $roster->cache->get($cache_tag);
+      }
+      else
+      {
+         $url = $this->_makeUrl( 6, $locale, false, $character, $realm );
+         if( $this->_requestXml($url) )
+         {
+            if( $is_XML )
+            {
+               $roster->cache->put($cache_tag);
+               return $this->xml;
+            }
+            $this->xmlParser->Parse($this->xml);
+            $char = $this->xmlParser->getParsedData();
+            $roster->cache->put($char, $cache_tag);
+            return $char;
+         }
+      }
+   }
+   
+   /**
+    * Fetch reputation of $character from the Armory
+    * $realm is required
+    * $locale is reqired
+    * Returns XML string
+    *
+    * @param string $character
+    * @param string $locale
+    * @param string $realm
+    * @return string | xml string
+    */   
+   function fetchCharacterReputationXML( $character, $locale, $realm )
+   {
+      return $this->fetchCharacterReputation($character, $locale, $realm, true);
+   }
+
+   /**
     * Sets $user_agent
     * Use to override default useragent
     *
@@ -407,6 +519,14 @@
          case 4:
          case 'character-talents':
             $mode = 'character-talents.xml?n=' . $char . '&r=' . urlencode($realm);
+            break;
+         case 5:
+         case 'character-skills':
+            $mode = 'character-skills.xml?n=' . $char . '&r=' . urlencode($realm);
+            break;
+         case 6:
+         case 'character-reputation':
+            $mode = 'character-reputation.xml?n=' . $char . '&r=' . urlencode($realm);
             break;
       }
 
Last edited by poetter on Mon Sep 10, 2007 3:08 am, edited 1 time in total.
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

svn[1314] Bug in armory.class.php

Postby ds » Sat Sep 08, 2007 11:28 am

Good point on the cache_tag. Thanks for the fixes and additions. I'll make the changes official my next commit.
Image
ds
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 297
Joined: Sat Jul 08, 2006 9:58 am

Re: svn[1314] Bug in armory.class.php

Postby poetter » Sat Sep 08, 2007 7:26 pm

nice, thx
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

svn[1314] Bug in armory.class.php

Postby ds » Mon Sep 10, 2007 3:08 am

Added in SVN: 1318
Image
ds
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 297
Joined: Sat Jul 08, 2006 9:58 am

Re: svn[1314] Bug in armory.class.php

Postby poetter » Mon Sep 10, 2007 4:51 am

very nice
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

Re: svn[1314] Bug in armory.class.php

Postby ds » Mon Sep 10, 2007 7:13 am

Added new Fetch Methods to SVN: 1319.
Some are useful... some not so much...
Code: Select all
fetchItemTooltipHTML($item_id, $locale, [ $character , $realm ] )
fetchItemInfoHTML($item_id, $locale )
fetchCharacterHTML( $character, $locale, $realm )
fetchGuildHTML( $guild, $locale, $realm )
fetchCharacterTalentsHTML( $character, $locale, $realm )
fetchCharacterSkillsHTML( $character, $locale, $realm )
fetchCharacterReputationHTML( $character, $locale, $realm )
Image
ds
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 297
Joined: Sat Jul 08, 2006 9:58 am

Re: svn[1314] Bug in armory.class.php

Postby poetter » Mon Sep 10, 2007 7:17 am

You read my thoughts. Tried to do this with the XML Methods. Was working, but trow a lot of errors
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

svn[1314] Bug in armory.class.php

Postby poetter » Tue Sep 11, 2007 5:55 am

Hi ds,

can you please add an urlencode around $char in _makeUrl function? Otherwise the charname is corrupted and no infos are fetched.
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

svn[1314] Bug in armory.class.php

Postby ds » Tue Sep 11, 2007 6:26 am

Yeah.. you know I was going to do that because I figured it would have problems with names with umlauts and such... I'll definitely add that next commit.

Anything else that I can add to this class that would prove useful to you and/or others?
Image
ds
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 297
Joined: Sat Jul 08, 2006 9:58 am

svn[1314] Bug in armory.class.php

Postby poetter » Tue Sep 11, 2007 3:16 pm

Don't know yet. Work's going on step by step. I'm waiting for the next svn release to get your changes. Is it possible to get read access to the repository?
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg


Return to Archived

Who is online

Users browsing this forum: No registered users and 1 guest

cron