LuminaWebsite/raids_live.php
Maaxxs b96bbd1780 Consilium: own Discord server - its roles decide who sees the Consilium; rights for Consilium raids and entries
Asked for: the alliances move to their own Discord server with the roles Force Commander, Legion Lead, Legion
Officer and Legionär. Decided: everyone with a role there sees the Consilium (our members too), no role per legion
(assignment stays on the website), new accounts are approved by our admins, rights per role as planned, a
permission for Consilium calendar entries that is assigned later. Server ID 1553882046793777283.

- Two Discord servers: settings.consilium_guild_id (seeded, Verwaltung -> Discord-Bot with a check whether the bot
  is there); a group's role lies on one of them (roles.discord_guild_id, NULL = legion, schema 71). Login and the
  periodic sync read both memberships (discord_fetch_memberships/discord_apply_memberships) and sync groups per
  server; name, avatar, joined date and classes come from the legion server, for allies from the Consilium server.
- Leaving: whoever leaves a server loses its groups; an account is deactivated only when it is on neither
  (discord_member_left_guild; bot_api.php takes in_guilds from the bot, the sync checks all servers, older bot
  versions cannot deactivate Consilium members). Logout text no longer names a server.
- Group form lists the roles of both servers, the group list marks Consilium roles; Consilium-Raids channel is
  chosen from the Consilium server's channels.
- Rights per area: consilium.raids / consilium.raids.manage for Consilium raids (create, manage, restore, delete),
  raids.create / raids.manage only for legion raids (raid_area_can_create, raid_area_can_manage_all,
  raid_can_manage asks the raid's area). consilium.calendar: only with it Consilium calendar entries (allies without
  it cannot add entries; legion members with it get "Für wen?" with legion/Consilium).
- Consilium member list: everyone with a role on the Consilium server - our legion as its own section, allied legions,
  without legion - with the Consilium ranks as tags; legion list and profiles leave the Consilium groups out for
  those who do not see the Consilium. Allies pick their class in the profile.
- Consilium admin page: setup checklist for the new structure with the groups of the Consilium server and their
  rights (setup only for roles.manage). Privacy page, README.

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

102 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();
// Rechte je Bereich wie auf raids.php
$canManageRaids = raid_area_can_manage_all($area);
$canSetRaidPoints = $canManageRaids && $area === 'legion' && user_has_permission('raids.points');
$canCreateRaids = raid_area_can_create($area);
// 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]);