Añadir /ban-history (Historial de sanciones): baneos y muteos
Lee las BD de AzerothCore: baneos de account_banned (cuenta), battlenet_account_bans (Battle.net) y character_banned (personajes de la cuenta); muteos de account_muted. Estado Activo/Activo (permanente)/Expirado según bandate/unbandate/active. Dos tablas (baneos con alcance, muteos) + info. lib/ban-history.ts (getSanctions), tolerante si AC no está poblado. Django stub. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import type { Metadata } from 'next'
|
||||
import { setRequestLocale } from 'next-intl/server'
|
||||
import { redirect, Link } from '@/i18n/navigation'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { getSanctions, type Sanction } from '@/lib/ban-history'
|
||||
import { PageShell } from '@/components/PageShell'
|
||||
import { ServiceBox } from '@/components/ServiceBox'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export const metadata: Metadata = { title: 'Historial de sanciones' }
|
||||
|
||||
/** Fecha en formato DD-MM-YYYY HH:MM:SS. */
|
||||
function fmt(d: Date): string {
|
||||
const p = (n: number) => String(n).padStart(2, '0')
|
||||
return `${p(d.getDate())}-${p(d.getMonth() + 1)}-${d.getFullYear()} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`
|
||||
}
|
||||
|
||||
function StatusCell({ s }: { s: Sanction }) {
|
||||
return <span className={s.active ? 'red-info2' : 'green-info2'}>{s.status}</span>
|
||||
}
|
||||
|
||||
/** Caja con la tabla de sanciones (baneos o muteos), o el vacío del diseño. */
|
||||
function SanctionBox({
|
||||
title,
|
||||
emptyText,
|
||||
rows,
|
||||
showScope,
|
||||
}: {
|
||||
title: string
|
||||
emptyText: string
|
||||
rows: Sanction[]
|
||||
showScope: boolean
|
||||
}) {
|
||||
return (
|
||||
<div className="box-content">
|
||||
<div className="title-box-content">
|
||||
<h2>{title}</h2>
|
||||
</div>
|
||||
<div className="body-box-content info-box-light">
|
||||
{rows.length === 0 ? (
|
||||
<table className="max-center-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="centered">
|
||||
<span>{emptyText}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
<table className="max-center-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
{showScope && <th>Alcance</th>}
|
||||
<th>Motivo</th>
|
||||
<th>Sancionado por</th>
|
||||
<th>Fecha</th>
|
||||
<th>Expira</th>
|
||||
<th>Estado</th>
|
||||
</tr>
|
||||
{rows.map((s, i) => (
|
||||
<tr key={i}>
|
||||
{showScope && (
|
||||
<td>
|
||||
<span>{s.scope}</span>
|
||||
</td>
|
||||
)}
|
||||
<td>
|
||||
<span>{s.reason}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span>{s.by}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span>{fmt(s.date)}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span>{s.expires ? fmt(s.expires) : 'Permanente'}</span>
|
||||
</td>
|
||||
<td>
|
||||
<StatusCell s={s} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default async function BanHistoryPage({ params }: { params: Promise<{ locale: string }> }) {
|
||||
const { locale } = await params
|
||||
setRequestLocale(locale)
|
||||
|
||||
const session = await getSession()
|
||||
if (!session.bnetId) redirect({ href: '/login', locale })
|
||||
if (!session.username) redirect({ href: '/select-account', locale })
|
||||
|
||||
const { bans, mutes } = await getSanctions(session.accountId!, session.bnetId)
|
||||
|
||||
return (
|
||||
<PageShell title="Historial de sanciones">
|
||||
<ServiceBox>
|
||||
<br />
|
||||
<p>Aquí podrás ver todas las sanciones que ha tenido la cuenta.</p>
|
||||
<p>
|
||||
Si tienes una sanción vigente, verás que su estado indica <span className="red-info2">Activo</span>.
|
||||
</p>
|
||||
<p>Para evitar que tu cuenta sea sancionada, recuerda respetar las normas de nuestro servidor.</p>
|
||||
<br />
|
||||
<div className="restore-item-table">
|
||||
<p>
|
||||
<i className="fas fa-exclamation-triangle"></i> <span>Importante:</span>
|
||||
</p>
|
||||
<p>
|
||||
Si tu cuenta aparece como sancionada o cerrada al intentar ingresar al reino, pero tu historial no tiene
|
||||
ninguna sanción activa, significa que has tenido un bloqueo automático temporal por demasiados intentos de
|
||||
inicio de sesión fallidos.
|
||||
</p>
|
||||
<p>
|
||||
Espera al menos 10 minutos para volver a intentar y asegúrate de usar nombre de cuenta y contraseña
|
||||
correctas.
|
||||
</p>
|
||||
</div>
|
||||
<br />
|
||||
<p>
|
||||
Para realizar un reclamo de sanción, por favor ingresa en nuestro <Link href="/forum">foro</Link> y visita la
|
||||
sección Reclamaciones.
|
||||
</p>
|
||||
</ServiceBox>
|
||||
|
||||
<SanctionBox title="Historial de baneos" emptyText="No hay baneos" rows={bans} showScope />
|
||||
<SanctionBox title="Historial de muteos" emptyText="No hay muteos" rows={mutes} showScope={false} />
|
||||
</PageShell>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import type { RowDataPacket } from 'mysql2'
|
||||
import { db, DB } from './db'
|
||||
|
||||
/** Una sanción (baneo o muteo) de la cuenta. */
|
||||
export interface Sanction {
|
||||
scope: string // 'Cuenta' | 'Battle.net' | 'Personaje: Nombre'
|
||||
reason: string
|
||||
by: string
|
||||
date: Date
|
||||
expires: Date | null // null = permanente
|
||||
active: boolean
|
||||
status: string // etiqueta: Activo / Activo (permanente) / Expirado
|
||||
}
|
||||
|
||||
/** Estado de un baneo a partir de sus timestamps UNIX (segundos) y el flag active. */
|
||||
function banState(bandate: number, unbandate: number, active?: number): { active: boolean; status: string; expires: Date | null } {
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
const permanent = unbandate === 0 || unbandate <= bandate
|
||||
const flagActive = active === undefined ? true : active === 1
|
||||
const stillActive = flagActive && (permanent || unbandate > now)
|
||||
return {
|
||||
active: stillActive,
|
||||
status: stillActive ? (permanent ? 'Activo (permanente)' : 'Activo') : 'Expirado',
|
||||
expires: permanent ? null : new Date(unbandate * 1000),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Historial de sanciones de una cuenta desde las BD de AzerothCore:
|
||||
* - Baneos: `acore_auth.account_banned` (cuenta de juego), `battlenet_account_bans`
|
||||
* (cuenta Battle.net) y `acore_characters.character_banned` (personajes de la cuenta).
|
||||
* - Muteos: `acore_auth.account_muted` (por cuenta de juego).
|
||||
* Cada consulta es tolerante a fallos (devuelve [] si la tabla no existe / AC no
|
||||
* está poblado) para no romper la página. Ordenado por fecha descendente.
|
||||
*/
|
||||
export async function getSanctions(accountId: number, bnetId?: number): Promise<{ bans: Sanction[]; mutes: Sanction[] }> {
|
||||
const bans: Sanction[] = []
|
||||
const mutes: Sanction[] = []
|
||||
if (!accountId) return { bans, mutes }
|
||||
|
||||
// 1) Baneos de la cuenta de juego.
|
||||
try {
|
||||
const [rows] = await db(DB.auth).query<RowDataPacket[]>(
|
||||
'SELECT bandate, unbandate, bannedby, banreason, active FROM account_banned WHERE id = ? ORDER BY bandate DESC',
|
||||
[accountId],
|
||||
)
|
||||
for (const r of rows) {
|
||||
const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active))
|
||||
bans.push({ scope: 'Cuenta', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
}
|
||||
} catch {
|
||||
/* AC no poblado */
|
||||
}
|
||||
|
||||
// 2) Baneos de la cuenta Battle.net (sin columna active).
|
||||
if (bnetId) {
|
||||
try {
|
||||
const [rows] = await db(DB.auth).query<RowDataPacket[]>(
|
||||
'SELECT bandate, unbandate, bannedby, banreason FROM battlenet_account_bans WHERE id = ? ORDER BY bandate DESC',
|
||||
[bnetId],
|
||||
)
|
||||
for (const r of rows) {
|
||||
const s = banState(Number(r.bandate), Number(r.unbandate))
|
||||
bans.push({ scope: 'Battle.net', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
}
|
||||
} catch {
|
||||
/* AC no poblado */
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Baneos de personaje (de los personajes de la cuenta).
|
||||
try {
|
||||
const [chars] = await db(DB.characters).query<RowDataPacket[]>('SELECT guid, name FROM characters WHERE account = ?', [accountId])
|
||||
if (chars.length > 0) {
|
||||
const nameByGuid = new Map<number, string>(chars.map((c) => [Number(c.guid), String(c.name)]))
|
||||
const guids = [...nameByGuid.keys()]
|
||||
const [rows] = await db(DB.characters).query<RowDataPacket[]>(
|
||||
`SELECT guid, bandate, unbandate, bannedby, banreason, active FROM character_banned WHERE guid IN (${guids.map(() => '?').join(',')}) ORDER BY bandate DESC`,
|
||||
guids,
|
||||
)
|
||||
for (const r of rows) {
|
||||
const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active))
|
||||
bans.push({ scope: `Personaje: ${nameByGuid.get(Number(r.guid)) ?? '?'}`, reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
/* AC no poblado */
|
||||
}
|
||||
|
||||
// 4) Muteos de la cuenta de juego (mutetime = fin del muteo).
|
||||
try {
|
||||
const [rows] = await db(DB.auth).query<RowDataPacket[]>(
|
||||
'SELECT mutedate, mutetime, mutedby, mutereason FROM account_muted WHERE guid = ? ORDER BY mutedate DESC',
|
||||
[accountId],
|
||||
)
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
for (const r of rows) {
|
||||
const end = Number(r.mutetime)
|
||||
const active = end > now
|
||||
mutes.push({
|
||||
scope: 'Cuenta',
|
||||
reason: String(r.mutereason || '—'),
|
||||
by: String(r.mutedby || '—'),
|
||||
date: new Date(Number(r.mutedate) * 1000),
|
||||
expires: end > 0 ? new Date(end * 1000) : null,
|
||||
active,
|
||||
status: active ? 'Activo' : 'Expirado',
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
/* AC no poblado */
|
||||
}
|
||||
|
||||
bans.sort((a, b) => b.date.getTime() - a.date.getTime())
|
||||
mutes.sort((a, b) => b.date.getTime() - a.date.getTime())
|
||||
return { bans, mutes }
|
||||
}
|
||||
Reference in New Issue
Block a user