Improve Name2Key support
This commit is contained in:
@@ -14,3 +14,4 @@ testing/
|
||||
localDeploy.js
|
||||
caspertech-node-metaverse-*.tgz
|
||||
dist/classes/cache
|
||||
examples/loginParameters.json
|
||||
|
||||
50
examples/Grid/Name2Key.ts
Normal file
50
examples/Grid/Name2Key.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { ExampleBot } from '../ExampleBot';
|
||||
|
||||
class Name2Key extends ExampleBot
|
||||
{
|
||||
async onConnected(): Promise<void>
|
||||
{
|
||||
const test1 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp');
|
||||
if (test1.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test1.avatarName === 'CasperHelp Resident')
|
||||
{
|
||||
console.log('Test 1 passed');
|
||||
}
|
||||
const test2 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp resident');
|
||||
if (test2.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test2.avatarName === 'CasperHelp Resident')
|
||||
{
|
||||
console.log('Test 2 passed');
|
||||
}
|
||||
|
||||
const test3 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp.resident');
|
||||
if (test3.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test3.avatarName === 'CasperHelp Resident')
|
||||
{
|
||||
console.log('Test 3 passed');
|
||||
}
|
||||
|
||||
const test4 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp', false);
|
||||
if (test4.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test4.avatarName === 'CasperHelp Resident')
|
||||
{
|
||||
console.log('Test 4 passed');
|
||||
}
|
||||
|
||||
const test5 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp resident', false);
|
||||
if (test5.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test5.avatarName === 'CasperHelp Resident')
|
||||
{
|
||||
console.log('Test 5 passed');
|
||||
}
|
||||
|
||||
const test6 = await this.bot.clientCommands.grid.avatarName2KeyAndName('casperhelp.resident', false);
|
||||
if (test6.avatarKey.toString() === '828f7198-42e5-41b4-bd60-926a33ea067b' && test6.avatarName === 'CasperHelp Resident')
|
||||
{
|
||||
console.log('Test 6 passed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new Name2Key().run().then(() =>
|
||||
{
|
||||
|
||||
}).catch((err) =>
|
||||
{
|
||||
console.error(err);
|
||||
});
|
||||
@@ -184,10 +184,6 @@ export class Circuit
|
||||
let subscription: null | Subscription = null;
|
||||
let timeout: Timer | null = null;
|
||||
const receivedChunks: { [key: number]: Buffer } = {};
|
||||
const progress = setInterval(() =>
|
||||
{
|
||||
console.log( ' ... Got ' + Object.keys(receivedChunks).length + ' packets');
|
||||
}, 5000);
|
||||
const resetTimeout = function(): void
|
||||
{
|
||||
if (timeout !== null)
|
||||
@@ -200,7 +196,6 @@ export class Circuit
|
||||
{
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
clearInterval(progress);
|
||||
reject(new Error('Xfer Timeout'));
|
||||
}, 10000);
|
||||
};
|
||||
@@ -241,7 +236,6 @@ export class Circuit
|
||||
{
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
clearInterval(progress);
|
||||
reject(new Error('Xfer Aborted'));
|
||||
}
|
||||
break;
|
||||
@@ -300,7 +294,6 @@ export class Circuit
|
||||
{
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
clearInterval(progress);
|
||||
const buf = Buffer.concat(conc);
|
||||
if (buf.length !== dataSize)
|
||||
{
|
||||
|
||||
@@ -269,131 +269,95 @@ export class GridCommands extends CommandsBase
|
||||
});
|
||||
}
|
||||
|
||||
avatarName2KeyAndName(name: string): Promise<{ avatarKey: UUID, avatarName: string }>
|
||||
async avatarName2KeyAndName(name: string, useCap = true): Promise<{ avatarKey: UUID, avatarName: string }>
|
||||
{
|
||||
name = name.trim().replace('.', ' ');
|
||||
name = name.toLowerCase();
|
||||
if (name.trim().indexOf(' ') === -1)
|
||||
{
|
||||
name = name.trim() + ' resident';
|
||||
}
|
||||
name = name.toLowerCase();
|
||||
|
||||
const queryID = UUID.random();
|
||||
return new Promise<{ avatarKey: UUID, avatarName: string }>((resolve, reject) =>
|
||||
if (useCap && await this.currentRegion.caps.isCapAvailable('AvatarPickerSearch'))
|
||||
{
|
||||
const aprm = new AvatarPickerRequestMessage();
|
||||
aprm.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID,
|
||||
QueryID: queryID
|
||||
};
|
||||
aprm.Data = {
|
||||
Name: Utils.StringToBuffer(name)
|
||||
};
|
||||
|
||||
this.circuit.sendMessage(aprm, PacketFlags.Reliable);
|
||||
this.circuit.waitForMessage<AvatarPickerReplyMessage>(Message.AvatarPickerReply, 10000, (apr: AvatarPickerReplyMessage): FilterResponse =>
|
||||
const trimmedName = name.replace(' resident', '');
|
||||
const result = await this.currentRegion.caps.capsGetXML(['AvatarPickerSearch', { page_size: '100', names: trimmedName }]);
|
||||
if (result.agents)
|
||||
{
|
||||
if (apr.AgentData.QueryID.toString() === queryID.toString())
|
||||
for (const agent of result.agents)
|
||||
{
|
||||
return FilterResponse.Finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FilterResponse.NoMatch;
|
||||
}
|
||||
}).then((apr: AvatarPickerReplyMessage) =>
|
||||
{
|
||||
let foundKey: UUID | undefined;
|
||||
let foundName: string | undefined;
|
||||
for (const dataBlock of apr.Data)
|
||||
{
|
||||
const resultName = (Utils.BufferToStringSimple(dataBlock.FirstName) + ' ' +
|
||||
Utils.BufferToStringSimple(dataBlock.LastName));
|
||||
if (resultName.toLowerCase() === name)
|
||||
if (!agent.username)
|
||||
{
|
||||
foundKey = dataBlock.AvatarID;
|
||||
foundName = resultName;
|
||||
continue;
|
||||
}
|
||||
const avatarName = agent.legacy_first_name + ' ' + agent.legacy_last_name;
|
||||
if (avatarName.toLowerCase() === name)
|
||||
{
|
||||
return {
|
||||
avatarName,
|
||||
avatarKey: new UUID(agent.id.toString()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundKey !== undefined && foundName !== undefined)
|
||||
{
|
||||
resolve({
|
||||
avatarName: foundName,
|
||||
avatarKey: foundKey
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
reject('Name not found')
|
||||
}
|
||||
}).catch((err) =>
|
||||
const queryID = UUID.random();
|
||||
|
||||
|
||||
const aprm = new AvatarPickerRequestMessage();
|
||||
aprm.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID,
|
||||
QueryID: queryID
|
||||
};
|
||||
aprm.Data = {
|
||||
Name: Utils.StringToBuffer(name)
|
||||
};
|
||||
|
||||
this.circuit.sendMessage(aprm, PacketFlags.Reliable);
|
||||
const apr: AvatarPickerReplyMessage = await this.circuit.waitForMessage<AvatarPickerReplyMessage>(Message.AvatarPickerReply, 10000, (apr: AvatarPickerReplyMessage): FilterResponse =>
|
||||
{
|
||||
if (apr.AgentData.QueryID.toString() === queryID.toString())
|
||||
{
|
||||
reject(err);
|
||||
});
|
||||
return FilterResponse.Finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FilterResponse.NoMatch;
|
||||
}
|
||||
});
|
||||
|
||||
let foundKey: UUID | undefined;
|
||||
let foundName: string | undefined;
|
||||
for (const dataBlock of apr.Data)
|
||||
{
|
||||
const resultName = (Utils.BufferToStringSimple(dataBlock.FirstName) + ' ' +
|
||||
Utils.BufferToStringSimple(dataBlock.LastName));
|
||||
if (resultName.toLowerCase() === name)
|
||||
{
|
||||
foundKey = dataBlock.AvatarID;
|
||||
foundName = resultName;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundKey !== undefined && foundName !== undefined)
|
||||
{
|
||||
return {
|
||||
avatarName: foundName,
|
||||
avatarKey: foundKey
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error('Name not found');
|
||||
}
|
||||
}
|
||||
|
||||
avatarName2Key(name: string): Promise<UUID>
|
||||
async avatarName2Key(name: string, useCap = true): Promise<UUID>
|
||||
{
|
||||
name = name.trim().replace('.', ' ');
|
||||
if (name.trim().indexOf(' ') === -1)
|
||||
{
|
||||
name = name.trim() + ' resident';
|
||||
}
|
||||
name = name.toLowerCase();
|
||||
|
||||
const queryID = UUID.random();
|
||||
return new Promise<UUID>((resolve, reject) =>
|
||||
{
|
||||
const aprm = new AvatarPickerRequestMessage();
|
||||
aprm.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID,
|
||||
QueryID: queryID
|
||||
};
|
||||
aprm.Data = {
|
||||
Name: Utils.StringToBuffer(name)
|
||||
};
|
||||
|
||||
this.circuit.sendMessage(aprm, PacketFlags.Reliable);
|
||||
this.circuit.waitForMessage<AvatarPickerReplyMessage>(Message.AvatarPickerReply, 10000, (apr: AvatarPickerReplyMessage): FilterResponse =>
|
||||
{
|
||||
if (apr.AgentData.QueryID.toString() === queryID.toString())
|
||||
{
|
||||
return FilterResponse.Finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FilterResponse.NoMatch;
|
||||
}
|
||||
}).then((apr: AvatarPickerReplyMessage) =>
|
||||
{
|
||||
let found: UUID | null = null;
|
||||
for (const dataBlock of apr.Data)
|
||||
{
|
||||
const resultName = (Utils.BufferToStringSimple(dataBlock.FirstName) + ' ' +
|
||||
Utils.BufferToStringSimple(dataBlock.LastName)).toLowerCase();
|
||||
if (resultName === name)
|
||||
{
|
||||
found = dataBlock.AvatarID;
|
||||
}
|
||||
}
|
||||
|
||||
if (found !== null)
|
||||
{
|
||||
resolve(found);
|
||||
}
|
||||
else
|
||||
{
|
||||
reject('Name not found')
|
||||
}
|
||||
}).catch((err) =>
|
||||
{
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
const result = await this.avatarName2KeyAndName(name, useCap);
|
||||
return result.avatarKey;
|
||||
}
|
||||
|
||||
async getBalance(): Promise<number>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@caspertech/node-metaverse",
|
||||
"version": "0.5.29",
|
||||
"version": "0.5.31",
|
||||
"description": "A node.js interface for Second Life.",
|
||||
"main": "dist/lib/index.js",
|
||||
"types": "dist/lib/index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user