Skip to content

Commit

Permalink
Added Refresh script (allow refresh basic server info without reloadi…
Browse files Browse the repository at this point in the history
…ng page), fixed Preview script working with any languages
  • Loading branch information
tltneon committed Jun 4, 2021
1 parent 99e6303 commit 419f1c1
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 20 deletions.
3 changes: 1 addition & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta http-equiv='content-style-type' content='text/css' />
<link rel='stylesheet' href='lgsl_files/styles/<?php echo $lgsl_config['style']; ?>' type='text/css' />
<?php echo ($lgsl_config['autoreload'] ? "<META HTTP-EQUIV='REFRESH' CONTENT=" . $lgsl_config['cache_time'] + 1 . " />" : ""); ?>
</head>

<body>

<div id="topmenu">
<li><a href="../../"><?php echo $lgsl_config['text']['mpg']; ?></a></li>
<?php if($lgsl_config['public_add']) echo '<li><a href="?s=add">'.$lgsl_config["text"]["aas"].'</a></li>';?>
Expand All @@ -32,7 +32,6 @@
//------------------------------------------------------------------------------------------------------------+
global $output, $lgsl_server_id;


$s = isset($_GET['s']) ? $_GET['s'] : "";

if (is_numeric($s)) { $lgsl_server_id = $s; require "lgsl_files/lgsl_details.php"; }
Expand Down
31 changes: 21 additions & 10 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@
<input type="checkbox" name="page_mod" onChange="changeCheckbox(event)" />
<input type="number" min="5" max="35" value="15" onChange="vars.page_lim = event.target.value" />
</p>
<p>
Automatically reload page:
<input type="checkbox" name="autoreload" onChange="changeCheckbox(event)" />
</p>
<p>
Time before a server needs updating:
<input type="number" min="0" max="3600" value="60" onChange="vars.cache_time = event.target.value" />
</p>
<p>
<l k="hideo"></l>:
<input type="checkbox" name="hide_offline" onChange="changeCheckbox(event)" />
Expand Down Expand Up @@ -316,6 +324,8 @@ function reloadLocale(){
image_mod: false,
page_mod: false,
page_lim: 15,
autoreload: false,
cache_time: 60,
hide_offline: false,
public_add: false,
totals: false,
Expand Down Expand Up @@ -434,7 +444,8 @@ function generateConfig()
"$lgsl_config['host_to_ip'] = 0; // 1=show the servers ip instead of its hostname \n" +
"$lgsl_config['public_add'] = "+ vars.public_add +"; // 1=servers require approval OR 2=servers shown instantly \n" +
"$lgsl_config['public_feed'] = 0; // 1=feed requests can add new servers to your list \n" +
"$lgsl_config['cache_time'] = 60; // seconds=time before a server needs updating \n" +
"$lgsl_config['cache_time'] = "+ vars.cache_time +"; // seconds=time before a server needs updating \n" +
"$lgsl_config['autoreload'] = "+ vars.autoreload +"; // 1=reloads page when cache_time is passed \n" +
"$lgsl_config['live_time'] = 3; // seconds=time allowed for updating servers per page load \n" +
"$lgsl_config['timeout'] = 0; // 1=gives more time for servers to respond but adds loading delay \n" +
"$lgsl_config['retry_offline'] = 0; // 1=repeats query when there is no response but adds loading delay \n" +
Expand Down Expand Up @@ -470,7 +481,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -498,7 +509,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -526,7 +537,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -554,7 +565,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -582,7 +593,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -610,7 +621,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -638,7 +649,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -666,7 +677,7 @@ function l(key){
"owiki": "Online Wiki: Ako na to",
"gener": "Vytvoriť konfiguráciu",
"creat": "Vytvoriť tabuľky",
"filla": "Musíš vyplniť povinné* údaje (krok 2).",
"filla": "Musíš vyplniť povinné* údaje (krok 1 or 2).",
"mysld": "Pripojenie <span style='color: red;'>Zlyhalo</span>: PHP rozšírenie mysqli nie je aktívne.",
"table": "LGSL <span style='color: red;'>tabulka nebola vytvorená</span>: nesprávny názov databázy alebo tabuľka už existuje.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down Expand Up @@ -694,7 +705,7 @@ function l(key){
"owiki": "Online Wiki: How to",
"gener": "Generate config",
"creat": "Create table",
"filla": "You need to fill required* inputs (step 2).",
"filla": "You need to fill required* inputs (step 1 or 2).",
"mysld": "Connect <span style='color: red;'>failed</span>: mysqli extension doesn't active.",
"table": "LGSL <span style='color: red;'>table wasn't created</span>: wrong database name or table already exists.",
"cretd": "Table <span style='color: green;'>successfully</span> created! Get to Step 2.",
Expand Down
2 changes: 1 addition & 1 deletion lgsl_files/lgsl_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
//------------------------------------------------------------------------------------------------------------+
// ADD THE FEED PROVIDER

if ($server['e']) { $server['e']['_feed_'] = "http://{$_SERVER['HTTP_HOST']}"; }
if (isset($server['e'])) { $server['e']['_feed_'] = "http://{$_SERVER['HTTP_HOST']}"; }

//------------------------------------------------------------------------------------------------------------+
// FEED USAGE LOGGING - 'logs' FOLDER MUST BE MANUALLY CREATED AND SET AS WRITABLE
Expand Down
16 changes: 9 additions & 7 deletions lgsl_files/scripts/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function imageExists(image_url){
var http = new XMLHttpRequest();
http.open('HEAD', image_url, false);
http.open('HEAD', 'lgsl_files/maps/' + image_url, false);
http.send();
return http.status != 404;
}
Expand All @@ -10,13 +10,14 @@ document.querySelectorAll('#server_list_table > tbody > tr > td.map_cell').forEa
let map = a.innerHTML.trim();
if(map != '--'){
let el = document.createElement('img');
let type = types[b].title.match(/Type: [\w]*/)[0].slice(6);
let game = types[b].title.match(/Game: [\w]*/)[0].slice(6);
let arr = types[b].title.match(/(\w{1,} \])/i)
let type = arr[0].slice(0, -2);
let game = arr[1].slice(0, -2);
let pathes = [
'lgsl_files/maps/' + type + '/' + game + '.jpg',
'lgsl_files/maps/' + type + '/' + game + '.png',
'lgsl_files/maps/' + type + '/' + game + '/' + map + '.jpg',
'lgsl_files/maps/' + type + '/' + game + '/' + map + '.png'
type + '/' + game + '.jpg',
type + '/' + game + '.png',
type + '/' + game + '/' + map + '.jpg',
type + '/' + game + '/' + map + '.png'
]
path = 'lgsl_files/other/map_no_image.jpg';
pathes.forEach(a => {
Expand All @@ -29,6 +30,7 @@ document.querySelectorAll('#server_list_table > tbody > tr > td.map_cell').forEa
el.style.height = '188px';
el.style.display = 'none';
el.style.position = 'absolute';
el.style.marginTop = '5px';
el.className = 'mapImage' + b;
a.appendChild(el);

Expand Down
59 changes: 59 additions & 0 deletions lgsl_files/scripts/refresh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function cl(){
let vars = document.querySelectorAll(".details_info .details_info_srow .details_info_ceil:nth-child(2)");
if(vars){
refreshData(vars[4].innerText, vars[1].innerText, vars[2].innerText, vars[3].innerText);
}
}
async function refreshData(type = 'source', ip, c_port, q_port){
let response = await fetch('lgsl_files/lgsl_feed.php?type='+type+'&ip='+ip+'&c_port='+c_port+'&q_port='+q_port+'&request=s&format=3');
if (response.ok) {
let status = await response.text();
status = JSON.parse(atob(status.slice(4, -4)));
let details = document.querySelectorAll(".details_info .details_info_srow .details_info_ceil:nth-child(2)");
details[0].innerText = (status.b.status == "1"
? (status.s.password == "1"
? "ONLINE WITH PASSWORD"
: "ONLINE")
: "OFFLINE");
details[6].innerText = status.s.map;
details[7].innerText = status.s.players + " / " + status.s.playersmax;
document.querySelector('[id^=servername]').innerText = status.s.name;
document.querySelector(".details_info_row:last-child").innerText = "Last update: " + (new Date()).toUTCString() + "\nServer last query: " + (new Date(Number(status.s.cache_time + '000'))).toUTCString() + " ";
a.appendChild(el);
}
else {
alert("HTTP Error: " + response.status);
}
}

let a = document.querySelector(".details_info_row:last-child");
let el = document.createElement("a");
if(a) {
el.onclick = () => {
cl();
}
a.appendChild(el);
el.innerText = "🔃";
let st = document.createElement("style");
st.innerText = `
.details_info_row:last-child a {
display: inline-block;
color: aliceblue;
transition-duration: 1s;
animation: loader 1.1s infinite linear;
font-size: 14px;
}
.details_info_row:last-child a:hover {
color: crimson;
cursor: pointer;
}
@keyframes loader {
0% {transform:rotate(45deg)}
25% {transform:rotate(90deg)}
50% {transform:rotate(135deg)}
75% {transform:rotate(180deg)}
100% {transform:rotate(225deg)}
}`;
document.body.appendChild(st);
}

0 comments on commit 419f1c1

Please # to comment.