This commit is contained in:
slawkens 2017-10-17 15:28:34 +02:00
commit 3d585a3d02
10 changed files with 125 additions and 53 deletions

View File

@ -175,13 +175,26 @@ INSERT INTO `myaac_news` (`id`, `type`, `date`, `category`, `title`, `body`, `pl
success($locale['step_database_imported_players']);
}
require LIBS . 'creatures.php';
if(Creatures::loadFromXML())
success($locale['step_database_loaded_creatures']);
require(LIBS . 'creatures.php');
if(Creatures::loadFromXML()) {
success($locale['step_database_loaded_monsters']);
if(Creatures::getMonstersList()->hasErrors()) {
$locale['step_database_error_monsters'] = str_replace('$LOG$', 'system/logs/error.log', $locale['step_database_error_monsters']);
warning($locale['step_database_error_monsters']);
}
}
else {
error(Creatures::getLastError());
}
require LIBS . 'spells.php';
if(Spells::loadFromXML())
require(LIBS . 'spells.php');
if(Spells::loadFromXML()) {
success($locale['step_database_loaded_spells']);
}
else {
error(Spells::getLastError());
}
$locale['step_finish_desc'] = str_replace('$ADMIN_PANEL$', generateLink(ADMIN_URL, $locale['step_finish_admin_panel'], true), $locale['step_finish_desc']);
$locale['step_finish_desc'] = str_replace('$HOMEPAGE$', generateLink(BASE_URL, $locale['step_finish_homepage'], true), $locale['step_finish_desc']);

View File

@ -15,6 +15,7 @@ if(file_exists(BASE . 'config.local.php')) // user customizations
require(BASE . 'config.local.php');
if(!isset($config['installed']) || !$config['installed']) {
header('Location: ' . BASE_URL);
die('AAC has not been installed yet or there was error during installation. Please install again.');
}

View File

@ -12,6 +12,9 @@
defined('MYAAC') or die('Direct access not allowed!');
class Creatures {
private static $monstersList = null;
private static $lastError = '';
public static function loadFromXML($show = false) {
global $config, $db;
@ -22,15 +25,22 @@ class Creatures {
echo "<h2>All records deleted from table 'myaac_monsters' in database.</h2>";
}
$allmonsters = new OTS_MonstersList($config['data_path'].'monster/');
try {
self::$monstersList = new OTS_MonstersList($config['data_path'].'monster/');
}
catch(Exception $e) {
self::$lastError = $e->getMessage();
return false;
}
//$names_added must be an array
$names_added[] = '';
//add monsters
foreach($allmonsters as $lol) {
$monster = $allmonsters->current();
foreach(self::$monstersList as $lol) {
$monster = self::$monstersList->current();
if(!$monster->loaded()) {
if($show) {
warning('Error while adding monster: ' . $allmonsters->currentFile());
warning('Error while adding monster: ' . self::$monstersList->currentFile());
}
continue;
}
@ -98,7 +108,7 @@ class Creatures {
if(!in_array($name, $names_added)) {
try {
$db->query("INSERT INTO `myaac_monsters` (`hide_creature`, `name`, `mana`, `exp`, `health`, `speed_lvl`, `use_haste`, `voices`, `immunities`, `summonable`, `convinceable`, `race`, `gfx_name`, `file_path`) VALUES (0, " . $db->quote($name) . ", " . $db->quote(empty($mana) ? 0 : $mana) . ", " . $db->quote($exp) . ", " . $db->quote($health) . ", " . $db->quote($speed_lvl) . ", " . $db->quote($use_haste) . ", " . $db->quote($voices_string) . ", " . $db->quote($immunities_string) . ", " . $db->quote($flags['summonable'] > 0 ? 1 : 0) . ", " . $db->quote($flags['convinceable'] > 0 ? 1 : 0) . ", ".$db->quote($race).", ".$db->quote($gfx_name).", " . $db->quote($allmonsters->currentFile()) . ")");
$db->query("INSERT INTO `myaac_monsters` (`hide_creature`, `name`, `mana`, `exp`, `health`, `speed_lvl`, `use_haste`, `voices`, `immunities`, `summonable`, `convinceable`, `race`, `gfx_name`, `file_path`) VALUES (0, " . $db->quote($name) . ", " . $db->quote(empty($mana) ? 0 : $mana) . ", " . $db->quote($exp) . ", " . $db->quote($health) . ", " . $db->quote($speed_lvl) . ", " . $db->quote($use_haste) . ", " . $db->quote($voices_string) . ", " . $db->quote($immunities_string) . ", " . $db->quote($flags['summonable'] > 0 ? 1 : 0) . ", " . $db->quote($flags['convinceable'] > 0 ? 1 : 0) . ", ".$db->quote($race).", ".$db->quote($gfx_name).", " . $db->quote(self::$monstersList->currentFile()) . ")");
if($show) {
success("Added: ".$name."<br/>");
@ -116,4 +126,12 @@ class Creatures {
return true;
}
public static function getMonstersList() {
return self::$monstersList;
}
public static function getLastError() {
return self::$lastError;
}
}

View File

@ -818,34 +818,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
*/
public function getAccess()
{
global $groups;
if(!isset($groups))
$groups = new OTS_Groups_List();
// by default
$access = 0;
if(fieldExist('group_id', 'accounts')) {
$query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch();
// if anything was found
$group = $groups->getGroup($query['group_id']);
if(!$group) return 0;
return $group->getAccess();
}
// finds groups of all characters
foreach( $this->getPlayersList() as $player)
{
$group = $player->getGroup();
// checks if group's access level is higher then previouls found highest
if( $group->getAccess() > $access)
{
$access = $group->getAccess();
}
}
return $access;
return $this->getGroupId();
}
public function getGroupId()
@ -858,10 +831,12 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
return $query['group_id'];
}
$db->query('SELECT `group_id` FROM `players` WHERE `account_id` = ' . $this->getId() . ' ORDER BY `group_id` DESC LIMIT 1')->fetch();
if(isset($query['group_id']))
$query = $this->db->query('SELECT `group_id` FROM `players` WHERE `account_id` = ' . (int) $this->getId() . ' ORDER BY `group_id` DESC LIMIT 1');
if($query->rowCount() == 1)
{
$query = $query->fetch();
return $query['group_id'];
}
return 0;
}

View File

@ -36,6 +36,8 @@ class OTS_MonstersList implements Iterator, Countable, ArrayAccess
*/
private $monsters = array();
private $lastMonsterFile = '';
private $hasErrors = false;
/**
* Loads monsters mapping file.
*
@ -57,9 +59,18 @@ class OTS_MonstersList implements Iterator, Countable, ArrayAccess
$this->monstersPath .= '/';
}
// check if monsters.xml exist
if(!@file_exists($this->monstersPath . 'monsters.xml')) {
log_append('error.log', '[OTS_MonstersList.php] Fatal error: Cannot load monsters.xml. File does not exist. (' . $this->monstersPath . 'monsters.xml' . '). Error: ' . print_r(error_get_last(), true));
throw new Exception('Error: Cannot load monsters.xml. File not found. More info in system/logs/error.log file.');
}
// loads monsters mapping file
$monsters = new DOMDocument();
$monsters->load($this->monstersPath . 'monsters.xml');
if(!@$monsters->load($this->monstersPath . 'monsters.xml')) {
log_append('error.log', '[OTS_MonstersList.php] Fatal error: Cannot load monsters.xml (' . $this->monstersPath . 'monsters.xml' . '). Error: ' . print_r(error_get_last(), true));
throw new Exception('Error: Cannot load monsters.xml. File is invalid. More info in system/logs/error.log file.');
}
foreach( $monsters->getElementsByTagName('monster') as $monster)
{
@ -101,6 +112,16 @@ class OTS_MonstersList implements Iterator, Countable, ArrayAccess
return isset($this->monsters[$name]);
}
function xmlErrorHandler($errno, $errstr, $errfile, $errline)
{
if($errno==E_WARNING && (substr_count($errstr,"DOMDocument::loadXML()")>0)) {
//throw new DOMException($errstr);
log_append('error.log', '[OTS_MonstersList.php] Fatal error: Cannot load ' . $this->lastMonsterFile . ' - ' . $errstr);
$this->hasErrors = true;
}
else
return false;
}
/**
* Returns loaded data of given monster.
*
@ -112,21 +133,31 @@ class OTS_MonstersList implements Iterator, Countable, ArrayAccess
*/
public function getMonster($name)
{
global $lastMonsterFile;
// checks if monster exists
if( isset($this->monsters[$name]) )
{
// loads file
$monster = new OTS_Monster();
//echo $this->monstersPath . $this->monsters[$name];
// check if monster file exist
if(file_exists($this->monstersPath . $this->monsters[$name])) {
$monster->loadXML(trim(file_get_contents($this->monstersPath . $this->monsters[$name])));
set_error_handler(array($this, 'xmlErrorHandler'));
$this->lastMonsterFile = $this->monstersPath . $this->monsters[$name];
@$monster->loadXML(trim(file_get_contents($this->monstersPath . $this->monsters[$name])));
restore_error_handler();
}
return $monster;
}
throw new OutOfBoundsException();
}
public function hasErrors() {
return $this->hasErrors;
}
/**
* Returns amount of monsters loaded.
*

View File

@ -93,9 +93,18 @@ class OTS_SpellsList implements IteratorAggregate, Countable
*/
public function __construct($file)
{
// loads DOM document
// check if spells.xml exist
if(!@file_exists($file)) {
log_append('error.log', '[OTS_SpellsList.php] Fatal error: Cannot load spells.xml. File does not exist. (' . $file . '). Error: ' . print_r(error_get_last(), true));
throw new Exception('Error: Cannot load spells.xml. File not found. More info in system/logs/error.log file.');
}
// loads monsters mapping file
$spells = new DOMDocument();
$spells->load($file);
if(!@$spells->load($file)) {
log_append('error.log', '[OTS_SpellsList.php] Fatal error: Cannot load spells.xml (' . $file . '). Error: ' . print_r(error_get_last(), true));
throw new Exception('Error: Cannot load spells.xml. File is invalid. More info in system/logs/error.log file.');
}
// loads runes
foreach( $spells->getElementsByTagName('rune') as $rune)

View File

@ -12,6 +12,9 @@
defined('MYAAC') or die('Direct access not allowed!');
class Spells {
private static $spellsList = null;
private static $lastError = '';
public static function loadFromXML($show = false) {
global $config, $db;
@ -26,15 +29,21 @@ class Spells {
$vocations_ids[$voc_name] = $voc_id;
}
$allspells = new OTS_SpellsList($config['data_path'].'spells/spells.xml');
try {
self::$spellsList = new OTS_SpellsList($config['data_path'].'spells/spells.xml');
}
catch(Exception $e) {
self::$lastError = $e->getMessage();
return false;
}
//add conjure spells
$conjurelist = $allspells->getConjuresList();
$conjurelist = self::$spellsList->getConjuresList();
if($show) {
echo "<h3>Conjure:</h3>";
}
foreach($conjurelist as $spellname) {
$spell = $allspells->getConjure($spellname);
$spell = self::$spellsList->getConjure($spellname);
$lvl = $spell->getLevel();
$mlvl = $spell->getMagicLevel();
$mana = $spell->getMana();
@ -88,13 +97,13 @@ class Spells {
}
//add instant spells
$instantlist = $allspells->getInstantsList();
$instantlist = self::$spellsList->getInstantsList();
if($show) {
echo "<h3>Instant:</h3>";
}
foreach($instantlist as $spellname) {
$spell = $allspells->getInstant($spellname);
$spell = self::$spellsList->getInstant($spellname);
$lvl = $spell->getLevel();
$mlvl = $spell->getMagicLevel();
$mana = $spell->getMana();
@ -151,4 +160,12 @@ class Spells {
return true;
}
public static function getSpellsList() {
return self::$spellsList;
}
public static function getLastError() {
return self::$lastError;
}
}

View File

@ -69,7 +69,8 @@ $locale['step_database_adding_field'] = 'Adding field';
$locale['step_database_modifying_field'] = 'Modifying field';
$locale['step_database_changing_field'] = 'Changing $FIELD$ to $FIELD_NEW$...';
$locale['step_database_imported_players'] = 'Imported player samples...';
$locale['step_database_loaded_creatures'] = 'Loaded creatures...';
$locale['step_database_loaded_monsters'] = 'Loaded monsters...';
$locale['step_database_error_monsters'] = 'There were some problems loading your monsters.xml file. Please check $LOG$ for more info.';
$locale['step_database_loaded_spells'] = 'Loaded spells...';
$locale['step_database_created_account'] = 'Created admin account...';
$locale['step_database_created_news'] = 'Created newses...';

View File

@ -65,7 +65,12 @@ $canEdit = hasFlag(FLAG_CONTENT_MONSTERS) || admin();
if(isset($_POST['reload_monsters']) && $canEdit)
{
require LIBS . 'creatures.php';
Creatures::loadFromXML(true);
if(Creatures::loadFromXML(true))
if(Creatures::getMonstersList()->hasErrors())
error('There were some problems loading your monsters.xml file. Please check system/logs/error.log for more info.');
else {
error(Creatures::getLastError());
}
}
if($canEdit)

View File

@ -16,7 +16,9 @@ $canEdit = hasFlag(FLAG_CONTENT_SPELLS) || admin();
if(isset($_POST['reload_spells']) && $canEdit)
{
require LIBS . 'spells.php';
Spells::loadFromXML(true);
if(!Spells::loadFromXML(true)) {
error(Spells::getLastError());
}
}
if($canEdit)