Skip to content

Commit

Permalink
Market: Display error message instead of crashing if fail to load ite…
Browse files Browse the repository at this point in the history
…ms.xml file.
  • Loading branch information
Znote committed Feb 4, 2019
1 parent 9404c90 commit 594e2c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 12 additions & 12 deletions engine/function/itemparser/itemlistparser.php
@@ -1,5 +1,4 @@
<?php

/* Returns a PHP array $id => 'name'
$items = getItemList();
echo $items[2160]; // Returns 'Crystal Coin'
Expand All @@ -18,17 +17,18 @@ function getItemById($id) {
}

function parseItems() {
global $config;

$items = simplexml_load_file($config['server_path'].'/data/items/items.xml');
$out = array();

// Create our parsed item list
foreach ($items->children() as $item) {
if ($item['id'] && $item['name'] != NULL) {
$out[(int)$item['id']] = (string)$item['name'];
$file = Config('server_path') . '/data/items/items.xml';
if (file_exists($file)) {
$itemList = array();
$items = simplexml_load_file($file);
// Create our parsed item list
foreach ($items->children() as $item) {
if ($item['id'] && $item['name'] != NULL) {
$itemList[(int)$item['id']] = (string)$item['name'];
}
}
return $itemList;
}

return $out;
return $file;
}
?>
15 changes: 15 additions & 0 deletions market.php
Expand Up @@ -5,6 +5,21 @@
$items = getItemList();
$compare = &$_GET['compare'];

// If we failed to load items.xml, a string is returned (not an array)
// with the attempted loaded file path.
// So if $items is not an array, send an error message, include the footer and ignore rest of this page.
if (is_array($items) === false):
?>
<h1>Marketplace</h1>
<p>Failed to load item list.</p>
<p>Attempted to load this file: <?php echo $items; ?></p>
<p>Configure correct 'server_path' in config.php.</p>
<p>If the path is correct, make sure your web user has access to read it.</p>
<?php
include 'layout/overall/footer.php';
die();
endif;

// If you are not comparing any items, present the list.
if (!$compare) {
$cache = new Cache('engine/cache/market');
Expand Down

0 comments on commit 594e2c0

Please sign in to comment.