web-next: herramientas de PD (transferir, comercio, códigos de promoción)
- /transfer-d-points: transferir PD a la cuenta dueña de un personaje (requiere token de seguridad; movimiento atómico con FOR UPDATE). - /trade-points: comercio PD<->oro mediante códigos de 1 solo uso (contraseña + token + Turnstile; oro al creador por SOAP; expira 1h; lock de 5s tras canjear; rollback total si falla la entrega). - /promo-code: canje de códigos por PD/PV (sensibles a mayúsculas/minúsculas, usos limitados, 1 canje por cuenta). - /admin/promo: panel para crear / editar / activar / desactivar / borrar códigos de promoción. - Tablas nuevas (sql/): home_tradecode, home_promocode, home_promoredemption. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { getSession } from '@/lib/session'
|
||||
import { checkSecurityToken } from '@/lib/security-token'
|
||||
import { getAccountIdByCharacterName } from '@/lib/characters'
|
||||
import { transferDPoints } from '@/lib/dpoints'
|
||||
|
||||
/**
|
||||
* Transfiere PD desde la cuenta en sesión a la cuenta dueña del personaje
|
||||
* indicado. Requiere el token de seguridad de la cuenta. Acción irreversible.
|
||||
*/
|
||||
export async function POST(request: Request) {
|
||||
const session = await getSession()
|
||||
if (!session.accountId || !session.username) {
|
||||
return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
|
||||
}
|
||||
|
||||
let body: Record<string, unknown> = {}
|
||||
try {
|
||||
body = await request.json()
|
||||
} catch {
|
||||
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
|
||||
}
|
||||
|
||||
const character = String(body.character ?? '').trim()
|
||||
const token = String(body.token ?? '').trim()
|
||||
const amount = Number(body.amount)
|
||||
|
||||
if (!character || !token) return Response.json({ success: false, error: 'missingFields' })
|
||||
if (!Number.isInteger(amount) || amount <= 0) return Response.json({ success: false, error: 'invalidAmount' })
|
||||
|
||||
if (!(await checkSecurityToken(session.accountId, token))) {
|
||||
return Response.json({ success: false, error: 'invalidToken' })
|
||||
}
|
||||
|
||||
const destAccountId = await getAccountIdByCharacterName(character)
|
||||
if (!destAccountId) return Response.json({ success: false, error: 'characterNotFound' })
|
||||
if (destAccountId === session.accountId) return Response.json({ success: false, error: 'sameAccount' })
|
||||
|
||||
const result = await transferDPoints(session.accountId, destAccountId, amount)
|
||||
return Response.json(result)
|
||||
}
|
||||
Reference in New Issue
Block a user