Added the server as argument, and improved the bug fix

This commit is contained in:
stanjg 2018-05-06 17:59:11 +02:00
parent 06a67bb4bb
commit 095d85bb60
No known key found for this signature in database
GPG key ID: 27D9DF9D28935303
2 changed files with 12 additions and 11 deletions

View file

@ -3,6 +3,8 @@
namespace Pterodactyl\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use JavaScript;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Database;
@ -10,8 +12,6 @@ use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\User;
use JavaScript;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
class StatisticsController extends Controller
@ -29,7 +29,7 @@ class StatisticsController extends Controller
$servers = Server::all();
$nodes = Node::all();
$serversCount = count($servers);
$nodesCount = Node::count();
$nodesCount = count($nodes);
$usersCount = User::count();
$eggsCount = Egg::count();
$databasesCount = Database::count();
@ -43,7 +43,11 @@ class StatisticsController extends Controller
$tokens = [];
foreach ($nodes as $node) {
$tokens[$node->id] = $this->keyProviderService->handle($node->servers->get(0), $request->user());
$server = Server::where('node_id', $node->id)->first();
if ($server == null)
continue;
$tokens[$node->id] = $this->keyProviderService->handle($server, $request->user());
}
Javascript::put([

View file

@ -61,12 +61,10 @@ var servers = Pterodactyl.servers;
var nodes = Pterodactyl.nodes;
for (let i = 0; i < servers.length; i++) {
setTimeout(getStatus, 200 * i);
setTimeout(getStatus, 200 * i, servers[i]);
}
var index = 0;
function getStatus() {
var server = servers[index];
function getStatus(server) {
var uuid = server.uuid;
var node = getNodeByID(server.node_id);
@ -109,13 +107,12 @@ function getStatus() {
statusChart.data.datasets[0].data[3]++;
statusChart.update();
});
index++;
}
function getNodeByID(id) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].id === id)
if (nodes[i].id === id) {
return nodes[i];
}
}
}