Skip to content

Commit

Permalink
update mon
Browse files Browse the repository at this point in the history
Обновление мониторинга и что-то еще
  • Loading branch information
alabamaster committed Jul 22, 2020
1 parent 45ec6f2 commit bd82d0c
Show file tree
Hide file tree
Showing 134 changed files with 15,337 additions and 150 deletions.
78 changes: 37 additions & 41 deletions app/js_post/actionBuy.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

require_once 'db_class.php';
require_once '../core/Model.php';
Expand All @@ -10,12 +10,16 @@
$db = require_once '../configs/db.php';

use app\lib\DB;
use app\lib\SourceQuery;
// use app\lib\SourceQuery;

if ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
die('method error');
}

// GameQ
require_once('../lib/GameQ/Autoloader.php');
$GameQ = new \GameQ\GameQ();

session_start();

function discount($cost, $discount)
Expand All @@ -26,8 +30,6 @@ function discount($cost, $discount)

function serverIp($ip, $port)
{
// $ip = (string)$ip;
// $port = (string)$port;
if ( $port == '27015' ) return $ip;
return $ip . ':' . $port;
}
Expand Down Expand Up @@ -105,30 +107,21 @@ function secToStrDate($secs)
break;

case '3': // мониторинг
require_once '../lib/SourceQuery.php';
$server_id = (int)$_POST['server_id'];
// префикс исправить
$sql = DB::run('SELECT `id`, `address` FROM `'.$db['prefix'].'_serverinfo` WHERE `id` = ? LIMIT 1', [ $server_id ])->fetch(PDO::FETCH_ASSOC);
list($ip, $port) = explode(":", $sql['address']);
$server = $ip . ':' . $port;

// ПОФИКСИТЬ ЧАСЫ В СПИСКЕ ИГРОКОВ
$sq = new SourceQuery($ip, $port);
$info = $sq->getInfos();
$players = $sq->getPlayers();

if ( !$info )
{
$info = array(
'map' => '-/-',
'name' => 'Сервер недоступен',
);
$displayNone = 'class="d-none"';
} else {
$displayNone = '';
}
$GameQ->addServer([
'type' => 'cs16',
'host' => $server,
]);
$results = $GameQ->process();
$result = $results[$server];

// map images
$url = "https://image.gametracker.com/images/maps/160x120/cs/" .$info['map']. ".jpg";
$url = "https://image.gametracker.com/images/maps/160x120/cs/" .$result['gq_mapname']. ".jpg";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
Expand All @@ -144,23 +137,22 @@ function secToStrDate($secs)
$mapimage = ($httpcode == 200) ? '<img id="mapImg" style="max-width: 136px;" class="mr-2 rounded" src="'.$url.'">' : '<img id="mapImg" style="max-width: 136px;" class="mr-2 rounded" src="https://image.gametracker.com/images/maps/160x120/nomap.jpg">';

?>
<div class="mess mess-ok d-flex animated zoomIn">
<div <?=$displayNone?>>
<?=$mapimage?>
</div>
<?php if($result['gq_online']):?>
<div class="d-flex animated zoomIn" style="padding: 5px;border: 1px solid #dadada;border-radius: 2px;color: #585858;">
<div><?=$mapimage?></div>
<div class="d-flex flex-column text-truncate">
<div><h6 class="m-0"><?=@$info['name']?></h6></div>
<div <?=$displayNone?> style="font-size: 14px;">
<i class="fa fa-picture-o" aria-hidden="true"></i> Карта <b><?=@$info['map']?></b>
<div><h6 class="m-0"><?=$result['hostname']?></h6></div>
<div style="font-size: 14px;">
<i class="fa fa-picture-o" aria-hidden="true"></i> Карта <b><?=$result['gq_mapname']?></b>, следующая карта <b><?=$result['amx_nextmap']?></b>
</div>
<div <?=$displayNone?> style="font-size: 14px;">
<i class="fa fa-user-o" aria-hidden="true"></i> Игроков <b><?=@$info['players']?>/<?=@$info['places']?></b>
<div style="font-size: 14px;">
<i class="fa fa-user-o" aria-hidden="true"></i> Игроков <b><?=$result['gq_numplayers']?>/<?=$result['gq_maxplayers']?></b>
</div>
<div <?=$displayNone?> style="font-size: 14px;">
<div style="font-size: 14px;">
<i class="fa fa-steam" aria-hidden="true"></i>
<a href="steam://connect/<?=@$info['ip']?>:<?=@$info['port']?>" title="Подключиться"><?=serverIp($info['ip'], $info['port'])?></a>
<a href="<?=$result['gq_joinlink']?>" title="Подключиться"><?=serverIp($ip, $port)?></a>
</div>
<div <?=$displayNone?> style="font-size: 14px;">
<div style="font-size: 14px;">
<i class="fa fa-users" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#players">Список игроков</a>
</div>
</div>
Expand All @@ -169,14 +161,14 @@ function secToStrDate($secs)
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="players">Игроки: <?=$info['name']?></h5>
<h5 class="modal-title" id="players">Игроки: <?=$result['hostname']?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- table -->
<?php if( empty($players[0]) ):?>
<?php if( empty($result['players']) ):?>
<div class="text-center font-weight-bold text-secondary">Нет игроков</div>
<?php else:?>
<div class="table-responsive mb-0">
Expand All @@ -190,13 +182,14 @@ function secToStrDate($secs)
</tr>
</thead>
<tbody>
<?php foreach ($players as $row) {
<?php foreach ($result['players'] as $row) {
$timeInGame = floor($row['gq_time'] / 60) % 60;
echo '
<tr>
<th scope="row">'.$row['id'].'</th>
<td>'.htmlspecialchars($row['name']).'</td>
<td>'.$row['score'].'</td>
<td>'.secToStrDate($row['time']).'</td>
<td>'.htmlspecialchars($row['gq_name']).'</td>
<td>'.$row['gq_score'].'</td>
<td>'.secToStrDate($row['gq_time']).'</td>
</tr>
';
}?>
Expand All @@ -209,6 +202,9 @@ function secToStrDate($secs)
</div>
</div>
</div>
<?php else:?>
<div class="animated zoomIn mess mess-error"><span>Сервер недоступен</span></div>
<?php endif;?>
<?php
break;

Expand Down
121 changes: 70 additions & 51 deletions app/js_post/actionProfileBuy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
error_reporting(E_ALL);

use app\lib\DB;
use app\lib\SourceQuery;

// GameQ
require_once('../lib/GameQ/Autoloader.php');
$GameQ = new \GameQ\GameQ();

if ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
die('method error');
Expand All @@ -27,6 +30,26 @@ function serverIp($ip, $port)
return $ip . ':' . $port;
}

function secToStrDate($secs)
{
$res = array();

$res['days'] = floor($secs / 86400);
$secs = $secs % 86400;

$res['hours'] = floor($secs / 3600);
$secs = $secs % 3600;

$res['minutes'] = floor($secs / 60);
$res['secs'] = $secs % 60;

$res['seconds'] = floor($secs / 60);
$res['secs'] = ($secs / 60);

// return $res;
return $res['hours'] . 'ч ' . $res['minutes'] . 'м ' . $res['seconds'] . 'с';
}

$case = (int) $_POST['case'];

$fk = $cfg['FK']; // freekassa array
Expand Down Expand Up @@ -76,30 +99,21 @@ function serverIp($ip, $port)
break;

case '3': // мониторинг
require_once '../lib/SourceQuery.php';
$server_id = (int)$_POST['server_id'];
// префикс исправить
$sql = DB::run('SELECT `id`, `address` FROM `'.$db['prefix'].'_serverinfo` WHERE `id` = ? LIMIT 1', [ $server_id ])->fetch(PDO::FETCH_ASSOC);
list($ip, $port) = explode(":", $sql['address']);
$server = $ip . ':' . $port;

// ПОФИКСИТЬ ЧАСЫ В СПИСКЕ ИГРОКОВ
$sq = new SourceQuery($ip, $port);
$info = $sq->getInfos();
$players = $sq->getPlayers();

if ( !$info )
{
$info = array(
'map' => '-/-',
'name' => 'Сервер недоступен',
);
$displayNone = 'class="d-none"';
} else {
$displayNone = '';
}
$GameQ->addServer([
'type' => 'cs16',
'host' => $server,
]);
$results = $GameQ->process();
$result = $results[$server];

// map images
$url = "https://image.gametracker.com/images/maps/160x120/cs/" .$info['map']. ".jpg";
$url = "https://image.gametracker.com/images/maps/160x120/cs/" .$result['gq_mapname']. ".jpg";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
Expand All @@ -111,27 +125,25 @@ function serverIp($ip, $port)
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);


$mapimage = ($httpcode == 200) ? '<img id="mapImg" style="max-width: 136px;" class="mr-2 rounded" src="'.$url.'">' : '<img id="mapImg" style="max-width: 136px;" class="mr-2 rounded" src="https://image.gametracker.com/images/maps/160x120/nomap.jpg">';

?>
<div class="mess mess-ok d-flex animated zoomIn">
<div <?=$displayNone?>>
<?=$mapimage?>
</div>
<?php if($result['gq_online']):?>
<div class="d-flex animated zoomIn" style="padding: 5px;border: 1px solid #dadada;border-radius: 2px;color: #585858;">
<div><?=$mapimage?></div>
<div class="d-flex flex-column text-truncate">
<div><h6 class="m-0"><?=@$info['name']?></h6></div>
<div <?=$displayNone?> style="font-size: 14px;">
<i class="fa fa-picture-o" aria-hidden="true"></i> Карта <b><?=@$info['map']?></b>
<div><h6 class="m-0"><?=$result['hostname']?></h6></div>
<div style="font-size: 14px;">
<i class="fa fa-picture-o" aria-hidden="true"></i> Карта <b><?=$result['gq_mapname']?></b>, следующая карта <b><?=$result['amx_nextmap']?></b>
</div>
<div <?=$displayNone?> style="font-size: 14px;">
<i class="fa fa-user-o" aria-hidden="true"></i> Игроков <b><?=@$info['players']?>/<?=@$info['places']?></b>
<div style="font-size: 14px;">
<i class="fa fa-user-o" aria-hidden="true"></i> Игроков <b><?=$result['gq_numplayers']?>/<?=$result['gq_maxplayers']?></b>
</div>
<div <?=$displayNone?> style="font-size: 14px;">
<div style="font-size: 14px;">
<i class="fa fa-steam" aria-hidden="true"></i>
<a href="steam://connect/<?=@$info['ip']?>:<?=@$info['port']?>"><?=@serverIp(@$info['ip'], @$info['port'])?></a>
<a href="<?=$result['gq_joinlink']?>" title="Подключиться"><?=serverIp($ip, $port)?></a>
</div>
<div <?=$displayNone?> style="font-size: 14px;">
<div style="font-size: 14px;">
<i class="fa fa-users" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#players">Список игроков</a>
</div>
</div>
Expand All @@ -140,43 +152,50 @@ function serverIp($ip, $port)
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="players"><?=$info['name']?></h5>
<h5 class="modal-title" id="players">Игроки: <?=$result['hostname']?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- table -->
<?php if( empty($result['players']) ):?>
<div class="text-center font-weight-bold text-secondary">Нет игроков</div>
<?php else:?>
<div class="table-responsive mb-0">
<table class="table table-sm table-bordered">
<thead>
<tr>
<td>Ник</td>
<td>Фраги</td>
<td>Время в игре</td>
</tr>
</thead>
<tbody>
<?php
foreach ($players as $row) {
$timeInGame = floor($row['time'] / 60) % 60;
<table class="table table-sm table-hover">
<thead>
<tr>
<th class="border-0" scope="col">#</th>
<th class="border-0" scope="col">Ник</th>
<th class="border-0" scope="col">Фраги</th>
<th class="border-0" scope="col">В игре</th>
</tr>
</thead>
<tbody>
<?php foreach ($result['players'] as $row) {
$timeInGame = floor($row['gq_time'] / 60) % 60;
echo '
<tr>
<td>'.$row['name'].'</td>
<td>'.$row['score'].'</td>
<td>'.$timeInGame.' мин.</td>
<th scope="row">'.$row['id'].'</th>
<td>'.htmlspecialchars($row['gq_name']).'</td>
<td>'.$row['gq_score'].'</td>
<td>'.secToStrDate($row['gq_time']).'</td>
</tr>
';
}
?>
</tbody>
}?>
</tbody>
</table>
</div>
</div>
<?php endif;?>
<!-- table // -->
</div>
</div>
</div>
</div>
<?php else:?>
<div class="animated zoomIn mess mess-error"><span>Сервер недоступен</span></div>
<?php endif;?>
<?php
break;

Expand Down
Loading

0 comments on commit bd82d0c

Please sign in to comment.