Files
node-metaverse/lib/classes/UUID.ts

178 lines
4.7 KiB
TypeScript
Raw Normal View History

import * as validator from 'validator';
- Add "GET" method to Caps - New events: ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectUpdateEvent, ObjectKilledEvent - Added getXML function to Color4, Vector2, Vector3, Vector4, GameObject, Region, Quaternion, UUID for opensim-compatible XML export - Added TextureAnim and ParticleSystem decoding to the "full" ObjectStore - Object store will automatically request missing "parent" prims - "setPersist" - When persist is TRUE, the ObjectStore will not forget about "killed" prims - useful for region scanning - Support for Flexible params, Light params, LightImage params, Mesh data, Sculpt maps - Fixed object scale being incorrectly calculated - Add terrain decoding (this was a ballache) - Add parcel map decoding - Add support for region windlight settings (region.environment) - Add support for materials (normal / specular maps) - Add getBuffer, getLong and bitwiseOr to UUID - Added a circular-reference-safe JSONStringify to Utils - Add XferFile capability to Circuit PUBLIC API: AssetCommands: - Rework "downloadAsset" to detect failures - NEW: downloadInventoryAsset() - uses TransferRequest for prim inventory items - NEW: getMaterials() - resolves material UUIDs RegionCommands: - NEW: getTerrainTextures() - NEW: exportSettings() - OpenSim XML export of region settings - NEW: async getTerrain() - Get binary terrain heightmap, 256x256 float32 - resolveObjects() - now fetches task inventory contents too. - resolveObjects() - fix calculation of land impact - NEW: getObjectByLocalID(localID: number, timeout: number) - NEW: getObjectByUUID(uuid: UUID, timeout: number) - NEW: getParcels(); - NEW: pruneObjects - removes missing GameObjects from a list - NEW: setPersist - prevent objectstore from forgetting about killed gameobjects
2018-10-31 11:28:24 +00:00
import * as Long from 'long';
2019-09-25 19:10:59 +01:00
import {XMLNode} from 'xmlbuilder';
const uuid = require('uuid');
export class UUID
{
private mUUID = '00000000-0000-0000-0000-000000000000';
static zero(): UUID
{
return new UUID();
}
static random(): UUID
{
const newUUID = uuid.v4();
return new UUID(newUUID);
}
- Add "GET" method to Caps - New events: ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectUpdateEvent, ObjectKilledEvent - Added getXML function to Color4, Vector2, Vector3, Vector4, GameObject, Region, Quaternion, UUID for opensim-compatible XML export - Added TextureAnim and ParticleSystem decoding to the "full" ObjectStore - Object store will automatically request missing "parent" prims - "setPersist" - When persist is TRUE, the ObjectStore will not forget about "killed" prims - useful for region scanning - Support for Flexible params, Light params, LightImage params, Mesh data, Sculpt maps - Fixed object scale being incorrectly calculated - Add terrain decoding (this was a ballache) - Add parcel map decoding - Add support for region windlight settings (region.environment) - Add support for materials (normal / specular maps) - Add getBuffer, getLong and bitwiseOr to UUID - Added a circular-reference-safe JSONStringify to Utils - Add XferFile capability to Circuit PUBLIC API: AssetCommands: - Rework "downloadAsset" to detect failures - NEW: downloadInventoryAsset() - uses TransferRequest for prim inventory items - NEW: getMaterials() - resolves material UUIDs RegionCommands: - NEW: getTerrainTextures() - NEW: exportSettings() - OpenSim XML export of region settings - NEW: async getTerrain() - Get binary terrain heightmap, 256x256 float32 - resolveObjects() - now fetches task inventory contents too. - resolveObjects() - fix calculation of land impact - NEW: getObjectByLocalID(localID: number, timeout: number) - NEW: getObjectByUUID(uuid: UUID, timeout: number) - NEW: getParcels(); - NEW: pruneObjects - removes missing GameObjects from a list - NEW: setPersist - prevent objectstore from forgetting about killed gameobjects
2018-10-31 11:28:24 +00:00
static getString(u?: UUID): string
{
if (u === undefined)
{
return UUID.zero().toString();
}
else
{
return u.toString();
}
}
2019-09-25 19:10:59 +01:00
static getXML(doc: XMLNode, u?: UUID)
- Add "GET" method to Caps - New events: ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectUpdateEvent, ObjectKilledEvent - Added getXML function to Color4, Vector2, Vector3, Vector4, GameObject, Region, Quaternion, UUID for opensim-compatible XML export - Added TextureAnim and ParticleSystem decoding to the "full" ObjectStore - Object store will automatically request missing "parent" prims - "setPersist" - When persist is TRUE, the ObjectStore will not forget about "killed" prims - useful for region scanning - Support for Flexible params, Light params, LightImage params, Mesh data, Sculpt maps - Fixed object scale being incorrectly calculated - Add terrain decoding (this was a ballache) - Add parcel map decoding - Add support for region windlight settings (region.environment) - Add support for materials (normal / specular maps) - Add getBuffer, getLong and bitwiseOr to UUID - Added a circular-reference-safe JSONStringify to Utils - Add XferFile capability to Circuit PUBLIC API: AssetCommands: - Rework "downloadAsset" to detect failures - NEW: downloadInventoryAsset() - uses TransferRequest for prim inventory items - NEW: getMaterials() - resolves material UUIDs RegionCommands: - NEW: getTerrainTextures() - NEW: exportSettings() - OpenSim XML export of region settings - NEW: async getTerrain() - Get binary terrain heightmap, 256x256 float32 - resolveObjects() - now fetches task inventory contents too. - resolveObjects() - fix calculation of land impact - NEW: getObjectByLocalID(localID: number, timeout: number) - NEW: getObjectByUUID(uuid: UUID, timeout: number) - NEW: getParcels(); - NEW: pruneObjects - removes missing GameObjects from a list - NEW: setPersist - prevent objectstore from forgetting about killed gameobjects
2018-10-31 11:28:24 +00:00
{
const str = UUID.getString(u);
doc.ele('UUID', str);
}
static fromXMLJS(obj: any, param: string): false | UUID
{
if (obj[param] === undefined)
{
return false;
}
if (Array.isArray(obj[param]) && obj[param].length > 0)
{
obj[param] = obj[param][0];
}
if (typeof obj[param] === 'string')
{
if (validator.isUUID(obj[param]))
{
return new UUID(obj[param]);
}
return false;
}
if (typeof obj[param] === 'object')
{
if (obj[param]['UUID'] !== undefined && Array.isArray(obj[param]['UUID']) && obj[param]['UUID'].length > 0)
{
const u = obj[param]['UUID'][0];
if (typeof u === 'string')
{
if (validator.isUUID(u))
{
return new UUID(u);
}
return false;
}
return false;
}
return false;
}
return false;
}
constructor(buf?: Buffer | string, pos?: number)
{
if (buf !== undefined)
{
if (typeof buf === 'string')
{
this.setUUID(buf);
}
else if (pos !== undefined)
{
2017-11-26 01:14:02 +00:00
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));
}
else
{
console.error('Can\'t accept UUIDs of type ' + typeof buf);
}
}
}
public setUUID(val: string): boolean
{
const test = val.trim();
if (validator.isUUID(test))
{
this.mUUID = test;
return true;
}
else
{
console.log('Invalid UUID: ' + test + ' (length ' + val.length + ')');
}
return false;
}
public toString = (): string =>
{
return this.mUUID;
};
writeToBuffer(buf: Buffer, pos: number)
{
2017-11-26 01:14:02 +00:00
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 binary = Buffer.from(shortened, 'hex');
binary.copy(buf, pos, 0);
}
public equals(cmp: UUID | string): boolean
{
if (typeof cmp === 'string')
{
return (cmp === this.mUUID);
}
else
{
return cmp.equals(this.mUUID);
}
}
- Add "GET" method to Caps - New events: ObjectPhysicsDataEvent, ParcelPropertiesEvent, NewObjectEvent, ObjectUpdateEvent, ObjectKilledEvent - Added getXML function to Color4, Vector2, Vector3, Vector4, GameObject, Region, Quaternion, UUID for opensim-compatible XML export - Added TextureAnim and ParticleSystem decoding to the "full" ObjectStore - Object store will automatically request missing "parent" prims - "setPersist" - When persist is TRUE, the ObjectStore will not forget about "killed" prims - useful for region scanning - Support for Flexible params, Light params, LightImage params, Mesh data, Sculpt maps - Fixed object scale being incorrectly calculated - Add terrain decoding (this was a ballache) - Add parcel map decoding - Add support for region windlight settings (region.environment) - Add support for materials (normal / specular maps) - Add getBuffer, getLong and bitwiseOr to UUID - Added a circular-reference-safe JSONStringify to Utils - Add XferFile capability to Circuit PUBLIC API: AssetCommands: - Rework "downloadAsset" to detect failures - NEW: downloadInventoryAsset() - uses TransferRequest for prim inventory items - NEW: getMaterials() - resolves material UUIDs RegionCommands: - NEW: getTerrainTextures() - NEW: exportSettings() - OpenSim XML export of region settings - NEW: async getTerrain() - Get binary terrain heightmap, 256x256 float32 - resolveObjects() - now fetches task inventory contents too. - resolveObjects() - fix calculation of land impact - NEW: getObjectByLocalID(localID: number, timeout: number) - NEW: getObjectByUUID(uuid: UUID, timeout: number) - NEW: getParcels(); - NEW: pruneObjects - removes missing GameObjects from a list - NEW: setPersist - prevent objectstore from forgetting about killed gameobjects
2018-10-31 11:28:24 +00:00
public getBuffer()
{
const buf = Buffer.allocUnsafe(16);
this.writeToBuffer(buf, 0);
return buf;
}
public getLong()
{
const buf = this.getBuffer();
return new Long(buf.readUInt32LE(7), buf.readUInt32LE(12));
}
public bitwiseOr(w: UUID): UUID
{
const buf1 = this.getBuffer();
const buf2 = w.getBuffer();
const buf3 = Buffer.allocUnsafe(16);
for (let x = 0; x < 16; x++)
{
buf3[x] = buf1[x] ^ buf2[x];
}
return new UUID(buf3, 0);
}
public CRC(): number
{
let retval = 0;
const bytes: Buffer = this.getBuffer();
retval += ((bytes[3] << 24) + (bytes[2] << 16) + (bytes[1] << 8) + bytes[0]);
retval += ((bytes[7] << 24) + (bytes[6] << 16) + (bytes[5] << 8) + bytes[4]);
retval += ((bytes[11] << 24) + (bytes[10] << 16) + (bytes[9] << 8) + bytes[8]);
retval += ((bytes[15] << 24) + (bytes[14] << 16) + (bytes[13] << 8) + bytes[12]);
return retval;
}
}