Improve login, replace deprecated substr calls
This commit is contained in:
@@ -88,9 +88,9 @@ class GroupChat extends ExampleBot
|
||||
}
|
||||
else if (event.from.toString() === this.bot.agentID().toString())
|
||||
{
|
||||
if (event.message.substr(0, 5) === 'ping ')
|
||||
if (event.message.substring(0, 5) === 'ping ')
|
||||
{
|
||||
const pingID = event.message.substr(5);
|
||||
const pingID = event.message.substring(5);
|
||||
if (this.pings[pingID])
|
||||
{
|
||||
const time = (new Date().getTime()) - this.pings[pingID];
|
||||
|
||||
@@ -10,6 +10,12 @@ import { Utils } from './classes/Utils';
|
||||
import { UUID } from './classes/UUID';
|
||||
import { BotOptionFlags } from './enums/BotOptionFlags';
|
||||
import { URL } from 'url';
|
||||
import * as os from 'os';
|
||||
|
||||
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
|
||||
const packageJson = require(packageJsonPath);
|
||||
const version = packageJson.version;
|
||||
|
||||
|
||||
export class LoginHandler
|
||||
{
|
||||
@@ -53,7 +59,7 @@ export class LoginHandler
|
||||
const macAddress: string[] = [];
|
||||
for (let i = 0; i < 12; i = i + 2)
|
||||
{
|
||||
macAddress.push(nameHash.substr(i, 2));
|
||||
macAddress.push(nameHash.substring(i, i + 2));
|
||||
}
|
||||
|
||||
let hardwareID: string | null = null;
|
||||
@@ -86,28 +92,50 @@ export class LoginHandler
|
||||
{
|
||||
password = params.getHashedPassword();
|
||||
}
|
||||
|
||||
let platform = '???'
|
||||
switch (os.platform())
|
||||
{
|
||||
case 'darwin':
|
||||
platform = 'mac';
|
||||
break;
|
||||
case 'linux':
|
||||
platform = 'lnx';
|
||||
break;
|
||||
case 'win32':
|
||||
platform = 'win';
|
||||
break;
|
||||
}
|
||||
|
||||
const versions = version.split('.');
|
||||
const major = versions.length > 0 ? versions[0] : '0';
|
||||
const minor = versions.length > 1 ? versions[1] : '0';
|
||||
const patch = versions.length > 2 ? versions[2] : '0';
|
||||
let build = major.padStart(2, '0') + minor.padStart(2, '0') + patch.padStart(2, '0');
|
||||
build = build.replace(/^0+/, '');
|
||||
|
||||
client.methodCall('login_to_simulator',
|
||||
[
|
||||
{
|
||||
'first': params.firstName,
|
||||
'last': params.lastName,
|
||||
'passwd': password,
|
||||
'start': params.start,
|
||||
'major': '0',
|
||||
'minor': '0',
|
||||
'patch': '1',
|
||||
'build': '0',
|
||||
'platform': 'win',
|
||||
'token': mfaToken,
|
||||
'mfa_hash': mfaHash,
|
||||
'id0': hardwareID,
|
||||
'mac': macAddress.join(':'),
|
||||
'viewer_digest': viewerDigest,
|
||||
'user_agent': 'node-metaverse',
|
||||
'author': 'nmv@caspertech.co.uk',
|
||||
'agree_to_tos': params.agreeToTOS,
|
||||
'read_critical': params.readCritical,
|
||||
'options': [
|
||||
first: params.firstName,
|
||||
last: params.lastName,
|
||||
passwd: password,
|
||||
start: params.start,
|
||||
channel: 'libnmv',
|
||||
major,
|
||||
minor,
|
||||
patch,
|
||||
build,
|
||||
platform,
|
||||
version: version + '.' + build,
|
||||
token: mfaToken,
|
||||
mfa_hash: mfaHash,
|
||||
id0: Utils.MD5String(String(hardwareID)),
|
||||
mac: macAddress.join(':'),
|
||||
viewer_digest: viewerDigest,
|
||||
agree_to_tos: params.agreeToTOS,
|
||||
read_critical: params.readCritical,
|
||||
options: [
|
||||
'inventory-root',
|
||||
'inventory-skeleton',
|
||||
'inventory-lib-root',
|
||||
|
||||
@@ -346,7 +346,7 @@ export class InventoryItem
|
||||
{
|
||||
if (result.value.indexOf('|') !== -1)
|
||||
{
|
||||
item.name = result.value.substr(0, result.value.indexOf('|'));
|
||||
item.name = result.value.substring(0, result.value.indexOf('|'));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -358,7 +358,7 @@ export class InventoryItem
|
||||
{
|
||||
if (result.value.indexOf('|') !== -1)
|
||||
{
|
||||
item.description = result.value.substr(0, result.value.indexOf('|'));
|
||||
item.description = result.value.substring(0, result.value.indexOf('|'));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -374,7 +374,7 @@ export class InventoryItem
|
||||
{
|
||||
if (result.value.indexOf('|') !== -1)
|
||||
{
|
||||
item.metadata = result.value.substr(0, result.value.indexOf('|'));
|
||||
item.metadata = result.value.substring(0, result.value.indexOf('|'));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -152,7 +152,7 @@ export class LLLindenText
|
||||
}
|
||||
else
|
||||
{
|
||||
return input.substr(index + 1);
|
||||
return input.substring(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as crypto from 'crypto';
|
||||
import { Utils } from './Utils';
|
||||
|
||||
export class LoginParameters
|
||||
{
|
||||
@@ -20,6 +20,6 @@ export class LoginParameters
|
||||
{
|
||||
return this.password;
|
||||
}
|
||||
return '$1$' + crypto.createHash('md5').update(this.password.substr(0, 16)).digest('hex');
|
||||
return '$1$' + Utils.MD5String(this.password.substring(0, 16));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ export class TarWriter extends Transform
|
||||
|
||||
private chopString(str: string, maxLength: number): string
|
||||
{
|
||||
return str.substr(0, maxLength - 1);
|
||||
return str.substring(0, maxLength - 1);
|
||||
}
|
||||
|
||||
private octalBuf(num: number, length: number): Buffer
|
||||
|
||||
@@ -7,17 +7,17 @@ export class UUID
|
||||
{
|
||||
private mUUID = '00000000-0000-0000-0000-000000000000';
|
||||
|
||||
static zero(): UUID
|
||||
public static zero(): UUID
|
||||
{
|
||||
return new UUID();
|
||||
}
|
||||
static random(): UUID
|
||||
public static random(): UUID
|
||||
{
|
||||
const newUUID = uuid.v4();
|
||||
return new UUID(newUUID);
|
||||
}
|
||||
|
||||
static getString(u?: UUID): string
|
||||
public static getString(u?: UUID): string
|
||||
{
|
||||
if (u === undefined)
|
||||
{
|
||||
@@ -29,13 +29,13 @@ export class UUID
|
||||
}
|
||||
}
|
||||
|
||||
static getXML(doc: XMLNode, u?: UUID): void
|
||||
public static getXML(doc: XMLNode, u?: UUID): void
|
||||
{
|
||||
const str = UUID.getString(u);
|
||||
doc.ele('UUID', str);
|
||||
}
|
||||
|
||||
static fromXMLJS(obj: any, param: string): false | UUID
|
||||
public static fromXMLJS(obj: any, param: string): false | UUID
|
||||
{
|
||||
if (obj[param] === undefined)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ export class UUID
|
||||
return false;
|
||||
}
|
||||
|
||||
constructor(buf?: Buffer | string, pos?: number)
|
||||
public constructor(buf?: Buffer | string, pos?: number)
|
||||
{
|
||||
if (buf !== undefined)
|
||||
{
|
||||
@@ -85,11 +85,11 @@ export class UUID
|
||||
{
|
||||
const uuidBuf: Buffer = buf.slice(pos, pos + 16);
|
||||
const hexString = uuidBuf.toString('hex');
|
||||
this.setUUID(hexString.substr(0, 8) + '-'
|
||||
+ hexString.substr(8, 4) + '-'
|
||||
+ hexString.substr(12, 4) + '-'
|
||||
+ hexString.substr(16, 4) + '-'
|
||||
+ hexString.substr(20, 12));
|
||||
this.setUUID(hexString.substring(0, 8) + '-'
|
||||
+ hexString.substring(8, 12) + '-'
|
||||
+ hexString.substring(12, 16) + '-'
|
||||
+ hexString.substring(16, 20) + '-'
|
||||
+ hexString.substring(20, 32));
|
||||
}
|
||||
else if (typeof buf === 'object' && buf.toString !== undefined)
|
||||
{
|
||||
@@ -122,9 +122,9 @@ export class UUID
|
||||
return this.mUUID;
|
||||
};
|
||||
|
||||
writeToBuffer(buf: Buffer, pos: number): void
|
||||
public writeToBuffer(buf: Buffer, pos: number): void
|
||||
{
|
||||
const shortened = this.mUUID.substr(0, 8) + this.mUUID.substr(9, 4) + this.mUUID.substr(14, 4) + this.mUUID.substr(19, 4) + this.mUUID.substr(24, 12);
|
||||
const shortened = this.mUUID.substring(0, 8) + this.mUUID.substring(9, 13) + this.mUUID.substring(14, 18) + this.mUUID.substring(19, 23) + this.mUUID.substring(24, 36);
|
||||
const binary = Buffer.from(shortened, 'hex');
|
||||
binary.copy(buf, pos, 0);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ export class Utils
|
||||
return crypto.createHash('sha1').update(str).digest('hex');
|
||||
}
|
||||
|
||||
static MD5String(str: string): string
|
||||
{
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
|
||||
static BufferToStringSimple(buf: Buffer): string
|
||||
{
|
||||
if (buf.length === 0)
|
||||
@@ -425,7 +430,7 @@ export class Utils
|
||||
{
|
||||
hex = '0' + hex;
|
||||
}
|
||||
return new Long(parseInt(hex.substr(8), 16), parseInt(hex.substr(0, 8), 16));
|
||||
return new Long(parseInt(hex.substring(8), 16), parseInt(hex.substring(0, 8), 16));
|
||||
}
|
||||
|
||||
static ReadRotationFloat(buf: Buffer, pos: number): number
|
||||
@@ -690,7 +695,7 @@ export class Utils
|
||||
}
|
||||
else
|
||||
{
|
||||
return str.substr(0, index - 1);
|
||||
return str.substring(0, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -931,8 +936,8 @@ export class Utils
|
||||
const sep = line.indexOf(' ');
|
||||
if (sep > 0)
|
||||
{
|
||||
key = line.substr(0, sep);
|
||||
value = line.substr(sep + 1);
|
||||
key = line.substring(0, sep);
|
||||
value = line.substring(sep + 1);
|
||||
}
|
||||
}
|
||||
else if (line.length === 1)
|
||||
|
||||
@@ -1048,7 +1048,7 @@ export class GameObject implements IGameObjectData
|
||||
}
|
||||
else if (result.key === 'name')
|
||||
{
|
||||
name = result.value.substr(0, result.value.indexOf('|'));
|
||||
name = result.value.substring(0, result.value.indexOf('|'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('Packets', () =>
|
||||
const files = fs.readdirSync(p);
|
||||
for (const file of files)
|
||||
{
|
||||
if (file.substr(file.length - 7) === '.packet')
|
||||
if (file.substring(file.length - 7) === '.packet')
|
||||
{
|
||||
const fullPath = p + '/' + file;
|
||||
const stats = fs.statSync(fullPath);
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@caspertech/node-metaverse",
|
||||
"version": "0.7.18",
|
||||
"version": "0.7.19",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@caspertech/node-metaverse",
|
||||
"version": "0.7.18",
|
||||
"version": "0.7.19",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@caspertech/llsd": "^1.0.5",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@caspertech/node-metaverse",
|
||||
"version": "0.7.18",
|
||||
"version": "0.7.19",
|
||||
"description": "A node.js interface for Second Life.",
|
||||
"main": "dist/lib/index.js",
|
||||
"types": "dist/lib/index.d.ts",
|
||||
|
||||
@@ -59,7 +59,7 @@ function getBlocks(str)
|
||||
count--;
|
||||
if (count === 0)
|
||||
{
|
||||
let s = str.substr(startPos+1, (i - startPos)-1);
|
||||
let s = str.substring(startPos + 1, i);
|
||||
block.push(s);
|
||||
started = false;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ fs.readFile('./message_template.msg', (err, data) =>
|
||||
let pos = line.indexOf('//');
|
||||
if (pos !== -1)
|
||||
{
|
||||
line = line.substr(0, pos-1);
|
||||
line = line.substring(0, pos-1);
|
||||
}
|
||||
newLines.push(line);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"strictBindCallApply": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"strictNullChecks": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": [
|
||||
"lib/**/*.ts",
|
||||
"examples/**/*.ts",
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitAny": true,
|
||||
"resolveJsonModule": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"strictBindCallApply": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"strictNullChecks": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"lib/**/*.ts",
|
||||
"examples/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user