Skip to content

Commit

Permalink
Charts now shows $lgsl_config['history_hours'] hours of server's history
Browse files Browse the repository at this point in the history
  • Loading branch information
tltneon committed Apr 8, 2024
1 parent 519ab3e commit 55782c2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
4 changes: 3 additions & 1 deletion charts.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function findMax(&$server) {
$max = $server->get_players_count('max') > 0 ? $server->get_players_count('max') : findMax($server);
$x0 = 30;
$y0 = 20;
$period = 60 * 60 * 24; // 1 day
global $lgsl_config;
$period = 3600 * $lgsl_config['history_hours'];
$xStep = 30;
$yStep = (int) ($max > 32 ? 9 : 100 / $max) + 1;

Expand Down Expand Up @@ -138,6 +139,7 @@ function findMax(&$server) {
imagettftext($im, 7, 0, 28, 8, $black, $font, $lgsl_config['text']['nam'] . ": " . trim($server->get_name(false)));
imagettftext($im, 6, 0, 27, 17, $black, $font, $lgsl_config['text']['adr'] . ": " . str_replace('https://', '', $server->get_address()));
imagettftext($im, 6, 0, $w - 52, 17, $black, $font, date($lgsl_config['text']['tzn']));
imagettftext($im, 6, 0, $w - 110, $h-3, $black, $font, "Shows last {$lgsl_config['history_hours']} hours");

$s = (isset($_SERVER['HTTPS']) ? 's' : '');
header("Link: <http{$s}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}>; rel=\"canonical\"");
Expand Down
15 changes: 7 additions & 8 deletions src/lgsl_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@
//------------------------------------------------------------------------------------------------------------+

if (!empty($_POST['lgsl_check_updates'])) {
$context = stream_context_create(["http" => ["header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"]]);
$lgsl_fp = file_get_contents("https://api.github.com/repos/tltneon/lgsl/branches/lgsl7", false, $context);
if (!$lgsl_fp) {
$stream = new Stream(PROTOCOL::HTTP);
$stream->open();
$stream->write("https://api.github.com/repos/tltneon/lgsl/branches/lgsl7");
$buffer1 = $stream->readJson();
if (!$buffer1) {
$output .= "
<div class='tt'>
CAN'T LOAD DATA FROM GITHUB.COM -> NO INTERNET CONNECTION?
Expand All @@ -137,10 +139,8 @@
";
return;
}
$buffer1 = json_decode($lgsl_fp, true);

$lgsl_fp = file_get_contents("https://api.github.com/repos/tltneon/lgsl/releases/latest", false, $context);
$buffer2 = json_decode($lgsl_fp, true);
$stream->write("https://api.github.com/repos/tltneon/lgsl/releases/latest");
$buffer2 = $stream->readJson();

$blocks = [
["Latest commit (LGSL7)", $buffer1["commit"]["commit"]["message"], date($lgsl_config['text']['tzn'], strtotime($buffer1["commit"]["commit"]["author"]["date"])), "https://github.com/tltneon/lgsl/archive/refs/heads/lgsl7.zip", $buffer1["commit"]["html_url"]],
Expand Down Expand Up @@ -168,7 +168,6 @@
</div>
" . lgsl_return_buttons() . "
";

return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public function lgsl_live_query($request = 'seph') {
if ($lgsl_config['history'] and LGSL::requestHas($request, "h") and $this->get_status() != self::PENDING) {
$last = end($this->_history);
if (!$last || time() - $last['t'] >= 60 * 15) { // RECORD IF 15 MINS IS PASSED
$history_limit = $lgsl_config['history_hours'] * 60 * 60;
$history_limit = $lgsl_config['history_hours'] * 3600;
foreach ($this->_history as $key => $value) {
if (time() - $this->_history[$key]['t'] > $history_limit) { // NOT OLDER THAN $lgsl_config['history_hours'] HOURS
unset($this->_history[$key]);
Expand Down
16 changes: 5 additions & 11 deletions src/lgsl_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
$fields = $server->sort_player_fields();
//$server = lgsl_sort_players($server->get_players());
//$server = lgsl_sort_extras($server->get_extras());
//$server = lgsl_server_html($server);

//------------------------------------------------------------------------------------------------------------+

Expand Down Expand Up @@ -108,16 +107,11 @@

if ($lgsl_config['image_mod']) {
if (extension_loaded('gd')) {
$output .= "
<div style='overflow-x: auto;'><img src='userbar.php?{$g}' alt='{$server->get_name()}'/></div>
<textarea onClick='this.select();'>[url={$p}?{$g}][img]{$p}userbar.php?{$g}[/img][/url]</textarea><br /><br />
<div style='overflow-x: auto;'><img src='userbar.php?{$g}&t=2' alt='{$server->get_name()}'/></div>
<textarea onClick='this.select();'>[url={$p}?{$g}][img]{$p}userbar.php?{$g}&t=2[/img][/url]</textarea><br /><br />
<img src='userbar.php?{$g}&t=3' alt='{$server->get_name()}'/><br />
<textarea onClick='this.select();'>[url={$p}?{$g}][img]{$p}userbar.php?{$g}&t=3[/img][/url]</textarea>
";
for ($i = 1; $i < 4; $i++) {
$output .= "
<div style='overflow-x: auto;'><img src='userbar.php?{$g}&t={$i}' alt='{$server->get_name()}'/></div>
<textarea onClick='this.select();'>[url={$p}?{$g}][img]{$p}userbar.php?{$g}&t={$i}[/img][/url]</textarea><br /><br />";
}
} else {
$output .= "<div id='invalid_server_id'> Error while trying to display image userbar: GD library not loaded (see php.ini) </div>";
}
Expand Down
2 changes: 1 addition & 1 deletion src/lgsl_protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@ public function __construct($protocol) {
private function _isHttp() {
return $this->_protocol === Protocol::HTTP;
}
public function open(&$server) {
public function open(&$server = null) {
global $lgsl_config;
if ($this->_isHttp()) {
if (!LGSL::isEnabled("curl")) return false;
Expand Down
5 changes: 3 additions & 2 deletions userbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function drawHistory(&$im, $x, $y, $w, $h, &$server) {
$grid = imagecolorallocate($im, 90, 90, 90);
$chart = imagecolorallocate($im, 120, 255, 120);
$x0 = $y0 = [];
$period = 60 * 60 *24;
global $lgsl_config;
$period = 3600 * $lgsl_config['history_hours'];
$history = $server->get_history();
$avg = 0; $avgc = 0;
foreach ($history as $key) {
Expand Down Expand Up @@ -52,7 +53,7 @@ function drawHistory(&$im, $x, $y, $w, $h, &$server) {
imageline($im, $x, $y - 1, $x, $y + $h, $axis);
imageline($im, $x + 1, floor($y + $h / 2), $x + $w - 2, floor($y + $h / 2), $grid);
imageline($im, $x + 1, $y, $x + $w - 2, $y, $grid);
imagestringup($im, 1, $x + $w + 3, $y + $h, "24 hrs", $grid);
imagestringup($im, 1, $x + $w + 3, $y + $h, "{$lgsl_config['history_hours']} hrs", $grid);
imageantialias($im, true);
imagesetthickness($im, 2);
for ($i=1; $i < count($x0); $i++) {
Expand Down

0 comments on commit 55782c2

Please sign in to comment.