Skip to content

Commit

Permalink
Removed couple warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tltneon committed Dec 27, 2024
1 parent 16d0e1c commit dfa8173
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 72 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
php
*.db
*.log
*.cache
*.phar
*.bat
15 changes: 10 additions & 5 deletions charts.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ function findMax(&$server) {
}
return $max + 1;
}
require "src/lgsl_class.php";
if (!LGSL::isEnabled("gd")) {
echo 'No GD ';
exit;
}

// SETTINGS
$w = 400;
$h = 150;
$im = @imagecreate($w, $h);
$im = @\imagecreate($w, $h);
$white = imagecolorallocate($im, 255, 255, 255);
$gray = imagecolorallocate($im, 225, 225, 225);
$black = imagecolorallocate($im, 0, 0, 0);
Expand All @@ -24,7 +29,6 @@ function findMax(&$server) {

// MAIN SECTION
header("Content-Type: image/png");
require "src/lgsl_class.php";
$s = (int) ($_GET['s'] ?? null);
$ip = $_GET['ip'] ?? null;
$port = (int) ($_GET['port'] ?? null);
Expand Down Expand Up @@ -78,9 +82,10 @@ function findMax(&$server) {
}
imagestring($im, 1, $x0 - 6, $maxY + 2, Date($timeFormat, time() - $period), $black);
for ($i = 1; $i < $xSteps + 1; $i++) {
imageline($im, $x0 + $xStep * $i, $y0, $x0 + $xStep * $i, $maxY - 1, $gray);
$str = Date($timeFormat, time() - $period + (int) ($i * round($xStep / $scaleX, 1)));
imagestring($im, 1, (($x0 + $xStep * $i) - 6), $maxY + 2, $str, $black);
$calcX = (int) ($x0 + $xStep * $i);
imageline($im, $calcX, $y0, $calcX, $maxY - 1, $gray);
$str = Date($timeFormat, time() - $period + (int) ($i * round($xStep / $scaleX, 1)));
imagestring($im, 1, ($calcX - 6), $maxY + 2, $str, $black);
}

if (count($history) > 0) {
Expand Down
3 changes: 3 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ function alertContents() {
?>
<select name='language' onChange='changeLang(event)'>
<?php
if (!isset($_COOKIE['lgsl_lang'])) {
$_COOKIE['lgsl_lang'] = tltneon\LGSL\Lang::EN;
}
foreach (tltneon\LGSL\Lang::list() as $lang) {
$select = $_COOKIE['lgsl_lang'] === $lang ? "selected": "";
echo "<option {$select}>{$lang}</option>";
Expand Down
33 changes: 31 additions & 2 deletions src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ static public function locationCoords($code) {
static public function normalizeString($string) {
return preg_replace("/[^a-z0-9_]/", "_", strtolower($string));
}
static public function showWarning($message) {
trigger_error($message, E_USER_WARNING);
}
}
//------------------------------------------------------------------------------------------------------------+
class Database {
Expand Down Expand Up @@ -517,7 +520,11 @@ class SqliteWrapper extends DBWrapper {
public $_id = 'rowid';
public function connect() {
global $lgsl_file_path, $lgsl_config;
$this->_connection = new \SQLite3("$lgsl_file_path/{$lgsl_config['db']['db']}.db");
try {
$this->_connection = new \SQLite3("$lgsl_file_path/{$lgsl_config['db']['db']}.db");
} catch (\Error $e) {
throw new \Exception("Failed to connect to SQLite database: {$e->getMessage()}");
}
}
public function get_error() {
if ($this->_connection->lastErrorCode())
Expand Down Expand Up @@ -810,7 +817,7 @@ public function getHistoryArray() {
public function getExtrasArray() {
return $this->_extra ?? [];
}
public function getName($html = true) {
public function getName($html = false) {
if ($this->isPending()) {
return LGSL::NONE;
}
Expand Down Expand Up @@ -1218,3 +1225,25 @@ function toString() {
$output .= "
</select>";
}
function shutdown() {
$e = error_get_last();
if ($e) {
if ($e['type'] === E_ERROR) {
$msg = isset($e['message']) ? $e['message'] : '';
$msg = str_replace(array('Uncaught Exception:','Stack trace:')
,array('<b>Uncaught Exception:</b><br />',
'<b>Stack trace:</b>'),$msg);
$msg = preg_replace('/[a-z0-9_\-]*\.php/i','$1<u>$0</u>',$msg);
$msg = preg_replace('/[0-9]/i','$1<em>$0</em>',$msg);
$msg = preg_replace('/[\(\)#\[\]\':]/i','$1<ss>$0</ss>',$msg);

echo "<style>
u{color:#ed6;text-decoration:none;} b{color:#ddd;letter-spacing:1px;} em{color:#cfc;font-style:normal;} ss{color:white;}
h2{letter-spacing:1px;font-size:1.5rem;color:#b8b;margin-top:0;} br{margin-bottom:1.8rem;}
.prettyphp{margin:3rem auto;line-height:1.4em;padding:2rem;background:#ffffff1a;font-size:1.1rem;border-radius:0.5rem;max-width:1000px;font-family:monospace;}
</style>
<div class='prettyphp'><h2>Fatal PHP error</h2><div>".nl2br($msg)."</div></div>";
}
}
}
register_shutdown_function('tltneon\LGSL\shutdown');
91 changes: 27 additions & 64 deletions src/lgsl_zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$zone_width = "{$lgsl_config['zone']['width']}px";
$zone_grid = $lgsl_config['grid'][$lgsl_zone_number] ?? 1;
$zone_count = 0;
$output = '';
$output = "<link rel='stylesheet' href='other/_lgsl_zone.css' type='text/css' />";

$request = empty($lgsl_config['players'][$lgsl_zone_number]) ? "s" : "sp";
if ($lgsl_zone_number) {
Expand All @@ -36,7 +36,7 @@
//$server_list = lgsl_sort_servers($server_list);

if (!$server_list) {
$output .= "<div style='margin:auto; text-align:center'>NO SERVERS IN ZONE {$lgsl_zone_number}</div>"; return;
$output .= "<div class='center'>NO SERVERS IN ZONE {$lgsl_zone_number}</div>"; return;
}

$output .= "
Expand All @@ -50,48 +50,12 @@
color: $link;
text-decoration:none;
}
.sidebarserver * {
scrollbar-width: thin;
scrollbar-color: black gray;
}
.sidebarserver *::-webkit-scrollbar {
height: 12px;
width: 12px;
}
.sidebarserver *::-webkit-scrollbar-track {
background: gray;
}
.sidebarserver *::-webkit-scrollbar-thumb {
background-color: black;
border-radius: 5px;
border: 3px solid gray;
}
.sidebarserver img {
border: none;
}
.marquee {
width:100%;
white-space:nowrap;
overflow:hidden;
}
.marquee span.on {
display:inline-block;
animation: marquee 10s infinite linear alternate;
}
.sidebarserver table:hover .marquee span.on {
animation: marquee 4s infinite linear alternate;
}
@keyframes marquee{
0%{transform: translateX(15px);}
100%{transform: translateX(calc(-100% + {$zone_width} - 15px));}
}
</style>
<table cellpadding='0' cellspacing='0' style='width:100%; margin:auto; text-align:center' class='sidebarserver'>
<table cellpadding='0' cellspacing='0' style='width:100%;' class='sidebarserver center'>
<tr>";

foreach ($server_list as $server) {
Expand All @@ -105,14 +69,18 @@
$zone_count ++;

$marquee = strlen($server->getName()) > 25 ? "class='on'" : "";
$location = "";
if ($lgsl_config['locations']) {
$location = "<img class='details_location_image flag f{$server->getLocation()} abs z2 t2 r2' title='{$server->getLocationFormatted()}' alt=''>";
}
$output .= "
<td style='vertical-align:top;'>
<table style='width:{$zone_width}; margin:auto; text-align:center;' cellpadding='0' cellspacing='2'>
<table style='width:{$zone_width};' cellpadding='0' cellspacing='2' class='center'>
<tr>
<td title='{$lang->get('slk')}' style='padding:0px;'>
<div style='width:{$zone_width}; white-space:nowrap; overflow:hidden;'>
<td class='p0' title='{$lang->get('slk')}'>
<div class='nooverflow' style='width:{$zone_width};'>
<a href='{$server->getConnectionLink()}'>
{$server->getAddress()}
</a>
Expand All @@ -121,34 +89,29 @@
</tr>
<tr>
<td title='{$server->getName()}' style='padding:0px;'>
<div class='marquee' style='width:{$zone_width}; white-space:nowrap; overflow:hidden;'>
<td class='p0' title='{$server->getName()}'>
<div class='marquee nooverflow' style='width:{$zone_width};'>
<span {$marquee}>{$server->getName()}</span>
</div>
</td>
</tr>
<tr>
<td style='padding:0px;'>
<div style='width:{$zone_width}; padding:0px; position:relative'>
<td class='p0'>
<div class='p0' style='width:{$zone_width}; position:relative'>
<a href='".LGSL::link($server->getIp(), $server->getConnectionPort())."' target='_blank'>
<img alt='' src='{$server->getMapImage()}' title='{$lang->get('vsd')}' style='vertical-align:middle; width: 100%; border-radius: 4px;'>
<img alt='' src='{$server->mapPasswordImage()}' title='{$lang->get('vsd')}' style='position:absolute; z-index:2; bottom:2px; right:2px;'>
<img alt='' src='{$server->addUrlPath($server->getGameIcon())}' title='{$server->getGameFormatted()}' style='position:absolute; z-index:2; top:2px; left:2px; width: 24px; border-radius: 4px;'>
";
if ($lgsl_config['locations'])
$output .= "
<img alt='' class='details_location_image flag f{$server->getLocation()}' title='{$server->getLocationFormatted()}' style='position:absolute; z-index:2; top:2px; right:2px;'>
";
$output .= "
<img class='rounded' src='{$server->getMapImage()}' title='{$lang->get('vsd')}' style='vertical-align:middle; width: 100%;' alt=''>
<img class='abs z2 b2 r2' src='{$server->mapPasswordImage()}' title='{$lang->get('vsd')}' alt=''>
<img class='abs z2 t2 l2 rounded' src='{$server->addUrlPath($server->getGameIcon())}' title='{$server->getGameFormatted()}' style='width: 24px;' alt=''>
{$location}
</a>
</div>
</td>
</tr>
<tr>
<td title='{$lang->get('map')}: {$server->getMap()}' style='padding:0px;'>
<div style='width:{$zone_width}; white-space:nowrap; overflow:hidden;'>
<td class='p0' title='{$lang->get('map')}: {$server->getMap()}'>
<div class='nooverflow' style='width:{$zone_width};'>
{$server->getMap()}
</div>
</td>
Expand All @@ -160,16 +123,16 @@

$output .= "
<tr>
<td style='border-radius: 4px;'>
<span style='padding:1px; float:left'> {$lang->get('zpl')} </span>
<span style='padding:1px; float:right'> {$server->getPlayersCountFormatted()} </span>";
<td class='p0 rounded'>
<span class='p1' style='float:left'> {$lang->get('zpl')} </span>
<span class='p1' style='float:right'> {$server->getPlayersCountFormatted()} </span>";
$players = $server->getPlayersArray();
if (count($players) > 0) {
$output .= "<div style='width:{$zone_width}; height:{$zone_height}; border-top: 1px solid #8080807a; overflow: overlay; text-align:left'>";

foreach ($players as $player) {
$output .= "
<div style='padding:1px; white-space:nowrap; overflow:hidden; text-align:left' title='{$player['name']}'> {$player['name']} </div>";
<div class='nooverflow p1' style='text-align:left' title='{$player['name']}'> {$player['name']} </div>";
}

$output .= "</div";
Expand All @@ -187,9 +150,9 @@
} else {
$output .= "
<tr>
<td style='padding:0px; border:1px solid; border-radius: 4px;'>
<span style='padding:1px; float:left'> {$lang->get('zpl')} </span>
<span style='padding:1px; float:right'> {$server->getPlayersCount()} </span>
<td class='p0 rounded' style='border:1px solid;'>
<span class='p1' style='float:left'> {$lang->get('zpl')} </span>
<span class='p1' style='float:right'> {$server->getPlayersCount()} </span>
</td>
</tr>";
}
Expand Down
Loading

0 comments on commit dfa8173

Please sign in to comment.