Some adjustments to script and template

This commit is contained in:
sfan5
2024-10-04 11:28:26 +02:00
parent 967c1a0b51
commit df032cb47c
4 changed files with 89 additions and 82 deletions

View File

@@ -15,7 +15,7 @@ First install node.js, e.g.:
Then install doT.js and its dependencies:
$ npm install dot 'commander@12.0.0' mkdirp
$ npm install dot 'commander@11.1.0' mkdirp
And finally compile the template:
@@ -32,12 +32,12 @@ Embedding the server list in a page
...
<script>
var master = {
root: 'http://servers.minetest.net/',
root: 'https://servers.minetest.net/',
limit: 10,
clients_min: 1,
no_flags: 1,
no_ping: 1,
no_uptime: 1
no_flags: true,
no_ping: true,
no_uptime: true
};
</script>
...
@@ -46,9 +46,8 @@ Embedding the server list in a page
...
<div id="server_list"></div>
...
<script src="https://servers.minetest.net/list.js"></script>
</body>
<script src="list.js"></script>
Setting up the server
---------------------
@@ -61,19 +60,16 @@ Setting up the server
2. Install required Python packages:
# You might have to use pip3 if your system defaults to Python 2
pip install -r requirements.txt
pip3 install -r requirements.txt
3. If using in production, install uwsgi and it's python plugin:
3. If using in production, install uwsgi and its python plugin:
pacman -S uwsgi uwsgi-plugin-python
# OR:
apt-get install uwsgi uwsgi-plugin-python
# OR:
pip install uwsgi
apt-get install uwsgi uwsgi-plugin-python3
4. Configure the server by adding options to `config.py`.
See `config-example.py` for defaults.
See `config-example.py` for defaults.
5. Start the server:
@@ -83,8 +79,8 @@ Setting up the server
$ # Then configure according to http://flask.pocoo.org/docs/deploying/uwsgi/
7. (optional) Configure the proxy server, if any. You should make the server
load static files directly from the static directory. Also, `/list`
should be served from `list.json`. Example for nginx:
load static files directly from the static directory. Also, `/list`
should be served from `list.json`. Example for nginx:
root /path/to/server/static;
rewrite ^/list$ /list.json;
@@ -94,35 +90,32 @@ Setting up the server
}
Setting up the server (Apache version)
---------------------
--------------------------------------
If you wish to use Apache to host the server list, do steps 1-2, 4, above. Additionally install/enable mod_wsgi and an Apache site config like the following:
# This config assumes you have the server list at DocumentRoot.
# Visitors to the server list in this config would visit http://local.server/ and
# apache would serve up the output from server.py. Static resources would be served
# from http://local.server/static.
# This config assumes you have the server list at DocumentRoot.
# Visitors to the server list in this config would visit http://local.server/ and
# apache would serve up the output from server.py. Static resources would be served
# from http://local.server/static.
# Where are the minetest-server files located?
DocumentRoot /var/games/minetest/serverlist
# Where are the minetest-server files located?
DocumentRoot /var/games/minetest/serverlist
# Serve up server.py at the root of the URL.
WSGIScriptAlias / /var/games/minetest/serverlist/server.py
# Serve up server.py at the root of the URL.
WSGIScriptAlias / /var/games/minetest/serverlist/server.py
# The name of the function that we call when we invoke server.py
WSGICallableObject app
# The name of the function that we call when we invoke server.py
WSGICallableObject app
# These options are necessary to enable Daemon mode. Without this, you'll have strange behavior
# with servers dropping off your list! You can tweak threads as needed. See mod_wsgi documentation.
WSGIProcessGroup minetest-serverlist
WSGIDaemonProcess minetest-serverlist threads=2
# These options are necessary to enable Daemon mode. Without this, you'll have strange behavior
# with servers dropping off your list! You can tweak threads as needed. See mod_wsgi documentation.
WSGIProcessGroup minetest-serverlist
WSGIDaemonProcess minetest-serverlist threads=2
<Directory /var/games/minetest/serverlist>
Require all granted
</Directory>
</VirtualHost>
<Directory /var/games/minetest/serverlist>
Require all granted
</Directory>
License
-------

View File

@@ -1,16 +1,21 @@
var master;
if (!master) master = {};
if (typeof(master.root) == 'undefined') master.root = window.location.href;
if (!master.output) master.output = '#server_list';
if (!master.list) master.list = "list";
if (!master.list_root) master.list_root = master.root;
if (!master.list_url) master.list_url = master.list_root + master.list;
if (!master)
master = {};
if (!master.root)
master.root = window.location.href;
if (!master.list)
master.list = "list";
if (!master.list_root)
master.list_root = master.root;
if (!master.list_url)
master.list_url = master.list_root + master.list;
master.cached_json = null;
// Utility functions used by the templating code
function humanTime(seconds) {
if (typeof(seconds) != "number") return '?';
if (typeof(seconds) != "number")
return '?';
var conv = {
y: 31536000,
d: 86400,
@@ -26,25 +31,25 @@ function humanTime(seconds) {
}
function escapeHTML(str) {
if(!str) return str;
if (!str)
return str;
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
function addressString(server) {
var isIPv6 = server.address.indexOf(":") != -1;
var addrStr = (isIPv6 ? '[' : '') +
escapeHTML(server.address) +
(isIPv6 ? ']' : '');
var addrStr = server.address;
if (addrStr.indexOf(':') != -1)
addrStr = '[' + addrStr + ']';
var shortStr = addrStr;
addrStr += ':' + server.port;
var str = '<span'
if (shortStr.length > 25) {
shortStr = shortStr.substr(0, 23) + "&hellip;";
str += ' title="' + addrStr + '"'
if (shortStr.length > 26) {
shortStr = shortStr.substring(0, 25) + "\u2026";
str += ' title="' + escapeHTML(addrStr) + '"'
}
if (server.port != 30000)
shortStr += ':' + server.port;
return str + '>' + shortStr + '</span>';
return str + '>' + escapeHTML(shortStr) + '</span>';
}
function tooltipString(str) {
@@ -53,30 +58,36 @@ function tooltipString(str) {
}
function hoverList(name, list) {
if (!list || list.length == 0) return '';
if (!list || list.length == 0)
return '';
var str = '<div class="mts_hover_list">'
str += '<b>' + name + '</b> (' + list.length + ')<br />';
str += '<b>' + escapeHTML(name) + '</b> (' + list.length + ')<br />';
for (var i in list) {
str += escapeHTML(list[i]) + '<br />';
}
return str + '</div>';
}
function hoverString(name, string) {
if (!string) return '';
function hoverString(name, str) {
if (!str)
return '';
if (typeof(str) != 'string')
str = str.toString();
return '<div class="mts_hover_list">'
+ '<b>' + name + '</b>:<br />'
+ escapeHTML(string) + '<br />'
+ '<b>' + escapeHTML(name) + '</b>:<br />'
+ escapeHTML(str) + '<br />'
+ '</div>';
}
function constantWidth(str, width) {
return '<span class="mts_cwidth" style="width:' + width + 'em;">' + str + '</span>';
if (typeof(str) != 'string')
str = str.toString();
return '<span class="mts_cwidth" style="width:' + width + 'em;">' + escapeHTML(str) + '</span>';
}
// Code that fetches & displays the actual list
function draw(json) {
master.draw = function(json) {
if (json == null)
return;
@@ -95,27 +106,32 @@ function draw(json) {
}
var html = window.render.servers(json);
jQuery(master.output).html(html);
jQuery('#server_list').html(html);
jQuery('.proto_select', master.output).on('change', function(e) {
jQuery('.proto_select', '#server_list').on('change', function(e) {
master.proto_range = e.target.value;
draw(master.cached_json); // re-render
master.draw(master.cached_json); // re-render
});
}
};
function get() {
master.get = function() {
jQuery.getJSON(master.list_url, function(json) {
master.cached_json = json;
draw(json);
master.draw(json);
});
}
};
function loaded(){
if (!master.no_refresh) {
setInterval(get, 60 * 1000);
}
get();
}
master.loaded = function() {
if (!master.no_refresh)
setInterval(master.get, 60 * 1000);
master.get();
};
master.showAll = function() {
delete master.min_clients;
delete master.limit;
master.get();
};
// https://github.com/pyrsmk/toast
@@ -123,8 +139,8 @@ this.toast=function(){var e=document,t=e.getElementsByTagName("head")[0],n=this.
toast(master.root + 'style.css', master.root + 'servers.js', function() {
if (typeof(jQuery) != 'undefined')
return loaded();
return master.loaded();
else
toast('//ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js', loaded);
toast('//ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js', master.loaded);
});

View File

@@ -16,7 +16,7 @@
<thead><tr>
{{? !master.no_address}}<th>Address[:Port]</th>{{?}}
{{? !master.no_clients}}<th>Players / Max{{? !master.no_avgtop}}<br/>Average / Top{{?}}</th>{{?}}
{{? !master.no_version}}<th class="version">Version, Game[, Mapgen]</th>{{?}}
{{? !master.no_version}}<th class="version">Version, Game, Mapgen</th>{{?}}
{{? !master.no_name}}<th>Name</th>{{?}}
{{? !master.no_description}}<th>Description</th>{{?}}
{{? !master.no_flags}}<th class="flags">Flags</th>{{?}}
@@ -47,7 +47,7 @@
{{? !master.no_name}}
<td class="name">
{{? server.url}}
<a href="{{!server.url}}">{{=tooltipString(server.name)}}</a>
<a href="{{!server.url}}" target="_blank">{{=tooltipString(server.name)}}</a>
{{??}}
{{=tooltipString(server.name)}}
{{?}}
@@ -63,8 +63,6 @@
{{=server.damage ? 'Dmg ' : ''}}
{{=server.pvp ? 'PvP ' : ''}}
{{=server.password ? 'Pwd ' : ''}}
{{=server.rollback ? 'Rol ' : ''}}
{{=server.can_see_far_names ? 'Far ' : ''}}
</td>{{?}}
{{? !master.no_uptime}}
<td class="uptime">
@@ -79,5 +77,5 @@
</tbody>
</table>
{{? master.min_clients || master.limit}}
<a href="javascript:delete master.min_clients; delete master.limit; get();">Show more...</a>
<a href="javascript:master.showAll()">Show all...</a>
{{?}}

View File

@@ -50,7 +50,7 @@
max-width: 32ch;
}
#server_list td.description {
max-width: 64ch;
max-width: 70ch;
}
.mts_hover_list {