Rust RCON returns Position as {x, y, z} object. Now formatted as
'x:123.4 y:56.7 z:89.0' instead of the default toString() garbage.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
94 lines
3.6 KiB
JavaScript
94 lines
3.6 KiB
JavaScript
/**
|
|
* Player info page — single player detail with quirk fixes.
|
|
*/
|
|
function PlayerInfoPage(params, container) {
|
|
var userid = params[2]; // SteamID from URL
|
|
|
|
var html =
|
|
'<div id="PlayerInfoController">' +
|
|
'<div class="row">' +
|
|
'<div class="col-lg-12">' +
|
|
'<h2 class="text-center">' +
|
|
'Player: <span id="pi-username">' + userid + '</span>' +
|
|
'<button id="pi-refresh" class="btn btn-secondary float-end" type="button"><i class="bi bi-arrow-clockwise"></i></button>' +
|
|
'</h2>' +
|
|
'<div class="btn-group d-flex mb-3">' +
|
|
'<a href="http://www.steamcommunity.com/profiles/' + userid + '" target="_blank" class="btn btn-secondary">' +
|
|
'<i class="bi bi-info-circle-fill"></i> Steam Profile' +
|
|
'</a>' +
|
|
'<button id="pi-kick" class="btn btn-warning"><i class="bi bi-trash-fill"></i> Kick</button>' +
|
|
'<button id="pi-ban" class="btn btn-danger"><i class="bi bi-ban-fill"></i> Ban</button>' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'<div class="col-lg-12">' +
|
|
'<div id="pi-notfound" class="alert alert-warning" style="display:none">This Player is currently not connected to this server!</div>' +
|
|
'</div>' +
|
|
'<div class="col-lg-12">' +
|
|
'<div id="pi-fields" class="row"><span class="text-white-50">Loading…</span></div>' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'</div>';
|
|
container.innerHTML = html;
|
|
|
|
function refresh() {
|
|
Rcon.getPlayers(function (players) {
|
|
var info = null;
|
|
for (var i = 0; i < players.length; i++) {
|
|
if (String(players[i].SteamID) === userid) { info = players[i]; break; }
|
|
}
|
|
|
|
if (!info) {
|
|
document.getElementById('pi-notfound').style.display = 'block';
|
|
document.getElementById('pi-fields').innerHTML = '';
|
|
return;
|
|
}
|
|
document.getElementById('pi-notfound').style.display = 'none';
|
|
|
|
// Fix known Rust RCON quirk: VoiationLevel → ViolationLevel
|
|
if (info.VoiationLevel !== undefined) {
|
|
info.ViolationLevel = info.VoiationLevel;
|
|
delete info.VoiationLevel;
|
|
}
|
|
|
|
// Remove XP remnants
|
|
delete info.CurrentLevel;
|
|
delete info.UnspentXp;
|
|
|
|
document.getElementById('pi-username').textContent = info.DisplayName || userid;
|
|
|
|
var fieldsHtml = '';
|
|
for (var key in info) {
|
|
if (info.hasOwnProperty(key)) {
|
|
var value = info[key];
|
|
if (key === 'Address') {
|
|
value = maskIp(value);
|
|
} else if (typeof value === 'object' && value !== null) {
|
|
// e.g. Position: {x, y, z}
|
|
value = 'x:' + (value.x || 0).toFixed(1) + ' y:' + (value.y || 0).toFixed(1) + ' z:' + (value.z || 0).toFixed(1);
|
|
}
|
|
fieldsHtml += '<div class="col-sm-4"><p>' + key + ': <span class="badge">' + value + '</span></p></div>';
|
|
}
|
|
}
|
|
document.getElementById('pi-fields').innerHTML = fieldsHtml;
|
|
});
|
|
}
|
|
|
|
document.getElementById('pi-refresh').addEventListener('click', refresh);
|
|
|
|
document.getElementById('pi-kick').addEventListener('click', function () {
|
|
if (confirm('Kick player ' + (document.getElementById('pi-username').textContent) + '?')) {
|
|
Rcon.command('kick ' + userid);
|
|
}
|
|
});
|
|
|
|
document.getElementById('pi-ban').addEventListener('click', function () {
|
|
var reason = prompt('Ban reason:', '');
|
|
if (reason !== null) {
|
|
Rcon.command('ban ' + userid + ' ' + (reason || 'No reason'));
|
|
}
|
|
});
|
|
|
|
if (Rcon.isConnected()) refresh();
|
|
else { var _c = function () { refresh(); Rcon.off('connected', _c); }; Rcon.on('connected', _c); }
|
|
}
|