"use server"; import { revalidatePath } from "next/cache"; import { auth } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import { rcon } from "@/lib/services/rcon"; // Emulator motto column is VARCHAR(127); keep the CMS-side write within bounds. const MOTTO_MAX = 127; /** * Update the SIGNED-IN user's motto. The id is taken from the session * (re-fetched via auth()), never from the submitted FormData, so a crafted * form cannot mutate another account. Mirrors AtomCMS: persist + RCON setmotto * so an online user sees the change live. */ export async function updateMotto(formData: FormData): Promise { const session = await auth(); if (!session?.user?.id) return; const id = Number(session.user.id); if (!Number.isFinite(id)) return; const motto = String(formData.get("motto") ?? "").slice(0, MOTTO_MAX); try { await prisma.user.update({ where: { id }, data: { motto } }); } catch { // DB unavailable — fail soft; nothing to persist. return; } try { await rcon.setMotto(id, motto); } catch { // RCON is best-effort; the change is already persisted. } revalidatePath("/settings"); }