Example #1
0
 public static function Init($emulator = '')
 {
     // Init the wowlib jsut once
     if (self::$initilized) {
         return;
     }
     // Init a start time for benchmarking
     $start = microtime(1);
     // Set emulator paths, and scan to see which emulators exist
     $path = path(WOWLIB_ROOT, 'library');
     self::$load = load_class('Loader');
     self::$Fs = self::$load->library('Filesystem');
     self::$emulators = self::$Fs->list_folders($path);
     // Make sure the emulator exists before defining it
     if (!is_array(self::$emulators)) {
         throw new Exception('Unable to open the wowlib/library folder. Please corretly set your permissions.', 2);
     } elseif (!empty($emulator)) {
         if (!in_array($emulator, self::$emulators)) {
             throw new Exception('Emulator ' . $emulator . ' not found in the emulators folder.', 3);
         }
         self::$emulator = strtolower($emulator);
     }
     // Get a full list of interfaces
     $path = path(WOWLIB_ROOT, 'interfaces');
     $list = self::$Fs->list_files($path);
     if (!is_array($list)) {
         throw new Exception('Unable to open the wowlib interfaces folder. Please corretly set your permissions.', 4);
     }
     // Autload each interface so the class' dont have to
     foreach ($list as $file) {
         include $path . DS . $file;
     }
     // Set that we are initialized, and get our init time for benchmarking
     self::$initilized = true;
     self::$initTime = round(microtime(1) - $start, 5);
 }
Example #2
0
/* 
| -------------------------------------------------------------- 
| This example shows you how to load a realm, and fetch an account
| --------------------------------------------------------------
*/
// Include the wowlib class
include 'Wowlib.php';
// Init the wowlib
Wowlib::Init($emulator);
// Fetch realm, and Dump the account id of 5
$Realm = Wowlib::getRealm('myrealmid', $connA);
$Account = $Realm->fetchAccount($accountId);
echo "This account username for account id {$accountId} is " . $Account->getUsername();
/* 
| -------------------------------------------------------------- 
| In this next example, Lets fetch a character
| --------------------------------------------------------------
*/
// Load a driver first, which ever is most compatible with your core revision
// We will skip the world data connection by placing null as the 3rd param
$Driver = Wowlib::load('_default', $connC, null);
// The driver... Each method under the driver object, is a class that is loacated
// inside the loaded driver folder "drivers/$emulator/_default" in this case
$Character = $Driver->characters->fetch(2);
if (is_object($Character)) {
    echo "<br /><br />This character's name is " . $Character->getName() . " and he is level " . $Character->getLevel() . "!";
} else {
    echo "<br /><br />Character Doesnt Exist :O";
}
// Echo benchmark time
echo "<br /><br />Rendered in " . round(microtime(1) - $start, 4) . " seconds";
Example #3
0
 public function wowlib($id = 0, $instance_as = FALSE)
 {
     // Get our realm id if none is provieded
     if ($id === 0) {
         $id = config('default_realm_id');
     }
     // Make sure we havent loaded the lib already
     $Obj = \Registry::load('Wowlib_r' . $id);
     if ($Obj !== NULL) {
         return $Obj;
     }
     // Make sure the wowlib is initialized
     if (!class_exists('Wowlib', false)) {
         $this->_initWowlib();
     }
     // Load our driver name
     $DB = $this->database('DB', FALSE);
     $realm = $DB->query("SELECT `id`, `name`, `driver`, `char_db`, `world_db` FROM `pcms_realms` WHERE `id`=" . $id)->fetchRow();
     // Make sure we didnt get a false DB return
     if ($realm === FALSE) {
         $language = load_language_file('messages');
         $message = $language['wowlib_realm_doesnt_exist'];
         show_error($message, array($id), E_ERROR);
     }
     // Add debug tracer
     \Debug::trace('Loading Wowlib driver "' . $realm['driver'] . '"', __FILE__, __LINE__);
     // Unserialize our database information
     $char = unserialize($realm['char_db']);
     $world = unserialize($realm['world_db']);
     // Init the driver
     $class = \Wowlib::load($realm['driver'], $char, $world);
     // Store the class statically and return the class
     \Registry::store('Wowlib_r' . $id, $class);
     // Check to see if the user wants to instance
     if ($instance_as !== FALSE) {
         get_instance()->{$instance_as} = $class;
     }
     return $class;
 }