From d7e0d429064a08ac3d862c2bcd67be7fe5729960 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Tue, 2 Aug 2022 19:00:47 +0200 Subject: [PATCH] Fallback on lineupname --- src/db/Player.ts | 11 ++++++++++- src/server/packets/SetLineupNameCsReq.ts | 12 ++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/db/Player.ts b/src/db/Player.ts index 9720941..8decf3b 100644 --- a/src/db/Player.ts +++ b/src/db/Player.ts @@ -1,5 +1,5 @@ import Session from "../server/kcp/Session"; -import { ExtraLineupType, HeroBasicType, LineupInfo, Vector } from "../data/proto/StarRail"; +import { AvatarType, ExtraLineupType, HeroBasicType, LineupInfo, Vector } from "../data/proto/StarRail"; import Logger from "../util/Logger"; import Account from "./Account"; import Avatar from "./Avatar"; @@ -77,6 +77,15 @@ export default class Player { const avatars = await Avatar.fromLineup(this.uid, lineup); let slot = 0; avatars.forEach(avatar => { + // Fallback lineup + if (!avatar.lineup) avatar.lineup = { + avatarType: AvatarType.AVATAR_FORMAL_TYPE, + hp: 10000, + id: 1001, + satiety: 100, + slot: slot, + sp: 10000 + } avatar.lineup.slot = slot++; }); return { diff --git a/src/server/packets/SetLineupNameCsReq.ts b/src/server/packets/SetLineupNameCsReq.ts index a25bc71..6fe94d6 100644 --- a/src/server/packets/SetLineupNameCsReq.ts +++ b/src/server/packets/SetLineupNameCsReq.ts @@ -5,10 +5,14 @@ import Session from "../kcp/Session"; export default async function handle(session: Session, packet: Packet) { const body = packet.body as SetLineupNameCsReq; - let curLineup = await session.player.getLineup(); - curLineup.name = body.name; - session.player.setLineup(curLineup); - session.player.save(); + try { + let curLineup = await session.player.getLineup(); + curLineup.name = body.name; + session.player.setLineup(curLineup); + session.player.save(); + } catch { + session.c.error("Failed to set lineup name", false); + } session.send("SetLineupNameScRsp", { retcode: 0,