adding support for playerlist info

This commit is contained in:
jenz 2026-02-13 21:48:37 +01:00
parent 4c88546d35
commit 8977cccbff
3 changed files with 134 additions and 77 deletions

View File

@ -5,96 +5,131 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UNLOZE Server Status</title> <title>UNLOZE Server Status</title>
<style> <style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #121212; color: #e0e0e0; padding: 20px; } body { font-family: 'Segoe UI', sans-serif; background: #121212; color: #e0e0e0; padding: 20px; margin: 0; }
.container { max-width: 900px; margin: auto; } .container { max-width: 900px; margin: auto; }
h1 { border-bottom: 2px solid #444; padding-bottom: 10px; color: #fff; }
.server-card { .server-card {
background: #1e1e1e; background: #1e1e1e;
border-radius: 8px; border-radius: 8px;
padding: 15px; padding: 15px;
margin-bottom: 15px; margin-bottom: 10px;
border-left: 5px solid #00ff41; /* Green accent */ border-left: 5px solid #00ff41;
display: flex; transition: background 0.2s;
justify-content: space-between;
align-items: center;
transition: transform 0.2s;
} }
.server-card:hover { transform: translateX(5px); background: #252525; }
.card-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.info-main { flex-grow: 1; } .info-main { flex-grow: 1; }
.server-name { font-weight: bold; font-size: 1.1em; color: #00ff41; margin-bottom: 5px; } .server-name { font-weight: bold; font-size: 1.1em; color: #00ff41; }
.server-sub { font-size: 0.9em; color: #aaa; } .server-sub { font-size: 0.9em; color: #aaa; }
.stats { text-align: right; min-width: 120px; } .stats { text-align: right; min-width: 100px; margin-right: 15px; }
.players { font-size: 1.2em; font-weight: bold; color: #fff; } .players-count { font-size: 1.2em; font-weight: bold; color: #fff; }
.btn-connect { .btn-connect {
background: #00ff41; background: #00ff41; color: #000; text-decoration: none;
color: #000; padding: 8px 15px; border-radius: 4px; font-weight: bold; font-size: 0.8em;
text-decoration: none;
padding: 8px 15px;
border-radius: 4px;
font-weight: bold;
font-size: 0.8em;
margin-left: 20px;
} }
.btn-connect:hover { background: #00cc33; }
/* Player List Styling */
.player-list-container {
display: none; /* Hidden by default */
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid #333;
}
.player-table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.player-table th { text-align: left; color: #00ff41; padding-bottom: 5px; border-bottom: 1px solid #333; }
.player-table td { padding: 5px 0; border-bottom: 1px solid #252525; }
.duration { color: #888; font-style: italic; }
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>UNLOZE Server Info</h1>
<div id="server-list">Loading servers...</div> <div id="server-list">Loading servers...</div>
</div> </div>
<script> <script>
function formatTime(seconds) {
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
return h > 0 ? `${h}h ${m}m` : `${m}m`;
}
function togglePlayers(id) {
const el = document.getElementById(`players-${id}`);
el.style.display = el.style.display === 'block' ? 'none' : 'block';
sendHeight(); // Recalculate iframe height when expanding
}
async function loadServers() { async function loadServers() {
try { try {
const response = await fetch('servers.json'); const response = await fetch('servers.json');
const data = await response.json(); const data = await response.json();
const listContainer = document.getElementById('server-list'); const listContainer = document.getElementById('server-list');
listContainer.innerHTML = ''; listContainer.innerHTML = '';
data.forEach(server => { data.forEach((server, index) => {
const card = document.createElement('div'); const card = document.createElement('div');
card.className = 'server-card'; card.className = 'server-card';
// Build Player Table rows
let playerRows = '';
if (server.player_infos && server.player_infos.length > 0) {
server.player_infos.forEach(p => {
playerRows += `
<tr>
<td>${p.name}</td>
<td>${p.score}</td>
<td class="duration">${formatTime(p.duration)}</td>
</tr>`;
});
} else {
playerRows = '<tr><td colspan="3" style="text-align:center; padding:10px;">No players online</td></tr>';
}
card.innerHTML = ` card.innerHTML = `
<div class="card-header" onclick="togglePlayers(${index})">
<div class="info-main"> <div class="info-main">
<div class="server-name">${server.name}</div> <div class="server-name">${server.name}</div>
<div class="server-sub">Map: <strong>${server.map}</strong></div> <div class="server-sub">Map: <strong>${server.map}</strong></div>
<div class="server-sub" style="color: #00ff41; font-family: monospace; margin-top: 4px;">
IP: ${server.ip}
</div>
</div> </div>
<div class="stats"> <div class="stats">
<div class="players">${server.players}</div> <div class="players-count">${server.players}</div>
<div class="server-sub">${server.ip}</div> <div class="server-sub">Players Online</div>
</div>
<a href="steam://connect/${server.ip}" class="btn-connect" onclick="event.stopPropagation()">CONNECT</a>
</div>
<div class="player-list-container" id="players-${index}">
<table class="player-table">
<thead>
<tr><th>Player Name</th><th>Score</th><th>Time</th></tr>
</thead>
<tbody>${playerRows}</tbody>
</table>
</div> </div>
<a href="steam://connect/${server.ip}" class="btn-connect">CONNECT</a>
`; `;
listContainer.appendChild(card); listContainer.appendChild(card);
}); });
// --- ADD THIS LINE HERE ---
// Tell the parent XenForo page to resize now that the content is actually here
sendHeight(); sendHeight();
} catch (error) { } catch (error) {
console.error('Error loading JSON:', error); console.error('Error:', error);
document.getElementById('server-list').innerText = 'Failed to load server data.'; }
} }
}
function sendHeight() { function sendHeight() {
// Add a little buffer (e.g., + 20) to ensure nothing is clipped const height = document.body.scrollHeight + 40;
const height = document.body.scrollHeight + 20;
window.parent.postMessage({ type: 'setHeight', height: height }, '*'); window.parent.postMessage({ type: 'setHeight', height: height }, '*');
} }
// Initial load loadServers();
loadServers(); setInterval(loadServers, 30000);
// Refresh every 30s
setInterval(loadServers, 30000);
</script> </script>
</body> </body>

View File

@ -2,5 +2,6 @@ flask
flask_cors flask_cors
waitress waitress
werkzeug werkzeug
python-a2s
python app.py python app.py

View File

@ -6,12 +6,32 @@ from werkzeug.middleware.proxy_fix import ProxyFix
import traceback import traceback
import json import json
from pprint import pprint from pprint import pprint
import a2s
from settings import ips, file_path from settings import ips, file_path
app = Flask(__name__) app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1) app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1)
CORS(app) CORS(app)
#AI slop
def get_player_list(ip, port):
address = (ip, int(port))
try:
# Get player information
players = a2s.players(address)
player_data = []
for p in players:
player_data.append({
"name": p.name,
"score": p.score,
"duration": p.duration # Seconds they've been online
})
return player_data
except Exception as e:
print(f"Error querying server: {e}")
return []
#nginx used for reserve proxy #nginx used for reserve proxy
@app.route('/', methods = ['POST']) @app.route('/', methods = ['POST'])
def get_server_info(): def get_server_info():
@ -30,7 +50,8 @@ def get_server_info():
map_ = server.split("**")[1].split(" ")[0] map_ = server.split("**")[1].split(" ")[0]
players = server.split("(")[1].split(")")[0] players = server.split("(")[1].split(")")[0]
ip = server.split("\n[")[1].split("]")[0] ip = server.split("\n[")[1].split("]")[0]
j = {"name": name, "map": map_, "players": players, "ip": ip} d = get_player_list(ip.split(":")[0], ip.split(":")[1])
j = {"name": name, "map": map_, "players": players, "ip": ip, "player_infos": d}
new_j.append(j) new_j.append(j)
#print(new_j) #print(new_j)