2008-09-21 18:10:17 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2008-10-05 22:05:18 +00:00
|
|
|
using ExtensionLoader;
|
|
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2008-09-21 18:10:17 +00:00
|
|
|
|
|
|
|
|
namespace Simian.Extensions
|
|
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
public class FriendManager : IExtension<Simian>
|
2008-09-21 18:10:17 +00:00
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
Simian server;
|
2008-09-21 18:10:17 +00:00
|
|
|
|
2008-10-29 20:11:28 +00:00
|
|
|
public FriendManager()
|
2008-09-21 18:10:17 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-29 20:11:28 +00:00
|
|
|
public void Start(Simian server)
|
2008-09-21 18:10:17 +00:00
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
this.server = server;
|
|
|
|
|
|
|
|
|
|
server.UDP.RegisterPacketCallback(PacketType.ImprovedInstantMessage, new PacketCallback(ImprovedInstantMessageHandler));
|
2008-09-21 18:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImprovedInstantMessageHandler(Packet packet, Agent agent)
|
|
|
|
|
{
|
|
|
|
|
ImprovedInstantMessagePacket im = (ImprovedInstantMessagePacket)packet;
|
|
|
|
|
InstantMessageDialog dialog = (InstantMessageDialog)im.MessageBlock.Dialog;
|
|
|
|
|
|
|
|
|
|
if (dialog == InstantMessageDialog.FriendshipOffered || dialog == InstantMessageDialog.FriendshipAccepted || dialog == InstantMessageDialog.FriendshipDeclined)
|
|
|
|
|
{
|
2009-01-30 19:24:38 +00:00
|
|
|
// HACK: Only works for agents currently online
|
|
|
|
|
Agent recipient;
|
|
|
|
|
if (server.Scene.TryGetAgent(im.MessageBlock.ToAgentID, out recipient))
|
2008-09-21 18:10:17 +00:00
|
|
|
{
|
2009-01-30 19:24:38 +00:00
|
|
|
ImprovedInstantMessagePacket sendIM = new ImprovedInstantMessagePacket();
|
2009-03-03 21:01:57 +00:00
|
|
|
sendIM.MessageBlock.RegionID = server.Scene.RegionID;
|
2009-01-30 19:24:38 +00:00
|
|
|
sendIM.MessageBlock.ParentEstateID = 1;
|
|
|
|
|
sendIM.MessageBlock.FromGroup = false;
|
2009-03-03 21:01:57 +00:00
|
|
|
sendIM.MessageBlock.FromAgentName = Utils.StringToBytes(agent.FullName);
|
2009-01-30 19:24:38 +00:00
|
|
|
sendIM.MessageBlock.ToAgentID = im.MessageBlock.ToAgentID;
|
|
|
|
|
sendIM.MessageBlock.Dialog = im.MessageBlock.Dialog;
|
|
|
|
|
sendIM.MessageBlock.Offline = (byte)InstantMessageOnline.Online;
|
2009-03-03 21:01:57 +00:00
|
|
|
sendIM.MessageBlock.ID = agent.ID;
|
2009-01-30 19:24:38 +00:00
|
|
|
sendIM.MessageBlock.Message = im.MessageBlock.Message;
|
2009-03-06 02:10:52 +00:00
|
|
|
sendIM.MessageBlock.BinaryBucket = Utils.EmptyBytes;
|
2009-01-30 19:24:38 +00:00
|
|
|
sendIM.MessageBlock.Timestamp = 0;
|
2009-03-03 21:01:57 +00:00
|
|
|
sendIM.MessageBlock.Position = agent.Avatar.GetSimulatorPosition();
|
2009-01-30 19:24:38 +00:00
|
|
|
|
2009-03-03 21:01:57 +00:00
|
|
|
sendIM.AgentData.AgentID = agent.ID;
|
2008-11-10 18:00:05 +00:00
|
|
|
|
2009-03-03 21:01:57 +00:00
|
|
|
server.UDP.SendPacket(recipient.ID, sendIM, PacketCategory.Transaction);
|
2008-09-21 18:10:17 +00:00
|
|
|
|
2009-01-30 19:24:38 +00:00
|
|
|
if (dialog == InstantMessageDialog.FriendshipAccepted)
|
|
|
|
|
{
|
2009-03-03 21:01:57 +00:00
|
|
|
bool receiverOnline = server.Scene.ContainsObject(agent.ID);
|
|
|
|
|
bool senderOnline = server.Scene.ContainsObject(recipient.ID);
|
2008-09-21 18:10:17 +00:00
|
|
|
|
2009-01-30 19:24:38 +00:00
|
|
|
if (receiverOnline)
|
2008-11-10 18:00:05 +00:00
|
|
|
{
|
2009-01-30 19:24:38 +00:00
|
|
|
if (senderOnline)
|
|
|
|
|
{
|
|
|
|
|
OnlineNotificationPacket notify = new OnlineNotificationPacket();
|
|
|
|
|
notify.AgentBlock = new OnlineNotificationPacket.AgentBlockBlock[0];
|
|
|
|
|
notify.AgentBlock[0] = new OnlineNotificationPacket.AgentBlockBlock();
|
2009-03-03 21:01:57 +00:00
|
|
|
notify.AgentBlock[0].AgentID = agent.ID;
|
|
|
|
|
server.UDP.SendPacket(recipient.ID, notify, PacketCategory.State);
|
2009-01-30 19:24:38 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OfflineNotificationPacket notify = new OfflineNotificationPacket();
|
|
|
|
|
notify.AgentBlock = new OfflineNotificationPacket.AgentBlockBlock[0];
|
|
|
|
|
notify.AgentBlock[0] = new OfflineNotificationPacket.AgentBlockBlock();
|
2009-03-03 21:01:57 +00:00
|
|
|
notify.AgentBlock[0].AgentID = agent.ID;
|
|
|
|
|
server.UDP.SendPacket(recipient.ID, notify, PacketCategory.State);
|
2009-01-30 19:24:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-09-21 18:10:17 +00:00
|
|
|
|
2009-01-30 19:24:38 +00:00
|
|
|
if (senderOnline)
|
|
|
|
|
{
|
2008-11-10 18:00:05 +00:00
|
|
|
if (receiverOnline)
|
2008-09-21 18:10:17 +00:00
|
|
|
{
|
2009-01-30 19:24:38 +00:00
|
|
|
OnlineNotificationPacket notify = new OnlineNotificationPacket();
|
|
|
|
|
notify.AgentBlock = new OnlineNotificationPacket.AgentBlockBlock[0];
|
|
|
|
|
notify.AgentBlock[0] = new OnlineNotificationPacket.AgentBlockBlock();
|
2009-03-03 21:01:57 +00:00
|
|
|
notify.AgentBlock[0].AgentID = recipient.ID;
|
|
|
|
|
server.UDP.SendPacket(agent.ID, notify, PacketCategory.State);
|
2008-11-10 18:00:05 +00:00
|
|
|
}
|
2009-01-30 19:24:38 +00:00
|
|
|
else
|
2008-11-10 18:00:05 +00:00
|
|
|
{
|
2009-01-30 19:24:38 +00:00
|
|
|
OfflineNotificationPacket notify = new OfflineNotificationPacket();
|
|
|
|
|
notify.AgentBlock = new OfflineNotificationPacket.AgentBlockBlock[0];
|
|
|
|
|
notify.AgentBlock[0] = new OfflineNotificationPacket.AgentBlockBlock();
|
2009-03-03 21:01:57 +00:00
|
|
|
notify.AgentBlock[0].AgentID = recipient.ID;
|
|
|
|
|
server.UDP.SendPacket(agent.ID, notify, PacketCategory.State);
|
2008-11-10 18:00:05 +00:00
|
|
|
}
|
2009-01-30 19:24:38 +00:00
|
|
|
}
|
2008-09-21 18:10:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|