Ein Aufrufer darf Organisator- und Spieler-Zugang kombinieren (Authorization + X-Player-Token). Berechtigungen prüfen jetzt einzelne Merkmale statt einer Rangstufe. In der Lobby gibt es „Selbst mitspielen?“, Teamlinks funktionieren auch im Organisator-Browser. Online-Status wird direkt nach dem Beitritt aktualisiert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
// Zugangsdaten pro Match im Browser. Nach Neuladen oder Verbindungsabbruch
|
||
// meldet sich der Client damit automatisch wieder an.
|
||
//
|
||
// Aufbau: { token, kind: 'organizer' | 'player' | 'spectator', playerToken? }
|
||
// playerToken gibt es nur beim Organisator, wenn er selbst einem Team beigetreten ist.
|
||
const KEY = (matchId) => `cs2mv:match:${matchId}`;
|
||
const memory = new Map();
|
||
|
||
export function getAccess(matchId) {
|
||
try {
|
||
return JSON.parse(localStorage.getItem(KEY(matchId))) ?? memory.get(matchId) ?? null;
|
||
} catch {
|
||
return memory.get(matchId) ?? null;
|
||
}
|
||
}
|
||
|
||
export function setAccess(matchId, access) {
|
||
memory.set(matchId, access);
|
||
try {
|
||
localStorage.setItem(KEY(matchId), JSON.stringify(access));
|
||
} catch {
|
||
/* privater Modus – Zugang gilt dann nur für diese Sitzung */
|
||
}
|
||
}
|
||
|
||
export function clearAccess(matchId) {
|
||
memory.delete(matchId);
|
||
try {
|
||
localStorage.removeItem(KEY(matchId));
|
||
} catch {
|
||
/* ignorieren */
|
||
}
|
||
}
|
||
|
||
export function getToken(matchId) {
|
||
return getAccess(matchId)?.token ?? null;
|
||
}
|
||
|
||
export function getPlayerToken(matchId) {
|
||
return getAccess(matchId)?.playerToken ?? null;
|
||
}
|
||
|
||
/** Spieler-Token neben dem Organisator-Zugang speichern bzw. entfernen (null). */
|
||
export function setPlayerToken(matchId, playerToken) {
|
||
const access = getAccess(matchId);
|
||
if (!access) return;
|
||
const next = { ...access };
|
||
if (playerToken) next.playerToken = playerToken;
|
||
else delete next.playerToken;
|
||
setAccess(matchId, next);
|
||
}
|