diff --git a/examples/Groups/GroupChat.ts b/examples/Groups/GroupChat.ts index 7dec5c4..17329c2 100644 --- a/examples/Groups/GroupChat.ts +++ b/examples/Groups/GroupChat.ts @@ -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]; diff --git a/lib/LoginHandler.ts b/lib/LoginHandler.ts index 81a57ed..4e57c28 100644 --- a/lib/LoginHandler.ts +++ b/lib/LoginHandler.ts @@ -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', diff --git a/lib/classes/InventoryItem.ts b/lib/classes/InventoryItem.ts index 3bd6d9e..cf14b30 100644 --- a/lib/classes/InventoryItem.ts +++ b/lib/classes/InventoryItem.ts @@ -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 { diff --git a/lib/classes/LLLindenText.ts b/lib/classes/LLLindenText.ts index ce25017..cf4e172 100644 --- a/lib/classes/LLLindenText.ts +++ b/lib/classes/LLLindenText.ts @@ -152,7 +152,7 @@ export class LLLindenText } else { - return input.substr(index + 1); + return input.substring(index + 1); } } } diff --git a/lib/classes/LoginParameters.ts b/lib/classes/LoginParameters.ts index 833eabe..2efe91c 100644 --- a/lib/classes/LoginParameters.ts +++ b/lib/classes/LoginParameters.ts @@ -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)); } } diff --git a/lib/classes/TarWriter.ts b/lib/classes/TarWriter.ts index 4ae9c6a..2843900 100644 --- a/lib/classes/TarWriter.ts +++ b/lib/classes/TarWriter.ts @@ -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 diff --git a/lib/classes/UUID.ts b/lib/classes/UUID.ts index d7eb74f..560508a 100644 --- a/lib/classes/UUID.ts +++ b/lib/classes/UUID.ts @@ -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); } diff --git a/lib/classes/Utils.ts b/lib/classes/Utils.ts index 9a887dc..0850dcd 100644 --- a/lib/classes/Utils.ts +++ b/lib/classes/Utils.ts @@ -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) diff --git a/lib/classes/public/GameObject.ts b/lib/classes/public/GameObject.ts index 43c66cb..07ea653 100644 --- a/lib/classes/public/GameObject.ts +++ b/lib/classes/public/GameObject.ts @@ -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('|')); } } } diff --git a/lib/tests/packets.spec.ts b/lib/tests/packets.spec.ts index 2882188..b326245 100644 --- a/lib/tests/packets.spec.ts +++ b/lib/tests/packets.spec.ts @@ -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); diff --git a/package-lock.json b/package-lock.json index 2518738..dd5181a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 37b2593..a98471a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tools/parseMessageTemplate.js b/tools/parseMessageTemplate.js index 8b6d4c7..2d6629e 100644 --- a/tools/parseMessageTemplate.js +++ b/tools/parseMessageTemplate.js @@ -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); } diff --git a/tsconfig.json b/tsconfig.json index 5599e5b..b5aabb6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" + ] }