2008-08-21 08:36:37 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2008-10-05 22:05:18 +00:00
|
|
|
using ExtensionLoader;
|
|
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2008-08-21 08:36:37 +00:00
|
|
|
|
|
|
|
|
namespace Simian.Extensions
|
|
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
public class Messaging : IExtension<Simian>
|
2008-08-21 08:36:37 +00:00
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
Simian server;
|
2008-08-21 08:36:37 +00:00
|
|
|
|
2008-10-29 20:11:28 +00:00
|
|
|
public Messaging()
|
2008-08-21 08:36:37 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-29 20:11:28 +00:00
|
|
|
public void Start(Simian server)
|
2008-08-21 08:36:37 +00:00
|
|
|
{
|
2008-10-29 20:11:28 +00:00
|
|
|
this.server = server;
|
|
|
|
|
|
|
|
|
|
server.UDP.RegisterPacketCallback(PacketType.ChatFromViewer, new PacketCallback(ChatFromViewerHandler));
|
|
|
|
|
server.UDP.RegisterPacketCallback(PacketType.ImprovedInstantMessage, new PacketCallback(ImprovedInstantMessageHandler));
|
2008-08-21 08:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChatFromViewerHandler(Packet packet, Agent agent)
|
|
|
|
|
{
|
|
|
|
|
ChatFromViewerPacket viewerChat = (ChatFromViewerPacket)packet;
|
|
|
|
|
|
2009-03-03 21:01:57 +00:00
|
|
|
server.Scene.ObjectChat(this, agent.ID, agent.ID, ChatAudibleLevel.Fully, (ChatType)viewerChat.ChatData.Type,
|
|
|
|
|
ChatSourceType.Agent, agent.FullName, agent.Avatar.GetSimulatorPosition(), viewerChat.ChatData.Channel,
|
2009-03-02 23:00:28 +00:00
|
|
|
Utils.BytesToString(viewerChat.ChatData.Message));
|
2008-08-21 08:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImprovedInstantMessageHandler(Packet packet, Agent agent)
|
|
|
|
|
{
|
|
|
|
|
ImprovedInstantMessagePacket im = (ImprovedInstantMessagePacket)packet;
|
|
|
|
|
InstantMessageDialog dialog = (InstantMessageDialog)im.MessageBlock.Dialog;
|
|
|
|
|
|
|
|
|
|
if (dialog == InstantMessageDialog.MessageFromAgent)
|
|
|
|
|
{
|
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-08-21 08:36:37 +00:00
|
|
|
{
|
2009-03-02 23:00:28 +00:00
|
|
|
// FIXME: Look into the fields we are setting to default values
|
2009-01-30 19:24:38 +00:00
|
|
|
ImprovedInstantMessagePacket sendIM = new ImprovedInstantMessagePacket();
|
2009-03-02 23:00:28 +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-03-02 23:00:28 +00:00
|
|
|
sendIM.MessageBlock.Timestamp = Utils.DateTimeToUnixTime(DateTime.Now);
|
2009-03-03 21:01:57 +00:00
|
|
|
sendIM.MessageBlock.Position = agent.Avatar.GetSimulatorPosition();
|
2008-11-10 18:00:05 +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.Messaging);
|
2008-08-21 08:36:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|