From ad1b43ba3e61608d698b0fa8fb2f9eb999478f65 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Tue, 2 Aug 2022 03:42:03 +0200 Subject: [PATCH] Fix avatar command --- src/commands/avatar.ts | 2 ++ src/commands/target.ts | 2 +- src/server/kcp/Session.ts | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commands/avatar.ts b/src/commands/avatar.ts index 0a7c376..d455b1e 100644 --- a/src/commands/avatar.ts +++ b/src/commands/avatar.ts @@ -29,4 +29,6 @@ export default async function handle(command: Command) { Avatar.remove(uid, avatarId).then(() => c.log(`Avatar ${avatarId} removed from ${uid}`)); break; } + + Interface.target.sync(); } \ No newline at end of file diff --git a/src/commands/target.ts b/src/commands/target.ts index 65fe303..84826d6 100644 --- a/src/commands/target.ts +++ b/src/commands/target.ts @@ -16,7 +16,7 @@ export default async function handle(command: Command) { SRServer.getInstance().sessions.forEach(client => { possibleTargets.push({ id: `${client.ctx.address}:${client.ctx.port}`, - uid: Number(client.account.uid), + uid: Number(client.player.db._id), session: client }); }); diff --git a/src/server/kcp/Session.ts b/src/server/kcp/Session.ts index c99e920..ab7fd8d 100644 --- a/src/server/kcp/Session.ts +++ b/src/server/kcp/Session.ts @@ -8,6 +8,8 @@ import Logger, { VerboseLevel } from '../../util/Logger'; import defaultHandler from '../packets/PacketHandler'; import Account from '../../db/Account'; import Player from '../../db/Player'; +import { PlayerSyncScNotify } from '../../data/proto/StarRail'; +import Avatar from '../../db/Avatar'; function r(...args: string[]) { return fs.readFileSync(resolve(__dirname, ...args)); @@ -68,6 +70,18 @@ export default class Session { }); } + public async sync() { + const avatars = await Avatar.fromUID(this.player.db._id); + this.send("PlayerSyncScNotify", { + avatarSync: { + avatarList: avatars.map(x => x.data), + }, + basicInfo: this.player.db.basicInfo + } as PlayerSyncScNotify); + + this.player.save(); + } + public send(name: PacketName, body: {}) { this.c.debug(body); const packet = Packet.encode(name, body);