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
|
||||
# **********************************************************************************
|
||||
@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
|
||||
def get_banned_players(server_id):
|
||||
srv = ServersController().get_server_instance_by_id(server_id)
|
||||
|
@ -1255,3 +1255,23 @@ class Helpers:
|
||||
if region == "EN":
|
||||
return "en"
|
||||
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:
|
||||
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"
|
||||
|
||||
|
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>
|
||||
|
||||
<div class="row">
|
||||
{% include "parts/server_players.html %}
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<style>
|
||||
.playerItem {
|
||||
@ -128,7 +135,7 @@
|
||||
$(document).ready(function () {
|
||||
console.log("ready!");
|
||||
|
||||
var bannedPlayers = `{{ data['banned_players'] }}`;
|
||||
var bannedPlayers = `{{ data['banned_players_html'] }}`;
|
||||
|
||||
var bannedPlayersDecoded = htmlDecode(bannedPlayers);
|
||||
|
||||
|
@ -47,18 +47,14 @@
|
||||
<h4 class="card-title"><i class="fas fa-calendar"></i> {{ translate('serverSchedules',
|
||||
'scheduledTasks', data['lang']) }} </h4>
|
||||
{% if data['user_data']['hints'] %}
|
||||
<span class="too_small" title="{{ translate('serverSchedules', 'cannotSee', data['lang']) }}" ,
|
||||
data-content="{{ translate('serverSchedules', 'cannotSeeOnMobile', data['lang']) }}" ,
|
||||
data-placement="bottom"></span>
|
||||
<span class="too_small" title="{{ translate('serverSchedules', 'cannotSee', data['lang']) }}" , data-content="{{ translate('serverSchedules', 'cannotSeeOnMobile', data['lang']) }}" , data-placement="bottom"></span>
|
||||
{% end %}
|
||||
<div><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></div>
|
||||
<div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-hover d-none d-lg-block responsive-table" id="schedule_table" width="100%"
|
||||
style="table-layout:fixed;">
|
||||
<table class="table table-hover d-none d-lg-block responsive-table" id="schedule_table" width="100%" style="table-layout:fixed;">
|
||||
<thead>
|
||||
<tr class="rounded">
|
||||
<th style="width: 2%; min-width: 10px;">{{ translate('serverSchedules', 'name', data['lang']) }}
|
||||
@ -105,14 +101,10 @@
|
||||
<p>{{schedule.next_run}}</p>
|
||||
</td>
|
||||
<td id="{{schedule.enabled}}" class="action">
|
||||
<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' }}">
|
||||
<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' }}">
|
||||
</td>
|
||||
<td id="{{schedule.action}}" class="action">
|
||||
<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">
|
||||
<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">
|
||||
<i class="fas fa-pencil-alt"></i>
|
||||
</button>
|
||||
<br>
|
||||
@ -126,8 +118,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<table class="table table-hover d-block d-lg-none" id="mini_schedule_table" width="100%"
|
||||
style="table-layout:fixed;">
|
||||
<table class="table table-hover d-block d-lg-none" id="mini_schedule_table" width="100%" style="table-layout:fixed;">
|
||||
<thead>
|
||||
<tr class="rounded">
|
||||
<th style="width: 25%; min-width: 50px;">{{ translate('serverSchedules', 'action', data['lang'])
|
||||
@ -160,8 +151,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="task_details_{{schedule.schedule_id}}" tabindex="-1" role="dialog"
|
||||
aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal fade" id="task_details_{{schedule.schedule_id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@ -208,19 +198,14 @@
|
||||
<p>zzzzzzz</p>
|
||||
{% end %}
|
||||
</li>
|
||||
<li id="{{schedule.enabled}}" class="action"
|
||||
style="border-top: .1em solid gray; border-bottom: .1em solid gray">
|
||||
<li id="{{schedule.enabled}}" class="action" style="border-top: .1em solid gray; border-bottom: .1em solid gray">
|
||||
<h4>{{ translate('serverSchedules', 'enabled', data['lang']) }}</h4>
|
||||
<input type="checkbox" class="schedule-enabled-toggle"
|
||||
data-schedule-id="{{schedule.schedule_id}}"
|
||||
data-schedule-enabled="{{ 'true' if schedule.enabled else 'false' }}">
|
||||
<input type="checkbox" class="schedule-enabled-toggle" data-schedule-id="{{schedule.schedule_id}}" data-schedule-enabled="{{ 'true' if schedule.enabled else 'false' }}">
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<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">
|
||||
<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">
|
||||
<i class="fas fa-pencil-alt"></i> {{ translate('serverSchedules', 'edit', data['lang'])
|
||||
}}
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user