LuminaWebsite/raids_live.php
Maaxxs 5aaf44eaec Consilium Elyseum: allied legions get their own view - own raids, calendar entries, member tab and shared live map sessions
Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.

- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
  dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
  area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
  legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
  users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
  (dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
  Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
  Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
  subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
  legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
  The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
  the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
  shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
  areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
  Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
  (guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
  database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 01:36:49 +02:00

101 lines
3.5 KiB
PHP

<?php
/**
* Live-Aktualisierung der Raid-Seite (assets/js/raids.js fragt hier regelmaessig nach).
*
* GET /raids_live.php?status=active&known=<raid_id>:<rev>,<raid_id>:<rev>,...
*
* Antwort: Reihenfolge der Raids, ihr aktueller Fingerabdruck (rev) und fertig gerenderte Karten
* fuer alle Raids, deren Fingerabdruck sich gegenueber "known" geaendert hat. Aenderungen aus dem
* Discord kommen so ebenfalls an, weil die Daten wie auf der Seite live von der Raid-API stammen.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raid_card.php';
// Wird per fetch() aufgerufen - Fehler deshalb als JSON statt Weiterleitung auf die Login-Seite.
if (!current_user()) {
http_response_code(401);
json_response(false, 'Bitte neu anmelden.');
}
// Bereich wie auf raids.php: Legion oder Consilium Elyseum - nur, wenn man ihn sehen darf
$area = (string) ($_GET['bereich'] ?? 'legion');
if (!in_array($area, ['legion', 'consilium'], true) || !raid_area_visible($area)) {
http_response_code(403);
json_response(false, 'Dir fehlt die Berechtigung, Raids zu sehen.');
}
$status = (string) ($_GET['status'] ?? 'active');
if (!in_array($status, RAID_STATUSES, true)) {
$status = 'active';
}
$known = [];
foreach (explode(',', (string) ($_GET['known'] ?? '')) as $pair) {
$parts = explode(':', trim($pair), 2);
if (count($parts) === 2 && ctype_digit($parts[0])) {
$known[$parts[0]] = $parts[1];
}
}
$currentUser = current_user();
$canManageRaids = user_has_permission('raids.manage');
$canSetRaidPoints = $canManageRaids && user_has_permission('raids.points');
$canCreateRaids = $canManageRaids || user_has_permission('raids.create');
// Die Formulare in den Karten brauchen das CSRF-Token der Sitzung - danach die Sitzung freigeben,
// damit eine langsame Raid-API andere Tabs derselben Person nicht blockiert.
csrf_token();
session_write_close();
try {
$raids = raids_in_area(fetch_raids($status), $area);
} catch (Throwable $e) {
http_response_code(502);
json_response(false, 'Raid-Daten konnten nicht geladen werden.');
}
try {
$raidSettings = raid_settings_all();
} catch (PDOException $e) {
$raidSettings = [];
}
$order = [];
$revs = [];
$changed = [];
foreach ($raids as $raid) {
$raidId = (string) (int) ($raid['raid_id'] ?? 0);
$rev = raid_card_rev($raid, $raidSettings[$raidId] ?? null);
$order[] = $raidId;
$revs[$raidId] = $rev;
if (isset($known[$raidId]) && $known[$raidId] !== $rev) {
$changed[$raidId] = $raid;
}
}
$cards = [];
if (!empty($changed)) {
$premades = [];
if ($canCreateRaids) {
try {
$premades = fetch_premades();
} catch (Throwable $e) {
$premades = [];
}
}
$context = [
'status' => $status,
'current_discord_id' => $currentUser['discord_id'] ?? null,
'current_user_id' => (int) $currentUser['id'],
'can_manage' => $canManageRaids,
'can_set_points' => $canSetRaidPoints,
'settings' => $raidSettings,
'premades' => $premades,
'premade_banners' => premade_banners_by_name(),
'new_since' => isset($_SESSION['raids_new_since']) ? (int) $_SESSION['raids_new_since'] : null,
];
foreach ($changed as $raidId => $raid) {
ob_start();
render_raid_card($raid, $context);
$cards[$raidId] = trim((string) ob_get_clean());
}
}
header('Cache-Control: no-store');
json_response(true, '', ['order' => $order, 'revs' => $revs, 'cards' => (object) $cards]);