Erster Commit
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Server-Events</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
background: #111;
|
||||
color: #eee;
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
}
|
||||
h1 { margin-top: 0; }
|
||||
a.back { color: #6fbf73; text-decoration: none; font-size: 14px; }
|
||||
a.back:hover { text-decoration: underline; }
|
||||
|
||||
.panel {
|
||||
background: #1a1a1a;
|
||||
border: 1px solid #333;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
margin-top: 16px;
|
||||
max-width: 500px;
|
||||
}
|
||||
.panel h2 { margin-top: 0; }
|
||||
|
||||
.status-line {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 0;
|
||||
border-bottom: 1px solid #333;
|
||||
font-size: 14px;
|
||||
}
|
||||
.status-line:last-child { border-bottom: none; }
|
||||
.status-badge {
|
||||
padding: 3px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.status-on { background: #1a4d2a; color: #6fbf73; }
|
||||
.status-off { background: #444; color: #999; }
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
||||
gap: 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.form-grid label { display: block; font-size: 12px; color: #999; margin-bottom: 4px; }
|
||||
input {
|
||||
background: #222;
|
||||
border: 1px solid #444;
|
||||
color: #eee;
|
||||
padding: 6px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #2c7a3d;
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 8px 14px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
margin-top: 12px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
button.danger { background: #a83232; }
|
||||
button:hover { opacity: 0.85; }
|
||||
|
||||
.msg { font-size: 13px; color: #6fbf73; min-height: 18px; margin-top: 8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a class="back" href="/index.html">← zurück zur Startseite</a>
|
||||
<h1>🎉 Server-Events</h1>
|
||||
|
||||
<div class="panel">
|
||||
<h2>Status</h2>
|
||||
<div class="status-line">
|
||||
<span>⭐ Doppel-XP</span>
|
||||
<span id="statusDoubleXp" class="status-badge status-off">Aus</span>
|
||||
</div>
|
||||
<div class="status-line">
|
||||
<span>💰 Rabatt-Aktion</span>
|
||||
<span id="statusDiscount" class="status-badge status-off">Aus</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<h2>⭐ Doppel-XP starten</h2>
|
||||
<div class="form-grid">
|
||||
<div>
|
||||
<label>Dauer (Minuten)</label>
|
||||
<input type="number" id="xpDuration" value="120" min="1">
|
||||
</div>
|
||||
</div>
|
||||
<button onclick="startEvent('doubleXp')">Starten</button>
|
||||
<button class="danger" onclick="stopEvent('doubleXp')">Vorzeitig beenden</button>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<h2>💰 Rabatt-Aktion starten</h2>
|
||||
<div class="form-grid">
|
||||
<div>
|
||||
<label>Dauer (Minuten)</label>
|
||||
<input type="number" id="discountDuration" value="120" min="1">
|
||||
</div>
|
||||
<div>
|
||||
<label>Rabatt (%)</label>
|
||||
<input type="number" id="discountPercent" value="20" min="1" max="90">
|
||||
</div>
|
||||
</div>
|
||||
<button onclick="startEvent('discount')">Starten</button>
|
||||
<button class="danger" onclick="stopEvent('discount')">Vorzeitig beenden</button>
|
||||
</div>
|
||||
|
||||
<div class="msg" id="eventMsg"></div>
|
||||
|
||||
<script>
|
||||
const token = localStorage.getItem("token");
|
||||
// Voll-Admin ODER passende Gruppen-Berechtigung reicht jetzt aus - der
|
||||
// Server prüft das bei jedem Aufruf ohnehin final ab (siehe requireAdmin);
|
||||
// hier reicht ein simpler Login-Check, authFetch() fängt fehlende Rechte
|
||||
// beim ersten echten API-Aufruf sauber ab (Meldung + Weiterleitung)
|
||||
let isAdmin = localStorage.getItem("isAdmin") === "true";
|
||||
|
||||
if (!token) {
|
||||
alert("Bitte zuerst einloggen.");
|
||||
location.href = "/index.html";
|
||||
}
|
||||
|
||||
async function authFetch(url, options = {}) {
|
||||
options.headers = { ...(options.headers || {}), "Authorization": "Bearer " + token };
|
||||
const res = await fetch(url, options);
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
alert("Sitzung abgelaufen oder kein Admin-Zugriff. Bitte erneut einloggen.");
|
||||
location.href = "/index.html";
|
||||
throw new Error("Nicht autorisiert");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function timeLeftLabel(endsAt) {
|
||||
const diff = endsAt - Date.now();
|
||||
if (diff <= 0) return "";
|
||||
const h = Math.floor(diff / 3600000);
|
||||
const m = Math.floor((diff % 3600000) / 60000);
|
||||
return h > 0 ? `noch ${h}h ${m}min` : `noch ${m}min`;
|
||||
}
|
||||
|
||||
async function loadStatus() {
|
||||
const res = await authFetch("/api/admin/events/status");
|
||||
const data = await res.json();
|
||||
renderStatus(data.events);
|
||||
}
|
||||
|
||||
function renderStatus(events) {
|
||||
const xpEl = document.getElementById("statusDoubleXp");
|
||||
if (events.doubleXp.active) {
|
||||
xpEl.textContent = "An - " + timeLeftLabel(events.doubleXp.endsAt);
|
||||
xpEl.className = "status-badge status-on";
|
||||
} else {
|
||||
xpEl.textContent = "Aus";
|
||||
xpEl.className = "status-badge status-off";
|
||||
}
|
||||
|
||||
const discEl = document.getElementById("statusDiscount");
|
||||
if (events.discount.active) {
|
||||
discEl.textContent = `An (${events.discount.percent}%) - ` + timeLeftLabel(events.discount.endsAt);
|
||||
discEl.className = "status-badge status-on";
|
||||
} else {
|
||||
discEl.textContent = "Aus";
|
||||
discEl.className = "status-badge status-off";
|
||||
}
|
||||
}
|
||||
|
||||
async function startEvent(type) {
|
||||
const durationMinutes = type === "doubleXp"
|
||||
? Number(document.getElementById("xpDuration").value) || 60
|
||||
: Number(document.getElementById("discountDuration").value) || 60;
|
||||
const percent = type === "discount" ? Number(document.getElementById("discountPercent").value) || 10 : undefined;
|
||||
|
||||
const res = await authFetch("/api/admin/events/start", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ type, durationMinutes, percent })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ok) {
|
||||
showMsg("Event gestartet und an alle Online-Spieler angekündigt.");
|
||||
renderStatus(data.events);
|
||||
} else {
|
||||
showMsg("Fehler: " + (data.error || "unbekannt"), true);
|
||||
}
|
||||
}
|
||||
|
||||
async function stopEvent(type) {
|
||||
if (!confirm("Dieses Event wirklich vorzeitig beenden?")) return;
|
||||
|
||||
const res = await authFetch("/api/admin/events/stop", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ type })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ok) {
|
||||
showMsg("Event beendet.");
|
||||
renderStatus(data.events);
|
||||
} else {
|
||||
showMsg("Fehler: " + (data.error || "unbekannt"), true);
|
||||
}
|
||||
}
|
||||
|
||||
function showMsg(text, isError) {
|
||||
const el = document.getElementById("eventMsg");
|
||||
el.style.color = isError ? "#e06c6c" : "#6fbf73";
|
||||
el.textContent = text;
|
||||
setTimeout(() => { el.textContent = ""; }, 4000);
|
||||
}
|
||||
|
||||
loadStatus();
|
||||
setInterval(loadStatus, 30000);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user