6337de73ad
La página de cuenta no se parecía a la de Django (oro descuadrado, info como
tabla, herramientas en grupos abiertos). Reescrita para replicar el
partials/my-account.html + isla AccountDashboard de Django:
- Información en DOS fieldsets (.account-fieldset): «Datos básicos» (cuentas,
correos, fecha de registro, IPs) y «Estado de la cuenta» (insignia de rango
nw-rank + PD/PV/créditos/token + baneo + reclutamiento). lib/account.ts
ampliado para traer reg_mail/email/joindate/last_ip/last_attempt_ip, estado
de baneo (account_banned) y nº de reclutados.
- Personajes en char-box con el markup exacto de Django: retrato flotante +
oro EN LÍNEA (monedas width=10). Antes las monedas salían a tamaño nativo
(descuadre) y apiladas.
- Herramientas en paneles plegables (acordeón) «OPCIONES DE CUENTA / OPCIONES
DE PERSONAJE» como Django (componente cliente AccountTools), con los
servicios ya implementados en Next y las etiquetas/descripciones exactas.
- globals.css: revertir otro reset del preflight de Tailwind — img{display:
block} apilaba verticalmente los iconos en línea (monedas); el tema los usa
inline como la web Django. Volvemos a img{display:inline}.
Verificado con Playwright (login real con cuenta de prueba + captura): info,
personajes con oro en línea y paneles que expanden con sus iconos; home sin
regresión por el cambio de img.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
176 lines
4.4 KiB
TypeScript
176 lines
4.4 KiB
TypeScript
import type { RowDataPacket } from 'mysql2'
|
|
import { db, DB } from './db'
|
|
import type { SessionData } from './session'
|
|
import { getZoneName, getClassCss, getCharacterImage, getRaceName, getClassName } from './character-info'
|
|
|
|
export interface Character {
|
|
name: string
|
|
level: number
|
|
gold: number
|
|
silver: number
|
|
copper: number
|
|
race: number
|
|
classId: number
|
|
className: string
|
|
raceName: string
|
|
classCss: string
|
|
zone: string
|
|
imageUrl: string
|
|
}
|
|
|
|
export interface AccountDashboard {
|
|
bnetEmail: string
|
|
gameAccount: string
|
|
regMail: string
|
|
email: string
|
|
joindate: string
|
|
lastIp: string
|
|
lastAttemptIp: string
|
|
dp: number
|
|
vp: number
|
|
battlepayCredits: number
|
|
securityTokenDate: string | null
|
|
isBanned: boolean
|
|
unbanDate: string | null
|
|
isRecruited: boolean
|
|
recruitedCount: number
|
|
characters: Character[]
|
|
}
|
|
|
|
/** Datos del panel de cuenta. Resiliente si las BD de AzerothCore no están pobladas. */
|
|
export async function getAccountDashboard(session: SessionData): Promise<AccountDashboard> {
|
|
const accountId = session.accountId ?? 0
|
|
|
|
let dp = 0
|
|
let vp = 0
|
|
try {
|
|
const [p] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT dp, vp FROM home_api_points WHERE accountID = ?',
|
|
[accountId],
|
|
)
|
|
if (p[0]) {
|
|
dp = p[0].dp
|
|
vp = p[0].vp
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
let battlepayCredits = 0
|
|
try {
|
|
const [c] = await db(DB.auth).query<RowDataPacket[]>(
|
|
'SELECT battlePayCredits FROM battlenet_accounts WHERE id = ?',
|
|
[session.bnetId ?? 0],
|
|
)
|
|
if (c[0]?.battlePayCredits != null) battlepayCredits = c[0].battlePayCredits
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
// Datos de la tabla account (correos, fecha, IPs, reclutador).
|
|
let regMail = ''
|
|
let email = ''
|
|
let joindate = ''
|
|
let lastIp = ''
|
|
let lastAttemptIp = ''
|
|
let isRecruited = false
|
|
try {
|
|
const [a] = await db(DB.auth).query<RowDataPacket[]>(
|
|
'SELECT reg_mail, email, last_ip, last_attempt_ip, joindate, recruiter FROM account WHERE id = ?',
|
|
[accountId],
|
|
)
|
|
if (a[0]) {
|
|
regMail = a[0].reg_mail || ''
|
|
email = a[0].email || ''
|
|
lastIp = a[0].last_ip || ''
|
|
lastAttemptIp = a[0].last_attempt_ip || ''
|
|
isRecruited = Boolean(a[0].recruiter)
|
|
if (a[0].joindate) joindate = new Date(a[0].joindate).toLocaleString('es-ES')
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
// Estado de baneo (account_banned activo).
|
|
let isBanned = false
|
|
let unbanDate: string | null = null
|
|
try {
|
|
const [bn] = await db(DB.auth).query<RowDataPacket[]>(
|
|
'SELECT unbandate FROM account_banned WHERE id = ? AND active = 1 LIMIT 1',
|
|
[accountId],
|
|
)
|
|
if (bn[0]) {
|
|
isBanned = true
|
|
unbanDate = new Date(Number(bn[0].unbandate) * 1000).toLocaleString('es-ES')
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
// Nº de amigos reclutados.
|
|
let recruitedCount = 0
|
|
try {
|
|
const [rc] = await db(DB.auth).query<RowDataPacket[]>(
|
|
'SELECT COUNT(*) AS n FROM account WHERE recruiter = ?',
|
|
[accountId],
|
|
)
|
|
if (rc[0]) recruitedCount = Number(rc[0].n)
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
let securityTokenDate: string | null = null
|
|
try {
|
|
const [s] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT created_at FROM home_securitytoken WHERE user_id = ? ORDER BY created_at DESC LIMIT 1',
|
|
[accountId],
|
|
)
|
|
if (s[0]) securityTokenDate = new Date(s[0].created_at).toISOString()
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
let characters: Character[] = []
|
|
try {
|
|
const [ch] = await db(DB.characters).query<RowDataPacket[]>(
|
|
'SELECT name, level, money, race, class, zone, gender FROM characters WHERE account = ?',
|
|
[accountId],
|
|
)
|
|
characters = ch.map((r) => ({
|
|
name: r.name,
|
|
level: r.level,
|
|
gold: Math.floor(r.money / 10000),
|
|
silver: Math.floor((r.money % 10000) / 100),
|
|
copper: r.money % 100,
|
|
race: r.race,
|
|
classId: r.class,
|
|
className: getClassName(r.class),
|
|
raceName: getRaceName(r.race),
|
|
classCss: getClassCss(r.class),
|
|
zone: getZoneName(r.zone),
|
|
imageUrl: getCharacterImage(r.class, r.race, r.gender),
|
|
}))
|
|
} catch {
|
|
/* la BD de personajes puede no estar poblada */
|
|
}
|
|
|
|
return {
|
|
bnetEmail: session.bnetEmail ?? '',
|
|
gameAccount: session.username ?? '',
|
|
regMail,
|
|
email,
|
|
joindate,
|
|
lastIp,
|
|
lastAttemptIp,
|
|
dp,
|
|
vp,
|
|
battlepayCredits,
|
|
securityTokenDate,
|
|
isBanned,
|
|
unbanDate,
|
|
isRecruited,
|
|
recruitedCount,
|
|
characters,
|
|
}
|
|
}
|