Skip to content

Commit

Permalink
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Clark-Casey (justincc) committed Apr 23, 2012
2 parents 1f8d1bc + 679da63 commit b798b32
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 58 deletions.
20 changes: 20 additions & 0 deletions OpenSim/Framework/OSChatMessage.cs
Expand Up @@ -51,10 +51,12 @@ public class OSChatMessage : EventArgs, IEventArgs
protected object m_senderObject;
protected ChatTypeEnum m_type;
protected UUID m_fromID;
protected UUID m_toID;

public OSChatMessage()
{
m_position = new Vector3();
m_toID = UUID.Zero;
}

/// <summary>
Expand Down Expand Up @@ -102,6 +104,15 @@ public string From
set { m_from = value; }
}

/// <summary>
/// The name of the sender (needed for scripts)
/// </summary>
public string To
{
get { return m_from; }
set { m_from = value; }
}

#region IEventArgs Members

/// TODO: Sender and SenderObject should just be Sender and of
Expand Down Expand Up @@ -131,6 +142,15 @@ public UUID SenderUUID
set { m_fromID = value; }
}

/// <summary>
/// The single recipient or all if not set.
/// </summary>
public UUID TargetUUID
{
get { return m_toID; }
set { m_toID = value; }
}

/// <summary>
///
/// </summary>
Expand Down
52 changes: 35 additions & 17 deletions OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
Expand Up @@ -186,6 +186,7 @@ protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMes
{
string fromName = c.From;
UUID fromID = UUID.Zero;
UUID targetID = c.TargetUUID;
string message = c.Message;
IScene scene = c.Scene;
Vector3 fromPos = c.Position;
Expand Down Expand Up @@ -221,24 +222,38 @@ protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMes
message = message.Substring(0, 1000);

// m_log.DebugFormat(
// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}",
// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType);
// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}, targetID {5}",
// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType, targetID);

HashSet<UUID> receiverIDs = new HashSet<UUID>();

foreach (Scene s in m_scenes)
{
// This should use ForEachClient, but clients don't have a position.
// If camera is moved into client, then camera position can be used
s.ForEachRootScenePresence(
delegate(ScenePresence presence)
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.ForEachRootScenePresence(
delegate(ScenePresence presence)
{
if (TrySendChatMessage(presence, fromPos, regionPos, fromID, 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)
{
if (TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, c.Type, message, sourceType))
receiverIDs.Add(presence.UUID);
if (TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, ChatTypeEnum.Say, message, sourceType, true))
receiverIDs.Add(presence.UUID);
}
);
}
}

(scene as Scene).EventManager.TriggerOnChatToClients(
fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully);
}
Expand Down Expand Up @@ -315,7 +330,7 @@ public virtual void OnChatBroadcast(Object sender, OSChatMessage c)
/// precondition</returns>
protected virtual bool TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos,
UUID fromAgentID, string fromName, ChatTypeEnum type,
string message, ChatSourceType src)
string message, ChatSourceType src, bool ignoreDistance)
{
// don't send stuff to child agents
if (presence.IsChildAgent) return false;
Expand All @@ -326,12 +341,15 @@ public virtual void OnChatBroadcast(Object sender, OSChatMessage c)
presence.Scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);

int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos);

if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance ||
type == ChatTypeEnum.Say && dis > m_saydistance ||
type == ChatTypeEnum.Shout && dis > m_shoutdistance)

if (!ignoreDistance)
{
return false;
if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance ||
type == ChatTypeEnum.Say && dis > m_saydistance ||
type == ChatTypeEnum.Shout && dis > m_shoutdistance)
{
return false;
}
}

// TODO: should change so the message is sent through the avatar rather than direct to the ClientView
Expand Down
70 changes: 35 additions & 35 deletions OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
Expand Up @@ -308,56 +308,56 @@ public void DeliverMessage(ChatTypeEnum type, int channel, string name, UUID id,
/// <param name='msg'>
/// Message.
/// </param>
public bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg, out string error)
public void DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg)
{
error = null;
// Is id an avatar?
ScenePresence sp = m_scene.GetScenePresence(target);

if (sp != null)
{
// Send message to avatar
// ignore if a child agent this is restricted to inside one region
if (sp.IsChildAgent)
return;

// Send message to the avatar.
// Channel zero only goes to the avatar
// non zero channel messages only go to the attachments
if (channel == 0)
{
m_scene.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Broadcast, 0, pos, name, id, false);
}

List<SceneObjectGroup> attachments = sp.GetAttachments();

if (attachments.Count == 0)
return true;

// Get uuid of attachments
List<UUID> targets = new List<UUID>();
foreach (SceneObjectGroup sog in attachments)
m_scene.SimChatToAgent(target, Utils.StringToBytes(msg), pos, name, id, false);
}
else
{
if (!sog.IsDeleted)
targets.Add(sog.UUID);
}
List<SceneObjectGroup> attachments = sp.GetAttachments();
if (attachments.Count == 0)
return;

// Need to check each attachment
foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
{
if (li.GetHostID().Equals(id))
continue;
// Get uuid of attachments
List<UUID> targets = new List<UUID>();
foreach (SceneObjectGroup sog in attachments)
{
if (!sog.IsDeleted)
targets.Add(sog.UUID);
}

if (m_scene.GetSceneObjectPart(li.GetHostID()) == null)
continue;
// Need to check each attachment
foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
{
if (li.GetHostID().Equals(id))
continue;

if (targets.Contains(li.GetHostID()))
QueueMessage(new ListenerInfo(li, name, id, msg));
}
if (m_scene.GetSceneObjectPart(li.GetHostID()) == null)
continue;

return true;
}
if (targets.Contains(li.GetHostID()))
QueueMessage(new ListenerInfo(li, name, id, msg));
}
}

// Need to toss an error here
if (channel == 0)
{
error = "Cannot use llRegionSayTo to message objects on channel 0";
return false;
return;
}

// No avatar found so look for an object
foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
{
// Dont process if this message is from yourself!
Expand All @@ -375,7 +375,7 @@ public bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name,
}
}

return true;
return;
}

protected void QueueMessage(ListenerInfo li)
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Region/Framework/Interfaces/IWorldComm.cs
Expand Up @@ -103,7 +103,7 @@ public interface IWorldComm
/// <param name='msg'>
/// Message.
/// </param>
bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg, out string error);
void DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg);

/// <summary>
/// Are there any listen events ready to be dispatched?
Expand Down
26 changes: 23 additions & 3 deletions OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
Expand Up @@ -38,8 +38,9 @@ namespace OpenSim.Region.Framework.Scenes
{
public partial class Scene
{

protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
UUID fromID, bool fromAgent, bool broadcast)
UUID fromID, UUID targetID, bool fromAgent, bool broadcast)
{
OSChatMessage args = new OSChatMessage();

Expand All @@ -63,14 +64,20 @@ public partial class Scene
}

args.From = fromName;
//args.
args.TargetUUID = targetID;

if (broadcast)
EventManager.TriggerOnChatBroadcast(this, args);
else
EventManager.TriggerOnChatFromWorld(this, args);
}


protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
UUID fromID, bool fromAgent, bool broadcast)
{
SimChat(message, type, channel, fromPos, fromName, fromID, UUID.Zero, fromAgent, broadcast);
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -108,6 +115,19 @@ public void SimChat(string message, string fromName)
{
SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true);
}
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="type"></param>
/// <param name="fromPos"></param>
/// <param name="fromName"></param>
/// <param name="fromAgentID"></param>
/// <param name="targetID"></param>
public void SimChatToAgent(UUID targetID, byte[] message, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
{
SimChat(message, ChatTypeEnum.Say, 0, fromPos, fromName, fromID, targetID, fromAgent, false);
}

/// <summary>
/// Invoked when the client requests a prim.
Expand Down
Expand Up @@ -839,13 +839,17 @@ public void llRegionSayTo(string target, int channel, string msg)

m_host.AddScriptLPS(1);

if (channel == ScriptBaseClass.DEBUG_CHANNEL)
{
return;
}

UUID TargetID;
UUID.TryParse(target, out TargetID);

IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
if (wComm != null)
if (!wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg, out error))
LSLError(error);
wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
}

public LSL_Integer llListen(int channelID, string name, string ID, string msg)
Expand Down

0 comments on commit b798b32

Please sign in to comment.