Make targetting navigation 100% nullsafe
This commit is contained in:
parent
590236cbfa
commit
91d842c1ec
@ -23,7 +23,7 @@ export default class Interface {
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
public static target: Session;
|
||||
public static target?: Session;
|
||||
|
||||
private constructor() { }
|
||||
|
||||
|
@ -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"})`);
|
||||
}
|
Loading…
Reference in New Issue
Block a user