2026-11-17 14:17:50 +01:00
<!doctype html>
< html lang = "de" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > Robot Clash – Admin< / title >
<!--
2026-11-19 02:11:13 +01:00
Robot Clash backend admin, served by the game server at /admin/ (e.g. https://roboclash.michael-media.de/admin/).
Saving needs an account with role 'admin' (seed accounts michi / benni, see server/scripts/reset-db.js) -
the server checks it, the page itself grants nothing. Writes the live settings every player reads (game/live.js).
2026-11-17 14:17:50 +01:00
-->
< style >
:root { --bg:#0b0e13; --panel:#161b22; --panel2:#1d232d; --line:#2d3442; --text:#e8ebf2; --dim:#8d95a8;
--accent:#ff7a1a; --good:#6dff9e; --warn:#ff5a4a; }
* { box-sizing:border-box; }
body { margin:0; background:var(--bg); color:var(--text); font:15px/1.4 "Segoe UI",system-ui,sans-serif; }
.wrap { max-width:820px; margin:0 auto; padding:24px 18px 60px; }
h1 { font-size:24px; margin:0 0 2px; color:var(--accent); letter-spacing:.03em; }
h1 small { color:var(--dim); font-size:13px; font-weight:normal; letter-spacing:0; }
h2 { font-size:15px; margin:22px 0 8px; color:var(--accent); border-bottom:1px solid var(--line); padding-bottom:5px; }
label { display:block; font-size:13px; color:var(--dim); margin:8px 0 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
width:100%; padding:8px 10px; background:#0b0e14; color:var(--text); border:1px solid var(--line);
border-radius:7px; font:inherit; }
textarea { min-height:52px; resize:vertical; }
input:focus, textarea:focus, select:focus { outline:none; border-color:var(--accent); }
.row { display:flex; gap:10px; flex-wrap:wrap; }
.row > div { flex:1; min-width:140px; }
button { font:inherit; color:var(--text); background:var(--panel2); border:1px solid var(--line);
border-radius:8px; padding:9px 16px; cursor:pointer; }
button:hover { border-color:var(--accent); }
button.primary { background:linear-gradient(#ff8f3a,#e8650a); color:#1a0c02; border-color:#ffa25a; font-weight:700; }
button.danger { border-color:#5a2e2e; color:var(--warn); }
.card { background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:16px 18px; margin-bottom:14px; }
.hide { display:none; }
.muted { color:var(--dim); font-size:13px; }
.pill { display:inline-block; background:var(--panel2); border:1px solid var(--line); border-radius:6px;
padding:2px 8px; font-size:12px; font-variant-numeric:tabular-nums; }
.checks { display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:4px 12px; margin-top:4px; }
.checks label { display:flex; align-items:center; gap:6px; margin:0; color:var(--text); font-size:13px; }
.checks input { width:auto; }
.status { margin-top:10px; font-size:13px; min-height:18px; }
.status.ok { color:var(--good); } .status.err { color:var(--warn); }
.chk { display:flex; align-items:center; gap:8px; margin:6px 0; }
.chk input { width:auto; }
pre { background:#0b0e14; border:1px solid var(--line); border-radius:7px; padding:10px; overflow:auto;
font-size:12px; color:var(--dim); max-height:220px; }
.bar { position:sticky; bottom:0; background:var(--bg); padding:12px 0 0; border-top:1px solid var(--line);
display:flex; gap:10px; flex-wrap:wrap; margin-top:16px; }
.preset { display:flex; align-items:center; gap:10px; background:var(--panel2); border:1px solid var(--line);
border-radius:8px; padding:8px 12px; margin-bottom:6px; }
.preset .pn { flex:1; font-weight:600; }
.preset .psub { color:var(--dim); font-size:12px; }
.preset button { padding:5px 11px; font-size:13px; }
< / style >
< / head >
< body >
< div class = "wrap" >
< h1 > Robot Clash – Admin < small > steuert, was alle Spieler sehen< / small > < / h1 >
<!-- login -->
< div class = "card" id = "login" >
< h2 > Anmelden< / h2 >
2026-11-19 02:11:13 +01:00
< p class = "muted" > Mit einem Spielkonto, das auf dem Server Admin-Recht hat (z. B. michi oder benni).< / p >
2026-11-17 14:17:50 +01:00
< div class = "row" >
2026-11-19 02:11:13 +01:00
< div > < label > Name oder E-Mail< / label > < input type = "text" id = "mail" autocomplete = "username" > < / div >
2026-11-17 14:17:50 +01:00
< div > < label > Passwort< / label > < input type = "password" id = "pass" autocomplete = "current-password" > < / div >
< / div >
< div class = "bar" > < button class = "primary" id = "bLogin" > Anmelden< / button > < / div >
< div class = "status" id = "loginMsg" > < / div >
< / div >
<!-- panel -->
< div class = "card hide" id = "panel" >
< h2 > Angemeldet< / h2 >
< p class = "muted" > Konto < b id = "who" > < / b > · UID < span class = "pill" id = "uid" > < / span >
< button id = "bOut" style = "padding:3px 10px;font-size:12px" > Abmelden< / button > < / p >
< p class = "muted" id = "uidHint" > < / p >
< h2 > 📣 Nachricht an alle (Titel + Lobby)< / h2 >
< div class = "row" >
< div > < label > Deutsch< / label > < input type = "text" id = "motdDe" maxlength = "120" placeholder = "z. B. Turnier am Samstag 20 Uhr" > < / div >
< div > < label > English< / label > < input type = "text" id = "motdEn" maxlength = "120" placeholder = "e.g. Tournament Saturday 8pm" > < / div >
< / div >
< h2 > 🏆 Event (läuft automatisch im Zeitfenster)< / h2 >
< div class = "chk" > < input type = "checkbox" id = "evOn" > < label for = "evOn" style = "margin:0" > Event aktiv< / label > < / div >
< div id = "evBody" >
< div class = "row" >
< div > < label > Name (DE)< / label > < input type = "text" id = "evDe" maxlength = "60" > < / div >
< div > < label > Name (EN)< / label > < input type = "text" id = "evEn" maxlength = "60" > < / div >
< / div >
< div class = "row" >
< div > < label > Von< / label > < input type = "datetime-local" id = "evFrom" > < / div >
< div > < label > Bis< / label > < input type = "datetime-local" id = "evTo" > < / div >
< / div >
< div class = "row" >
< div > < label > Preisgeld × < / label > < input type = "number" id = "evMul" min = "0.5" max = "5" step = "0.5" value = "1" > < / div >
< div > < label > Klasse erzwingen< / label > < select id = "evCls" > < / select > < / div >
< div > < label > Arena erzwingen< / label > < select id = "evArena" > < / select > < / div >
< / div >
< div class = "chk" > < input type = "checkbox" id = "evTour" > < label for = "evTour" style = "margin:0" > Turnier freischalten (ohne Startgeld)< / label > < / div >
< / div >
< h2 > 💾 Gespeicherte Events (Bibliothek)< / h2 >
< p class = "muted" > Vorlage aus dem Formular oben speichern, später mit einem Klick wieder aktivieren.
„Aktivieren“ setzt das Zeitfenster neu (ab jetzt + Dauer).< / p >
< div class = "row" >
< div > < label > Vorlage-Name< / label > < input type = "text" id = "presetName" maxlength = "40" placeholder = "z. B. Schwergewichts-Wochenende" > < / div >
< div > < label > Dauer beim Aktivieren (Stunden)< / label > < input type = "number" id = "presetHours" min = "1" max = "720" value = "48" > < / div >
< / div >
< div class = "bar" style = "position:static;border:none;padding:0;margin:8px 0 0" >
< button id = "bPresetSave" > Vorlage speichern< / button >
< button id = "bEvOff" class = "danger" > Laufendes Event stoppen< / button >
< / div >
< div id = "presetList" style = "margin-top:10px" > < / div >
< h2 > 🔓 Freischaltung (leer = alles frei)< / h2 >
< p class = "muted" > Nur Angehaktes ist im Shop verfügbar. Nichts angehakt = keine Sperre.< / p >
< details > < summary class = "muted" style = "cursor:pointer" > Teile< / summary > < div class = "checks" id = "ckParts" > < / div > < / details >
< details > < summary class = "muted" style = "cursor:pointer;margin-top:6px" > Arenen< / summary > < div class = "checks" id = "ckArenas" > < / div > < / details >
< details > < summary class = "muted" style = "cursor:pointer;margin-top:6px" > Klassen< / summary > < div class = "checks" id = "ckClasses" > < / div > < / details >
< h2 > 🛠 Betrieb< / h2 >
< div class = "chk" > < input type = "checkbox" id = "tourOn" > < label for = "tourOn" style = "margin:0" > < b > Turnier für alle öffnen< / b > (gratis Teilnahme; aus = Turnier ausgeblendet)< / label > < / div >
< div class = "chk" > < input type = "checkbox" id = "offOn" > < label for = "offOn" style = "margin:0" > Online-Modus abschalten (alle in die Kampagne)< / label > < / div >
< label > Mindest-Build (ältere Dateien bekommen „bitte neu laden“) – leer lassen, wenn egal< / label >
< input type = "text" id = "buildMin" placeholder = "z. B. 20261115.2223" >
< div class = "bar" >
< button class = "primary" id = "bSave" > Speichern (für alle sofort)< / button >
< button id = "bReload" > Vom Server laden< / button >
< button class = "danger" id = "bClear" > Alles löschen< / button >
< / div >
< div class = "status" id = "saveMsg" > < / div >
< h2 > Aktueller Serverstand< / h2 >
< pre id = "dump" > – < / pre >
< / div >
< / div >
2026-11-19 02:11:13 +01:00
< script src = "/kit/kit-core.js" > < / script >
< script src = "/kit/kit-scores.js" > < / script >
< script src = "/parts.js" > < / script >
< script src = "/robot.js" > < / script >
< script src = "/combat.js" > < / script >
< script src = "/protocol.js" > < / script >
< script src = "/net.js" > < / script >
2026-11-17 14:17:50 +01:00
< script >
(function () {
'use strict';
var RC = window.RC, Kit = window.Kit;
2026-11-19 02:11:13 +01:00
var net = RC.Net({ serverUrl: '' }); // same origin: the page is served by the game server
// tiny adapter: the page's get/put/push/del calls -> the server's admin endpoints
var db = {
get: function (p) { return net.api('GET', p === 'live' ? '/api/live' : '/api/admin/events'); },
put: function (p, v) { return net.api('PUT', '/api/admin/live', v).then(function (r) { return !!(r & & r.ok); }); },
push: function (p, v) { return net.api('POST', '/api/admin/events', v).then(function (r) { return r & & r.name; }); },
del: function (p) { return net.api('DELETE', '/api/admin/events/' + encodeURIComponent(p.split('/').pop())); },
};
2026-11-17 14:17:50 +01:00
var $ = function (id) { return document.getElementById(id); };
// ---- build the pick lists from the real game data ----
function opt(sel, items, label) {
sel.innerHTML = '< option value = "" > – < / option > ' + items.map(function (x) {
return '< option value = "' + x.id + '" > ' + label(x) + '< / option > '; }).join('');
}
opt($('evCls'), RC.CLASSES, function (c) { return c.id + ' (≤' + c.max + ' kg)'; });
opt($('evArena'), RC.ARENAS, function (a) { return a.name; });
function checks(box, items, label) {
box.innerHTML = items.map(function (x) {
return '< label > < input type = "checkbox" value = "' + x.id + '" > ' + label(x) + '< / label > '; }).join('');
}
checks($('ckParts'), RC.PART_LIST, function (p) { return p.name + ' (' + p.slot + ')'; });
checks($('ckArenas'), RC.ARENAS, function (a) { return a.name; });
checks($('ckClasses'), RC.CLASSES, function (c) { return c.id; });
function getChecks(box) {
return Array.prototype.slice.call(box.querySelectorAll('input:checked')).map(function (i) { return i.value; });
}
function setChecks(box, ids) {
ids = ids || [];
Array.prototype.forEach.call(box.querySelectorAll('input'), function (i) { i.checked = ids.indexOf(i.value) >= 0; });
}
// datetime-local < - > ms
function toLocal(ms) {
if (!ms) return '';
var d = new Date(ms - new Date().getTimezoneOffset() * 60000);
return d.toISOString().slice(0, 16);
}
function fromLocal(v) { return v ? new Date(v).getTime() : 0; }
// ---- login ----
function showPanel(acc) {
$('login').classList.add('hide');
$('panel').classList.remove('hide');
$('who').textContent = acc.email || acc.name;
$('uid').textContent = acc.uid;
2026-11-19 02:11:13 +01:00
$('uidHint').textContent = net.auth.current & & net.auth.current.admin ? 'Admin-Recht: ja.' : 'Kein Admin-Recht - Speichern wird vom Server abgelehnt.';
2026-11-17 14:17:50 +01:00
loadLive();
loadPresets();
}
$('bLogin').onclick = function () {
var msg = $('loginMsg'); msg.className = 'status'; msg.textContent = 'Anmelden…';
net.auth.login($('mail').value.trim(), $('pass').value).then(function (r) {
if (r.ok) { showPanel(net.auth.current); }
else { msg.className = 'status err'; msg.textContent = 'Fehlgeschlagen: ' + (r.error || 'unbekannt'); }
});
};
$('pass').addEventListener('keydown', function (e) { if (e.key === 'Enter') $('bLogin').click(); });
$('bOut').onclick = function () { net.auth.logout(); location.reload(); };
// ---- read current /live into the form ----
function fill(d) {
d = d || {};
var m = d.motd || {}; $('motdDe').value = m.de || ''; $('motdEn').value = m.en || '';
var e = d.event || {};
$('evOn').checked = !!d.event;
var en = e.name || {};
$('evDe').value = en.de || ''; $('evEn').value = en.en || '';
$('evFrom').value = toLocal(e.from); $('evTo').value = toLocal(e.to);
$('evMul').value = e.prizeMul || 1;
$('evCls').value = e.cls || ''; $('evArena').value = e.arena || '';
$('evTour').checked = !!e.tournament;
var u = d.unlock || {};
setChecks($('ckParts'), u.parts); setChecks($('ckArenas'), u.arenas); setChecks($('ckClasses'), u.classes);
var f = d.flags || {};
$('offOn').checked = !!f.onlineOff;
$('tourOn').checked = !!f.tournament;
$('buildMin').value = (d.build & & d.build.min) || '';
$('dump').textContent = JSON.stringify(d, null, 2);
toggleEv();
}
function toggleEv() { $('evBody').style.opacity = $('evOn').checked ? '1' : '.4'; }
$('evOn').onchange = toggleEv;
function loadLive() {
2026-11-19 02:11:13 +01:00
db.get('live').then(function (d) { fill(d || {}); });
2026-11-17 14:17:50 +01:00
}
$('bReload').onclick = loadLive;
// ---- collect the form into the /live object ----
function collect() {
var out = {};
var mde = $('motdDe').value.trim(), men = $('motdEn').value.trim();
if (mde || men) out.motd = { de: mde, en: men };
if ($('evOn').checked) {
var ev = { id: 'ev' + Date.now().toString(36), type: 'event',
name: { de: $('evDe').value.trim(), en: $('evEn').value.trim() },
from: fromLocal($('evFrom').value), to: fromLocal($('evTo').value),
prizeMul: parseFloat($('evMul').value) || 1, tournament: $('evTour').checked };
if ($('evCls').value) ev.cls = $('evCls').value;
if ($('evArena').value) ev.arena = $('evArena').value;
out.event = ev;
}
var parts = getChecks($('ckParts')), arenas = getChecks($('ckArenas')), classes = getChecks($('ckClasses'));
if (parts.length || arenas.length || classes.length) out.unlock = { parts: parts, arenas: arenas, classes: classes };
var flags = {};
if ($('offOn').checked) flags.onlineOff = true;
if ($('tourOn').checked) flags.tournament = true;
if (Object.keys(flags).length) out.flags = flags;
var bmin = $('buildMin').value.trim();
if (bmin) out.build = { min: bmin };
return out;
}
$('bSave').onclick = function () {
var data = collect(), msg = $('saveMsg');
msg.className = 'status'; msg.textContent = 'Speichern…';
2026-11-19 02:11:13 +01:00
db.put('live', data).then(function (ok) {
2026-11-17 14:17:50 +01:00
if (ok) { msg.className = 'status ok'; msg.textContent = 'Gespeichert – alle Spieler sehen es sofort.'; $('dump').textContent = JSON.stringify(data, null, 2); }
2026-11-19 02:11:13 +01:00
else { msg.className = 'status err'; msg.textContent = 'Abgelehnt. Hat dein Konto Admin-Recht?'; }
2026-11-17 14:17:50 +01:00
});
};
$('bClear').onclick = function () {
if (!confirm('Wirklich alles zurücksetzen? Danach läuft kein Event, keine Nachricht, keine Sperre.')) return;
2026-11-19 02:11:13 +01:00
db.put('live', {}).then(function (ok) {
2026-11-17 14:17:50 +01:00
var msg = $('saveMsg');
msg.className = ok ? 'status ok' : 'status err';
msg.textContent = ok ? 'Zurückgesetzt.' : 'Abgelehnt.';
if (ok) fill({});
});
};
// ---- event library (/admin/events) ----
// read just the event part of the current form into a reusable preset
function eventFromForm() {
return {
name: { de: $('evDe').value.trim(), en: $('evEn').value.trim() },
prizeMul: parseFloat($('evMul').value) || 1,
cls: $('evCls').value || '', arena: $('evArena').value || '',
tournament: $('evTour').checked,
};
}
// put a preset back into the event form
function presetToForm(ev, hours) {
$('evOn').checked = true; toggleEv();
var n = ev.name || {}; $('evDe').value = n.de || ''; $('evEn').value = n.en || '';
$('evMul').value = ev.prizeMul || 1; $('evCls').value = ev.cls || ''; $('evArena').value = ev.arena || '';
$('evTour').checked = !!ev.tournament;
var from = Date.now(), to = from + (hours || 48) * 3600000;
$('evFrom').value = toLocal(from); $('evTo').value = toLocal(to);
}
function loadPresets() {
2026-11-19 02:11:13 +01:00
db.get('admin/events').then(function (m) { renderPresets(m || {}); });
2026-11-17 14:17:50 +01:00
}
function renderPresets(m) {
var box = $('presetList'), keys = Object.keys(m);
if (!keys.length) { box.innerHTML = '< p class = "muted" > Noch keine Vorlagen gespeichert.< / p > '; return; }
box.innerHTML = keys.map(function (k) {
var p = m[k] || {}, ev = p.event || {}, nm = (ev.name & & (ev.name.de || ev.name.en)) || p.name || '(ohne Name)';
var sub = 'Preisgeld x' + (ev.prizeMul || 1) + (ev.tournament ? ' · Turnier' : '') +
(ev.cls ? ' · ' + ev.cls : '') + (ev.arena ? ' · ' + ev.arena : '') + ' · ' + (p.hours || 48) + ' h';
return '< div class = "preset" data-k = "' + k + '" > < div > < div class = "pn" > ' + esc(p.name || nm) +
'< / div > < div class = "psub" > ' + esc(sub) + '< / div > < / div > ' +
'< button class = "primary" data-act = "on" > Aktivieren< / button > ' +
'< button data-act = "load" > Laden< / button > ' +
'< button class = "danger" data-act = "del" > Löschen< / button > < / div > ';
}).join('');
Array.prototype.forEach.call(box.querySelectorAll('.preset'), function (row) {
var k = row.dataset.k, p = m[k];
row.querySelector('[data-act="load"]').onclick = function () { presetToForm(p.event || {}, p.hours); };
row.querySelector('[data-act="on"]').onclick = function () { activatePreset(p); };
row.querySelector('[data-act="del"]').onclick = function () {
if (!confirm('Vorlage „' + (p.name || '') + '“ löschen?')) return;
2026-11-19 02:11:13 +01:00
db.del('admin/events/' + k).then(loadPresets);
2026-11-17 14:17:50 +01:00
};
});
}
function esc(s) { return String(s).replace(/[& < >"]/g, function (c) { return ({ '& ': '& ', '< ': '< ', '>': '> ', '"': '" ' })[c]; }); }
// activate: load the preset into the form, set a fresh window, then publish the whole /live
function activatePreset(p) {
presetToForm(p.event || {}, p.hours);
$('bSave').click();
}
$('bPresetSave').onclick = function () {
var name = $('presetName').value.trim();
if (!name) { alert('Bitte einen Vorlage-Namen eingeben.'); return; }
var preset = { name: name, hours: parseInt($('presetHours').value, 10) || 48, event: eventFromForm() };
2026-11-19 02:11:13 +01:00
db.push('admin/events', preset).then(function (key) {
2026-11-17 14:17:50 +01:00
$('presetName').value = '';
var msg = $('saveMsg'); msg.className = key ? 'status ok' : 'status err';
2026-11-19 02:11:13 +01:00
msg.textContent = key ? 'Vorlage gespeichert.' : 'Vorlage abgelehnt – hat dein Konto Admin-Recht?';
2026-11-17 14:17:50 +01:00
loadPresets();
});
};
// stop the running event without touching motd / unlocks / flags
$('bEvOff').onclick = function () {
$('evOn').checked = false; toggleEv();
$('bSave').click();
};
// already signed in from a previous visit?
if (net.auth.resume & & net.auth.resume() & & net.auth.current) showPanel(net.auth.current);
})();
< / script >
< / body >
< / html >