diff --git a/src/commands/Interface.ts b/src/commands/Interface.ts index fab8d2c..82f0bc8 100644 --- a/src/commands/Interface.ts +++ b/src/commands/Interface.ts @@ -23,7 +23,7 @@ export default class Interface { output: process.stdout }); - public static target: Session; + public static target?: Session; private constructor() { } diff --git a/src/commands/target.ts b/src/commands/target.ts index ce3e983..22a23bc 100644 --- a/src/commands/target.ts +++ b/src/commands/target.ts @@ -15,26 +15,27 @@ export default async function handle(command: Command) { SRServer.getInstance().sessions.forEach(client => { possibleTargets.push({ - id: `${client.ctx.address}:${client.ctx.port}`, - uid: client.player.uid, + id: `${client.ctx.address}:${client.ctx.port} (UID: ${client.account.uid})`, + uid: Number(client.account.uid), session: client }); }); if (!target) { c.log("No target specified"); + if (Interface.target) c.log(`Current target: ${Interface.target.account.name} (UID: ${Interface.target.account.uid})`); c.log("Possible targets: "); possibleTargets.forEach(x => c.trail(`${x.id} (UID: ${x.uid})`)); - if(!possibleTargets[1] && possibleTargets[0]){ - c.log(`Auto target the only session ${possibleTargets[0].uid}`); + if (!possibleTargets[1] && possibleTargets[0]) { + c.log(`Auto targetting the only session ${possibleTargets[0].uid}`); Interface.target = possibleTargets[0].session; - } + } return; } - const autoTarget = findBestMatch(target, possibleTargets.map(x => x.id))?.bestMatch.target; + const autoTarget = findBestMatch(target, possibleTargets.map(x => x.id))?.bestMatch?.target; - Interface.target = possibleTargets.find(x => x.id === autoTarget)!.session; + Interface.target = possibleTargets.find(x => x.id === autoTarget)?.session; - c.log(`Target set to ${autoTarget}`); + c.log(`Target set to ${Interface.target ? Interface.target.account.name : "none"} (UID: ${Interface.target ? Interface.target.account.uid : "none"})`); } \ No newline at end of file