Merge branch 'bug/player-controls' into 'dev'

Fix bug where server id was hard coded on cmd send

See merge request crafty-controller/crafty-commander!236
This commit is contained in:
Andrew 2022-04-03 03:43:22 +00:00
commit 7dc1047db9
2 changed files with 109 additions and 97 deletions

View File

@ -9,14 +9,15 @@
<div class="content-wrapper"> <div class="content-wrapper">
<!-- Page Title Header Starts--> <!-- Page Title Header Starts-->
<div class="row page-title-header"> <div class="row page-title-header">
<div class="col-12"> <div class="col-12">
<div class="page-header"> <div class="page-header">
<h4 class="page-title"> <h4 class="page-title">
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{ data['server_stats']['server_id']['server_name'] }} {{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{
<br /> data['server_stats']['server_id']['server_name'] }}
<small>UUID: {{ data['server_stats']['server_id']['server_uuid'] }}</small> <br />
<small>UUID: {{ data['server_stats']['server_id']['server_uuid'] }}</small>
</h4> </h4>
</div> </div>
</div> </div>
@ -24,71 +25,77 @@
</div> </div>
<!-- Page Title Header Ends--> <!-- Page Title Header Ends-->
{% include "parts/details_stats.html %} {% include "parts/details_stats.html" %}
<div class="row"> <div class="row">
<div class="col-sm-12 grid-margin"> <div class="col-sm-12 grid-margin">
<div class="card"> <div class="card">
<div class="card-body pt-0"> <div class="card-body pt-0">
{% include "parts/server_controls_list.html %} {% include "parts/server_controls_list.html" %}
<div class="row"> <div class="row">
<div class="col-md-6 col-sm-12"> <div class="col-md-6 col-sm-12">
<style> <style>
.playerItem { .playerItem {
background: #1c1e2f; background: #1c1e2f;
padding: 1rem; padding: 1rem;
display: flex; display: flex;
flex-flow: row wrap; flex-flow: row wrap;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin: 1rem 0px 1rem 0px; margin: 1rem 0px 1rem 0px;
} }
.playerItem h3 {
vertical-align: middle;
padding: 0px;
margin: 0px;
margin-right: 1.5rem;
}
.playerItem button {
vertical-align: middle;
margin: 0.25rem;
}
.playerUnban { .playerItem h3 {
margin-bottom: 1rem; vertical-align: middle;
} padding: 0px;
margin: 0px;
margin-right: 1.5rem;
}
.banned span { .playerItem button {
font-size: 1.1rem; vertical-align: middle;
} margin: 0.25rem;
</style> }
<h2>{{ translate('serverPlayerManagement', 'players', data['lang']) }}:</h2>
<ul style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
{% for player in data['get_players']() %}
<li class="playerItem">
<h3>{{ player }}</h3>
<div class="buttons">
<button onclick="send_command_to_server('ban {{ player }}')" type="button" class="btn btn-danger">Ban</button>
<button onclick="send_command_to_server('kick {{ player }}')" type="button" class="btn btn-outline-danger">Kick</button>
<button onclick="send_command_to_server('op {{ player }}')" type="button" class="btn btn-warning">OP</button>
<button onclick="send_command_to_server('deop {{ player }}')" type="button" class="btn btn-outline-warning">De-OP</button>
</div>
</li>
{% end %}
</ul>
</div>
<div class="col-md-6 col-sm-12">
<h2>{{ translate('serverPlayerManagement', 'bannedPlayers', data['lang']) }}:</h2>
<ul id="bannedPlayers" style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
<li class="playerItem banned">
<h3>{{ translate('serverPlayerManagement', 'loadingBannedPlayers', data['lang']) }}</h3>
</li>
</ul> .playerUnban {
</div> margin-bottom: 1rem;
}
.banned span {
font-size: 1.1rem;
}
</style>
<h2>{{ translate('serverPlayerManagement', 'players', data['lang']) }}:</h2>
<ul style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
{% for player in data['get_players']() %}
<li class="playerItem">
<h3>{{ player }}</h3>
<div class="buttons">
<button onclick="send_command_to_server('ban {{ player }}')" type="button"
class="btn btn-danger">Ban</button>
<button onclick="send_command_to_server('kick {{ player }}')" type="button"
class="btn btn-outline-danger">Kick</button>
<button onclick="send_command_to_server('op {{ player }}')" type="button"
class="btn btn-warning">OP</button>
<button onclick="send_command_to_server('deop {{ player }}')" type="button"
class="btn btn-outline-warning">De-OP</button>
</div>
</li>
{% end %}
</ul>
</div> </div>
<div class="col-md-6 col-sm-12">
<h2>{{ translate('serverPlayerManagement', 'bannedPlayers', data['lang']) }}:</h2>
<ul id="bannedPlayers" style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
<li class="playerItem banned">
<h3>{{ translate('serverPlayerManagement', 'loadingBannedPlayers', data['lang']) }}</h3>
</li>
</ul>
</div>
</div>
</div> </div>
</div> </div>
@ -104,48 +111,48 @@
{% block js %} {% block js %}
<script> <script>
const serverId = new URLSearchParams(document.location.search).get('id')
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
function getCookie(name) {
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
return r ? r[1] : undefined;
}
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security function htmlDecode(input) {
function getCookie(name) { var e = document.createElement('textarea');
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); e.innerHTML = input;
return r ? r[1] : undefined; // handle case of empty input
} return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
function htmlDecode(input){ $(document).ready(function () {
var e = document.createElement('textarea'); console.log("ready!");
e.innerHTML = input;
// handle case of empty input
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
$( document ).ready(function() { var bannedPlayers = `{{ data['banned_players'] }}`;
console.log( "ready!" );
var bannedPlayers = `{{ data['banned_players'] }}`; var bannedPlayersDecoded = htmlDecode(bannedPlayers);
var bannedPlayersDecoded = htmlDecode(bannedPlayers); $("#bannedPlayers").html(bannedPlayersDecoded)
$("#bannedPlayers").html(bannedPlayersDecoded) });
function send_command_to_server(command) {
console.log(command)
var token = getCookie("_xsrf")
console.log('sending command: ' + command)
$.ajax({
type: "POST",
headers: { 'X-XSRFToken': token },
url: '/ajax/send_command?id=' + serverId,
data: { command },
success: function (data) {
console.log("got response:");
console.log(data);
},
}); });
}
function send_command_to_server (command) {
console.log(command)
var token = getCookie("_xsrf")
console.log('sending command: ' + command)
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/ajax/send_command?id=1',
data: { command },
success: function(data){
console.log("got response:");
console.log(data);
},
});
}
</script> </script>

View File

@ -230,7 +230,7 @@
<h3 id="file_warn"></h3> <h3 id="file_warn"></h3>
<button class="btn btn-success" onclick="save()"><i class="fas fa-save"></i> {{ translate('serverFiles', <button class="btn btn-success" onclick="save()"><i class="fas fa-save"></i> {{ translate('serverFiles',
'save', data['lang']) }}</button> 'save', data['lang']) }}</button>
<span style="color: white;" id="save_status"></span> <span style="color: #2fb689; margin-left: 10px;" id="save_status"></span>
</div> </div>
</div> </div>
@ -503,18 +503,22 @@
editor.on('change', function (event) { editor.on('change', function (event) {
if (!event.ctrlKey && !event.shiftKey) { if (!event.ctrlKey && !event.shiftKey) {
if (file_loaded) { if (file_loaded) {
document.getElementById('save_status').innerHTML = ''; document.getElementById('save_status').innerHTML = '<i class="fal fa-file"></i>';
document.getElementById('save_status').style.color = 'gray';
} else { } else {
document.getElementById('save_status').innerHTML = '<i class="fal fa-check-circle"></i>'; document.getElementById('save_status').innerHTML = '<i class="fal fa-file-check"></i>';
document.getElementById('save_status').style.color = '#2fb689';
} }
} }
}); });
editor.on('undo', function (event) { editor.on('undo', function (event) {
document.getElementById('save_status').innerHTML = ''; document.getElementById('save_status').innerHTML = '<i class="fal fa-file-xmark"></i>';
document.getElementById('save_status').style.color = 'gray';
}); });
editor.on('redo', function (event) { editor.on('redo', function (event) {
document.getElementById('save_status').innerHTML = ''; document.getElementById('save_status').innerHTML = '<i class="fal fa-file-xmark"></i>';
document.getElementById('save_status').style.color = 'gray';
}); });
@ -573,7 +577,8 @@
}, },
success: function (data) { success: function (data) {
console.log("got response:"); console.log("got response:");
document.getElementById("save_status").innerHTML = '<i class="fal fa-check-circle"></i>'; document.getElementById("save_status").innerHTML = '<i class="fal fa-file-check"></i>';
document.getElementById('save_status').style.color = '#2fb689';
console.log(data); console.log(data);
}, },
}); });