mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Improve player display
This commit is contained in:
parent
ad0e130b07
commit
84a09ad9be
@ -513,6 +513,26 @@ class ServersController(metaclass=Singleton):
|
|||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
# Servers Helpers Methods
|
# Servers Helpers Methods
|
||||||
# **********************************************************************************
|
# **********************************************************************************
|
||||||
|
@staticmethod
|
||||||
|
def get_cached_players(server_id):
|
||||||
|
srv = ServersController().get_server_instance_by_id(server_id)
|
||||||
|
stats = srv.stats_helper.get_server_stats()
|
||||||
|
server_path = stats["server_id"]["path"]
|
||||||
|
path = os.path.join(server_path, "usercache.json")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(
|
||||||
|
Helpers.get_os_understandable_path(path), encoding="utf-8"
|
||||||
|
) as file:
|
||||||
|
content = file.read()
|
||||||
|
file.close()
|
||||||
|
except Exception as ex:
|
||||||
|
print(ex)
|
||||||
|
return None
|
||||||
|
|
||||||
|
return json.loads(content)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_banned_players(server_id):
|
def get_banned_players(server_id):
|
||||||
srv = ServersController().get_server_instance_by_id(server_id)
|
srv = ServersController().get_server_instance_by_id(server_id)
|
||||||
|
@ -1255,3 +1255,23 @@ class Helpers:
|
|||||||
if region == "EN":
|
if region == "EN":
|
||||||
return "en"
|
return "en"
|
||||||
return lang + "-" + region
|
return lang + "-" + region
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_player_avatar(uuid):
|
||||||
|
mojang_response = requests.get(
|
||||||
|
f"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}"
|
||||||
|
)
|
||||||
|
if mojang_response.status_code == 200:
|
||||||
|
uuid_profile = mojang_response.json()
|
||||||
|
profile_properties = uuid_profile["properties"]
|
||||||
|
for property in profile_properties:
|
||||||
|
if property["name"] == "textures":
|
||||||
|
decodedBytes = base64.b64decode(property["value"])
|
||||||
|
decodedStr = decodedBytes.decode("utf-8")
|
||||||
|
textureJson = json.loads(decodedStr)
|
||||||
|
skin_url = textureJson["textures"]["SKIN"]["url"]
|
||||||
|
skin_response = requests.get(skin_url, stream=True)
|
||||||
|
if skin_response.status_code == 200:
|
||||||
|
return base64.b64encode(skin_response.content)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
@ -780,7 +780,34 @@ class PanelHandler(BaseHandler):
|
|||||||
):
|
):
|
||||||
if not superuser:
|
if not superuser:
|
||||||
self.redirect("/panel/error?error=Unauthorized access")
|
self.redirect("/panel/error?error=Unauthorized access")
|
||||||
page_data["banned_players"] = get_banned_players_html()
|
page_data["banned_players_html"] = get_banned_players_html()
|
||||||
|
page_data[
|
||||||
|
"banned_players"
|
||||||
|
] = self.controller.servers.get_banned_players(server_id)
|
||||||
|
page_data[
|
||||||
|
"cached_players"
|
||||||
|
] = self.controller.servers.get_cached_players(server_id)
|
||||||
|
|
||||||
|
page_data["all_players"] = []
|
||||||
|
for player in page_data["cached_players"]:
|
||||||
|
if player["name"] in page_data["get_players"]:
|
||||||
|
player["status"] = "online"
|
||||||
|
else:
|
||||||
|
player["status"] = "offline"
|
||||||
|
temp_date = datetime.datetime.strptime(
|
||||||
|
player["expiresOn"], "%Y-%m-%d %H:%M:%S %z"
|
||||||
|
)
|
||||||
|
player["last_seen"] = (
|
||||||
|
temp_date - datetime.timedelta(30, 0, 0, 0, 0, 0, 0)
|
||||||
|
).strftime("%Y/%m/%d %H:%M:%S")
|
||||||
|
player["avatar"] = Helpers.get_player_avatar(player["uuid"])
|
||||||
|
page_data["all_players"].append(player)
|
||||||
|
for player in page_data["banned_players"]:
|
||||||
|
player["banned"] = True
|
||||||
|
temp_date = datetime.datetime.strptime(
|
||||||
|
player["created"], "%Y-%m-%d %H:%M:%S %z"
|
||||||
|
)
|
||||||
|
player["banned_on"] = (temp_date).strftime("%Y/%m/%d %H:%M:%S")
|
||||||
|
|
||||||
template = f"panel/server_{subpage}.html"
|
template = f"panel/server_{subpage}.html"
|
||||||
|
|
||||||
|
61
app/frontend/templates/panel/parts/server_players.html
Normal file
61
app/frontend/templates/panel/parts/server_players.html
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<div class="col-md-6 col-sm-12">
|
||||||
|
<h2>{{ translate('serverPlayerManagement', 'players', data['lang']) }}:</h2>
|
||||||
|
<table class="table table-sm-responsive">
|
||||||
|
<thead class="thead">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Player</th>
|
||||||
|
<th scope="col">Status</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for player in data['all_players'] %}
|
||||||
|
<tr id="playerItem-{{ player['name'] }}" class="playerItem--">
|
||||||
|
<td>
|
||||||
|
<strong> {{ player['name'] }}</strong>
|
||||||
|
</td>
|
||||||
|
{% if player['status'] == 'online' %}
|
||||||
|
<td><span class="text-success"><i class="fas fa-signal"></i> {{ player['status'] }}</span></td>
|
||||||
|
{% elif player['status'] == 'offline' %}
|
||||||
|
<td><span class="text-warning"><i class="fa-solid fa-signal-slash"></i> Last connexion : {{ player['last_seen'] }}</span></td>
|
||||||
|
{% end %}
|
||||||
|
<td class="buttons">
|
||||||
|
{% if data['server_stats']['running'] %}
|
||||||
|
<button onclick="send_command_to_server(`ban {{ player['name'] }}`)" type="button" class="btn btn-danger">Ban</button>
|
||||||
|
<button onclick="send_command_to_server(`kick {{ player['name'] }}`)" type="button" class="btn btn-outline-danger">Kick</button>
|
||||||
|
<button onclick="send_command_to_server(`op {{ player['name'] }}`)" type="button" class="btn btn-warning">OP</button>
|
||||||
|
<button onclick="send_command_to_server(`deop {{ player['name'] }}`)" type="button" class="btn btn-outline-warning">De-OP</button>
|
||||||
|
{% else %}
|
||||||
|
<span> Unavailable (Server Offline)</span>
|
||||||
|
{% end %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% end %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-sm-12">
|
||||||
|
<h2>{{ translate('serverPlayerManagement', 'bannedPlayers', data['lang']) }}:</h2>
|
||||||
|
<table class="table table-sm-responsive">
|
||||||
|
<thead class="thead">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Player</th>
|
||||||
|
<th scope="col">Status</th>
|
||||||
|
<th scope="col">Reason</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for player in data['banned_players'] %}
|
||||||
|
<tr id="playerItem-{{ player }}" class="playerItem--">
|
||||||
|
<td><strong> {{ player['name'] }}</strong></td>
|
||||||
|
<td>Banned on {{ player['banned_on'] }}</td>
|
||||||
|
<td>Banned by : {{ player['source'] }} <br />Reason : {{ player['reason'] }}</td>
|
||||||
|
<td class="buttons">
|
||||||
|
<button onclick="send_command_to_server(`pardon {{ player['name'] }} `)" type="button" class="btn btn-danger">Unban</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% end %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
@ -39,6 +39,13 @@
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
{% include "parts/server_players.html %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-md-6 col-sm-12">
|
<div class="col-md-6 col-sm-12">
|
||||||
<style>
|
<style>
|
||||||
.playerItem {
|
.playerItem {
|
||||||
@ -128,7 +135,7 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
console.log("ready!");
|
console.log("ready!");
|
||||||
|
|
||||||
var bannedPlayers = `{{ data['banned_players'] }}`;
|
var bannedPlayers = `{{ data['banned_players_html'] }}`;
|
||||||
|
|
||||||
var bannedPlayersDecoded = htmlDecode(bannedPlayers);
|
var bannedPlayersDecoded = htmlDecode(bannedPlayers);
|
||||||
|
|
||||||
|
@ -47,18 +47,14 @@
|
|||||||
<h4 class="card-title"><i class="fas fa-calendar"></i> {{ translate('serverSchedules',
|
<h4 class="card-title"><i class="fas fa-calendar"></i> {{ translate('serverSchedules',
|
||||||
'scheduledTasks', data['lang']) }} </h4>
|
'scheduledTasks', data['lang']) }} </h4>
|
||||||
{% if data['user_data']['hints'] %}
|
{% if data['user_data']['hints'] %}
|
||||||
<span class="too_small" title="{{ translate('serverSchedules', 'cannotSee', data['lang']) }}" ,
|
<span class="too_small" title="{{ translate('serverSchedules', 'cannotSee', data['lang']) }}" , data-content="{{ translate('serverSchedules', 'cannotSeeOnMobile', data['lang']) }}" , data-placement="bottom"></span>
|
||||||
data-content="{{ translate('serverSchedules', 'cannotSeeOnMobile', data['lang']) }}" ,
|
|
||||||
data-placement="bottom"></span>
|
|
||||||
{% end %}
|
{% end %}
|
||||||
<div><button
|
<div>
|
||||||
onclick="location.href=`/panel/add_schedule?id={{ data['server_stats']['server_id']['server_id'] }}`"
|
<button onclick="location.href=`/panel/add_schedule?id={{ data['server_stats']['server_id']['server_id'] }}`" class="btn btn-info">{{ translate('serverSchedules', 'create', data['lang']) }}<i class="fas fa-pencil-alt"></i></button>
|
||||||
class="btn btn-info">{{ translate('serverSchedules', 'create', data['lang']) }}<i
|
</div>
|
||||||
class="fas fa-pencil-alt"></i></button></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover d-none d-lg-block responsive-table" id="schedule_table" width="100%"
|
<table class="table table-hover d-none d-lg-block responsive-table" id="schedule_table" width="100%" style="table-layout:fixed;">
|
||||||
style="table-layout:fixed;">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="rounded">
|
<tr class="rounded">
|
||||||
<th style="width: 2%; min-width: 10px;">{{ translate('serverSchedules', 'name', data['lang']) }}
|
<th style="width: 2%; min-width: 10px;">{{ translate('serverSchedules', 'name', data['lang']) }}
|
||||||
@ -105,14 +101,10 @@
|
|||||||
<p>{{schedule.next_run}}</p>
|
<p>{{schedule.next_run}}</p>
|
||||||
</td>
|
</td>
|
||||||
<td id="{{schedule.enabled}}" class="action">
|
<td id="{{schedule.enabled}}" class="action">
|
||||||
<input style="width: 10px !important;" type="checkbox" class="schedule-enabled-toggle"
|
<input style="width: 10px !important;" type="checkbox" class="schedule-enabled-toggle" data-schedule-id="{{schedule.schedule_id}}" data-schedule-enabled="{{ 'true' if schedule.enabled else 'false' }}">
|
||||||
data-schedule-id="{{schedule.schedule_id}}"
|
|
||||||
data-schedule-enabled="{{ 'true' if schedule.enabled else 'false' }}">
|
|
||||||
</td>
|
</td>
|
||||||
<td id="{{schedule.action}}" class="action">
|
<td id="{{schedule.action}}" class="action">
|
||||||
<button
|
<button onclick="window.location.href='/panel/edit_schedule?id={{ data['server_stats']['server_id']['server_id'] }}&sch_id={{schedule.schedule_id}}'" class="btn btn-info">
|
||||||
onclick="window.location.href='/panel/edit_schedule?id={{ data['server_stats']['server_id']['server_id'] }}&sch_id={{schedule.schedule_id}}'"
|
|
||||||
class="btn btn-info">
|
|
||||||
<i class="fas fa-pencil-alt"></i>
|
<i class="fas fa-pencil-alt"></i>
|
||||||
</button>
|
</button>
|
||||||
<br>
|
<br>
|
||||||
@ -126,8 +118,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<hr />
|
<hr />
|
||||||
<table class="table table-hover d-block d-lg-none" id="mini_schedule_table" width="100%"
|
<table class="table table-hover d-block d-lg-none" id="mini_schedule_table" width="100%" style="table-layout:fixed;">
|
||||||
style="table-layout:fixed;">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="rounded">
|
<tr class="rounded">
|
||||||
<th style="width: 25%; min-width: 50px;">{{ translate('serverSchedules', 'action', data['lang'])
|
<th style="width: 25%; min-width: 50px;">{{ translate('serverSchedules', 'action', data['lang'])
|
||||||
@ -160,8 +151,7 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
<div class="modal fade" id="task_details_{{schedule.schedule_id}}" tabindex="-1" role="dialog"
|
<div class="modal fade" id="task_details_{{schedule.schedule_id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@ -208,19 +198,14 @@
|
|||||||
<p>zzzzzzz</p>
|
<p>zzzzzzz</p>
|
||||||
{% end %}
|
{% end %}
|
||||||
</li>
|
</li>
|
||||||
<li id="{{schedule.enabled}}" class="action"
|
<li id="{{schedule.enabled}}" class="action" style="border-top: .1em solid gray; border-bottom: .1em solid gray">
|
||||||
style="border-top: .1em solid gray; border-bottom: .1em solid gray">
|
|
||||||
<h4>{{ translate('serverSchedules', 'enabled', data['lang']) }}</h4>
|
<h4>{{ translate('serverSchedules', 'enabled', data['lang']) }}</h4>
|
||||||
<input type="checkbox" class="schedule-enabled-toggle"
|
<input type="checkbox" class="schedule-enabled-toggle" data-schedule-id="{{schedule.schedule_id}}" data-schedule-enabled="{{ 'true' if schedule.enabled else 'false' }}">
|
||||||
data-schedule-id="{{schedule.schedule_id}}"
|
|
||||||
data-schedule-enabled="{{ 'true' if schedule.enabled else 'false' }}">
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button
|
<button onclick="window.location.href='/panel/edit_schedule?id={{ data['server_stats']['server_id']['server_id'] }}&sch_id={{schedule.schedule_id}}'" class="btn btn-info">
|
||||||
onclick="window.location.href='/panel/edit_schedule?id={{ data['server_stats']['server_id']['server_id'] }}&sch_id={{schedule.schedule_id}}'"
|
|
||||||
class="btn btn-info">
|
|
||||||
<i class="fas fa-pencil-alt"></i> {{ translate('serverSchedules', 'edit', data['lang'])
|
<i class="fas fa-pencil-alt"></i> {{ translate('serverSchedules', 'edit', data['lang'])
|
||||||
}}
|
}}
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user