Esempio n. 1
0
        private Hashtable ProcessChatSessionRequest(Hashtable mDhttpMethod, UUID Agent)
        {
            OSDMap rm = (OSDMap)OSDParser.DeserializeLLSDXml((string)mDhttpMethod["requestbody"]);
            string method = rm["method"].AsString();

            UUID sessionid = UUID.Parse(rm["session-id"].AsString());

            IScenePresence SP = findScenePresence (Agent);
            IEventQueueService eq = SP.Scene.RequestModuleInterface<IEventQueueService>();

            if (method == "start conference")
            {
                //Create the session.
                CreateSession(new ChatSession()
                {
                    Members = new List<ChatSessionMember>(),
                    SessionID = sessionid,
                    Name = SP.Name + " Conference"
                });

                OSDArray parameters = (OSDArray)rm["params"];
                //Add other invited members.
                foreach (OSD param in parameters)
                {
                    AddDefaultPermsMemberToSession(param.AsUUID(), sessionid);
                }

                //Add us to the session!
                AddMemberToGroup(new ChatSessionMember()
                {
                    AvatarKey = Agent,
                    CanVoiceChat = true,
                    IsModerator = true,
                    MuteText = false,
                    MuteVoice = false,
                    HasBeenAdded = true
                }, sessionid);


                //Inform us about our room
                OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                block.AgentID = Agent;
                block.CanVoiceChat = true;
                block.IsModerator = true;
                block.MuteText = false;
                block.MuteVoice = false;
                block.Transition = "ENTER";
                eq.ChatterBoxSessionAgentListUpdates(sessionid, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, Agent, "ENTER", findScene(Agent).RegionInfo.RegionHandle);

                OpenMetaverse.Messages.Linden.ChatterBoxSessionStartReplyMessage cs = new OpenMetaverse.Messages.Linden.ChatterBoxSessionStartReplyMessage();
                cs.VoiceEnabled = true;
                cs.TempSessionID = UUID.Random();
                cs.Type = 1;
                cs.Success = true;
                cs.SessionID = sessionid;
                cs.SessionName = SP.Name + " Conference";
                cs.ModeratedVoice = true;

                Hashtable responsedata = new Hashtable();
                responsedata["int_response_code"] = 200; //501; //410; //404;
                responsedata["content_type"] = "text/plain";
                responsedata["keepalive"] = false;
                OSDMap map = cs.Serialize();
                responsedata["str_response_string"] = map.ToString();
                return responsedata;
            }
            else if (method == "accept invitation")
            {
                //They would like added to the group conversation
                List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> Us = new List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();
                List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> NotUsAgents = new List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();

                ChatSession session = GetSession(sessionid);
                if (session != null)
                {
                    ChatSessionMember thismember = FindMember(sessionid, Agent);
                    //Tell all the other members about the incoming member
                    foreach (ChatSessionMember sessionMember in session.Members)
                    {
                        OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                        block.AgentID = sessionMember.AvatarKey;
                        block.CanVoiceChat = sessionMember.CanVoiceChat;
                        block.IsModerator = sessionMember.IsModerator;
                        block.MuteText = sessionMember.MuteText;
                        block.MuteVoice = sessionMember.MuteVoice;
                        block.Transition = "ENTER"; 
                        if (sessionMember.AvatarKey == thismember.AvatarKey)
                            Us.Add(block);
                        else
                        {
                            if (sessionMember.HasBeenAdded) // Don't add not joined yet agents. They don't watn to be here.
                                NotUsAgents.Add(block);
                        }
                    }
                    thismember.HasBeenAdded = true;
                    foreach (ChatSessionMember member in session.Members)
                    {
                        if (member.AvatarKey == thismember.AvatarKey)
                        {
                            //Tell 'us' about all the other agents in the group
                            eq.ChatterBoxSessionAgentListUpdates(session.SessionID, NotUsAgents.ToArray(), member.AvatarKey, "ENTER", findScene(Agent).RegionInfo.RegionHandle);
                        }
                        else
                        {
                            //Tell 'other' agents about the new agent ('us')
                            eq.ChatterBoxSessionAgentListUpdates(session.SessionID, Us.ToArray(), member.AvatarKey, "ENTER", findScene(Agent).RegionInfo.RegionHandle);
                        }
                    }
                }
                Hashtable responsedata = new Hashtable();
                responsedata["int_response_code"] = 200; //501; //410; //404;
                responsedata["content_type"] = "text/plain";
                responsedata["keepalive"] = false;
                responsedata["str_response_string"] = "Accepted";
                return responsedata;
            }
            else if (method == "mute update")
            {
                //Check if the user is a moderator
                Hashtable responsedata = new Hashtable();
                if (!CheckModeratorPermission(Agent, sessionid))
                {
                    responsedata["int_response_code"] = 200; //501; //410; //404;
                    responsedata["content_type"] = "text/plain";
                    responsedata["keepalive"] = false;
                    responsedata["str_response_string"] = "Accepted";
                    return responsedata;
                }

                OSDMap parameters = (OSDMap)rm["params"];
                UUID AgentID = parameters["agent_id"].AsUUID();
                OSDMap muteInfoMap = (OSDMap)parameters["mute_info"];

                ChatSessionMember thismember = FindMember(sessionid, Agent);
                if (muteInfoMap.ContainsKey("text"))
                    thismember.MuteText = muteInfoMap["text"].AsBoolean();
                if (muteInfoMap.ContainsKey("voice"))
                    thismember.MuteVoice = muteInfoMap["voice"].AsBoolean();

                OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                block.AgentID = thismember.AvatarKey;
                block.CanVoiceChat = thismember.CanVoiceChat;
                block.IsModerator = thismember.IsModerator;
                block.MuteText = thismember.MuteText;
                block.MuteVoice = thismember.MuteVoice;
                block.Transition = "ENTER";

                // Send an update to the affected user
                eq.ChatterBoxSessionAgentListUpdates(sessionid, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, AgentID, "", findScene(Agent).RegionInfo.RegionHandle);
                
                responsedata["int_response_code"] = 200; //501; //410; //404;
                responsedata["content_type"] = "text/plain";
                responsedata["keepalive"] = false;
                responsedata["str_response_string"] = "Accepted";
                return responsedata;
            }
            else
            {
                m_log.Warn("ChatSessionRequest : " + method);
                Hashtable responsedata = new Hashtable();
                responsedata["int_response_code"] = 200; //501; //410; //404;
                responsedata["content_type"] = "text/plain";
                responsedata["keepalive"] = false;
                responsedata["str_response_string"] = "Accepted";
                return responsedata;
            }
        }
Esempio n. 2
0
        private Hashtable ProcessChatSessionRequest(Hashtable mDhttpMethod, UUID Agent)
        {
            OSDMap rm     = (OSDMap)OSDParser.DeserializeLLSDXml((string)mDhttpMethod["requestbody"]);
            string method = rm["method"].AsString();

            UUID sessionid = UUID.Parse(rm["session-id"].AsString());

            IScenePresence     SP = findScenePresence(Agent);
            IEventQueueService eq = SP.Scene.RequestModuleInterface <IEventQueueService>();

            if (method == "start conference")
            {
                //Create the session.
                CreateSession(new ChatSession()
                {
                    Members   = new List <ChatSessionMember>(),
                    SessionID = sessionid,
                    Name      = SP.Name + " Conference"
                });

                OSDArray parameters = (OSDArray)rm["params"];
                //Add other invited members.
                foreach (OSD param in parameters)
                {
                    AddDefaultPermsMemberToSession(param.AsUUID(), sessionid);
                }

                //Add us to the session!
                AddMemberToGroup(new ChatSessionMember()
                {
                    AvatarKey    = Agent,
                    CanVoiceChat = true,
                    IsModerator  = true,
                    MuteText     = false,
                    MuteVoice    = false,
                    HasBeenAdded = true
                }, sessionid);


                //Inform us about our room
                OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                block.AgentID      = Agent;
                block.CanVoiceChat = true;
                block.IsModerator  = true;
                block.MuteText     = false;
                block.MuteVoice    = false;
                block.Transition   = "ENTER";
                eq.ChatterBoxSessionAgentListUpdates(sessionid, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, Agent, "ENTER", findScene(Agent).RegionInfo.RegionHandle);

                OpenMetaverse.Messages.Linden.ChatterBoxSessionStartReplyMessage cs = new OpenMetaverse.Messages.Linden.ChatterBoxSessionStartReplyMessage();
                cs.VoiceEnabled   = true;
                cs.TempSessionID  = UUID.Random();
                cs.Type           = 1;
                cs.Success        = true;
                cs.SessionID      = sessionid;
                cs.SessionName    = SP.Name + " Conference";
                cs.ModeratedVoice = true;

                Hashtable responsedata = new Hashtable();
                responsedata["int_response_code"] = 200; //501; //410; //404;
                responsedata["content_type"]      = "text/plain";
                responsedata["keepalive"]         = false;
                OSDMap map = cs.Serialize();
                responsedata["str_response_string"] = map.ToString();
                return(responsedata);
            }
            else if (method == "accept invitation")
            {
                //They would like added to the group conversation
                List <OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> Us          = new List <OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();
                List <OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> NotUsAgents = new List <OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();

                ChatSession session = GetSession(sessionid);
                if (session != null)
                {
                    ChatSessionMember thismember = FindMember(sessionid, Agent);
                    //Tell all the other members about the incoming member
                    foreach (ChatSessionMember sessionMember in session.Members)
                    {
                        OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                        block.AgentID      = sessionMember.AvatarKey;
                        block.CanVoiceChat = sessionMember.CanVoiceChat;
                        block.IsModerator  = sessionMember.IsModerator;
                        block.MuteText     = sessionMember.MuteText;
                        block.MuteVoice    = sessionMember.MuteVoice;
                        block.Transition   = "ENTER";
                        if (sessionMember.AvatarKey == thismember.AvatarKey)
                        {
                            Us.Add(block);
                        }
                        else
                        {
                            if (sessionMember.HasBeenAdded) // Don't add not joined yet agents. They don't watn to be here.
                            {
                                NotUsAgents.Add(block);
                            }
                        }
                    }
                    thismember.HasBeenAdded = true;
                    foreach (ChatSessionMember member in session.Members)
                    {
                        if (member.AvatarKey == thismember.AvatarKey)
                        {
                            //Tell 'us' about all the other agents in the group
                            eq.ChatterBoxSessionAgentListUpdates(session.SessionID, NotUsAgents.ToArray(), member.AvatarKey, "ENTER", findScene(Agent).RegionInfo.RegionHandle);
                        }
                        else
                        {
                            //Tell 'other' agents about the new agent ('us')
                            eq.ChatterBoxSessionAgentListUpdates(session.SessionID, Us.ToArray(), member.AvatarKey, "ENTER", findScene(Agent).RegionInfo.RegionHandle);
                        }
                    }
                }
                Hashtable responsedata = new Hashtable();
                responsedata["int_response_code"]   = 200; //501; //410; //404;
                responsedata["content_type"]        = "text/plain";
                responsedata["keepalive"]           = false;
                responsedata["str_response_string"] = "Accepted";
                return(responsedata);
            }
            else if (method == "mute update")
            {
                //Check if the user is a moderator
                Hashtable responsedata = new Hashtable();
                if (!CheckModeratorPermission(Agent, sessionid))
                {
                    responsedata["int_response_code"]   = 200; //501; //410; //404;
                    responsedata["content_type"]        = "text/plain";
                    responsedata["keepalive"]           = false;
                    responsedata["str_response_string"] = "Accepted";
                    return(responsedata);
                }

                OSDMap parameters  = (OSDMap)rm["params"];
                UUID   AgentID     = parameters["agent_id"].AsUUID();
                OSDMap muteInfoMap = (OSDMap)parameters["mute_info"];

                ChatSessionMember thismember = FindMember(sessionid, Agent);
                if (muteInfoMap.ContainsKey("text"))
                {
                    thismember.MuteText = muteInfoMap["text"].AsBoolean();
                }
                if (muteInfoMap.ContainsKey("voice"))
                {
                    thismember.MuteVoice = muteInfoMap["voice"].AsBoolean();
                }

                OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                block.AgentID      = thismember.AvatarKey;
                block.CanVoiceChat = thismember.CanVoiceChat;
                block.IsModerator  = thismember.IsModerator;
                block.MuteText     = thismember.MuteText;
                block.MuteVoice    = thismember.MuteVoice;
                block.Transition   = "ENTER";

                // Send an update to the affected user
                eq.ChatterBoxSessionAgentListUpdates(sessionid, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, AgentID, "", findScene(Agent).RegionInfo.RegionHandle);

                responsedata["int_response_code"]   = 200; //501; //410; //404;
                responsedata["content_type"]        = "text/plain";
                responsedata["keepalive"]           = false;
                responsedata["str_response_string"] = "Accepted";
                return(responsedata);
            }
            else
            {
                m_log.Warn("ChatSessionRequest : " + method);
                Hashtable responsedata = new Hashtable();
                responsedata["int_response_code"]   = 200; //501; //410; //404;
                responsedata["content_type"]        = "text/plain";
                responsedata["keepalive"]           = false;
                responsedata["str_response_string"] = "Accepted";
                return(responsedata);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Remove the member from this session
        /// </summary>
        /// <param name="client"></param>
        /// <param name="im"></param>
        public void DropMemberFromSession(IClientAPI client, GridInstantMessage im)
        {
            ChatSession session;
            ChatSessions.TryGetValue(im.imSessionID, out session);
            if (session == null)
                return;
            ChatSessionMember member = new ChatSessionMember() { AvatarKey = UUID.Zero };
            foreach (ChatSessionMember testmember in session.Members)
            {
                if (member.AvatarKey == im.fromAgentID)
                    member = testmember;
            }

            if (member.AvatarKey != UUID.Zero)
                session.Members.Remove(member);

            if (session.Members.Count == 0)
            {
                ChatSessions.Remove(session.SessionID);
                return;
            }

            OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
            block.AgentID = member.AvatarKey;
            block.CanVoiceChat = member.CanVoiceChat;
            block.IsModerator = member.IsModerator;
            block.MuteText = member.MuteText;
            block.MuteVoice = member.MuteVoice;
            block.Transition = "LEAVE";
            IEventQueueService eq = client.Scene.RequestModuleInterface<IEventQueueService>();
            foreach (ChatSessionMember sessionMember in session.Members)
            {
                eq.ChatterBoxSessionAgentListUpdates(session.SessionID, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, sessionMember.AvatarKey, "LEAVE", findScene(sessionMember.AvatarKey).RegionInfo.RegionHandle);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Remove the member from this session
        /// </summary>
        /// <param name="client"></param>
        /// <param name="im"></param>
        public void DropMemberFromSession(IClientAPI client, GridInstantMessage im)
        {
            ChatSession session;

            ChatSessions.TryGetValue(UUID.Parse(im.imSessionID.ToString()), out session);
            if (session == null)
            {
                return;
            }
            ChatSessionMember member = new ChatSessionMember()
            {
                AvatarKey = UUID.Zero
            };

            foreach (ChatSessionMember testmember in session.Members)
            {
                if (member.AvatarKey == UUID.Parse(im.fromAgentID.ToString()))
                {
                    member = testmember;
                }
            }

            if (member.AvatarKey != UUID.Zero)
            {
                session.Members.Remove(member);
            }

            if (session.Members.Count == 0)
            {
                ChatSessions.Remove(session.SessionID);
                return;
            }

            OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
            block.AgentID      = member.AvatarKey;
            block.CanVoiceChat = member.CanVoiceChat;
            block.IsModerator  = member.IsModerator;
            block.MuteText     = member.MuteText;
            block.MuteVoice    = member.MuteVoice;
            block.Transition   = "LEAVE";
            IEventQueueService eq = client.Scene.RequestModuleInterface <IEventQueueService>();

            foreach (ChatSessionMember sessionMember in session.Members)
            {
                eq.ChatterBoxSessionAgentListUpdates(session.SessionID, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, sessionMember.AvatarKey, "LEAVE", findScene(sessionMember.AvatarKey).RegionInfo.RegionHandle);
            }
        }
        /// <summary>
        /// Remove the member from this session
        /// </summary>
        /// <param name="client"></param>
        /// <param name="im"></param>
        public void DropMemberFromSession (IClientAPI client, GridInstantMessage im, bool forwardOn)
        {
            ChatSession session = m_groupData.GetSession(im.imSessionID);
            if(session == null)
                return;
            ChatSessionMember member = new ChatSessionMember() { AvatarKey = UUID.Zero };
            foreach(ChatSessionMember testmember in session.Members)
            {
                if(testmember.AvatarKey == im.fromAgentID)
                    member = testmember;
            }

            if(member.AvatarKey != UUID.Zero)
            {
                member.HasBeenAdded = false;
            }

            if(GetMemeberCount(session) == 0)
            {
                m_groupData.RemoveSession(session.SessionID);//Noone is left!
                return;
            }

            OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
            block.AgentID = member.AvatarKey;
            block.CanVoiceChat = member.CanVoiceChat;
            block.IsModerator = member.IsModerator;
            block.MuteText = member.MuteText;
            block.MuteVoice = member.MuteVoice;
            block.Transition = "LEAVE";
            List<UUID> usersToForwardTo = new List<UUID>();
            IEventQueueService eq = client.Scene.RequestModuleInterface<IEventQueueService>();
            foreach(ChatSessionMember sessionMember in session.Members)
            {
                IClientAPI user = GetActiveClient(sessionMember.AvatarKey);
                if(user != null)
                    eq.ChatterBoxSessionAgentListUpdates(session.SessionID, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, sessionMember.AvatarKey, "LEAVE", user.Scene.RegionInfo.RegionHandle);
                else
                    usersToForwardTo.Add(sessionMember.AvatarKey);
            }
            if(forwardOn)
            {
                im.dialog = 212;//Don't keep forwarding on other sims
                m_msgTransferModule.SendInstantMessages(im, usersToForwardTo);
            }
        }
        private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
        {
            IScenePresence presence;
            if((presence = remoteClient.Scene.GetScenePresence(remoteClient.AgentId)) == null || presence.IsChildAgent)
                return; //Must exist and not be a child
            if (m_debugEnabled)
            {
                m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

                DebugGridInstantMessage(im);
            }

            // Start group IM session
            if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart))
            {
                if (m_debugEnabled) m_log.InfoFormat("[GROUPS-MESSAGING]: imSessionID({0}) toAgentID({1})", im.imSessionID, im.toAgentID);

                UUID GroupID = im.imSessionID;
                UUID AgentID = im.fromAgentID;

                GroupRecord groupInfo = m_groupData.GetGroupRecord(AgentID, GroupID, null);
    
                if (groupInfo != null)
                {
                    if(!m_groupsModule.GroupPermissionCheck(AgentID, GroupID, GroupPowers.JoinChat))
                        return;//They have to be able to join to create a group chat
                    //Create the session.
                    IEventQueueService queue = remoteClient.Scene.RequestModuleInterface<IEventQueueService>();
                    if(m_groupData.CreateSession(new ChatSession()
                    {
                        Members = new List<ChatSessionMember>(),
                        SessionID = GroupID,
                        Name = groupInfo.GroupName
                    }))
                    {
                        m_groupData.AddMemberToGroup(new ChatSessionMember()
                        {
                            AvatarKey = AgentID,
                            CanVoiceChat = false,
                            IsModerator = GetIsModerator(AgentID, GroupID),
                            MuteText = false,
                            MuteVoice = false,
                            HasBeenAdded = true
                        }, GroupID);

                        foreach(GroupMembersData gmd in m_groupData.GetGroupMembers(AgentID, GroupID))
                        {
                            if(gmd.AgentID != AgentID)//Add everyone else too
                            {
                                if((gmd.AgentPowers & (ulong)GroupPowers.JoinChat) == (ulong)GroupPowers.JoinChat)//Only if they can join
                                {
                                    m_groupData.AddMemberToGroup(new ChatSessionMember()
                                    {
                                        AvatarKey = gmd.AgentID,
                                        CanVoiceChat = false,
                                        IsModerator = GetIsModerator(gmd.AgentID, GroupID),
                                        MuteText = false,
                                        MuteVoice = false,
                                        HasBeenAdded = false
                                    }, GroupID);
                                }
                            }
                        }
                        //Tell us that it was made successfully
                        ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID);
                    }
                    else
                    {
                        ChatSession thisSession = m_groupData.GetSession(GroupID);
                        //A session already exists
                        //Add us
                        m_groupData.AddMemberToGroup(new ChatSessionMember()
                        {
                            AvatarKey = AgentID,
                            CanVoiceChat = false,
                            IsModerator = GetIsModerator(AgentID, GroupID),
                            MuteText = false,
                            MuteVoice = false,
                            HasBeenAdded = true
                        }, GroupID);

                        //Tell us that we entered successfully
                        ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID);
                        List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> Us = new List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();
                        List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> NotUsAgents = new List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();

                        foreach(ChatSessionMember sessionMember in thisSession.Members)
                        {
                            OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                            block.AgentID = sessionMember.AvatarKey;
                            block.CanVoiceChat = sessionMember.CanVoiceChat;
                            block.IsModerator = sessionMember.IsModerator;
                            block.MuteText = sessionMember.MuteText;
                            block.MuteVoice = sessionMember.MuteVoice;
                            block.Transition = "ENTER";
                            if(AgentID == sessionMember.AvatarKey)
                                Us.Add(block);
                            if(sessionMember.HasBeenAdded) // Don't add not joined yet agents. They don't want to be here.
                                NotUsAgents.Add(block);
                        }
                        foreach(ChatSessionMember member in thisSession.Members)
                        {
                            if(member.AvatarKey == AgentID)
                            {
                                //Tell 'us' about all the other agents in the group
                                queue.ChatterBoxSessionAgentListUpdates(GroupID, NotUsAgents.ToArray(), member.AvatarKey, "ENTER", remoteClient.Scene.RegionInfo.RegionHandle);
                            }
                            else
                            {
                                //Tell 'other' agents about the new agent ('us')
                                IClientAPI otherAgent = GetActiveClient(member.AvatarKey);
                                if(otherAgent != null)//Local, so we can send it directly
                                    queue.ChatterBoxSessionAgentListUpdates(GroupID, Us.ToArray(), member.AvatarKey, "ENTER", otherAgent.Scene.RegionInfo.RegionHandle);
                                else
                                {
                                    ISyncMessagePosterService amps = m_sceneList[0].RequestModuleInterface<ISyncMessagePosterService>();
                                    if(amps != null)
                                    {
                                        OSDMap message = new OSDMap();
                                        message["Method"] = "GroupSessionAgentUpdate";
                                        message["AgentID"] = AgentID;
                                        message["Message"] = ChatterBoxSessionAgentListUpdates(GroupID, Us.ToArray(), "ENTER");
                                        amps.Post(message, remoteClient.Scene.RegionInfo.RegionHandle);
                                    }
                                }
                            }
                        }
                    }

                    //Tell us that we entered
                    OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock ourblock = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                    ourblock.AgentID = AgentID;
                    ourblock.CanVoiceChat = true;
                    ourblock.IsModerator = true;
                    ourblock.MuteText = false;
                    ourblock.MuteVoice = false;
                    ourblock.Transition = "ENTER";
                    queue.ChatterBoxSessionAgentListUpdates(GroupID, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { ourblock }, AgentID, "ENTER", remoteClient.Scene.RegionInfo.RegionHandle);
                }
            }
            // Send a message from locally connected client to a group
            else if ((im.dialog == (byte)InstantMessageDialog.SessionSend) && im.message != "")
            {
                UUID GroupID = im.imSessionID;
                UUID AgentID = im.fromAgentID;

                if (m_debugEnabled) 
                    m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString());

                ChatSessionMember memeber = m_groupData.FindMember(im.imSessionID, AgentID);
                if(memeber == null || memeber.MuteText)
                    return;//Not in the chat or muted
                SendMessageToGroup(im, GroupID);
            }
            else if(im.dialog == (byte)InstantMessageDialog.SessionDrop)
                DropMemberFromSession(remoteClient, im, true);
            else if(im.dialog == (byte)212)//Forwarded sessionDrop
                DropMemberFromSession(remoteClient, im, false);
        }
        private void MuteUser (UUID sessionid, IEventQueueService eq, UUID AgentID, ChatSessionMember thismember, bool forward)
        {
            OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
            block.AgentID = thismember.AvatarKey;
            block.CanVoiceChat = thismember.CanVoiceChat;
            block.IsModerator = thismember.IsModerator;
            block.MuteText = thismember.MuteText;
            block.MuteVoice = thismember.MuteVoice;
            block.Transition = "ENTER";

            // Send an update to the affected user
            IClientAPI affectedUser = GetActiveClient(thismember.AvatarKey);
            if(affectedUser != null)
                eq.ChatterBoxSessionAgentListUpdates(sessionid, new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[] { block }, AgentID, "ENTER", affectedUser.Scene.RegionInfo.RegionHandle);
            else if(forward)
                SendMutedUserIM(thismember, sessionid);
        }
        private string OnChatSessionRequest (UUID Agent, OSDMap rm)
        {
            string method = rm["method"].AsString();

            UUID sessionid = UUID.Parse(rm["session-id"].AsString());

            IClientAPI SP = GetActiveClient(Agent);
            IEventQueueService eq = SP.Scene.RequestModuleInterface<IEventQueueService>();

            if(method == "accept invitation")
            {
                //They would like added to the group conversation
                List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> Us = new List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();
                List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> NotUsAgents = new List<OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();

                ChatSession session = m_groupData.GetSession(sessionid);
                if(session != null)
                {
                    ChatSessionMember thismember = m_groupData.FindMember(sessionid, Agent);
                    if(thismember == null)
                        return "";//No user with that session
                    //Tell all the other members about the incoming member
                    thismember.HasBeenAdded = true;
                    foreach(ChatSessionMember sessionMember in session.Members)
                    {
                        OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block = new OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
                        block.AgentID = sessionMember.AvatarKey;
                        block.CanVoiceChat = sessionMember.CanVoiceChat;
                        block.IsModerator = sessionMember.IsModerator;
                        block.MuteText = sessionMember.MuteText;
                        block.MuteVoice = sessionMember.MuteVoice;
                        block.Transition = "ENTER";
                        if(Agent == sessionMember.AvatarKey)
                            Us.Add(block);
                        if(sessionMember.HasBeenAdded) // Don't add not joined yet agents. They don't want to be here.
                            NotUsAgents.Add(block);
                    }
                    foreach(ChatSessionMember member in session.Members)
                    {
                        if(member.AvatarKey == thismember.AvatarKey)
                        {
                            //Tell 'us' about all the other agents in the group
                            eq.ChatterBoxSessionAgentListUpdates(session.SessionID, NotUsAgents.ToArray(), member.AvatarKey, "ENTER", SP.Scene.RegionInfo.RegionHandle);
                        }
                        else
                        {
                            //Tell 'other' agents about the new agent ('us')
                            IClientAPI otherAgent = GetActiveClient(member.AvatarKey);
                            if(otherAgent != null)//Local, so we can send it directly
                                eq.ChatterBoxSessionAgentListUpdates(session.SessionID, Us.ToArray(), member.AvatarKey, "ENTER", otherAgent.Scene.RegionInfo.RegionHandle);
                            else
                            {
                                ISyncMessagePosterService amps = m_sceneList[0].RequestModuleInterface<ISyncMessagePosterService>();
                                if(amps != null)
                                {
                                    OSDMap message = new OSDMap();
                                    message["Method"] = "GroupSessionAgentUpdate";
                                    message["AgentID"] = thismember.AvatarKey;
                                    message["Message"] = ChatterBoxSessionAgentListUpdates(session.SessionID, Us.ToArray(), "ENTER");
                                    amps.Post(message, SP.Scene.RegionInfo.RegionHandle);
                                }
                            }
                        }
                    }
                    return "Accepted";
                }
                else
                    return ""; //not this type of session
            }
            else if(method == "mute update")
            {
                //Check if the user is a moderator
                if(!GetIsModerator(Agent, sessionid))
                    return "";

                OSDMap parameters = (OSDMap)rm["params"];
                UUID AgentID = parameters["agent_id"].AsUUID();
                OSDMap muteInfoMap = (OSDMap)parameters["mute_info"];

                ChatSessionMember thismember = m_groupData.FindMember(sessionid, AgentID);
                if(muteInfoMap.ContainsKey("text"))
                    thismember.MuteText = muteInfoMap["text"].AsBoolean();
                if(muteInfoMap.ContainsKey("voice"))
                    thismember.MuteVoice = muteInfoMap["voice"].AsBoolean();
                MuteUser(sessionid, eq, AgentID, thismember, true);

                return "Accepted";
            }
            else
            {
                m_log.Warn("ChatSessionRequest : " + method);
                return "";
            }
        }