mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
add some error handling
This commit is contained in:
parent
4f47455cfe
commit
1eb6330f1c
1 changed files with 10 additions and 0 deletions
|
|
@ -50,6 +50,10 @@ class Parser {
|
||||||
$chat = [];
|
$chat = [];
|
||||||
/** @var ParsedPlayer[] $players */
|
/** @var ParsedPlayer[] $players */
|
||||||
$players = [];
|
$players = [];
|
||||||
|
|
||||||
|
if (!isset($data['rounds'])) {
|
||||||
|
throw new \Exception('Error while parsing demo, no users rounds found');
|
||||||
|
}
|
||||||
foreach ($data['rounds'] as $round) {
|
foreach ($data['rounds'] as $round) {
|
||||||
if ($round['winner'] === 'red') {
|
if ($round['winner'] === 'red') {
|
||||||
++$red;
|
++$red;
|
||||||
|
|
@ -58,6 +62,9 @@ class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($data['chat'])) {
|
||||||
|
throw new \Exception('Error while parsing demo, no users chat found');
|
||||||
|
}
|
||||||
foreach ($data['chat'] as $message) {
|
foreach ($data['chat'] as $message) {
|
||||||
if (isset($message['from'])) {
|
if (isset($message['from'])) {
|
||||||
$chat[] = new ChatMessage($message['from'],
|
$chat[] = new ChatMessage($message['from'],
|
||||||
|
|
@ -65,6 +72,9 @@ class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($data['users'])) {
|
||||||
|
throw new \Exception('Error while parsing demo, no users field found');
|
||||||
|
}
|
||||||
foreach ($data['users'] as $player) {
|
foreach ($data['users'] as $player) {
|
||||||
$class = 0;
|
$class = 0;
|
||||||
$classSpawns = 0;
|
$classSpawns = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue