Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #12: Implement try-catch to avoid exception #13

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions laravel/app/Http/Controllers/Helpers/BannerVariableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Instance;
use Carbon\Carbon;
use Illuminate\Support\Facades\Redis;
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\ServerQueryException;
use PlanetTeamSpeak\TeamSpeak3Framework\Node\Server;
use Predis\Connection\ConnectionException;

Expand Down Expand Up @@ -79,20 +80,32 @@ public function get_current_client_list(): array
public function get_current_servergroup_list(): array
{
$this->virtualserver->clientListReset();
$servergroups = [];

/**
* SERVERGROUP MEMBER ONLINE COUNTER VARIABLE
*/
try {
$client_list = $this->virtualserver->clientList();
} catch (ServerQueryException) {
return array_change_key_case($servergroups, CASE_UPPER);
}

$client_servergroup_ids = [];
foreach ($this->virtualserver->clientList() as $client) {
foreach ($client_list as $client) {
$client_servergroup_ids = array_merge($client_servergroup_ids, explode(',', $client->client_servergroups));
}

/**
* VIRTUALSERVER SERVERGROUPS
*/
$servergroups = [];
foreach ($this->virtualserver->serverGroupList(['type' => 1]) as $servergroup) {
try {
$servergroup_list = $this->virtualserver->serverGroupList(['type' => 1]);
} catch (ServerQueryException) {
return array_change_key_case($servergroups, CASE_UPPER);
}

foreach ($servergroup_list as $servergroup) {
$servergroups['servergroup_'.$servergroup->sgid.'_id'] = $servergroup->sgid;
$servergroups['servergroup_'.$servergroup->sgid.'_name'] = $servergroup->name;
$servergroups['servergroup_'.$servergroup->sgid.'_member_total_count'] = count($this->virtualserver->serverGroupClientList($servergroup->sgid));
Expand Down