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;
 }
Beispiel #2
0
        /// <summary>
        /// Send chat to listeners.
        /// </summary>
        /// <param name='message'></param>
        /// <param name='type'>/param>
        /// <param name='channel'></param>
        /// <param name='fromPos'></param>
        /// <param name='fromName'></param>
        /// <param name='fromID'></param>
        /// <param name='targetID'></param>
        /// <param name='fromAgent'></param>
        /// <param name='broadcast'></param>
        protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
                               UUID fromID, UUID targetID, bool fromAgent, bool broadcast)
        {
            OSChatMessage args = new OSChatMessage();

            args.Message    = Utils.BytesToString(message);
            args.Channel    = channel;
            args.Type       = type;
            args.Position   = fromPos;
            args.SenderUUID = fromID;
            args.Scene      = this;

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

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

//            m_log.DebugFormat(
//                "[SCENE]: Sending message {0} on channel {1}, type {2} from {3}, broadcast {4}",
//                args.Message.Replace("\n", "\\n"), args.Channel, args.Type, fromName, broadcast);

            if (broadcast)
            {
                EventManager.TriggerOnChatBroadcast(this, args);
            }
            else
            {
                EventManager.TriggerOnChatFromWorld(this, args);
            }
        }
Beispiel #3
0
        public override void OnChatFromWorld(Object sender, OSChatMessage c)
        {
            if (m_replacingChatModule)
            {
                // when we are replacing ChatModule, we treat
                // OnChatFromClient like OnChatBroadcast for
                // concierged regions, effectively extending the
                // range of chat to cover the whole
                // region. however, we don't do this for whisper
                // (got to have some privacy)
                if (c.Type != ChatTypeEnum.Whisper)
                {
                    base.OnChatBroadcast(sender, c);
                    return;
                }

                base.OnChatFromWorld(sender, c);
            }
            return;
        }
        void EventManager_OnChatFromClient(object sender, OSChatMessage chat)
        {
            if (!m_enabled)
            {
                return;
            }
            if (chat.Message == "" || chat.SenderUUID == chat.DestinationUUID)
            {
                return;
            }

            if (chat.Message.Length < m_minWordLength)
            {
                return;                                        //too small, nothing to filter, dont waste time
            }
            StringBuilder result = new StringBuilder(chat.Message);

            DoFilteringOnStatement(result);

            chat.Message = result.ToString();
        }
        public virtual bool SendChatMessageToNeighbors(OSChatMessage message, ChatSourceType type, RegionInfo region)
        {
            bool RetVal = false;
            List <GridRegion> NotifiedRegions = m_LocalService.SendChatMessageToNeighbors(message, type, region, out RetVal);

            if (Neighbors.ContainsKey(region.RegionID))
            {
                int RegionsNotInformed = Neighbors[region.RegionID].Count - NotifiedRegions.Count;

                //We informed all of them locally, so quit early
                if (RegionsNotInformed == 0)
                {
                    return(RetVal);
                }

                //Now add the remote ones and tell it which ones have already been informed locally so that it doesn't inform them twice
                InformNeighborsOfChatMessage(message, type, region, NotifiedRegions, Neighbors[region.RegionID]);
            }
            //This tells the chat module whether we should send the message in the region it originated from, and if it
            return(RetVal);
        }
        protected virtual void OnChatEvent(OSChatMessage chat)
        {
            if (chat.Sender.AgentId != m_awaitingReplyFrom)
            {
                return;
            }

            if (chat.Channel != ButtonMap[chat.Sender.AgentId].Channel)
            {
                return;
            }

            NextProcessDelegate nextProcess = m_nextProcess;

            Deactivate();

            m_log.InfoFormat(
                "[WATER WARS]: Received chat [{0}] from {1}", chat, chat.Sender.AgentId);

            nextProcess(chat);
        }
Beispiel #7
0
        /// <summary>
        /// Trigger chat coming from this connection.
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="type"></param>
        /// <param name="message"></param>
        public bool Chat(int channel, ChatTypeEnum type, string message)
        {
            ChatMessage handlerChatFromClient = OnChatFromClient;

            if (handlerChatFromClient != null)
            {
                OSChatMessage args = new OSChatMessage();
                args.Channel = channel;
                args.From    = Name;
                args.Message = message;
                args.Type    = type;

                args.Scene      = Scene;
                args.Sender     = this;
                args.SenderUUID = AgentId;

                handlerChatFromClient(this, args);
            }

            return(true);
        }
        void OnEmptyScriptCompileQueue(int numScriptsFailed, string message)
        {
            if (m_firstEmptyCompileQueue || m_oarFileLoading)
            {
                OSChatMessage c = new OSChatMessage();
                if (m_firstEmptyCompileQueue)
                {
                    c.Message = "server_startup,";
                }
                else
                {
                    c.Message = "oar_file_load,";
                }
                m_firstEmptyCompileQueue = false;
                m_oarFileLoading         = false;

                m_scene.Backup(false);

                c.From = "RegionReady";
                if (m_lastOarLoadedOk)
                {
                    c.Message += "1,";
                }
                else
                {
                    c.Message += "0,";
                }
                c.Channel    = m_channelNotify;
                c.Message   += numScriptsFailed.ToString() + "," + message;
                c.Type       = ChatTypeEnum.Region;
                c.Position   = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30);
                c.Sender     = null;
                c.SenderUUID = UUID.Zero;
                c.Scene      = m_scene;

                m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}",
                                 m_scene.RegionInfo.RegionName, c.Message, m_channelNotify);
                m_scene.EventManager.TriggerOnChatBroadcast(this, c);
            }
        }
        void ProcessCommand(object Sender, OSChatMessage Chat)
        {
            ScenePresence sp = m_scene.GetScenePresence(Chat.SenderUUID);

            MessageDialog(sp.ControllingClient, String.Format("Recieved: {1}:{0}", Chat.Message, sp.ControllingClient.Name));
            string[] MessParts = Chat.Message.Split(default(char[]));
            m_log.DebugFormat("[MENTOR] Command recieved: {0}", MessParts[0]);
            switch (MessParts[0].ToLower())
            {
            case "alert":
                switch (MessParts[1].ToLower())
                {
                case "on":
                    Enabled = true;
                    MessageDialog(sp.ControllingClient, "Mentor Alert is On");
                    break;

                case "off":
                    Enabled = false;
                    MessageDialog(sp.ControllingClient, "Mentor Alert is Off");
                    break;

                default:
                    if (Enabled)
                    {
                        MessageDialog(sp.ControllingClient, "Mentor Alert is on");
                    }
                    else
                    {
                        MessageDialog(sp.ControllingClient, "Mentor Alert is off");
                    }
                    break;
                }
                break;

            default:

                break;
            }
        }
Beispiel #10
0
        // This function is lifted from the IRCConnector because it
        // contains information that is not differentiating from an
        // IRC point-of-view.

        public static void OSChat(IRCConnector p_irc, OSChatMessage c, bool cmsg)
        {
            // m_log.DebugFormat("[IRC-OSCHAT] from {0}:{1}", p_irc.Server, p_irc.IrcChannel);

            try
            {
                // Scan through the set of unique channel configuration for those
                // that belong to this connector. And then forward the message to
                // all regions known to those channels.
                // Note that this code is responsible for completing some of the
                // settings for the inbound OSChatMessage

                foreach (ChannelState cs in IRCBridgeModule.m_channels)
                {
                    if (p_irc == cs.irc)
                    {
                        // This non-IRC differentiator moved to here

                        if (cmsg && !cs.ClientReporting)
                        {
                            continue;
                        }

                        // This non-IRC differentiator moved to here

                        c.Channel = (cs.RelayPrivateChannels ? cs.RelayChannel : 0);

                        foreach (RegionState region in cs.clientregions)
                        {
                            region.OSChat(cs.irc, c);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_log.ErrorFormat("[IRC-OSCHAT]: BroadcastSim Exception: {0}", ex.Message);
                m_log.Debug(ex);
            }
        }
Beispiel #11
0
        /// <summary>
        /// This sets the estateID for the region if the estate password is set right
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnChatFromClient(object sender, OSChatMessage e)
        {
            //For Estate Password
            EstateChange Change = null;

            if (ChannelDirectory.TryGetValue(e.Sender.AgentId, out Change))
            {
                //Check whether the channel is right
                if (Change.Channel == e.Channel)
                {
                    ((IClientAPI)sender).OnChatFromClient -= OnChatFromClient;
                    ChannelDirectory.Remove(e.Sender.AgentId);
                    IWorldComm comm = ((Scene)((IClientAPI)sender).Scene).RequestModuleInterface <IWorldComm>();
                    //Unblock the channel now that we have the password
                    comm.RemoveBlockedChannel(Change.Channel);

                    string Password = Util.Md5Hash(e.Message);
                    //Try to switch estates
                    bool changed = DataManager.DataManager.RequestPlugin <IEstateConnector>().LinkRegion(((Scene)((IClientAPI)sender).Scene).RegionInfo.RegionID, (int)Change.EstateID, Password);
                    if (!changed)
                    {
                        //Revert it, it didn't work
                        ((Scene)((IClientAPI)sender).Scene).RegionInfo.EstateSettings.EstateID = Change.OldEstateID;
                        ((IClientAPI)sender).SendAgentAlertMessage("Unable to connect to the given estate.", false);
                    }
                    else
                    {
                        ((Scene)((IClientAPI)sender).Scene).RegionInfo.EstateSettings.EstateID = Change.EstateID;
                        ((Scene)((IClientAPI)sender).Scene).RegionInfo.EstateSettings.Save();
                        ((IClientAPI)sender).SendAgentAlertMessage("Estate Updated.", false);
                    }
                    //Tell the clients to update all references to the new settings
                    foreach (IScenePresence sp in ((IClientAPI)sender).Scene.GetScenePresences())
                    {
                        HandleRegionInfoRequest(sp.ControllingClient, ((Scene)((IClientAPI)sender).Scene));
                    }
                }
            }
        }
Beispiel #12
0
        public override void OnChatFromClient(Object sender, OSChatMessage c)
        {
            if (m_replacingChatModule)
            {
                // replacing ChatModule: need to redistribute
                // ChatFromClient to interested subscribers

                Scene scene = (Scene)c.Scene;
                scene.EventManager.TriggerOnChatFromClient(sender, c);

                if (m_conciergedScenes.Contains(c.Scene))
                {
                    // Force avatar position to be server-known avatar position. (Former contents of FixPositionOfChatMessage.)
                    ScenePresence avatar;
                    if (scene.TryGetAvatar(c.SenderUUID, out avatar))
                    {
                        c.Position = avatar.AbsolutePosition;
                    }

                    // when we are replacing ChatModule, we treat
                    // OnChatFromClient like OnChatBroadcast for
                    // concierged regions, effectively extending the
                    // range of chat to cover the whole
                    // region. however, we don't do this for whisper
                    // (got to have some privacy)
                    if (c.Type != ChatTypeEnum.Whisper)
                    {
                        base.OnChatBroadcast(sender, c);
                        return;
                    }
                }

                // redistribution will be done by base class
                base.OnChatFromClient(sender, c);
            }

            // TODO: capture chat
            return;
        }
Beispiel #13
0
        /// -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        // -----------------------------------------------------------------
        public Dispatcher.Messages.ResponseBase ChatHandler(Dispatcher.Messages.RequestBase request)
        {
            if (request.GetType() != typeof(ChatRequest))
            {
                return(OperationFailed("wrong type"));
            }

            ChatRequest   req = (ChatRequest)request;
            OSChatMessage msg = new OSChatMessage();

            msg.Scene    = m_scene;
            msg.Type     = ChatTypeEnum.Say;
            msg.Sender   = null;
            msg.From     = req._UserAccount.Name;
            msg.Message  = req.Message;
            msg.Position = req.Position;
            msg.Channel  = req.Channel;

            m_scene.EventManager.TriggerOnChatBroadcast(new Object(), msg);

            return(new Dispatcher.Messages.ResponseBase(ResponseCode.Success, ""));
        }
Beispiel #14
0
        private void onChat(object sender, OSChatMessage chat)
        {
            lock (m_dialogs)
            {
                DialogData data = m_dialogs.Find(x => x.ListenerID == chat.Channel && x.UserID == chat.Sender.AgentId);

                if (data != null)
                {
                    if (chat.Message != "<--" && chat.Message != "-->" && chat.Message != "<- EXIT ->" && chat.Message != " " && chat.Message != String.Empty)
                    {
                        m_scriptEngine.PostScriptEvent(data.ScriptID, "listen", new Object[] { data.ListenerID, chat.From.ToString(), data.UserID.ToString(), chat.Message });
                        return;
                    }

                    if (chat.Message == " " || chat.Message == String.Empty)
                    {
                        return;
                    }

                    if (chat.Message == "<- EXIT ->")
                    {
                        m_dialogs.Remove(data);
                        return;
                    }

                    if (chat.Message == "-->")
                    {
                        data.CurrentPage++;
                    }

                    if (chat.Message == "<--")
                    {
                        data.CurrentPage--;
                    }

                    m_dialogModule.SendDialogToUser(data.UserID, data.ObjectName, data.HostID, data.OwnerID, data.getMessage(), new UUID("00000000-0000-2222-3333-100000001000"), data.ListenerID, data.getPageButtons(data.CurrentPage));
                }
            }
        }
        protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
                               UUID fromID, bool fromAgent, bool broadcast)
        {
            OSChatMessage args = new OSChatMessage();

            args.Message    = Utils.BytesToString(message);
            args.Channel    = channel;
            args.Type       = type;
            args.Position   = fromPos;
            args.SenderUUID = fromID;
            args.Scene      = this;

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

            args.From = fromName;
            //args.

            if (broadcast)
            {
                EventManager.TriggerOnChatBroadcast(this, args);
            }
            else
            {
                EventManager.TriggerOnChatFromWorld(this, args);
            }
        }
Beispiel #16
0
        private void SendOnChatFromClient(int channel, string message, ChatTypeEnum chatType)
        {
            if (channel == 0)
            {
                message = message.Trim();
                if (string.IsNullOrEmpty(message))
                {
                    return;
                }
            }
            OSChatMessage chatFromClient = new OSChatMessage();

            chatFromClient.Channel    = channel;
            chatFromClient.From       = Name;
            chatFromClient.Message    = message;
            chatFromClient.Position   = StartPos;
            chatFromClient.Scene      = m_scene;
            chatFromClient.Sender     = this;
            chatFromClient.SenderUUID = AgentId;
            chatFromClient.Type       = chatType;

            OnChatFromClient(this, chatFromClient);
        }
Beispiel #17
0
        public virtual void OnChatFromClient(Object sender, OSChatMessage c)
        {
            c = FixPositionOfChatMessage(c);

            // redistribute to interested subscribers
            Scene scene = (Scene)c.Scene;

            scene.EventManager.TriggerOnChatFromClient(sender, c);

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

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

            DeliverChatToAvatars(ChatSourceType.Agent, c);
        }
Beispiel #18
0
        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);
                    });
        }
        public bool OnNewChatMessageFromWorld(OSChatMessage c, out OSChatMessage newc)
        {
            IScenePresence SP = c.Scene.GetScenePresence(c.SenderUUID);
            if (SP != null)
            {
                if (!SP.IsChildAgent)
                {
                    //Check that the agent is allows to speak in this reigon
                    if (SP.GodLevel != 0 && !!m_authorizedSpeakers.Contains(c.SenderUUID))
                        m_authorizedSpeakers.Add(c.SenderUUID);

                    if (SP.GodLevel != 0 && !m_authList.Contains(c.SenderUUID))
                        m_authList.Add(c.SenderUUID);

                    if (!m_authorizedSpeakers.Contains(c.SenderUUID))
                    {
                        newc = c;
                        //They can't talk, so block it
                        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, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", ChatTypeEnum.Region,
                                                      message[1] + " changed.", ChatSourceType.System, -1);
                    }
                    if (message[1] == "WhisperDistance")
                    {
                        chatModule.WhisperDistance = Convert.ToInt32(message[2]);
                        chatModule.TrySendChatMessage(senderSP, c.Position, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", ChatTypeEnum.Region,
                                                      message[1] + " changed.", ChatSourceType.System, -1);
                    }
                    if (message[1] == "ShoutDistance")
                    {
                        chatModule.ShoutDistance = Convert.ToInt32(message[2]);
                        chatModule.TrySendChatMessage(senderSP, c.Position, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", 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, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", 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, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", 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, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", ChatTypeEnum.Region, "Chat blocked.",
                                                      ChatSourceType.System, -1);
                    }
                    //Allow chat from all again
                    if (message[1] == "AllowChat")
                    {
                        m_blockChat = false;
                        chatModule.TrySendChatMessage(senderSP, c.Position, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", ChatTypeEnum.Region, "Chat allowed.",
                                                      ChatSourceType.System, -1);
                    }
                    //Remove speaking priviledges 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, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", 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, new Vector3(c.Scene.RegionInfo.RegionLocX,
                                                                                        c.Scene.RegionInfo.RegionLocY, 0),
                                                      UUID.Zero, "AuroraChat", 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 (SP.GodLevel != 0 && m_indicategod)
                    c.Message = m_godPrefix + c.Message;
            }

            newc = c;
            return true;
        }
Beispiel #20
0
        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;
            //args.

            if (broadcast)
            {
                OnChatBroadcast(scene, args);
                scene.EventManager.TriggerOnChatBroadcast(scene, args);
            }
            else
            {
                OnChatFromWorld(scene, args);
                scene.EventManager.TriggerOnChatFromWorld(scene, args);
            }
        }
Beispiel #21
0
        /// <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 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 void AnnounceToAgentsRegion(Scene scene, string msg)
        // {
        //     ScenePresence agent = null;
        //     if ((client.Scene is Scene) && (client.Scene as Scene).TryGetScenePresence(client.AgentId, out agent))
        //         AnnounceToAgentsRegion(agent, msg);
        //     else
        //         m_log.DebugFormat("[Concierge]: could not find an agent for client {0}", client.Name);
        // }
        protected void AnnounceToAgentsRegion(IScene scene, string msg)
        {
            OSChatMessage c = new OSChatMessage();
            c.Message = msg;
            c.Type = ChatTypeEnum.Say;
            c.Channel = 0;
            c.Position = PosOfGod;
            c.From = m_whoami;
            c.Sender = null;
            c.SenderUUID = UUID.Zero;
            c.Scene = scene;

            scene.EventManager.TriggerOnChatBroadcast(this, c);
        }
Beispiel #24
0
        protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c)
        {
            string fromName = c.From;
            string fromNamePrefix = "";
            UUID fromID = UUID.Zero;
            UUID ownerID = UUID.Zero;
            string message = c.Message;
            Scene scene = c.Scene as Scene;
            UUID destination = c.Destination;
            Vector3 fromPos = c.Position;
            Vector3 regionPos = new Vector3(scene.RegionInfo.WorldLocX, scene.RegionInfo.WorldLocY, 0);

            bool checkParcelHide = false;
            UUID sourceParcelID = UUID.Zero;
            Vector3 hidePos = fromPos;

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

            if(!m_scenes.Contains(scene))
            {
                m_log.WarnFormat("[CHAT]: message from unkown scene {0} ignored",
                                     scene.RegionInfo.RegionName);
                return;
            }

            switch (sourceType)
            {
                case ChatSourceType.Agent:
                    ScenePresence avatar = (scene as Scene).GetScenePresence(c.Sender.AgentId);
                    fromPos = avatar.AbsolutePosition;
                    fromName = avatar.Name;
                    fromID = c.Sender.AgentId;
                    if (avatar.IsViewerUIGod)
                    { // let gods speak to outside or things may get confusing
                        fromNamePrefix = m_adminPrefix;
                        checkParcelHide = false;
                    }
                    else
                    {
                        checkParcelHide = true;
                    }
                    destination = UUID.Zero; // Avatars cant "SayTo"
                    ownerID = c.Sender.AgentId;

                    hidePos = fromPos;
                    break;

                case ChatSourceType.Object:
                    fromID = c.SenderUUID;

                    if (c.SenderObject != null && c.SenderObject is SceneObjectPart)
                    {
                        ownerID = ((SceneObjectPart)c.SenderObject).OwnerID;
                        if (((SceneObjectPart)c.SenderObject).ParentGroup.IsAttachment)
                        {
                            checkParcelHide = true;
                            hidePos = ((SceneObjectPart)c.SenderObject).ParentGroup.AbsolutePosition;
                        }
                    }
                    break;
            }

            // TODO: iterate over message
            if (message.Length >= 1000) // libomv limit
                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);

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

            if (checkParcelHide)
            {
                checkParcelHide = false;
                if (c.Type < ChatTypeEnum.DebugChannel && destination == UUID.Zero)
                {
                    ILandObject srcland = scene.LandChannel.GetLandObject(hidePos.X, hidePos.Y);
                    if (srcland != null && !srcland.LandData.SeeAVs)
                    {
                        sourceParcelID = srcland.LandData.GlobalID;
                        checkParcelHide = true;
                    }
                }
            }

            scene.ForEachScenePresence(
                delegate(ScenePresence presence)
                {
                    if (destination != UUID.Zero && presence.UUID != destination)
                        return;

                    if(presence.IsChildAgent)
                        {
                            if(checkParcelHide)
                                return;
                            if (TrySendChatMessage(presence, fromPos, regionPos, fromID,
                                        ownerID, fromNamePrefix + fromName, c.Type,
                                        message, sourceType, (destination != UUID.Zero)))
                                receiverIDs.Add(presence.UUID);
                            return;
                        }

                    ILandObject Presencecheck = scene.LandChannel.GetLandObject(presence.AbsolutePosition.X,            presence.AbsolutePosition.Y);
                    if (Presencecheck != null)
                    {
                        if (checkParcelHide)
                        {
                            if (sourceParcelID != Presencecheck.LandData.GlobalID && !presence.IsViewerUIGod)
                                return;
                        }
                        if (c.Sender == null || Presencecheck.IsEitherBannedOrRestricted(c.Sender.AgentId) != true)
                        {
                            if (TrySendChatMessage(presence, fromPos, regionPos, fromID,
                                        ownerID, fromNamePrefix + fromName, c.Type,
                                        message, sourceType, (destination != UUID.Zero)))
                                receiverIDs.Add(presence.UUID);
                        }
                    }
                });

            scene.EventManager.TriggerOnChatToClients(
                fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully);
        }
        protected override void OnChatFromClient(IClientAPI sender, OSChatMessage c)
        {
            if (m_replacingChatModule)
            {
                // replacing ChatModule: need to redistribute
                // ChatFromClient to interested subscribers
                c = FixPositionOfChatMessage(c);

                IScene scene = c.Scene;
                scene.EventManager.TriggerOnChatFromClient(sender, c);

                if (m_conciergedScenes.Contains(c.Scene))
                {
                    // when we are replacing ChatModule, we treat
                    // OnChatFromClient like OnChatBroadcast for
                    // concierged regions, effectively extending the
                    // range of chat to cover the whole
                    // region. however, we don't do this for whisper
                    // (got to have some privacy)
                    if (c.Type != ChatTypeEnum.Whisper)
                    {
                        base.OnChatBroadcast(sender, c);
                        return;
                    }
                }

                // redistribution will be done by base class
                base.OnChatFromClient(sender, c);
            }

            // TODO: capture chat
            return;
        }
        public bool OnNewChatMessageFromWorld(OSChatMessage c, out OSChatMessage newc)
        {
            string[] operators = c.Message.Split(' ');
            TranslatorUserInfo UInfo = null;

            if (operators[0].StartsWith("translate", StringComparison.CurrentCultureIgnoreCase))
            {
                // Example to turn on translator
                // translator en >> fr         translator en > fr
                // translator fr << en         translator fr < en

                if (operators[2].Contains(">")) //Covers > and >>, 
                {
                    UserInfos[c.SenderUUID] = new TranslatorUserInfo
                                                  {
                                                      enabled = true,
                                                      From = Language.GetValue(operators[1]),
                                                      To = Language.GetValue(operators[3])
                                                  };
                }
                else if (operators[2].Contains("<")) //Covers < and <<, 
                {
                    UserInfos[c.SenderUUID] = new TranslatorUserInfo
                                                  {
                                                      enabled = true,
                                                      From = Language.GetValue(operators[3]),
                                                      To = Language.GetValue(operators[1])
                                                  };
                }
            }
            else if (c.Message.StartsWith("translator settings", StringComparison.CurrentCultureIgnoreCase))
            {
                if (UserInfos.TryGetValue(c.SenderUUID, out UInfo))
                {
                    if (operators[2] == "enabled")
                        UInfo.enabled = bool.Parse(operators[3]);
                    if (operators[2] == "showold")
                        UInfo.ShowNonTranslated = bool.Parse(operators[3]);
                }
            }
            else if (c.Message.StartsWith("translator help", StringComparison.CurrentCultureIgnoreCase))
            {
                c.Message = "Translate: \n" +
                            "translate from >> to  - translates from language 'from' into language 'to'\n" +
                            "Settings:\n" +
                            "translator settings enabled true/false - enables the translator\n" +
                            "translator settings showold true/false - shows the original chat\n" +
                            "Languages\n";
                foreach (Language lang in Language.TranslatableList)
                {
                    c.Message += lang.Name + " - " + lang.Value + "\n";
                }
            }
            else if (UserInfos.TryGetValue(c.SenderUUID, out UInfo))
            {
                //If enabled, ask google translator about it
                if (UInfo.enabled)
                {
                    TranslateClient tc =
                        new TranslateClient("http://ajax.googleapis.com/ajax/services/language/translate");
                    string translated = "";
                    try
                    {
                        translated = tc.Translate(c.Message, UInfo.From.Value, UInfo.To.Value);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("[Aurora Translator]: Error in requesting translation, " + ex);
                    }
                    if (!UInfo.ShowNonTranslated)
                        c.Message = translated;
                    else
                        c.Message = translated + " (" + c.Message + ")";
                }
            }
            newc = c;
            return true;
        }
Beispiel #27
0
        protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c)
        {
            string  fromName  = c.From;
            UUID    fromID    = UUID.Zero;
            UUID    ownerID   = UUID.Zero;
            UUID    targetID  = c.TargetUUID;
            string  message   = c.Message;
            Scene   scene     = (Scene)c.Scene;
            Vector3 fromPos   = c.Position;
            Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
                                            scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);

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

            switch (sourceType)
            {
            case ChatSourceType.Agent:
                ScenePresence avatar = scene.GetScenePresence(c.Sender.AgentId);
                fromPos  = avatar.AbsolutePosition;
                fromName = avatar.Name;
                fromID   = c.Sender.AgentId;
                ownerID  = c.Sender.AgentId;

                break;

            case ChatSourceType.Object:
                fromID = c.SenderUUID;

                if (c.SenderObject != null && c.SenderObject is SceneObjectPart)
                {
                    ownerID = ((SceneObjectPart)c.SenderObject).OwnerID;
                }

                break;
            }

            // TODO: iterate over message
            if (message.Length >= 1000) // libomv limit
            {
                message = message.Substring(0, 1000);
            }

//            m_log.DebugFormat(
//                "[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>();

            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
                scene.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 = 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.EventManager.TriggerOnChatToClients(
                fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully);
        }
 void EventManager_OnChatFromClient(IClientAPI sender, OSChatMessage chat)
 {
     if (chat.Message == "" || sender == null || chat.Channel != m_chatToIRCChannel)
         return;
     Client client;
     if(TryGetClient(sender.AgentId, out client))
     {
         Util.FireAndForget(delegate(object o)
         {
             IScenePresence sp = sender.Scene.GetScenePresence(sender.AgentId);
             if (sp != null)
             {
                 string channel;
                 if (m_channel.TryGetValue(sp.CurrentParcel.LandData.GlobalID, out channel))
                 {
                     client.SendChat("(grid: " +
                         MainServer.Instance.ServerURI.Remove(0, 7) + ") - " +
                         chat.Message, channel);
                 }
             }
         });
     }
 }
Beispiel #29
0
 private void EventManager_OnChatFromClient(object sender, OSChatMessage chat)
 {
     if (_OnChat != null)
     {
         HandleChatPacket(chat);
         return;
     }
 }
Beispiel #30
0
        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
        }
        void OnStartupComplete(IScene scene, List<string> data)
        {
            int num = 0;
            while (num < data.Count - 1)
            {
                string type = data[num].ToString();
                int len = Convert.ToInt32(data[num + 1]);
                num += 2;
                if (type == "ScriptEngine")
                {
                    if (m_firstEmptyCompileQueue || m_oarFileLoading)
                    {
                        OSChatMessage c = new OSChatMessage();
                        if (m_firstEmptyCompileQueue)
                            c.Message = "server_startup,";
                        else
                            c.Message = "oar_file_load,";
                        m_firstEmptyCompileQueue = false;
                        m_oarFileLoading = false;

                        c.From = "RegionReady";
                        if (m_lastOarLoadedOk)
                            c.Message += "1,";
                        else
                            c.Message += "0,";
                        c.Channel = m_channelNotify;
                        //Equiv of 'c.Message += numScriptsFailed.ToString() + "," + message;'
                        c.Message += data[num] + "," + data[num+1];
                        c.Type = ChatTypeEnum.Region;
                        c.Position = new Vector3((m_scene.RegionInfo.RegionSizeX * 0.5f), (m_scene.RegionInfo.RegionSizeY * 0.5f), 30);
                        c.Sender = null;
                        c.SenderUUID = UUID.Zero;
                        c.Scene = m_scene;

                        m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}",
                                         m_scene.RegionInfo.RegionName, c.Message, m_channelNotify);
                        m_scene.EventManager.TriggerOnChatBroadcast(this, c);
                    }
                }
                else
                    num += len;
            }
        }
 void OnChat(Object sender, OSChatMessage chat)
 {
     if (chat.Channel != m_channel)
     {
         return;
     }
     else if (m_isBusy)
     {
         Dialog("Busy. Wait a few moments and try again...");
     }
     else if (chat.Message == "show")
     {
         m_isBusy = true;
         if (m_isHidden == true)
         {
             Dialog("Show...");
             InitializePyramid(m_scene);
             m_isHidden = false;
         }
         else
         {
             Dialog("Already shown");
         }
         m_isBusy = false;
     }
     else if (chat.Message == "hide")
     {
         m_isBusy = true;
         if (m_isHidden == false)
         {
             Dialog("Hide...");
             foreach (SceneObjectGroup sog in m_prims)
             {
                 m_scene.DeleteSceneObject(sog, false);
             }
             m_prims.Clear();
             m_isHidden = true;
         }
         else
         {
             Dialog("Already hidden");
         }
         m_isBusy = false;
     }
     else if (chat.Message == "step")
     {
         m_isBusy = true;
         if (m_isHidden == false)
         {
             if (m_stepCount < m_maxSteps)
             {
                 Dialog("Updating pyramid...");
                 foreach (SceneObjectGroup sog in m_prims)
                 {
                     DoSierpinski(sog, m_size);
                 }
                 m_size = new Vector3(m_size.X / 2, m_size.Y / 2, m_size.Z / 2);
                 m_prims.Clear();
                 Dialog(m_newprims.Count + " prims");
                 m_prims = new List <SceneObjectGroup>(m_newprims);
                 m_newprims.Clear();
                 m_stepCount++;
             }
             else
             {
                 Dialog("Too many prims. Resetting pyramid.  Please wait...");
                 foreach (SceneObjectGroup sog in m_prims)
                 {
                     m_scene.DeleteSceneObject(sog, false);
                 }
                 m_prims.Clear();
                 InitializePyramid(m_scene);
                 m_stepCount = 0;
             }
         }
         else
         {
             Dialog("Must 'show' first...");
         }
         m_isBusy = false;
     }
     else
     {
         Dialog("Invalid command");
     }
 }
Beispiel #33
0
 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);
             }
         }
     }
 }
        protected void AnnounceToAgent(IScenePresence agent, string msg)
        {
            OSChatMessage c = new OSChatMessage();
            c.Message = msg;
            c.Type = ChatTypeEnum.Say;
            c.Channel = 0;
            c.Position = PosOfGod;
            c.From = m_whoami;
            c.Sender = null;
            c.SenderUUID = UUID.Zero;
            c.Scene = agent.Scene;

            agent.ControllingClient.SendChatMessage(msg, (byte) ChatTypeEnum.Say, PosOfGod, m_whoami, UUID.Zero,
                                                    (byte)ChatSourceType.Object, (byte)ChatAudibleLevel.Fully);
        }
        // This handler detects chat events int he virtual world.
        public void OnSimChat(Object sender, OSChatMessage msg)
        {
            // early return if this comes from the IRC forwarder

            if (cs.irc.Equals(sender))
            {
                return;
            }

            // early return if nothing to forward

            if (msg.Message.Length == 0)
            {
                return;
            }

            // check for commands coming from avatars or in-world
            // object (if commands are enabled)

            if (cs.CommandsEnabled && msg.Channel == cs.CommandChannel)
            {
                m_log.DebugFormat("[IRC-Region {0}] command on channel {1}: {2}", Region, msg.Channel, msg.Message);

                string[] messages = msg.Message.Split(' ');
                string   command  = messages[0].ToLower();

                try
                {
                    switch (command)
                    {
                    // These commands potentially require a change in the
                    // underlying ChannelState.

                    case "server":
                        cs.Close(this);
                        cs = cs.UpdateServer(this, messages[1]);
                        cs.Open(this);
                        break;

                    case "port":
                        cs.Close(this);
                        cs = cs.UpdatePort(this, messages[1]);
                        cs.Open(this);
                        break;

                    case "channel":
                        cs.Close(this);
                        cs = cs.UpdateChannel(this, messages[1]);
                        cs.Open(this);
                        break;

                    case "nick":
                        cs.Close(this);
                        cs = cs.UpdateNickname(this, messages[1]);
                        cs.Open(this);
                        break;

                    // These may also (but are less likely) to require a
                    // change in ChannelState.

                    case "client-reporting":
                        cs = cs.UpdateClientReporting(this, messages[1]);
                        break;

                    case "in-channel":
                        cs = cs.UpdateRelayIn(this, messages[1]);
                        break;

                    case "out-channel":
                        cs = cs.UpdateRelayOut(this, messages[1]);
                        break;

                    // These are all taken to be temporary changes in state
                    // so the underlying connector remains intact. But note
                    // that with regions sharing a connector, there could
                    // be interference.

                    case "close":
                        enabled = false;
                        cs.Close(this);
                        break;

                    case "connect":
                        enabled = true;
                        cs.Open(this);
                        break;

                    case "reconnect":
                        enabled = true;
                        cs.Close(this);
                        cs.Open(this);
                        break;

                    // This one is harmless as far as we can judge from here.
                    // If it is not, then the complaints will eventually make
                    // that evident.

                    default:
                        m_log.DebugFormat("[IRC-Region {0}] Forwarding unrecognized command to IRC : {1}",
                                          Region, msg.Message);
                        cs.irc.Send(msg.Message);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    m_log.WarnFormat("[IRC-Region {0}] error processing in-world command channel input: {1}",
                                     Region, ex.Message);
                    m_log.Debug(ex);
                }

                return;
            }

            // The command channel remains enabled, even if we have otherwise disabled the IRC
            // interface.

            if (!enabled)
            {
                return;
            }

            // drop messages unless they are on a valid in-world
            // channel as configured in the ChannelState

            if (!cs.ValidInWorldChannels.Contains(msg.Channel))
            {
                m_log.DebugFormat("[IRC-Region {0}] dropping message {1} on channel {2}", Region, msg, msg.Channel);
                return;
            }

            ScenePresence avatar   = null;
            string        fromName = msg.From;

            if (msg.Sender != null)
            {
                avatar = scene.GetScenePresence(msg.Sender.AgentId);
                if (avatar != null)
                {
                    fromName = avatar.Name;
                }
            }

            if (!cs.irc.Connected)
            {
                m_log.WarnFormat("[IRC-Region {0}] IRCConnector not connected: dropping message from {1}", Region, fromName);
                return;
            }

            m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message);

            if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL))
            {
                string txt = msg.Message;
                if (txt.StartsWith("/me "))
                {
                    txt = String.Format("{0} {1}", fromName, msg.Message.Substring(4));
                }

                cs.irc.PrivMsg(cs.PrivateMessageFormat, fromName, Region, txt);
                return;
            }

            if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword &&
                msg.Channel == cs.RelayChannelOut)
            {
                Match m = cs.AccessPasswordRegex.Match(msg.Message);
                if (null != m)
                {
                    m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(),
                                      m.Groups["message"].ToString());
                    cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(),
                                   scene.RegionInfo.RegionName, m.Groups["message"].ToString());
                }
            }
        }
Beispiel #36
0
        public bool OnNewChatMessageFromWorld(OSChatMessage c, out OSChatMessage newc)
        {
            string[]           operators = c.Message.Split(' ');
            TranslatorUserInfo UInfo     = null;

            if (operators[0].StartsWith("translate", StringComparison.CurrentCultureIgnoreCase))
            {
                // Example to turn on translator
                // translator en >> fr         translator en > fr
                // translator fr << en         translator fr < en

                if (operators[2].Contains(">")) //Covers > and >>,
                {
                    UserInfos[c.SenderUUID] = new TranslatorUserInfo()
                    {
                        enabled = true,
                        From    = Aurora.GoogleAPIs.Language.GetValue(operators[1]),
                        To      = Aurora.GoogleAPIs.Language.GetValue(operators[3])
                    };
                }
                else if (operators[2].Contains("<")) //Covers < and <<,
                {
                    UserInfos[c.SenderUUID] = new TranslatorUserInfo()
                    {
                        enabled = true,
                        From    = Aurora.GoogleAPIs.Language.GetValue(operators[3]),
                        To      = Aurora.GoogleAPIs.Language.GetValue(operators[1])
                    };
                }
            }
            else if (c.Message.StartsWith("translator settings", StringComparison.CurrentCultureIgnoreCase))
            {
                if (UserInfos.TryGetValue(c.SenderUUID, out UInfo))
                {
                    if (operators[2] == "enabled")
                    {
                        UInfo.enabled = bool.Parse(operators[3]);
                    }
                    if (operators[2] == "showold")
                    {
                        UInfo.ShowNonTranslated = bool.Parse(operators[3]);
                    }
                }
            }
            else if (c.Message.StartsWith("translator help", StringComparison.CurrentCultureIgnoreCase))
            {
                c.Message = "Translate: \n" +
                            "translate from >> to  - translates from language 'from' into language 'to'\n" +
                            "Settings:\n" +
                            "translator settings enabled true/false - enables the translator\n" +
                            "translator settings showold true/false - shows the original chat\n" +
                            "Languages\n";
                foreach (Aurora.GoogleAPIs.Language lang in Aurora.GoogleAPIs.Language.TranslatableList)
                {
                    c.Message += lang.Name + " - " + lang.Value + "\n";
                }
            }
            else if (UserInfos.TryGetValue(c.SenderUUID, out UInfo))
            {
                //If enabled, ask google translator about it
                if (UInfo.enabled)
                {
                    TranslateClient tc         = new TranslateClient("http://ajax.googleapis.com/ajax/services/language/translate");
                    string          translated = "";
                    try
                    {
                        translated = tc.Translate(c.Message, UInfo.From.Value, UInfo.To.Value);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("[Aurora Translator]: Error in requesting translation, " + ex.ToString());
                    }
                    if (!UInfo.ShowNonTranslated)
                    {
                        c.Message = translated;
                    }
                    else
                    {
                        c.Message = translated + " (" + c.Message + ")";
                    }
                }
            }
            newc = c;
            return(true);
        }
        protected override void OnChatBroadcast(Object sender, OSChatMessage c)
        {
            if (m_replacingChatModule)
            {
                // distribute chat message to each and every avatar in
                // the region
                base.OnChatBroadcast(sender, c);
            }

            // TODO: capture logic
            return;
        }
        void OnChat(Object sender, OSChatMessage chat)
        {
            if (chat.Channel != m_channel)
            {
                return;
            }
            else if (chat.Message == "show")
            {
                if (m_isHidden)
                {
                    Dialog("Show...");
                    InitializeMatrix(m_scene);
                }
                else
                {
                    Dialog("Already showing");
                }
            }
            else if (m_isHidden == false)
            {
                if (chat.Message == "hide")
                {
                    if (m_isRunning)
                    {
                        StopAutomata();
                    }
                    Dialog("Hide...");
                    foreach (SceneObjectGroup sog in m_prims)
                    {
                        m_scene.DeleteSceneObject(sog, false);
                    }
                    m_prims.Clear();
                    m_matrix = new float[m_xCells * m_yCells];

                    m_isHidden = true;
                }
                else if (chat.Message == "start")
                {
                    if (!m_isRunning)
                    {
                        Dialog("Start...");
                        m_isRunning = true;
                        m_timer.Start();
                    }
                    else
                    {
                        Dialog("Already running");
                    }
                }
                else if (chat.Message == "stop")
                {
                    if (m_isRunning)
                    {
                        Dialog("Stop...");
                        StopAutomata();
                    }
                    else
                    {
                        Dialog("Already stopped");
                    }
                }
                else if (chat.Message == "reset")
                {
                    if (m_isRunning)
                    {
                        StopAutomata();
                    }
                    Dialog("Randomize...");
                    RandomizeMatrix();
                }
                else
                {
                    Dialog("Invalid command");
                }
            }
            else
            {
                Dialog("Must 'show' first");
            }
        }
Beispiel #39
0
        /// <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);
        }
Beispiel #40
0
        protected virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c)
        {
            string  fromName  = c.From;
            UUID    fromID    = UUID.Zero;
            UUID    destID    = c.DestinationUUID;
            string  message   = c.Message;
            IScene  scene     = c.Scene;
            Vector3 fromPos   = c.Position;
            Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize,
                                            scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);

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

            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);
                fromPos  = avatar.AbsolutePosition;
                fromName = avatar.Name;
                fromID   = c.Sender.AgentId;

                break;

            case ChatSourceType.Object:
                fromID = c.SenderUUID;

                break;
            }

            // TODO: iterate over message
            if (message.Length >= 1000) // libomv limit
            {
                message = message.Substring(0, 1000);
            }

            // m_log.DebugFormat("[CHAT]: DCTA: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, c.Type, sourceType);

            foreach (Scene s in m_scenes)
            {
                s.ForEachScenePresence(delegate(ScenePresence presence)
                {
                    if (!presence.IsChildAgent)
                    {
                        if ((destID == UUID.Zero) || (destID == presence.UUID))
                        {
                            TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName,
                                               c.Type, message, sourceType);
                        }
                    }
                });
            }
        }
Beispiel #41
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;
            Vector3 regionPos = scene != null
                                    ? new Vector3(scene.RegionInfo.RegionLocX,
                                                  scene.RegionInfo.RegionLocY, 0)
                                    : Vector3.Zero;

            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);

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

            foreach (IScenePresence presence in from s in m_scenes
                                                select s.GetScenePresences() into ScenePresences
                                                from presence in ScenePresences
                                                where !presence.IsChildAgent
                                                let fromRegionPos = fromPos + regionPos
                                                let toRegionPos = presence.AbsolutePosition +
                                                                  new Vector3(presence.Scene.RegionInfo.RegionLocX,
                                                                              presence.Scene.RegionInfo.RegionLocY, 0)
                                                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, regionPos, fromID, fromName, c.Type, message, sourceType,
                                   c.Range);
            }
        }
Beispiel #42
0
        public 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 != 0 && c.Channel != DEBUG_CHANNEL && c.Type != ChatTypeEnum.Region)
            {
                return;
            }

            ChatTypeEnum cType = c.Type;

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

            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;
            UUID           ownerID    = UUID.Zero;
            ChatSourceType sourceType = ChatSourceType.Object;

            if (null != c.Sender)
            {
                ScenePresence avatar = (c.Scene as Scene).GetScenePresence(c.Sender.AgentId);
                fromID     = c.Sender.AgentId;
                fromName   = avatar.Name;
                ownerID    = c.Sender.AgentId;
                sourceType = ChatSourceType.Agent;
            }
            else if (c.SenderUUID != UUID.Zero)
            {
                fromID  = c.SenderUUID;
                ownerID = ((SceneObjectPart)c.SenderObject).OwnerID;
            }

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

            ((Scene)c.Scene).ForEachScenePresence(
                delegate(ScenePresence 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) &&
                    (((SceneObjectPart)c.SenderObject).OwnerID != client.AgentId))
                {
                    return;
                }

                presence.Scene.EventManager.TriggerOnChatToClient(c.Message, fromID,
                                                                  client.AgentId, presence.Scene.RegionInfo.RegionID, (uint)Util.UnixTimeSinceEpoch(),
                                                                  ChatToClientType.InworldChat);

                client.SendChatMessage(c.Message, (byte)cType, CenterOfRegion, fromName, fromID, ownerID,
                                       (byte)sourceType, (byte)ChatAudibleLevel.Fully);
            });
        }
Beispiel #43
0
        /// <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 != "")
            {
#if (!ISWIN)
                foreach (string pluginMain in ChatPlugins.Keys)
                {
                    if (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;
                    }
                }
#else
                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;
                }
#endif

            }
            string Name2 = "";
            if (sender is IClientAPI)
            {
                Name2 = (sender).Name;
            }
            c.From = Name2;

            DeliverChatToAvatars(ChatSourceType.Agent, c);
        }
 /// <summary>
 ///   Tell the client what the result is
 /// </summary>
 /// <param name = "result"></param>
 /// <param name = "scene"></param>
 /// <param name = "position"></param>
 private void BuildAndSendResult(float result, IScene scene, Vector3 position)
 {
     OSChatMessage 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);
 }
 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);
 }
 void EventManager_OnChatFromClient(IClientAPI sender, OSChatMessage chat)
 {
     if(chat.Message == "" || sender == null || chat.Channel != m_chatToIRCChannel)
         return;
     Client client;
     if(TryGetClient(sender.AgentId, out client))
     {
         Util.FireAndForget(delegate(object o)
         {
             client.SendChat("(grid: " +
                 MainServer.Instance.ServerURI.Remove(0, 7) + ") - " +
                 chat.Message, m_channel);
         });
     }
 }
Beispiel #47
0
        public virtual void OnChatBroadcast(Object sender, OSChatMessage c)
        {
            if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL)
            {
                return;
            }

            ChatTypeEnum cType = c.Type;

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

            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)
            {
                ScenePresence avatar = (c.Scene as Scene).GetScenePresence(c.Sender.AgentId);
                fromID     = c.Sender.AgentId;
                fromName   = avatar.Name;
                sourceType = ChatSourceType.Agent;
            }
            else if (c.SenderUUID != UUID.Zero)
            {
                fromID = c.SenderUUID;
            }

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

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

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

                client.SendChatMessage(
                    c.Message, (byte)cType, CenterOfRegion, fromName, fromID, fromID,
                    (byte)sourceType, (byte)ChatAudibleLevel.Fully);

                receiverIDs.Add(client.AgentId);
            });

            (c.Scene as Scene).EventManager.TriggerOnChatToClients(
                fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully);
        }
        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);
            });
        }
        private void OnChatFromClient(object sender, OSChatMessage msg)
        {
            if (msg.Sender == null)
            {
                return;
            }

            //m_log.DebugFormat("chan {0} msg {1}", msg.Channel, msg.Message);

            IClientAPI client = msg.Sender;

            if (!m_floaters.ContainsKey(client.AgentId))
            {
                return;
            }

            string[] parts = msg.Message.Split(new char[] { ':' });
            if (parts.Length == 0)
            {
                return;
            }

            ScenePresence sp = m_scene.GetScenePresence(client.AgentId);

            if (sp == null || sp.IsChildAgent)
            {
                return;
            }

            Dictionary <int, FloaterData> d = m_floaters[client.AgentId];

            // Work around a viewer bug - VALUE from any
            // dialog can appear on this channel and needs to
            // be dispatched to ALL open dialogs for the user
            if (msg.Channel == 427169570)
            {
                if (parts[0] == "VALUE")
                {
                    foreach (FloaterData dd in d.Values)
                    {
                        if (dd.Handler(client, dd, parts))
                        {
                            m_floaters[client.AgentId].Remove(dd.Channel);
                            SendToClient(sp, String.Format("># floater {0} destroy", dd.FloaterName));
                            break;
                        }
                    }
                }
                return;
            }

            if (!d.ContainsKey(msg.Channel))
            {
                return;
            }

            FloaterData data = d[msg.Channel];

            if (parts[0] == "NOTIFY")
            {
                if (parts[1] == "cancel" || parts[1] == data.FloaterName)
                {
                    m_floaters[client.AgentId].Remove(data.Channel);
                    SendToClient(sp, String.Format("># floater {0} destroy", data.FloaterName));
                }
            }

            if (data.Handler != null && data.Handler(client, data, parts))
            {
                m_floaters[client.AgentId].Remove(data.Channel);
                SendToClient(sp, String.Format("># floater {0} destroy", data.FloaterName));
            }
        }
        public void TestScriptCrossOnSameSimulator()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            UUID userId            = TestHelpers.ParseTail(0x1);
            int  sceneObjectIdTail = 0x2;

            EntityTransferModule           etmA = new EntityTransferModule();
            EntityTransferModule           etmB = new EntityTransferModule();
            LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
            XEngine xEngineA = new XEngine();
            XEngine xEngineB = new XEngine();

            xEngineA.DebugLevel = 1;
            xEngineB.DebugLevel = 1;

            IConfigSource configSource = new IniConfigSource();

            IConfig startupConfig = configSource.AddConfig("Startup");

            startupConfig.Set("DefaultScriptEngine", "XEngine");
            startupConfig.Set("TrustBinaries", "true");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");

            xEngineConfig.Set("Enabled", "true");
            xEngineConfig.Set("StartDelay", "0");

            // These tests will not run with AppDomainLoading = true, at least on mono.  For unknown reasons, the call
            // to AssemblyResolver.OnAssemblyResolve fails.
            xEngineConfig.Set("AppDomainLoading", "false");

            IConfig modulesConfig = configSource.AddConfig("Modules");

            modulesConfig.Set("EntityTransferModule", etmA.Name);
            modulesConfig.Set("SimulationServices", lscm.Name);

            SceneHelpers sh     = new SceneHelpers();
            TestScene    sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
            TestScene    sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);

            SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
            SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
            SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
            sceneA.StartScripts();
            sceneB.StartScripts();

            SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);

            soSceneA.AbsolutePosition = new Vector3(128, 10, 20);

            string soSceneAName         = soSceneA.Name;
            string scriptItemSceneAName = "script1";

            // CREATE SCRIPT TODO
            InventoryItemBase scriptItemSceneA = new InventoryItemBase();

            //            itemTemplate.ID = itemId;
            scriptItemSceneA.Name    = scriptItemSceneAName;
            scriptItemSceneA.Folder  = soSceneA.UUID;
            scriptItemSceneA.InvType = (int)InventoryType.LSL;

            AutoResetEvent chatEvent       = new AutoResetEvent(false);
            OSChatMessage  messageReceived = null;

            sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };

            sceneA.RezNewScript(userId, scriptItemSceneA,
                                @"integer c = 0;

default
{    
    state_entry()
    {
        llSay(0, ""Script running"");
    }

    changed(integer change)
    {
        llSay(0, ""Changed"");
    }

    touch_start(integer n)
    {
        c = c + 1; 
        llSay(0, (string)c);
    }
}");

            chatEvent.WaitOne(60000);

            Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
            Assert.That(messageReceived.Message, Is.EqualTo("Script running"));

            {
                // XXX: Should not be doing this so directly.  Should call some variant of EventManager.touch() instead.
                DetectParams[] det = new DetectParams[1];
                det[0]     = new DetectParams();
                det[0].Key = userId;
                det[0].Populate(sceneA);

                EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);

                messageReceived = null;
                chatEvent.Reset();
                xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
                chatEvent.WaitOne(60000);

                Assert.That(messageReceived.Message, Is.EqualTo("1"));
            }

            AutoResetEvent chatEventB = new AutoResetEvent(false);

            sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEventB.Set(); };

            messageReceived = null;
            chatEventB.Reset();
            // Cross with a negative value
            soSceneA.AbsolutePosition = new Vector3(128, -10, 20);

            chatEventB.WaitOne(60000);
            Assert.That(messageReceived, Is.Not.Null, "No Changed message received.");
            Assert.That(messageReceived.Message, Is.Not.Null, "Changed message without content");
            Assert.That(messageReceived.Message, Is.EqualTo("Changed"));

            // TEST sending event to moved prim and output
            {
                SceneObjectGroup  soSceneB         = sceneB.GetSceneObjectGroup(soSceneAName);
                TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneAName);

                // XXX: Should not be doing this so directly.  Should call some variant of EventManager.touch() instead.
                DetectParams[] det = new DetectParams[1];
                det[0]     = new DetectParams();
                det[0].Key = userId;
                det[0].Populate(sceneB);

                EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);

                messageReceived = null;
                chatEventB.Reset();
                xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
                chatEventB.WaitOne(60000);

                Assert.That(messageReceived.Message, Is.EqualTo("2"));
            }
        }
Beispiel #51
0
        public void ListenerRun()
        {
            string inputLine;
            int    resetk = m_resetk;

            try
            {
                while (m_enabled && m_connected)
                {
                    if ((inputLine = m_reader.ReadLine()) == null)
                    {
                        throw new Exception("Listener input socket closed");
                    }

                    // m_log.Info("[IRCConnector]: " + inputLine);

                    if (inputLine.Contains("PRIVMSG"))
                    {
                        Dictionary <string, string> data = ExtractMsg(inputLine);

                        // Any chat ???
                        if (data != null)
                        {
                            OSChatMessage c = new OSChatMessage();
                            c.Message    = data["msg"];
                            c.Type       = ChatTypeEnum.Region;
                            c.Position   = CenterOfRegion;
                            c.From       = data["nick"];
                            c.Sender     = null;
                            c.SenderUUID = UUID.Zero;

                            // Is message "\001ACTION foo bar\001"?
                            // Then change to: "/me foo bar"

                            if ((1 == c.Message[0]) && c.Message.Substring(1).StartsWith("ACTION"))
                            {
                                c.Message = String.Format("/me {0}", c.Message.Substring(8, c.Message.Length - 9));
                            }

                            ChannelState.OSChat(this, c, false);
                        }
                    }
                    else
                    {
                        ProcessIRCCommand(inputLine);
                    }
                }
            }
            catch (Exception /*e*/)
            {
                // m_log.ErrorFormat("[IRC-Connector-{0}]: ListenerRun exception trap: {1}", idn, e.Message);
                // m_log.Debug(e);
            }

            // This is potentially circular, but harmless if so.
            // The connection is marked as not connected the first time
            // through reconnect.

            if (m_enabled && (m_resetk == resetk))
            {
                Reconnect();
            }
        }
        public override void OnChatFromWorld(Object sender, OSChatMessage c)
        {
            if (m_replacingChatModule)
            {
                if (m_conciergedScenes.Contains(c.Scene))
                {
                    // when we are replacing ChatModule, we treat
                    // OnChatFromClient like OnChatBroadcast for
                    // concierged regions, effectively extending the
                    // range of chat to cover the whole
                    // region. however, we don't do this for whisper
                    // (got to have some privacy)
                    if (c.Type != ChatTypeEnum.Whisper)
                    {
                        base.OnChatBroadcast(sender, c);
                        return;
                    }
                }

                base.OnChatFromWorld(sender, c);
            }
            return;
        }