From 5c0a0bc2e0951745fd52f5c01f2ee2c0aee49a3a Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Fri, 3 Oct 2008 14:53:11 +0000 Subject: This changeset changes the way chat from client is routed: old way: each region module interested in chat from client had to - subscribe to scene.EventManager.OnNewClient - then in its OnNewClient delegate it would subscribe to client.OnChatFromViewer to capture chat messages coming new way: ChatModule is the only region module that uses the "old way" approach but is now forwarding all client chat via scene.EventManager.OnChatFromClient - each region module interested in chat from client now only subscribes to scene.EventManager.OnChatFromClient this not only simplifies code, but also allows us to substitute ChatModule with derived classes (ConciergeModule is going to be one example). Also, this changeset changes ChatFromViewer to ChatFromClient as it doesn't necessarily have to be a viewer that is a chat source. i've taken great care to only comment out those OnNewClient delegates that were only used for getting at the client chat --- hope it's not breaking anything. --- .../Environment/Modules/Avatar/Chat/ChatModule.cs | 193 +++++++++++---------- .../Modules/Avatar/Chat/IRCBridgeModule.cs | 26 ++- .../Modules/Avatar/Concierge/ConciergeModule.cs | 66 ++++--- .../ContentManagementSystem/CMController.cs | 5 +- .../Modules/Scripting/WorldComm/WorldCommModule.cs | 12 +- .../Environment/Modules/World/NPC/NPCAvatar.cs | 32 ++-- 6 files changed, 175 insertions(+), 159 deletions(-) (limited to 'OpenSim/Region/Environment/Modules') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs index 606ce7e..34a604e 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs @@ -64,26 +64,25 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat { m_scenes.Add(scene); scene.EventManager.OnNewClient += OnNewClient; - scene.EventManager.OnChatFromWorld += OnSimChat; - scene.EventManager.OnChatBroadcast += OnSimBroadcast; + scene.EventManager.OnChatFromWorld += OnChatFromWorld; + scene.EventManager.OnChatBroadcast += OnChatBroadcast; } + } - // wrap this in a try block so that defaults will work if - // the config file doesn't specify otherwise. - try - { - m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); - m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); - m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); - } - catch (Exception) - { - } - m_log.InfoFormat("[CHAT] initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, - m_whisperdistance, m_saydistance, m_shoutdistance); + // wrap this in a try block so that defaults will work if + // the config file doesn't specify otherwise. + try + { + m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); + m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); + m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); } + catch (Exception) + { + } + m_log.InfoFormat("[CHAT] initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, + m_whisperdistance, m_saydistance, m_shoutdistance); } - public void PostInitialise() { } @@ -104,8 +103,89 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat #endregion - #region ISimChat Members - public void OnSimBroadcast(Object sender, OSChatMessage c) + + public void OnNewClient(IClientAPI client) + { + try + { + client.OnChatFromClient += OnChatFromClient; + } + catch (Exception ex) + { + m_log.Error("[CHAT]: NewClient exception trap:" + ex.ToString()); + } + } + + public virtual void OnChatFromClient(Object sender, OSChatMessage e) + { + // redistribute to interested subscribers + Scene scene = (Scene)e.Scene; + scene.EventManager.TriggerOnChatFromClient(sender, e); + + // early return if not on public or debug channel + if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return; + + // sanity check: + if (e.Sender == null) + { + m_log.ErrorFormat("[CHAT] OnChatFromClient from {0} has empty Sender field!", sender); + return; + } + + string message = e.Message; + if (e.Channel == DEBUG_CHANNEL) e.Type = ChatTypeEnum.DebugChannel; + + ScenePresence avatar = scene.GetScenePresence(e.Sender.AgentId); + Vector3 fromPos = avatar.AbsolutePosition; + Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, + scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); + string fromName = avatar.Firstname + " " + avatar.Lastname; + UUID fromID = e.Sender.AgentId; + + DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Agent, message); + } + + public void OnChatFromWorld(Object sender, OSChatMessage e) + { + Scene scene = (Scene) e.Scene; + + // early return if not on public or debug channel + if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return; + + // Filled in since it's easier than rewriting right now. + Vector3 fromPos = e.Position; + Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, + scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); + + string fromName = e.From; + string message = e.Message; + UUID fromID = e.SenderUUID; + + if (e.Channel == DEBUG_CHANNEL) + e.Type = ChatTypeEnum.DebugChannel; + + DeliverChatToAvatars(fromPos, regionPos, fromID, fromName, e.Type, ChatSourceType.Object, message); + } + + protected void DeliverChatToAvatars(Vector3 pos, Vector3 regionPos, UUID uuid, string name, + ChatTypeEnum chatType, ChatSourceType sourceType, string message) + { + // iterate over message + if (message.Length >= 1000) // libomv limit + message = message.Substring(0, 1000); + + foreach (Scene s in m_scenes) + { + s.ForEachScenePresence(delegate(ScenePresence presence) + { + TrySendChatMessage(presence, pos, regionPos, uuid, name, + chatType, message, sourceType); + }); + } + } + + + public void OnChatBroadcast(Object sender, OSChatMessage c) { // We only want to relay stuff on channel 0 and on the debug channel if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL) return; @@ -153,83 +233,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat }); } - public void OnSimChat(Object sender, OSChatMessage e) - { - // early return if not on public or debug channel - if (e.Channel != 0 && e.Channel != DEBUG_CHANNEL) return; - - ScenePresence avatar = null; - Scene scene = (Scene) e.Scene; - - //TODO: Remove the need for this check - if (scene == null) - scene = m_scenes[0]; - - // Filled in since it's easier than rewriting right now. - Vector3 fromPos = e.Position; - Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, - scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); - - string fromName = e.From; - string message = e.Message; - UUID fromID = e.SenderUUID; - - if (message.Length >= 1000) // libomv limit - message = message.Substring(0, 1000); - - if (e.Sender != null) - { - avatar = scene.GetScenePresence(e.Sender.AgentId); - } - - if (avatar != null) - { - fromPos = avatar.AbsolutePosition; - regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, - scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); - fromName = avatar.Firstname + " " + avatar.Lastname; - fromID = e.Sender.AgentId; - } - - if (e.Channel == DEBUG_CHANNEL) - e.Type = ChatTypeEnum.DebugChannel; - - // chat works by redistributing every incoming chat - // message to each avatar in the scene - foreach (Scene s in m_scenes) - { - s.ForEachScenePresence( - delegate(ScenePresence presence) - { - if (e.Channel == DEBUG_CHANNEL) - { - TrySendChatMessage(presence, fromPos, regionPos, - fromID, fromName, e.Type, - message, ChatSourceType.Object); - } - else - { - TrySendChatMessage(presence, fromPos, regionPos, - fromID, fromName, e.Type, - message, ChatSourceType.Agent); - } - }); - } - } - - #endregion - - public void OnNewClient(IClientAPI client) - { - try - { - client.OnChatFromViewer += OnSimChat; - } - catch (Exception ex) - { - m_log.Error("[CHAT]: NewClient exception trap:" + ex.ToString()); - } - } private void TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos, UUID fromAgentID, string fromName, ChatTypeEnum type, diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs index eba65a9..5840cb2 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs @@ -93,6 +93,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat m_scenes.Add(scene); scene.EventManager.OnNewClient += OnNewClient; scene.EventManager.OnChatFromWorld += OnSimChat; + scene.EventManager.OnChatFromClient += OnSimChat; scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; } @@ -236,7 +237,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat if (avatar != null) { - fromName = avatar.Firstname + " " + avatar.Lastname; + fromName = avatar.Name; } // Try to reconnect to server if not connected @@ -277,21 +278,19 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat { try { - string clientName = String.Format("{0} {1}", client.FirstName, client.LastName); - - client.OnChatFromViewer += OnSimChat; + // client.OnChatFromViewer += OnSimChat; client.OnLogout += OnClientLoggedOut; client.OnConnectionClosed += OnClientLoggedOut; - if (clientName != m_last_new_user) + if (client.Name != m_last_new_user) { if ((m_irc.Enabled) && (m_irc.Connected)) { - m_log.DebugFormat("[IRC] {0} logging on", clientName); + m_log.DebugFormat("[IRC] {0} logging on", client.Name); m_irc.PrivMsg(m_irc.Nick, "Sim", - String.Format("notices {0} logging on", clientName)); + String.Format("notices {0} logging on", client.Name)); } - m_last_new_user = clientName; + m_last_new_user = client.Name; } } catch (Exception ex) @@ -343,21 +342,20 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat { if ((m_irc.Enabled) && (m_irc.Connected)) { - string clientName = String.Format("{0} {1}", client.FirstName, client.LastName); // handles simple case. May not work for hundred connecting in per second. // and the NewClients calles getting interleved // but filters out multiple reports - if (clientName != m_last_leaving_user) + if (client.Name != m_last_leaving_user) { Console.WriteLine("Avatar was seen logging out."); //Console.ReadLine(); Console.WriteLine(); - m_last_leaving_user = clientName; - m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} logging out", clientName)); - m_log.InfoFormat("[IRC]: {0} logging out", clientName); + m_last_leaving_user = client.Name; + m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} logging out", client.Name)); + m_log.InfoFormat("[IRC]: {0} logging out", client.Name); } - if (m_last_new_user == clientName) + if (m_last_new_user == client.Name) m_last_new_user = null; } } diff --git a/OpenSim/Region/Environment/Modules/Avatar/Concierge/ConciergeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Concierge/ConciergeModule.cs index 0c0f553..d9730dd 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Concierge/ConciergeModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Concierge/ConciergeModule.cs @@ -50,7 +50,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge private int _conciergeChannel = 42; private List _scenes = new List(); private IConfig _config; - private string _whoami = null; + private string _whoami = "conferencier"; internal object _syncy = new object(); @@ -78,8 +78,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge return; } - _conciergeChannel = config.Configs["Concierge"].GetInt("concierge_channel", _conciergeChannel); - _whoami = _config.GetString("concierge_name", "conferencier"); + if (_config != null) + { + _conciergeChannel = config.Configs["Concierge"].GetInt("concierge_channel", _conciergeChannel); + _whoami = _config.GetString("whoami", "conferencier"); + } + _log.InfoFormat("[Concierge] reporting as \"{0}\" to our users", _whoami); lock (_syncy) { @@ -88,8 +92,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge _scenes.Add(scene); // subscribe to NewClient events scene.EventManager.OnNewClient += OnNewClient; + scene.EventManager.OnNewClient += OnNewClient; - // subscribe to *Chat events + // subscribe to *Chat events and FilterChat* events scene.EventManager.OnChatFromWorld += OnSimChat; scene.EventManager.OnChatBroadcast += OnSimBroadcast; @@ -124,18 +129,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge #region ISimChat Members public void OnSimBroadcast(Object sender, OSChatMessage c) { - if (_conciergeChannel == c.Channel) - { - // concierge request: interpret - return; - } - - if (0 == c.Channel || DEBUG_CHANNEL == c.Channel) - { - // log as avatar/prim chat - return; - } - + // log to buffer? return; } @@ -149,6 +143,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge if (0 == c.Channel || DEBUG_CHANNEL == c.Channel) { + // if (_amplify) + // { + + // } + // log as avatar/prim chat return; } @@ -161,14 +160,20 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge public void OnNewClient(IClientAPI client) { - try - { - client.OnChatFromViewer += OnSimChat; - } - catch (Exception ex) - { - _log.Error("[Concierge]: NewClient exception trap:" + ex.ToString()); - } + client.OnLogout += OnClientLoggedOut; + client.OnConnectionClosed += OnClientLoggedOut; + + _log.DebugFormat("[Concierge] {0} logs on to {1}", client.Name, client.Scene.RegionInfo.RegionName); + AnnounceToAgentsRegion(client, String.Format("{0} logs on to {1}", client.Name, client.Scene.RegionInfo.RegionName)); + } + + public void OnClientLoggedOut(IClientAPI client) + { + client.OnLogout -= OnClientLoggedOut; + client.OnConnectionClosed -= OnClientLoggedOut; + + _log.DebugFormat("[Concierge] {0} logs off from {1}", client.Name, client.Scene.RegionInfo.RegionName); + AnnounceToAgentsRegion(client, String.Format("{0} logs off from {1}", client.Name, client.Scene.RegionInfo.RegionName)); } @@ -188,13 +193,22 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Concierge public void ClientLoggedOut(IClientAPI client) { - string clientName = String.Format("{0} {1}", client.FirstName, client.LastName); - _log.DebugFormat("[CONCIERGE] {0} logging off.", clientName); + _log.DebugFormat("[Concierge] {0} logs out of {1}", client.Name, client.Scene.RegionInfo.RegionName); + AnnounceToAgentsRegion(client, String.Format("{0} logs out of {1}", client.Name, client.Scene.RegionInfo.RegionName)); } static private Vector3 posOfGod = new Vector3(128, 128, 9999); + protected void AnnounceToAgentsRegion(IClientAPI client, string msg) + { + ScenePresence agent = null; + if ((client.Scene is Scene) && (client.Scene as Scene).TryGetAvatar(client.AgentId, out agent)) + AnnounceToAgentsRegion(agent, msg); + else + _log.DebugFormat("[Concierge] could not find an agent for client {0}", client.Name); + } + protected void AnnounceToAgentsRegion(ScenePresence scenePresence, string msg) { OSChatMessage c = new OSChatMessage(); diff --git a/OpenSim/Region/Environment/Modules/ContentManagementSystem/CMController.cs b/OpenSim/Region/Environment/Modules/ContentManagementSystem/CMController.cs index cdd4f4e..6eaaacd 100644 --- a/OpenSim/Region/Environment/Modules/ContentManagementSystem/CMController.cs +++ b/OpenSim/Region/Environment/Modules/ContentManagementSystem/CMController.cs @@ -381,7 +381,7 @@ namespace OpenSim.Region.Environment.Modules.ContentManagement protected void StartManaging(IClientAPI client) { m_log.Debug("[CONTENT MANAGEMENT] Registering channel with chat services."); - client.OnChatFromViewer += SimChatSent; + // client.OnChatFromClient += SimChatSent; //init = true; OnNewClient(client); @@ -412,7 +412,7 @@ namespace OpenSim.Region.Environment.Modules.ContentManagement { IClientAPI client = presence.ControllingClient; m_log.Debug("[CONTENT MANAGEMENT] Unregistering channel with chat services."); - client.OnChatFromViewer -= SimChatSent; + // client.OnChatFromViewer -= SimChatSent; m_log.Debug("[CONTENT MANAGEMENT] Removing handlers to client"); client.OnUpdatePrimScale -= UpdateSingleScale; @@ -641,6 +641,7 @@ namespace OpenSim.Region.Environment.Modules.ContentManagement m_log.Debug("[CONTENT MANAGEMENT] Initializing Content Management System."); scene.EventManager.OnNewClient += StartManaging; + scene.EventManager.OnChatFromClient += SimChatSent; scene.EventManager.OnRemovePresence += StopManaging; // scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; scene.EventManager.OnObjectBeingRemovedFromScene += GroupBeingDeleted; diff --git a/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs index ae5eefc..f5ec389 100644 --- a/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs @@ -116,7 +116,7 @@ namespace OpenSim.Region.Environment.Modules.Scripting.WorldComm m_scene = scene; m_scene.RegisterModuleInterface(this); m_listenerManager = new ListenerManager(maxlisteners, maxhandles); - m_scene.EventManager.OnNewClient += NewClient; + m_scene.EventManager.OnChatFromClient += DeliverClientMessage; m_pendingQ = new Queue(); m_pending = Queue.Synchronized(m_pendingQ); } @@ -203,7 +203,7 @@ namespace OpenSim.Region.Environment.Modules.Scripting.WorldComm /// enqueue the message for delivery to the objects listen event handler. /// The enqueued ListenerInfo no longer has filter values, but the actually trigged values. /// Objects that do an llSay have their messages delivered here and for nearby avatars, - /// the OnChatFromViewer event is used. + /// the OnChatFromClient event is used. /// /// type of delvery (whisper,say,shout or regionwide) /// channel to sent on @@ -311,10 +311,10 @@ namespace OpenSim.Region.Environment.Modules.Scripting.WorldComm #endregion - private void NewClient(IClientAPI client) - { - client.OnChatFromViewer += DeliverClientMessage; - } + // private void NewClient(IClientAPI client) + // { + // client.OnChatFromViewer += DeliverClientMessage; + // } /******************************************************************** * diff --git a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs index 78aee92..33eade2 100644 --- a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs @@ -59,22 +59,22 @@ namespace OpenSim.Region.Environment.Modules.World.NPC public void Say(string message) { - SendOnChatFromViewer(message, ChatTypeEnum.Say); + SendOnChatFromClient(message, ChatTypeEnum.Say); } public void Shout(string message) { - SendOnChatFromViewer(message, ChatTypeEnum.Shout); + SendOnChatFromClient(message, ChatTypeEnum.Shout); } public void Whisper(string message) { - SendOnChatFromViewer(message, ChatTypeEnum.Whisper); + SendOnChatFromClient(message, ChatTypeEnum.Whisper); } public void Broadcast(string message) { - SendOnChatFromViewer(message, ChatTypeEnum.Broadcast); + SendOnChatFromClient(message, ChatTypeEnum.Broadcast); } public void GiveMoney(UUID target, int amount) @@ -132,19 +132,19 @@ namespace OpenSim.Region.Environment.Modules.World.NPC #region Internal Functions - private void SendOnChatFromViewer(string message, ChatTypeEnum chatType) + private void SendOnChatFromClient(string message, ChatTypeEnum chatType) { - OSChatMessage chatFromViewer = new OSChatMessage(); - chatFromViewer.Channel = 0; - chatFromViewer.From = Name; - chatFromViewer.Message = message; - chatFromViewer.Position = StartPos; - chatFromViewer.Scene = m_scene; - chatFromViewer.Sender = this; - chatFromViewer.SenderUUID = AgentId; - chatFromViewer.Type = chatType; + OSChatMessage chatFromClient = new OSChatMessage(); + chatFromClient.Channel = 0; + chatFromClient.From = Name; + chatFromClient.Message = message; + chatFromClient.Position = StartPos; + chatFromClient.Scene = m_scene; + chatFromClient.Sender = this; + chatFromClient.SenderUUID = AgentId; + chatFromClient.Type = chatType; - OnChatFromViewer(this, chatFromViewer); + OnChatFromClient(this, chatFromClient); } #endregion @@ -161,7 +161,7 @@ namespace OpenSim.Region.Environment.Modules.World.NPC public event Action OnConnectionClosed; public event GenericMessage OnGenericMessage; public event ImprovedInstantMessage OnInstantMessage; - public event ChatMessage OnChatFromViewer; + public event ChatMessage OnChatFromClient; public event TextureRequest OnRequestTexture; public event RezObject OnRezObject; public event ModifyTerrain OnModifyTerrain; -- cgit v1.1