コード例 #1
0
 /**
  * Load the battle index from the session or cache file and return success
  * @param bool include_session
  * @return bool
  */
 public static function load_battle_index($include_session = true)
 {
     // Collect references to global objects
     $db = cms_database::get_database();
     $this_index = array();
     // Default the battles index to an empty array
     $battles_index = array();
     // If caching is turned OFF, or a cache has not been created
     if (!MMRPG_CONFIG_CACHE_INDEXES || !file_exists(MMRPG_CONFIG_BATTLES_CACHE_PATH)) {
         // Start indexing the battle data files
         $battles_cache_markup = self::index_battle_data();
         // Implode the markup into a single string and enclose in PHP tags
         $battles_cache_markup = implode('', $battles_cache_markup);
         $battles_cache_markup = "<?php\n" . $battles_cache_markup . "\n?>";
         // Write the index to a cache file, if caching is enabled
         $battles_cache_file = @fopen(MMRPG_CONFIG_BATTLES_CACHE_PATH, 'w');
         if (!empty($battles_cache_file)) {
             @fwrite($battles_cache_file, $battles_cache_markup);
             @fclose($battles_cache_file);
         }
     }
     // Include the cache file so it can be evaluated
     require_once MMRPG_CONFIG_BATTLES_CACHE_PATH;
     //die('<pre>$battles_index => '.print_r($battles_index, true).'</pre>');
     // Return false if we got nothing from the index
     if (empty($battles_index)) {
         return array();
     }
     // Loop through the battles and index them after serializing
     foreach ($battles_index as $token => $array) {
         $this_index[$token] = json_encode($array);
     }
     // Additionally, include any dynamic session-based battles
     if (!empty($include_session) && !empty($_SESSION['GAME']['values']['battle_index'])) {
         // The session-based battles exist, so merge them with the index
         $this_index = array_merge($this_index, $_SESSION['GAME']['values']['battle_index']);
     }
     //echo('<pre>self::$database_index = $this_index => '.print_r($this_index, true).'</pre>');
     // Update the internal index
     self::$database_index = $this_index;
     // Return the index on success
     return true;
 }