Improve login, replace deprecated substr calls

This commit is contained in:
Casper Warden
2023-11-29 16:01:50 +00:00
parent 09db20682e
commit 58c5a1a08e
14 changed files with 114 additions and 78 deletions

View File

@@ -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
{

View File

@@ -152,7 +152,7 @@ export class LLLindenText
}
else
{
return input.substr(index + 1);
return input.substring(index + 1);
}
}
}

View File

@@ -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));
}
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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('|'));
}
}
}