Receive and respond to friend requests and inventory offers
This commit is contained in:
2
dist/classes/ClientEvents.d.ts
vendored
2
dist/classes/ClientEvents.d.ts
vendored
@@ -9,11 +9,13 @@ import { DisconnectEvent } from '../events/DisconnectEvent';
|
||||
import { GroupChatEvent } from '../events/GroupChatEvent';
|
||||
import { GroupChatSessionJoinEvent } from '../events/GroupChatSessionJoinEvent';
|
||||
import { GroupChatSessionAgentListEvent } from '../events/GroupChatSessionAgentListEvent';
|
||||
import { InventoryOfferedEvent } from '../events/InventoryOfferedEvent';
|
||||
export declare class ClientEvents {
|
||||
onNearbyChat: Subject<ChatEvent>;
|
||||
onInstantMessage: Subject<InstantMessageEvent>;
|
||||
onGroupInvite: Subject<GroupInviteEvent>;
|
||||
onFriendRequest: Subject<FriendRequestEvent>;
|
||||
onInventoryOffered: Subject<InventoryOfferedEvent>;
|
||||
onLure: Subject<LureEvent>;
|
||||
onTeleportEvent: Subject<TeleportEvent>;
|
||||
onDisconnected: Subject<DisconnectEvent>;
|
||||
|
||||
1
dist/classes/ClientEvents.js
vendored
1
dist/classes/ClientEvents.js
vendored
@@ -7,6 +7,7 @@ class ClientEvents {
|
||||
this.onInstantMessage = new Subject_1.Subject();
|
||||
this.onGroupInvite = new Subject_1.Subject();
|
||||
this.onFriendRequest = new Subject_1.Subject();
|
||||
this.onInventoryOffered = new Subject_1.Subject();
|
||||
this.onLure = new Subject_1.Subject();
|
||||
this.onTeleportEvent = new Subject_1.Subject();
|
||||
this.onDisconnected = new Subject_1.Subject();
|
||||
|
||||
2
dist/classes/ClientEvents.js.map
vendored
2
dist/classes/ClientEvents.js.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"ClientEvents.js","sourceRoot":"","sources":["../../lib/classes/ClientEvents.ts"],"names":[],"mappings":";;AAGA,0CAAqC;AASrC;IAAA;QAEI,iBAAY,GAAuB,IAAI,iBAAO,EAAa,CAAC;QAC5D,qBAAgB,GAAiC,IAAI,iBAAO,EAAuB,CAAC;QACpF,kBAAa,GAA8B,IAAI,iBAAO,EAAoB,CAAC;QAC3E,oBAAe,GAAgC,IAAI,iBAAO,EAAsB,CAAC;QACjF,WAAM,GAAuB,IAAI,iBAAO,EAAa,CAAC;QACtD,oBAAe,GAA2B,IAAI,iBAAO,EAAiB,CAAC;QACvE,mBAAc,GAA8B,IAAI,iBAAO,EAAmB,CAAC;QAC3E,qBAAgB,GAAoB,IAAI,iBAAO,EAAU,CAAC;QAC1D,gBAAW,GAA4B,IAAI,iBAAO,EAAkB,CAAC;QACrE,2BAAsB,GAAuC,IAAI,iBAAO,EAA6B,CAAC;QACtG,+BAA0B,GAA4C,IAAI,iBAAO,EAAkC,CAAC;IACxH,CAAC;CAAA;AAbD,oCAaC"}
|
||||
{"version":3,"file":"ClientEvents.js","sourceRoot":"","sources":["../../lib/classes/ClientEvents.ts"],"names":[],"mappings":";;AAGA,0CAAqC;AAUrC;IAAA;QAEI,iBAAY,GAAuB,IAAI,iBAAO,EAAa,CAAC;QAC5D,qBAAgB,GAAiC,IAAI,iBAAO,EAAuB,CAAC;QACpF,kBAAa,GAA8B,IAAI,iBAAO,EAAoB,CAAC;QAC3E,oBAAe,GAAgC,IAAI,iBAAO,EAAsB,CAAC;QACjF,uBAAkB,GAAmC,IAAI,iBAAO,EAAyB,CAAC;QAC1F,WAAM,GAAuB,IAAI,iBAAO,EAAa,CAAC;QACtD,oBAAe,GAA2B,IAAI,iBAAO,EAAiB,CAAC;QACvE,mBAAc,GAA8B,IAAI,iBAAO,EAAmB,CAAC;QAC3E,qBAAgB,GAAoB,IAAI,iBAAO,EAAU,CAAC;QAC1D,gBAAW,GAA4B,IAAI,iBAAO,EAAkB,CAAC;QACrE,2BAAsB,GAAuC,IAAI,iBAAO,EAA6B,CAAC;QACtG,+BAA0B,GAA4C,IAAI,iBAAO,EAAkC,CAAC;IACxH,CAAC;CAAA;AAdD,oCAcC"}
|
||||
41
dist/classes/Comms.js
vendored
41
dist/classes/Comms.js
vendored
@@ -10,6 +10,8 @@ const ChatSourceType_1 = require("../enums/ChatSourceType");
|
||||
const InstantMessageEventFlags_1 = require("../enums/InstantMessageEventFlags");
|
||||
const GroupInviteEvent_1 = require("../events/GroupInviteEvent");
|
||||
const GroupChatEvent_1 = require("../events/GroupChatEvent");
|
||||
const FriendRequestEvent_1 = require("../events/FriendRequestEvent");
|
||||
const InventoryOfferedEvent_1 = require("../events/InventoryOfferedEvent");
|
||||
class Comms {
|
||||
constructor(circuit, agent, clientEvents) {
|
||||
this.clientEvents = clientEvents;
|
||||
@@ -47,13 +49,36 @@ class Comms {
|
||||
this.clientEvents.onGroupInvite.next(giEvent);
|
||||
break;
|
||||
case InstantMessageDialog_1.InstantMessageDialog.InventoryOffered:
|
||||
break;
|
||||
{
|
||||
const fromName = Utils_1.Utils.BufferToStringSimple(im.MessageBlock.FromAgentName);
|
||||
const message = Utils_1.Utils.BufferToStringSimple(im.MessageBlock.Message);
|
||||
const ioEvent = new InventoryOfferedEvent_1.InventoryOfferedEvent();
|
||||
ioEvent.from = im.AgentData.AgentID;
|
||||
ioEvent.fromName = fromName;
|
||||
ioEvent.message = message;
|
||||
ioEvent.requestID = im.MessageBlock.ID;
|
||||
ioEvent.source = ChatSourceType_1.ChatSourceType.Agent;
|
||||
this.clientEvents.onInventoryOffered.next(ioEvent);
|
||||
break;
|
||||
}
|
||||
case InstantMessageDialog_1.InstantMessageDialog.InventoryAccepted:
|
||||
break;
|
||||
case InstantMessageDialog_1.InstantMessageDialog.InventoryDeclined:
|
||||
break;
|
||||
case InstantMessageDialog_1.InstantMessageDialog.TaskInventoryOffered:
|
||||
break;
|
||||
{
|
||||
const fromName = Utils_1.Utils.BufferToStringSimple(im.MessageBlock.FromAgentName);
|
||||
const message = Utils_1.Utils.BufferToStringSimple(im.MessageBlock.Message);
|
||||
const ioEvent = new InventoryOfferedEvent_1.InventoryOfferedEvent();
|
||||
ioEvent.from = im.AgentData.AgentID;
|
||||
ioEvent.fromName = fromName;
|
||||
ioEvent.message = message;
|
||||
ioEvent.requestID = im.MessageBlock.ID;
|
||||
ioEvent.source = ChatSourceType_1.ChatSourceType.Object;
|
||||
ioEvent.type = im.MessageBlock.BinaryBucket.readUInt8(0);
|
||||
this.clientEvents.onInventoryOffered.next(ioEvent);
|
||||
break;
|
||||
}
|
||||
case InstantMessageDialog_1.InstantMessageDialog.TaskInventoryAccepted:
|
||||
break;
|
||||
case InstantMessageDialog_1.InstantMessageDialog.TaskInventoryDeclined:
|
||||
@@ -120,7 +145,17 @@ class Comms {
|
||||
case InstantMessageDialog_1.InstantMessageDialog.GroupNoticeRequested:
|
||||
break;
|
||||
case InstantMessageDialog_1.InstantMessageDialog.FriendshipOffered:
|
||||
break;
|
||||
{
|
||||
const fromName = Utils_1.Utils.BufferToStringSimple(im.MessageBlock.FromAgentName);
|
||||
const message = Utils_1.Utils.BufferToStringSimple(im.MessageBlock.Message);
|
||||
const frEvent = new FriendRequestEvent_1.FriendRequestEvent();
|
||||
frEvent.from = im.AgentData.AgentID;
|
||||
frEvent.fromName = fromName;
|
||||
frEvent.message = message;
|
||||
frEvent.requestID = im.MessageBlock.ID;
|
||||
this.clientEvents.onFriendRequest.next(frEvent);
|
||||
break;
|
||||
}
|
||||
case InstantMessageDialog_1.InstantMessageDialog.FriendshipAccepted:
|
||||
break;
|
||||
case InstantMessageDialog_1.InstantMessageDialog.FriendshipDeclined:
|
||||
|
||||
2
dist/classes/Comms.js.map
vendored
2
dist/classes/Comms.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/classes/Inventory.d.ts
vendored
4
dist/classes/Inventory.d.ts
vendored
@@ -1,9 +1,10 @@
|
||||
import { UUID } from './UUID';
|
||||
import { ClientEvents } from './ClientEvents';
|
||||
import { AssetType } from '../enums/AssetType';
|
||||
export declare class Inventory {
|
||||
main: {
|
||||
skeleton: {
|
||||
typeDefault: number;
|
||||
typeDefault: AssetType;
|
||||
version: number;
|
||||
name: string;
|
||||
folderID: UUID;
|
||||
@@ -24,4 +25,5 @@ export declare class Inventory {
|
||||
};
|
||||
private clientEvents;
|
||||
constructor(clientEvents: ClientEvents);
|
||||
findFolderForType(type: AssetType): UUID;
|
||||
}
|
||||
|
||||
17
dist/classes/Inventory.js
vendored
17
dist/classes/Inventory.js
vendored
@@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const UUID_1 = require("./UUID");
|
||||
const AssetType_1 = require("../enums/AssetType");
|
||||
class Inventory {
|
||||
constructor(clientEvents) {
|
||||
this.main = {
|
||||
@@ -10,6 +12,21 @@ class Inventory {
|
||||
};
|
||||
this.clientEvents = clientEvents;
|
||||
}
|
||||
findFolderForType(type) {
|
||||
if (this.main.root === undefined) {
|
||||
return UUID_1.UUID.zero();
|
||||
}
|
||||
if (type === AssetType_1.AssetType.Folder) {
|
||||
return this.main.root;
|
||||
}
|
||||
let found = UUID_1.UUID.zero();
|
||||
this.main.skeleton.forEach((folder) => {
|
||||
if (folder.typeDefault === type) {
|
||||
found = folder.folderID;
|
||||
}
|
||||
});
|
||||
return found;
|
||||
}
|
||||
}
|
||||
exports.Inventory = Inventory;
|
||||
//# sourceMappingURL=Inventory.js.map
|
||||
2
dist/classes/Inventory.js.map
vendored
2
dist/classes/Inventory.js.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"Inventory.js","sourceRoot":"","sources":["../../lib/classes/Inventory.ts"],"names":[],"mappings":";;AAGA;IA6BI,YAAY,YAA0B;QA3BtC,SAAI,GASA;YACA,QAAQ,EAAE,EAAE;SACf,CAAC;QACF,YAAO,GAUH;YACA,QAAQ,EAAE,EAAE;SACf,CAAC;QAKE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AAjCD,8BAiCC"}
|
||||
{"version":3,"file":"Inventory.js","sourceRoot":"","sources":["../../lib/classes/Inventory.ts"],"names":[],"mappings":";;AAAA,iCAA4B;AAE5B,kDAA6C;AAE7C;IA6BI,YAAY,YAA0B;QA3BtC,SAAI,GASA;YACA,QAAQ,EAAE,EAAE;SACf,CAAC;QACF,YAAO,GAUH;YACA,QAAQ,EAAE,EAAE;SACf,CAAC;QAKE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IACD,iBAAiB,CAAC,IAAe;QAE7B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CACjC,CAAC;YACG,MAAM,CAAC,WAAI,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC;QACD,EAAE,CAAC,CAAC,IAAI,KAAK,qBAAS,CAAC,MAAM,CAAC,CAC9B,CAAC;YACG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1B,CAAC;QACD,IAAI,KAAK,GAAG,WAAI,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAElC,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC,CAChC,CAAC;gBACG,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC;YAC5B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;CACJ;AArDD,8BAqDC"}
|
||||
@@ -1,6 +1,8 @@
|
||||
import { CommandsBase } from './CommandsBase';
|
||||
import { UUID } from '../UUID';
|
||||
import { ChatType } from '../../enums/ChatType';
|
||||
import { FriendRequestEvent } from '../../events/FriendRequestEvent';
|
||||
import { InventoryOfferedEvent } from '../../events/InventoryOfferedEvent';
|
||||
export declare class CommunicationsCommands extends CommandsBase {
|
||||
sendInstantMessage(to: UUID | string, message: string): Promise<void>;
|
||||
nearbyChat(message: string, type: ChatType, channel?: number): Promise<void>;
|
||||
@@ -14,5 +16,10 @@ export declare class CommunicationsCommands extends CommandsBase {
|
||||
typeInstantMessage(to: UUID | string, message: string, thinkingTime?: number, charactersPerSecond?: number): Promise<void>;
|
||||
typeLocalMessage(message: string, thinkingTime?: number, charactersPerSecond?: number): Promise<void>;
|
||||
startGroupChatSession(sessionID: UUID | string, message: string): Promise<void>;
|
||||
acceptFriendRequest(event: FriendRequestEvent): Promise<void>;
|
||||
private respondToInventoryOffer(event, response);
|
||||
acceptInventoryOffer(event: InventoryOfferedEvent): Promise<void>;
|
||||
rejectInventoryOffer(event: InventoryOfferedEvent): Promise<void>;
|
||||
rejectFriendRequest(event: FriendRequestEvent): Promise<void>;
|
||||
sendGroupMessage(groupID: UUID | string, message: string): Promise<number>;
|
||||
}
|
||||
|
||||
78
dist/classes/commands/CommunicationsCommands.js
vendored
78
dist/classes/commands/CommunicationsCommands.js
vendored
@@ -9,6 +9,10 @@ const Vector3_1 = require("../Vector3");
|
||||
const ChatFromViewer_1 = require("../messages/ChatFromViewer");
|
||||
const ChatType_1 = require("../../enums/ChatType");
|
||||
const InstantMessageDialog_1 = require("../../enums/InstantMessageDialog");
|
||||
const AcceptFriendship_1 = require("../messages/AcceptFriendship");
|
||||
const AssetType_1 = require("../../enums/AssetType");
|
||||
const DeclineFriendship_1 = require("../messages/DeclineFriendship");
|
||||
const ChatSourceType_1 = require("../../enums/ChatSourceType");
|
||||
class CommunicationsCommands extends CommandsBase_1.CommandsBase {
|
||||
sendInstantMessage(to, message) {
|
||||
const circuit = this.circuit;
|
||||
@@ -285,6 +289,80 @@ class CommunicationsCommands extends CommandsBase_1.CommandsBase {
|
||||
}
|
||||
});
|
||||
}
|
||||
acceptFriendRequest(event) {
|
||||
const accept = new AcceptFriendship_1.AcceptFriendshipMessage();
|
||||
accept.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID
|
||||
};
|
||||
accept.TransactionBlock = {
|
||||
TransactionID: event.requestID
|
||||
};
|
||||
accept.FolderData = [];
|
||||
accept.FolderData.push({
|
||||
'FolderID': this.agent.inventory.findFolderForType(AssetType_1.AssetType.CallingCard)
|
||||
});
|
||||
const sequenceNo = this.circuit.sendMessage(accept, PacketFlags_1.PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
respondToInventoryOffer(event, response) {
|
||||
const agentName = this.agent.firstName + ' ' + this.agent.lastName;
|
||||
const im = new ImprovedInstantMessage_1.ImprovedInstantMessageMessage();
|
||||
const folder = this.agent.inventory.findFolderForType(event.type);
|
||||
const binary = Buffer.allocUnsafe(16);
|
||||
folder.writeToBuffer(binary, 0);
|
||||
im.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID
|
||||
};
|
||||
im.MessageBlock = {
|
||||
FromGroup: false,
|
||||
ToAgentID: event.from,
|
||||
ParentEstateID: 0,
|
||||
RegionID: UUID_1.UUID.zero(),
|
||||
Position: Vector3_1.Vector3.getZero(),
|
||||
Offline: 0,
|
||||
Dialog: response,
|
||||
ID: event.requestID,
|
||||
Timestamp: Math.floor(new Date().getTime() / 1000),
|
||||
FromAgentName: Utils_1.Utils.StringToBuffer(agentName),
|
||||
Message: Utils_1.Utils.StringToBuffer(''),
|
||||
BinaryBucket: binary
|
||||
};
|
||||
im.EstateBlock = {
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(im, PacketFlags_1.PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
acceptInventoryOffer(event) {
|
||||
if (event.source === ChatSourceType_1.ChatSourceType.Object) {
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog_1.InstantMessageDialog.TaskInventoryAccepted);
|
||||
}
|
||||
else {
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog_1.InstantMessageDialog.InventoryAccepted);
|
||||
}
|
||||
}
|
||||
rejectInventoryOffer(event) {
|
||||
if (event.source === ChatSourceType_1.ChatSourceType.Object) {
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog_1.InstantMessageDialog.TaskInventoryDeclined);
|
||||
}
|
||||
else {
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog_1.InstantMessageDialog.InventoryDeclined);
|
||||
}
|
||||
}
|
||||
rejectFriendRequest(event) {
|
||||
const reject = new DeclineFriendship_1.DeclineFriendshipMessage();
|
||||
reject.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID
|
||||
};
|
||||
reject.TransactionBlock = {
|
||||
TransactionID: event.requestID
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(reject, PacketFlags_1.PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
sendGroupMessage(groupID, message) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.startGroupChatSession(groupID, message).then(() => {
|
||||
|
||||
File diff suppressed because one or more lines are too long
5
dist/events/FriendRequestEvent.d.ts
vendored
5
dist/events/FriendRequestEvent.d.ts
vendored
@@ -1,2 +1,7 @@
|
||||
import { UUID } from '../classes/UUID';
|
||||
export declare class FriendRequestEvent {
|
||||
from: UUID;
|
||||
fromName: string;
|
||||
requestID: UUID;
|
||||
message: string;
|
||||
}
|
||||
|
||||
2
dist/events/FriendRequestEvent.js.map
vendored
2
dist/events/FriendRequestEvent.js.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"FriendRequestEvent.js","sourceRoot":"","sources":["../../lib/events/FriendRequestEvent.ts"],"names":[],"mappings":";;AAAA;CAGC;AAHD,gDAGC"}
|
||||
{"version":3,"file":"FriendRequestEvent.js","sourceRoot":"","sources":["../../lib/events/FriendRequestEvent.ts"],"names":[],"mappings":";;AAEA;CAMC;AAND,gDAMC"}
|
||||
11
dist/events/InventoryOfferedEvent.d.ts
vendored
Normal file
11
dist/events/InventoryOfferedEvent.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { UUID } from '../classes/UUID';
|
||||
import { ChatSourceType } from '../enums/ChatSourceType';
|
||||
import { AssetType } from '../enums/AssetType';
|
||||
export declare class InventoryOfferedEvent {
|
||||
from: UUID;
|
||||
fromName: string;
|
||||
requestID: UUID;
|
||||
message: string;
|
||||
source: ChatSourceType;
|
||||
type: AssetType;
|
||||
}
|
||||
6
dist/events/InventoryOfferedEvent.js
vendored
Normal file
6
dist/events/InventoryOfferedEvent.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class InventoryOfferedEvent {
|
||||
}
|
||||
exports.InventoryOfferedEvent = InventoryOfferedEvent;
|
||||
//# sourceMappingURL=InventoryOfferedEvent.js.map
|
||||
1
dist/events/InventoryOfferedEvent.js.map
vendored
Normal file
1
dist/events/InventoryOfferedEvent.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"InventoryOfferedEvent.js","sourceRoot":"","sources":["../../lib/events/InventoryOfferedEvent.ts"],"names":[],"mappings":";;AAIA;CAQC;AARD,sDAQC"}
|
||||
@@ -51,6 +51,34 @@ bot.clientEvents.onInstantMessage.subscribe((IMEvent) =>
|
||||
}
|
||||
});
|
||||
|
||||
bot.clientEvents.onFriendRequest.subscribe((event) =>
|
||||
{
|
||||
if (event.from.toString() === master)
|
||||
{
|
||||
console.log("Accepting friend request from " + event.fromName);
|
||||
bot.clientCommands.comms.acceptFriendRequest(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Rejecting friend request from " + event.fromName);
|
||||
bot.clientCommands.comms.rejectFriendRequest(event);
|
||||
}
|
||||
});
|
||||
|
||||
bot.clientEvents.onInventoryOffered.subscribe((event) =>
|
||||
{
|
||||
if (event.from.toString() === master)
|
||||
{
|
||||
console.log("Accepting inventory offer from " + event.fromName);
|
||||
bot.clientCommands.comms.acceptInventoryOffer(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Rejecting inventory offer from " + event.fromName);
|
||||
bot.clientCommands.comms.rejectInventoryOffer(event);
|
||||
}
|
||||
});
|
||||
|
||||
bot.clientEvents.onDisconnected.subscribe((DisconnectEvent) =>
|
||||
{
|
||||
isConnected = false;
|
||||
|
||||
@@ -9,6 +9,7 @@ import {DisconnectEvent} from '../events/DisconnectEvent';
|
||||
import {GroupChatEvent} from '../events/GroupChatEvent';
|
||||
import {GroupChatSessionJoinEvent} from '../events/GroupChatSessionJoinEvent';
|
||||
import {GroupChatSessionAgentListEvent} from '../events/GroupChatSessionAgentListEvent';
|
||||
import {InventoryOfferedEvent} from '../events/InventoryOfferedEvent';
|
||||
|
||||
export class ClientEvents
|
||||
{
|
||||
@@ -16,6 +17,7 @@ export class ClientEvents
|
||||
onInstantMessage: Subject<InstantMessageEvent> = new Subject<InstantMessageEvent>();
|
||||
onGroupInvite: Subject<GroupInviteEvent> = new Subject<GroupInviteEvent>();
|
||||
onFriendRequest: Subject<FriendRequestEvent> = new Subject<FriendRequestEvent>();
|
||||
onInventoryOffered: Subject<InventoryOfferedEvent> = new Subject<InventoryOfferedEvent>();
|
||||
onLure: Subject<LureEvent> = new Subject<LureEvent>();
|
||||
onTeleportEvent: Subject<TeleportEvent> = new Subject<TeleportEvent>();
|
||||
onDisconnected: Subject<DisconnectEvent> = new Subject<DisconnectEvent>();
|
||||
|
||||
@@ -15,6 +15,8 @@ import {ChatSourceType} from '../enums/ChatSourceType';
|
||||
import {InstantMessageEventFlags} from '../enums/InstantMessageEventFlags';
|
||||
import {GroupInviteEvent} from '../events/GroupInviteEvent';
|
||||
import {GroupChatEvent} from '../events/GroupChatEvent';
|
||||
import {FriendRequestEvent} from '../events/FriendRequestEvent';
|
||||
import {InventoryOfferedEvent} from '../events/InventoryOfferedEvent';
|
||||
|
||||
export class Comms
|
||||
{
|
||||
@@ -63,13 +65,38 @@ export class Comms
|
||||
this.clientEvents.onGroupInvite.next(giEvent);
|
||||
break;
|
||||
case InstantMessageDialog.InventoryOffered:
|
||||
{
|
||||
const fromName = Utils.BufferToStringSimple(im.MessageBlock.FromAgentName);
|
||||
const message = Utils.BufferToStringSimple(im.MessageBlock.Message);
|
||||
|
||||
const ioEvent = new InventoryOfferedEvent();
|
||||
ioEvent.from = im.AgentData.AgentID;
|
||||
ioEvent.fromName = fromName;
|
||||
ioEvent.message = message;
|
||||
ioEvent.requestID = im.MessageBlock.ID;
|
||||
ioEvent.source = ChatSourceType.Agent;
|
||||
this.clientEvents.onInventoryOffered.next(ioEvent);
|
||||
break;
|
||||
}
|
||||
case InstantMessageDialog.InventoryAccepted:
|
||||
break;
|
||||
case InstantMessageDialog.InventoryDeclined:
|
||||
break;
|
||||
case InstantMessageDialog.TaskInventoryOffered:
|
||||
{
|
||||
const fromName = Utils.BufferToStringSimple(im.MessageBlock.FromAgentName);
|
||||
const message = Utils.BufferToStringSimple(im.MessageBlock.Message);
|
||||
|
||||
const ioEvent = new InventoryOfferedEvent();
|
||||
ioEvent.from = im.AgentData.AgentID;
|
||||
ioEvent.fromName = fromName;
|
||||
ioEvent.message = message;
|
||||
ioEvent.requestID = im.MessageBlock.ID;
|
||||
ioEvent.source = ChatSourceType.Object;
|
||||
ioEvent.type = im.MessageBlock.BinaryBucket.readUInt8(0);
|
||||
this.clientEvents.onInventoryOffered.next(ioEvent);
|
||||
break;
|
||||
}
|
||||
case InstantMessageDialog.TaskInventoryAccepted:
|
||||
break;
|
||||
case InstantMessageDialog.TaskInventoryDeclined:
|
||||
@@ -136,7 +163,19 @@ export class Comms
|
||||
case InstantMessageDialog.GroupNoticeRequested:
|
||||
break;
|
||||
case InstantMessageDialog.FriendshipOffered:
|
||||
{
|
||||
const fromName = Utils.BufferToStringSimple(im.MessageBlock.FromAgentName);
|
||||
const message = Utils.BufferToStringSimple(im.MessageBlock.Message);
|
||||
|
||||
const frEvent = new FriendRequestEvent();
|
||||
frEvent.from = im.AgentData.AgentID;
|
||||
frEvent.fromName = fromName;
|
||||
frEvent.message = message;
|
||||
frEvent.requestID = im.MessageBlock.ID;
|
||||
|
||||
this.clientEvents.onFriendRequest.next(frEvent);
|
||||
break;
|
||||
}
|
||||
case InstantMessageDialog.FriendshipAccepted:
|
||||
break;
|
||||
case InstantMessageDialog.FriendshipDeclined:
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import {UUID} from './UUID';
|
||||
import {ClientEvents} from './ClientEvents';
|
||||
import {AssetType} from '../enums/AssetType';
|
||||
|
||||
export class Inventory
|
||||
{
|
||||
main: {
|
||||
skeleton: {
|
||||
typeDefault: number,
|
||||
typeDefault: AssetType,
|
||||
version: number,
|
||||
name: string,
|
||||
folderID: UUID,
|
||||
@@ -34,4 +35,24 @@ export class Inventory
|
||||
{
|
||||
this.clientEvents = clientEvents;
|
||||
}
|
||||
findFolderForType(type: AssetType): UUID
|
||||
{
|
||||
if (this.main.root === undefined)
|
||||
{
|
||||
return UUID.zero();
|
||||
}
|
||||
if (type === AssetType.Folder)
|
||||
{
|
||||
return this.main.root;
|
||||
}
|
||||
let found = UUID.zero();
|
||||
this.main.skeleton.forEach((folder) =>
|
||||
{
|
||||
if (folder.typeDefault === type)
|
||||
{
|
||||
found = folder.folderID;
|
||||
}
|
||||
});
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,12 @@ import {ChatType} from '../../enums/ChatType';
|
||||
import {InstantMessageDialog} from '../../enums/InstantMessageDialog';
|
||||
import Timer = NodeJS.Timer;
|
||||
import {GroupChatSessionJoinEvent} from '../../events/GroupChatSessionJoinEvent';
|
||||
import {FriendRequestEvent} from '../../events/FriendRequestEvent';
|
||||
import {AcceptFriendshipMessage} from '../messages/AcceptFriendship';
|
||||
import {AssetType} from '../../enums/AssetType';
|
||||
import {DeclineFriendshipMessage} from '../messages/DeclineFriendship';
|
||||
import {InventoryOfferedEvent} from '../../events/InventoryOfferedEvent';
|
||||
import {ChatSourceType} from '../../enums/ChatSourceType';
|
||||
|
||||
export class CommunicationsCommands extends CommandsBase
|
||||
{
|
||||
@@ -358,6 +364,98 @@ export class CommunicationsCommands extends CommandsBase
|
||||
});
|
||||
}
|
||||
|
||||
acceptFriendRequest(event: FriendRequestEvent): Promise<void>
|
||||
{
|
||||
const accept: AcceptFriendshipMessage = new AcceptFriendshipMessage();
|
||||
accept.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID
|
||||
};
|
||||
accept.TransactionBlock = {
|
||||
TransactionID: event.requestID
|
||||
};
|
||||
accept.FolderData = [];
|
||||
accept.FolderData.push(
|
||||
{
|
||||
'FolderID': this.agent.inventory.findFolderForType(AssetType.CallingCard)
|
||||
}
|
||||
);
|
||||
const sequenceNo = this.circuit.sendMessage(accept, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
private respondToInventoryOffer(event: InventoryOfferedEvent, response: InstantMessageDialog): Promise<void>
|
||||
{
|
||||
const agentName = this.agent.firstName + ' ' + this.agent.lastName;
|
||||
const im: ImprovedInstantMessageMessage = new ImprovedInstantMessageMessage();
|
||||
|
||||
const folder = this.agent.inventory.findFolderForType(event.type);
|
||||
const binary = Buffer.allocUnsafe(16);
|
||||
folder.writeToBuffer(binary, 0);
|
||||
|
||||
im.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID
|
||||
};
|
||||
im.MessageBlock = {
|
||||
FromGroup: false,
|
||||
ToAgentID: event.from,
|
||||
ParentEstateID: 0,
|
||||
RegionID: UUID.zero(),
|
||||
Position: Vector3.getZero(),
|
||||
Offline: 0,
|
||||
Dialog: response,
|
||||
ID: event.requestID,
|
||||
Timestamp: Math.floor(new Date().getTime() / 1000),
|
||||
FromAgentName: Utils.StringToBuffer(agentName),
|
||||
Message: Utils.StringToBuffer(''),
|
||||
BinaryBucket: binary
|
||||
};
|
||||
im.EstateBlock = {
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
acceptInventoryOffer(event: InventoryOfferedEvent): Promise<void>
|
||||
{
|
||||
if (event.source === ChatSourceType.Object)
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.TaskInventoryAccepted);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.InventoryAccepted);
|
||||
}
|
||||
}
|
||||
|
||||
rejectInventoryOffer(event: InventoryOfferedEvent): Promise<void>
|
||||
{
|
||||
if (event.source === ChatSourceType.Object)
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.TaskInventoryDeclined);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.InventoryDeclined);
|
||||
}
|
||||
}
|
||||
|
||||
rejectFriendRequest(event: FriendRequestEvent): Promise<void>
|
||||
{
|
||||
const reject: DeclineFriendshipMessage = new DeclineFriendshipMessage();
|
||||
reject.AgentData = {
|
||||
AgentID: this.agent.agentID,
|
||||
SessionID: this.circuit.sessionID
|
||||
};
|
||||
reject.TransactionBlock = {
|
||||
TransactionID: event.requestID
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(reject, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
sendGroupMessage(groupID: UUID | string, message: string): Promise<number>
|
||||
{
|
||||
return new Promise<number>((resolve, reject) =>
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import {UUID} from '../classes/UUID';
|
||||
|
||||
export class FriendRequestEvent
|
||||
{
|
||||
|
||||
from: UUID;
|
||||
fromName: string;
|
||||
requestID: UUID;
|
||||
message: string;
|
||||
}
|
||||
13
lib/events/InventoryOfferedEvent.ts
Normal file
13
lib/events/InventoryOfferedEvent.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {UUID} from '../classes/UUID';
|
||||
import {ChatSourceType} from '../enums/ChatSourceType';
|
||||
import {AssetType} from '../enums/AssetType';
|
||||
|
||||
export class InventoryOfferedEvent
|
||||
{
|
||||
from: UUID;
|
||||
fromName: string;
|
||||
requestID: UUID;
|
||||
message: string;
|
||||
source: ChatSourceType;
|
||||
type: AssetType;
|
||||
}
|
||||
Reference in New Issue
Block a user