ChatFromViewer Arguments
Inheritance: System.EventArgs, IEventArgs
 public bool OnNewChatMessageFromWorld (OSChatMessage c, out OSChatMessage newc)
 {
     string [] operators = c.Message.Split (' ');
     if (operators [0] == "calc.Add") {
         if (operators.Length == 3) {
             float Num1 = float.Parse (operators [1]);
             float Num2 = float.Parse (operators [2]);
             float RetVal = Num1 + Num2;
             BuildAndSendResult (RetVal, c.Scene, c.Position);
         }
     }
     if (operators [0] == "calc.Subtract") {
         if (operators.Length == 3) {
             float Num1 = float.Parse (operators [1]);
             float Num2 = float.Parse (operators [2]);
             float RetVal = Num1 - Num2;
             BuildAndSendResult (RetVal, c.Scene, c.Position);
         }
     }
     if (operators [0] == "calc.Multiply") {
         if (operators.Length == 3) {
             float Num1 = float.Parse (operators [1]);
             float Num2 = float.Parse (operators [2]);
             float RetVal = Num1 * Num2;
             BuildAndSendResult (RetVal, c.Scene, c.Position);
         }
     }
     if (operators [0] == "calc.Divide") {
         if (operators.Length == 3) {
             float Num1 = float.Parse (operators [1]);
             float Num2 = float.Parse (operators [2]);
             float RetVal = Num1 / Num2;
             BuildAndSendResult (RetVal, c.Scene, c.Position);
         }
     }
     newc = c;
     //Block the message from going to everyone, only the server needed to hear
     return true;
 }
 private void DeliverClientMessage(Object sender, OSChatMessage e)
 {
     if (null != e.Sender)
         DeliverMessage(e.Type, e.Channel, e.Sender.Name, e.Sender.AgentId, e.Message, e.Position, -1, UUID.Zero);
     else
         DeliverMessage(e.Type, e.Channel, e.From, UUID.Zero, e.Message, e.Position, -1, UUID.Zero);
 }
 public OSChatMessage Copy()
 {
     OSChatMessage message = new OSChatMessage
                                 {
                                     Channel = Channel,
                                     From = From,
                                     Message = Message,
                                     Position = Position,
                                     Range = Range,
                                     Scene = Scene,
                                     Sender = Sender,
                                     SenderObject = SenderObject,
                                     SenderUUID = SenderUUID,
                                     Type = Type,
                                     ToAgentID = ToAgentID
                                 };
     return message;
 }
 /// <summary>
 ///     Tell the client what the result is
 /// </summary>
 /// <param name="result"></param>
 /// <param name="scene"></param>
 /// <param name="position"></param>
 static void BuildAndSendResult (float result, IScene scene, Vector3 position)
 {
     var message = new OSChatMessage {
         From = "Server",
         Message = "Result: " + result,
         Channel = 0,
         Type = ChatTypeEnum.Region,
         Position = position,
         Sender = null,
         SenderUUID = UUID.Zero,
         Scene = scene
     };
     scene.EventManager.TriggerOnChatBroadcast (null, message);
 }
        public bool OnNewChatMessageFromWorld (OSChatMessage c, out OSChatMessage newc)
        {
            bool isGod = false;
            IScenePresence sP = c.Scene.GetScenePresence (c.SenderUUID);
            if (sP != null) {
                if (!sP.IsChildAgent) {
                    // Check if the sender is a 'god...'
                    if (sP.GodLevel != 0) {
                        isGod = true;

                        // add to authorized users
                        if (!m_authorizedSpeakers.Contains (c.SenderUUID))
                            m_authorizedSpeakers.Add (c.SenderUUID);

                        if (!m_authList.Contains (c.SenderUUID))
                            m_authList.Add (c.SenderUUID);
                    }

                    //Check that the agent is allowed to speak in this region
                    if (!m_authorizedSpeakers.Contains (c.SenderUUID)) {
                        //They can't talk, so block it
                        newc = c;
                        return false;
                    }
                }
            }

            if (c.Message.Contains ("Chat.")) {
                if (!m_useAuth || m_authList.Contains (c.SenderUUID)) {
                    IScenePresence senderSP;
                    c.Scene.TryGetScenePresence (c.SenderUUID, out senderSP);
                    string [] message = c.Message.Split ('.');
                    if (message [1] == "SayDistance") {
                        chatModule.SayDistance = Convert.ToInt32 (message [2]);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [1] + " changed.", ChatSourceType.System, -1);
                    }
                    if (message [1] == "WhisperDistance") {
                        chatModule.WhisperDistance = Convert.ToInt32 (message [2]);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [1] + " changed.", ChatSourceType.System, -1);
                    }
                    if (message [1] == "ShoutDistance") {
                        chatModule.ShoutDistance = Convert.ToInt32 (message [2]);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [1] + " changed.", ChatSourceType.System, -1);
                    }
                    //Add the user to the list of allowed speakers and 'chat' admins
                    if (message [1] == "AddToAuth") {
                        IScenePresence NewSP;
                        c.Scene.TryGetAvatarByName (message [2], out NewSP);
                        m_authList.Add (NewSP.UUID);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [2] + " added.", ChatSourceType.System, -1);
                    }
                    if (message [1] == "RemoveFromAuth") {
                        IScenePresence NewSP;
                        c.Scene.TryGetAvatarByName (message [2], out NewSP);
                        m_authList.Remove (NewSP.UUID);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [2] + " added.", ChatSourceType.System, -1);
                    }
                    //Block chat from those not in the auth list
                    if (message [1] == "BlockChat") {
                        m_blockChat = true;
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region, "Chat blocked.",
                                                      ChatSourceType.System, -1);
                    }
                    //Allow chat from all again
                    if (message [1] == "AllowChat") {
                        m_blockChat = false;
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region, "Chat allowed.",
                                                      ChatSourceType.System, -1);
                    }
                    //Remove speaking privileges from an individual
                    if (message [1] == "RevokeSpeakingRights") {
                        IScenePresence NewSP;
                        c.Scene.TryGetAvatarByName (message [2], out NewSP);
                        m_authorizedSpeakers.Remove (NewSP.UUID);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [2] + " - revoked.", ChatSourceType.System, -1);
                    }
                    //Allow an individual to speak again
                    if (message [1] == "GiveSpeakingRights") {
                        IScenePresence NewSP;
                        c.Scene.TryGetAvatarByName (message [2], out NewSP);
                        m_authorizedSpeakers.Add (NewSP.UUID);
                        chatModule.TrySendChatMessage (senderSP, c.Position,
                                                      UUID.Zero, "UniverseChat", ChatTypeEnum.Region,
                                                      message [2] + " - revoked.", ChatSourceType.System, -1);
                    }
                }

                newc = c;
                // Block commands from normal chat
                return false;
            }

            if (sP != null) {
                //Add the god prefix
                if (isGod && m_indicategod)
                    c.Message = m_godPrefix + c.Message;
            }

            newc = c;
            return true;
        }
        protected virtual void OnChatBroadcast(Object sender, OSChatMessage c)
        {
            // unless the chat to be broadcast is of type Region, we
            // drop it if its channel is neither 0 nor DEBUG_CHANNEL
            if (c.Channel != DEFAULT_CHANNEL && c.Channel != DEBUG_CHANNEL && c.Type != ChatTypeEnum.Region) return;

            ChatTypeEnum cType = c.Type;
            if (c.Channel == DEBUG_CHANNEL)
                cType = ChatTypeEnum.DebugChannel;

            if (c.Range > m_maxChatDistance)
                c.Range = m_maxChatDistance;

            if (cType == ChatTypeEnum.SayTo)
                //Change to something client can understand as SayTo doesn't exist except on the server
                cType = ChatTypeEnum.Owner;

            if (cType == ChatTypeEnum.Region)
                cType = ChatTypeEnum.Say;

            if (c.Message.Length > 1100)
                c.Message = c.Message.Substring(0, 1000);

            // broadcast chat works by redistributing every incoming chat
            // message to each avatar in the scene.
            string fromName = c.From;

            UUID fromID = UUID.Zero;
            ChatSourceType sourceType = ChatSourceType.Object;
            if (null != c.Sender)
            {
                IScenePresence avatar = c.Scene.GetScenePresence(c.Sender.AgentId);
                fromID = c.Sender.AgentId;
                fromName = avatar.Name;
                sourceType = ChatSourceType.Agent;
            }

            // MainConsole.Instance.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType);

            c.Scene.ForEachScenePresence(
                delegate(IScenePresence presence)
                    {
                        // ignore chat from child agents
                        if (presence.IsChildAgent) return;

                        IClientAPI client = presence.ControllingClient;

                        // don't forward SayOwner chat from objects to
                        // non-owner agents
                        if ((c.Type == ChatTypeEnum.Owner) &&
                            (null != c.SenderObject) &&
                            (c.SenderObject.OwnerID != client.AgentId))
                            return;

                        // don't forward SayTo chat from objects to
                        // non-targeted agents
                        if ((c.Type == ChatTypeEnum.SayTo) &&
                            (c.ToAgentID != client.AgentId))
                            return;
                        bool cached = false;
                        MuteList[] mutes = GetMutes(client.AgentId, out cached);
                        foreach (MuteList m in mutes)
                            if (m.MuteID == c.SenderUUID ||
                                (c.SenderObject != null && m.MuteID == c.SenderObject.ParentEntity.UUID))
                                return;
                        client.SendChatMessage(c.Message, (byte) cType,
                                               new Vector3(client.Scene.RegionInfo.RegionSizeX*0.5f,
                                                           client.Scene.RegionInfo.RegionSizeY*0.5f, 30), fromName,
                                               fromID,
                                               (byte) sourceType, (byte) ChatAudibleLevel.Fully);
                    });
        }
        /// <summary>
        ///     New chat message from the client
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="c"></param>
        protected virtual void OnChatFromClient(IClientAPI sender, OSChatMessage c)
        {
            c = FixPositionOfChatMessage(c);

            // redistribute to interested subscribers
            if (c.Message != "")
                c.Scene.EventManager.TriggerOnChatFromClient(sender, c);

            // early return if not on public or debug channel
            if (c.Channel != DEFAULT_CHANNEL && c.Channel != DEBUG_CHANNEL) return;

            // sanity check:
            if (c.Sender == null)
            {
                MainConsole.Instance.ErrorFormat("[CHAT] OnChatFromClient from {0} has empty Sender field!", sender);
                return;
            }

            //If the message is not blank, tell the plugins about it
            if (c.Message != "")
            {
                foreach (
                    string pluginMain in
                        ChatPlugins.Keys.Where(
                            pluginMain => pluginMain == "all" || c.Message.StartsWith(pluginMain + ".")))
                {
                    IChatPlugin plugin;
                    ChatPlugins.TryGetValue(pluginMain, out plugin);
                    //If it returns false, stop the message from being sent
                    if (!plugin.OnNewChatMessageFromWorld(c, out c))
                        return;
                }
            }
            string Name2 = "";
            if (sender is IClientAPI)
            {
                Name2 = (sender).Name;
            }
            c.From = Name2;

            DeliverChatToAvatars(ChatSourceType.Agent, c);
        }
        public void SimChat(string message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
            UUID fromID, bool fromAgent, bool broadcast, float range, UUID ToAgentID, IScene scene)
        {
            OSChatMessage args = new OSChatMessage
                                     {
                                         Message = message,
                                         Channel = channel,
                                         Type = type,
                                         Position = fromPos,
                                         Range = range,
                                         SenderUUID = fromID,
                                         Scene = scene,
                                         ToAgentID = ToAgentID
                                     };

            if (fromAgent)
            {
                IScenePresence user = scene.GetScenePresence(fromID);
                if (user != null)
                    args.Sender = user.ControllingClient;
            }
            else
            {
                args.SenderObject = scene.GetSceneObjectPart(fromID);
            }

            args.From = fromName;

            if (broadcast)
            {
                OnChatBroadcast(scene, args);
                scene.EventManager.TriggerOnChatBroadcast(scene, args);
            }
            else
            {
                OnChatFromWorld(scene, args);
                scene.EventManager.TriggerOnChatFromWorld(scene, args);
            }
        }
        /// <summary>
        ///     Set the correct position for the chat message
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        protected OSChatMessage FixPositionOfChatMessage(OSChatMessage c)
        {
            IScenePresence avatar;
            if ((avatar = c.Scene.GetScenePresence(c.Sender.AgentId)) != null)
                c.Position = avatar.AbsolutePosition;

            return c;
        }
        public virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c)
        {
            string fromName = c.From;
            UUID fromID = UUID.Zero;
            string message = c.Message;
            IScene scene = c.Scene;
            Vector3 fromPos = c.Position;

            if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel;

            IScenePresence avatar = (scene != null && c.Sender != null)
                                        ? scene.GetScenePresence(c.Sender.AgentId)
                                        : null;
            switch (sourceType)
            {
                case ChatSourceType.Agent:
                    if (scene != null)
                    {
                        if (avatar != null && message == "")
                        {
                            fromPos = avatar.AbsolutePosition;
                            fromName = avatar.Name;
                            fromID = c.Sender.AgentId;
                            //Always send this so it fires on typing start and end
                            IAttachmentsModule attMod = scene.RequestModuleInterface<IAttachmentsModule>();
                            if (attMod != null)
                                attMod.SendScriptEventToAttachments(avatar.UUID, "changed", new object[] {Changed.STATE});
                        }
                        else
                            fromID = c.SenderUUID;
                    }
                    else
                        fromID = c.SenderUUID;
                    break;

                case ChatSourceType.Object:
                    fromID = c.SenderUUID;

                    break;
            }

            if (message.Length >= 1000) // libomv limit
                message = message.Substring(0, 1000);

            foreach (IScenePresence presence in from presence in m_Scene.GetScenePresences()
                                                where !presence.IsChildAgent
                                                let fromRegionPos = fromPos
                                                let toRegionPos = presence.AbsolutePosition
                                                let dis = (int) Util.GetDistanceTo(toRegionPos, fromRegionPos)
                                                where
                                                    (c.Type != ChatTypeEnum.Whisper || dis <= m_whisperdistance) &&
                                                    (c.Type != ChatTypeEnum.Say || dis <= m_saydistance) &&
                                                    (c.Type != ChatTypeEnum.Shout || dis <= m_shoutdistance) &&
                                                    (c.Type != ChatTypeEnum.Custom || dis <= c.Range)
                                                where
                                                    sourceType != ChatSourceType.Agent || avatar == null ||
                                                    avatar.CurrentParcel == null ||
                                                    (avatar.CurrentParcelUUID == presence.CurrentParcelUUID ||
                                                     (!avatar.CurrentParcel.LandData.Private &&
                                                      !presence.CurrentParcel.LandData.Private))
                                                select presence)
            {
                //If one of them is in a private parcel, and the other isn't in the same parcel, don't send the chat message
                TrySendChatMessage(presence, fromPos, fromID, fromName, c.Type, message, sourceType,
                                   c.Range);
            }
        }
        /// <summary>
        ///     Send the message from the prim to the avatars in the regions
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="c"></param>
        public virtual void OnChatFromWorld(Object sender, OSChatMessage c)
        {
            // early return if not on public or debug channel
            if (c.Channel != DEFAULT_CHANNEL && c.Channel != DEBUG_CHANNEL) return;

            if (c.Range > m_maxChatDistance) //Check for max distance
                c.Range = m_maxChatDistance;

            DeliverChatToAvatars(ChatSourceType.Object, c);
        }
        private void HandleChatPacket(OSChatMessage chat)
        {
            if (string.IsNullOrEmpty(chat.Message))
                return;

            // Object?
            if (chat.Sender == null && chat.SenderObject != null)
            {
                ChatEventArgs e = new ChatEventArgs
                                      {
                                          Sender = new SOPObject(m_internalScene, chat.SenderObject.LocalId, m_security),
                                          Text = chat.Message,
                                          Channel = chat.Channel
                                      };

                _OnChat(this, e);
                return;
            }
            // Avatar?
            if (chat.Sender != null && chat.SenderObject == null)
            {
                ChatEventArgs e = new ChatEventArgs
                                      {
                                          Sender = new SPAvatar(m_internalScene, chat.SenderUUID, m_security),
                                          Text = chat.Message,
                                          Channel = chat.Channel
                                      };

                _OnChat(this, e);
                return;
            }
            // Skip if other
        }
 private void EventManager_OnChatFromWorld(object sender, OSChatMessage chat)
 {
     if (_OnChat != null)
     {
         HandleChatPacket(chat);
         return;
     }
 }
 public void TriggerOnChatFromWorld(Object sender, OSChatMessage chat)
 {
     ChatFromWorldEvent handlerChatFromWorld = OnChatFromWorld;
     if (handlerChatFromWorld != null)
     {
         foreach (ChatFromWorldEvent d in handlerChatFromWorld.GetInvocationList())
         {
             try
             {
                 d(sender, chat);
             }
             catch (Exception e)
             {
                 MainConsole.Instance.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerOnChatFromWorld failed - continuing.  {0} {1}",
                     e, e.StackTrace);
             }
         }
     }
 }
Beispiel #15
0
        public virtual void DeliverChatToAvatars (ChatSourceType sourceType, OSChatMessage c)
        {
            string fromName = c.From;
            UUID fromID = UUID.Zero;
            string message = c.Message;
            IScene scene = c.Scene;
            Vector3 fromPos = c.Position;

            if (c.Channel == DEBUG_CHANNEL)
                c.Type = ChatTypeEnum.DebugChannel;

            IScenePresence avatar = (scene != null && c.Sender != null)
                                        ? scene.GetScenePresence (c.Sender.AgentId)
                                        : null;
            switch (sourceType) {
            case ChatSourceType.Agent:
                if (scene != null) {
                    if (avatar != null && message == "") {
                        fromPos = avatar.AbsolutePosition;
                        fromName = avatar.Name;
                        fromID = c.Sender.AgentId;
                        //Always send this so it fires on typing start and end
                        IAttachmentsModule attMod = scene.RequestModuleInterface<IAttachmentsModule> ();
                        if (attMod != null)
                            attMod.SendScriptEventToAttachments (avatar.UUID, "changed", new object [] { Changed.STATE });
                    } else
                        fromID = c.SenderUUID;
                } else
                    fromID = c.SenderUUID;
                break;

            case ChatSourceType.Object:
                fromID = c.SenderUUID;

                break;
            }


            // from below it appears that if the source is an agent then do not send messge??
            //if (sourceType == ChatSourceType.Agent)
            //    return;

            if (message.Length >= 1000) // libomv limit
                message = message.Substring (0, 1000);

            // determine who should receive the message
            var presences = m_Scene.GetScenePresences ();
            var fromRegionPos = fromPos;

            foreach (IScenePresence presence in presences) {
                if (presence.IsChildAgent)
                    continue;

                // check presence distances
                var toRegionPos = presence.AbsolutePosition;
                var dis = (int)Util.GetDistanceTo (toRegionPos, fromRegionPos);

                if (c.Type == ChatTypeEnum.Custom && dis > c.Range)                 // further than the defined custom range
                    continue;

                if (c.Type == ChatTypeEnum.Shout && dis > m_shoutdistance)          // too far for shouting
                    continue;

                if (c.Type == ChatTypeEnum.Say && dis > m_saydistance)              // too far for normal chat
                    continue;

                if (c.Type == ChatTypeEnum.Whisper && dis > m_whisperdistance)      // too far out for whisper
                    continue;

                // This appears to be incorrect and potentially breaks local chat - Emperor Starfinder - May 16, 2016
                //if (avatar != null) {
                //    if (avatar.CurrentParcelUUID != presence.CurrentParcelUUID)     // not in the same parcel
                //        continue;

                // This appears to be the way that is necessary for local chat to work
                if (sourceType == ChatSourceType.Agent)
                {
                    if (avatar != null)
                    {
                        if (avatar.CurrentParcel != null)
                        {
                            if (avatar.CurrentParcelUUID != presence.CurrentParcelUUID)     // not in the same parcel
                                continue;
                            
                           //If both are not in the same private parcel, don't send the chat message
                           //if (!(avatar.CurrentParcel.LandData.Private && presence.CurrentParcel.LandData.Private))
                           if (avatar.CurrentParcel.LandData.Private && !presence.CurrentParcel.LandData.Private)
                                continue;
                        }
                    }

                    // This appears to be incorrect and potentially breaks local chat - Emperor Starfinder - May 16, 2016
                    // If both are not in the same proviate parcel, don't send the chat message
                    //if (!(avatar.CurrentParcel.LandData.Private && presence.CurrentParcel.LandData.Private))
                    //    continue;
                }

                // this one is good to go....
                TrySendChatMessage (presence, fromPos, fromID, fromName, c.Type, message, sourceType,
                        c.Range);
            }
            /* previous for reference - remove when verified - greythane -
            foreach (IScenePresence presence in from presence in m_Scene.GetScenePresences()
                                                where !presence.IsChildAgent
                                                let fromRegionPos = fromPos
                                                let toRegionPos = presence.AbsolutePosition
                                                let dis = (int) Util.GetDistanceTo(toRegionPos, fromRegionPos)
                                                where
                                                    (c.Type != ChatTypeEnum.Whisper || dis <= m_whisperdistance) &&
                                                    (c.Type != ChatTypeEnum.Say || dis <= m_saydistance) &&
                                                    (c.Type != ChatTypeEnum.Shout || dis <= m_shoutdistance) &&
                                                    (c.Type != ChatTypeEnum.Custom || dis <= c.Range)
                                                where
                                                    sourceType != ChatSourceType.Agent || avatar == null ||
                                                    avatar.CurrentParcel == null ||
                                                    (avatar.CurrentParcelUUID == presence.CurrentParcelUUID ||
                                                     (!avatar.CurrentParcel.LandData.Private &&
                                                      !presence.CurrentParcel.LandData.Private))
                                                select presence)
            {
                //If one of them is in a private parcel, and the other isn't in the same parcel, don't send the chat message
                TrySendChatMessage (presence, fromPos, fromID, fromName, c.Type, message, sourceType,
                    c.Range);
            }
            */
        }
 public void TriggerOnChatBroadcast(Object sender, OSChatMessage chat)
 {
     ChatBroadcastEvent handlerChatBroadcast = OnChatBroadcast;
     if (handlerChatBroadcast != null)
     {
         foreach (ChatBroadcastEvent d in handlerChatBroadcast.GetInvocationList())
         {
             try
             {
                 d(sender, chat);
             }
             catch (Exception e)
             {
                 MainConsole.Instance.ErrorFormat("[Event Manager]: Delegate for TriggerOnChatBroadcast failed - continuing.  {0} {1}", e, e.StackTrace);
             }
         }
     }
 }