mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Royalprint: Mcstatus (#72)
This commit is contained in:
parent
eb028d620b
commit
7331619d6d
8 changed files with 188 additions and 3 deletions
|
@ -15,3 +15,4 @@ PyNaCl>=1.3.0
|
||||||
werkzeug>=0.15.4
|
werkzeug>=0.15.4
|
||||||
flask>=1.0.3
|
flask>=1.0.3
|
||||||
markdown2>=2.3.8
|
markdown2>=2.3.8
|
||||||
|
mcstatus>=2.2.1
|
||||||
|
|
|
@ -8,7 +8,7 @@ class TestConfig:
|
||||||
TG_AK = os.environ["TG_AK"]
|
TG_AK = os.environ["TG_AK"]
|
||||||
|
|
||||||
|
|
||||||
app = create_app(TestConfig, [rp_home, rp_wikiview, rp_tglogin, rp_docs, rp_wikiedit])
|
app = create_app(TestConfig, [rp_home, rp_wikiview, rp_tglogin, rp_docs, rp_wikiedit, rp_mcstatus])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -5,5 +5,6 @@ from .wikiview import rp as rp_wikiview
|
||||||
from .tglogin import rp as rp_tglogin
|
from .tglogin import rp as rp_tglogin
|
||||||
from .docs import rp as rp_docs
|
from .docs import rp as rp_docs
|
||||||
from .wikiedit import rp as rp_wikiedit
|
from .wikiedit import rp as rp_wikiedit
|
||||||
|
from .mcstatus import rp as rp_mcstatus
|
||||||
|
|
||||||
__all__ = ["rp_home", "rp_wikiview", "rp_tglogin", "rp_docs", "rp_wikiedit"]
|
__all__ = ["rp_home", "rp_wikiview", "rp_tglogin", "rp_docs", "rp_wikiedit", "rp_mcstatus"]
|
||||||
|
|
29
royalnet/web/royalprints/mcstatus/__init__.py
Normal file
29
royalnet/web/royalprints/mcstatus/__init__.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""Minecraft server status :py:class:`royalnet.web.Royalprint`."""
|
||||||
|
import os
|
||||||
|
import flask as f
|
||||||
|
import socket
|
||||||
|
from ... import Royalprint
|
||||||
|
from mcstatus import MinecraftServer
|
||||||
|
|
||||||
|
|
||||||
|
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
|
||||||
|
rp = Royalprint("mcstatus", __name__, url_prefix="/mcstatus", template_folder=tmpl_dir)
|
||||||
|
|
||||||
|
|
||||||
|
@rp.route("/<server_str>")
|
||||||
|
def mcstatus_index(server_str: str):
|
||||||
|
try:
|
||||||
|
if ":" not in server_str:
|
||||||
|
server_str += ":25565"
|
||||||
|
server = MinecraftServer.lookup(server_str)
|
||||||
|
status = server.status()
|
||||||
|
try:
|
||||||
|
query = server.query()
|
||||||
|
except (socket.timeout, ConnectionRefusedError, OSError):
|
||||||
|
query = None
|
||||||
|
except socket.gaierror:
|
||||||
|
return "No such address", 404
|
||||||
|
except (socket.timeout, ConnectionRefusedError, OSError):
|
||||||
|
status = None
|
||||||
|
query = None
|
||||||
|
return f.render_template("mcstatus.html", server_str=server_str, status=status, query=query)
|
54
royalnet/web/royalprints/mcstatus/templates/mcstatus.html
Normal file
54
royalnet/web/royalprints/mcstatus/templates/mcstatus.html
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ server_str }} - RYG MCstatus
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="doublebox">
|
||||||
|
<div class="top">
|
||||||
|
<span class="left">Minecraft Status</span>
|
||||||
|
</div>
|
||||||
|
<div class="bot">
|
||||||
|
<div class="mcstatus-grid">
|
||||||
|
{% if query %}
|
||||||
|
{% if status.favicon %}
|
||||||
|
<div class="mcstatus-icon"><img class="mcstatus-icon-img" src="{{ status.favicon }}" alt="Server icon"></div>
|
||||||
|
{% else %}
|
||||||
|
<div class="mcstatus-icon"><div class="mcstatus-icon-img" title="Server icon"></div></div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="mcstatus-address"><span class="server-up">{{ server_str }}</span></div>
|
||||||
|
<div class="mcstatus-description"><span>{{ query.motd }}</span></div>
|
||||||
|
<div class="mcstatus-players"><span>{{ query.players.online }}</span>/<span>{{ query.players.max }}</span></div>
|
||||||
|
<div class="mcstatus-version"><span>{{ query.software.brand }}</span> <span>{{ query.software.version }}</span> (<span>{{ status.version.protocol }}</span>)</div>
|
||||||
|
{% elif status %}
|
||||||
|
{% if status.favicon %}
|
||||||
|
<div class="mcstatus-icon"><img class="mcstatus-icon-img" src="{{ status.favicon }}" alt="Server icon"></div>
|
||||||
|
{% else %}
|
||||||
|
<div class="mcstatus-icon"><div class="mcstatus-icon-img" title="Server icon"></div></div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="mcstatus-address"><span class="server-up">{{ server_str }}</span></div>
|
||||||
|
<div class="mcstatus-description"><span>{{ status.description }}</span></div>
|
||||||
|
<div class="mcstatus-players"><span>{{ status.players.online }}</span>/<span>{{ status.players.max }}</span></div>
|
||||||
|
<div class="mcstatus-version"><span>{{ status.version.name }}</span> (<span>{{ status.version.protocol }}</span>)</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="mcstatus-icon"><div class="mcstatus-icon-img" title="Server icon"></div></div>
|
||||||
|
<div class="mcstatus-address"><span class="server-down">{{ server_str }}</span></div>
|
||||||
|
<div class="mcstatus-description"><span>-</span></div>
|
||||||
|
<div class="mcstatus-players"><span>0</span>/<span>0</span></div>
|
||||||
|
<div class="mcstatus-version"><span>Offline</span> (<span>-</span>)</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if query %}
|
||||||
|
<div class="mcstatus-playerlist">
|
||||||
|
<h3>Giocatori connessi:</h3>
|
||||||
|
<ul>
|
||||||
|
{% for player in query.players.names %}
|
||||||
|
<li>{{ player }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -513,4 +513,48 @@ button[disabled=""] {
|
||||||
.wikiedit-form .CodeMirror .cm-header {
|
.wikiedit-form .CodeMirror .cm-header {
|
||||||
color: #ffffff !important;
|
color: #ffffff !important;
|
||||||
}
|
}
|
||||||
|
.mcstatus-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 64px auto auto;
|
||||||
|
grid-column-gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-icon {
|
||||||
|
grid-column: 1;
|
||||||
|
grid-row-start: 1;
|
||||||
|
grid-row-end: 3;
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-icon .mcstatus-icon-img {
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-address {
|
||||||
|
font-weight: bold;
|
||||||
|
grid-column: 2;
|
||||||
|
justify-self: start;
|
||||||
|
grid-row: 1;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-address .server-up {
|
||||||
|
color: #7dff7d;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-address .server-down {
|
||||||
|
color: #ff7d7d;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-description {
|
||||||
|
grid-column: 2;
|
||||||
|
justify-self: start;
|
||||||
|
grid-row: 2;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-players {
|
||||||
|
grid-column: 3;
|
||||||
|
justify-self: end;
|
||||||
|
grid-row: 1;
|
||||||
|
}
|
||||||
|
.mcstatus-grid .mcstatus-version {
|
||||||
|
grid-column: 3;
|
||||||
|
justify-self: end;
|
||||||
|
grid-row: 2;
|
||||||
|
}
|
||||||
/*# sourceMappingURL=ryg.css.map */
|
/*# sourceMappingURL=ryg.css.map */
|
File diff suppressed because one or more lines are too long
|
@ -621,3 +621,59 @@ nav {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mcstatus-grid {
|
||||||
|
display: grid;
|
||||||
|
|
||||||
|
grid-template-columns: 64px auto auto;
|
||||||
|
grid-column-gap: 12px;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.mcstatus-icon {
|
||||||
|
grid-column: 1;
|
||||||
|
grid-row-start: 1;
|
||||||
|
grid-row-end: 3;
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
|
||||||
|
.mcstatus-icon-img {
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.mcstatus-address {
|
||||||
|
font-weight: bold;
|
||||||
|
|
||||||
|
grid-column: 2;
|
||||||
|
justify-self: start;
|
||||||
|
grid-row: 1;
|
||||||
|
|
||||||
|
.server-up {
|
||||||
|
color: @pastel-lime;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-down {
|
||||||
|
color: @pastel-red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.mcstatus-description {
|
||||||
|
grid-column: 2;
|
||||||
|
justify-self: start;
|
||||||
|
grid-row: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mcstatus-players {
|
||||||
|
grid-column: 3;
|
||||||
|
justify-self: end;
|
||||||
|
grid-row: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mcstatus-version {
|
||||||
|
grid-column: 3;
|
||||||
|
justify-self: end;
|
||||||
|
grid-row: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue