Following on from 476a7d3e (which wasn't enough), make chat across regions on different simulators work.

Also resolves an issue of multiple chatting if the originating simulators had more than one region and they were neighbours
user_profiles
Justin Clark-Casey (justincc) 2013-03-22 01:42:47 +00:00
parent 1f17ef6d3c
commit c4d9a23f26
1 changed files with 31 additions and 56 deletions

View File

@ -50,7 +50,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
private int m_saydistance = 20;
private int m_shoutdistance = 100;
private int m_whisperdistance = 10;
private List<Scene> m_scenes = new List<Scene>();
internal object m_syncy = new object();
@ -82,18 +81,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
public virtual void AddRegion(Scene scene)
{
if (!m_enabled) return;
if (!m_enabled)
return;
lock (m_syncy)
{
if (!m_scenes.Contains(scene))
{
m_scenes.Add(scene);
scene.EventManager.OnNewClient += OnNewClient;
scene.EventManager.OnChatFromWorld += OnChatFromWorld;
scene.EventManager.OnChatBroadcast += OnChatBroadcast;
}
}
scene.EventManager.OnNewClient += OnNewClient;
scene.EventManager.OnChatFromWorld += OnChatFromWorld;
scene.EventManager.OnChatBroadcast += OnChatBroadcast;
m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName,
m_whisperdistance, m_saydistance, m_shoutdistance);
@ -105,18 +98,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
public virtual void RemoveRegion(Scene scene)
{
if (!m_enabled) return;
if (!m_enabled)
return;
lock (m_syncy)
{
if (m_scenes.Contains(scene))
{
scene.EventManager.OnNewClient -= OnNewClient;
scene.EventManager.OnChatFromWorld -= OnChatFromWorld;
scene.EventManager.OnChatBroadcast -= OnChatBroadcast;
m_scenes.Remove(scene);
}
}
scene.EventManager.OnNewClient -= OnNewClient;
scene.EventManager.OnChatFromWorld -= OnChatFromWorld;
scene.EventManager.OnChatBroadcast -= OnChatBroadcast;
}
public virtual void Close()
@ -191,7 +178,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
UUID ownerID = UUID.Zero;
UUID targetID = c.TargetUUID;
string message = c.Message;
IScene scene = c.Scene;
Scene scene = (Scene)c.Scene;
Vector3 fromPos = c.Position;
Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
@ -201,13 +188,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
switch (sourceType)
{
case ChatSourceType.Agent:
if (!(scene is Scene))
{
m_log.WarnFormat("[CHAT]: scene {0} is not a Scene object, cannot obtain scene presence for {1}",
scene.RegionInfo.RegionName, c.Sender.AgentId);
return;
}
ScenePresence avatar = (scene as Scene).GetScenePresence(c.Sender.AgentId);
ScenePresence avatar = scene.GetScenePresence(c.Sender.AgentId);
fromPos = avatar.AbsolutePosition;
fromName = avatar.Name;
fromID = c.Sender.AgentId;
@ -234,36 +215,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
HashSet<UUID> receiverIDs = new HashSet<UUID>();
foreach (Scene s in m_scenes)
if (targetID == UUID.Zero)
{
if (targetID == UUID.Zero)
{
// This should use ForEachClient, but clients don't have a position.
// If camera is moved into client, then camera position can be used
s.ForEachScenePresence(
delegate(ScenePresence presence)
{
if (TrySendChatMessage(
presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false))
receiverIDs.Add(presence.UUID);
}
);
}
else
{
// This is a send to a specific client eg from llRegionSayTo
// no need to check distance etc, jand send is as say
ScenePresence presence = s.GetScenePresence(targetID);
if (presence != null && !presence.IsChildAgent)
// This should use ForEachClient, but clients don't have a position.
// If camera is moved into client, then camera position can be used
scene.ForEachScenePresence(
delegate(ScenePresence presence)
{
if (TrySendChatMessage(
presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true))
presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false))
receiverIDs.Add(presence.UUID);
}
);
}
else
{
// This is a send to a specific client eg from llRegionSayTo
// no need to check distance etc, jand send is as say
ScenePresence presence = scene.GetScenePresence(targetID);
if (presence != null && !presence.IsChildAgent)
{
if (TrySendChatMessage(
presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true))
receiverIDs.Add(presence.UUID);
}
}
(scene as Scene).EventManager.TriggerOnChatToClients(
scene.EventManager.TriggerOnChatToClients(
fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully);
}
@ -348,9 +326,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
UUID fromAgentID, UUID ownerID, string fromName, ChatTypeEnum type,
string message, ChatSourceType src, bool ignoreDistance)
{
// don't send stuff to child agents
if (presence.IsChildAgent) return false;
Vector3 fromRegionPos = fromPos + regionPos;
Vector3 toRegionPos = presence.AbsolutePosition +
new Vector3(presence.Scene.RegionInfo.RegionLocX * Constants.RegionSize,