private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
        {
            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 = new UUID(im.imSessionID);
                UUID AgentID = new UUID(im.fromAgentID);

                GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero.ToString(), GroupID, null);

                if (groupInfo != null)
                {
                    AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID);

                    ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID);

                    IEventQueue queue = remoteClient.Scene.RequestModuleInterface <IEventQueue>();
                    if (queue != null)
                    {
                        var update  = new GroupChatListAgentUpdateData(AgentID);
                        var updates = new List <GroupChatListAgentUpdateData> {
                            update
                        };
                        queue.ChatterBoxSessionAgentListUpdates(GroupID, remoteClient.AgentId, updates);
                    }
                }
            }

            // Send a message from locally connected client to a group
            if ((im.dialog == (byte)InstantMessageDialog.SessionSend))
            {
                UUID GroupID = new UUID(im.imSessionID);
                UUID AgentID = new UUID(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());
                }

                //If this agent is sending a message, then they want to be in the session
                AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID);

                SendMessageToGroup(im, GroupID);
            }
        }
        private void AddAgentToSession(UUID AgentID, UUID GroupID, GridInstantMessage msg)
        {
            // Agent not in session and hasn't dropped from session
            // Add them to the session for now, and Invite them
            AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID);

            IClientAPI activeClient = GetActiveClient(AgentID);

            if (activeClient != null)
            {
                GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero.ToString(), GroupID, null);
                if (groupInfo != null)
                {
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[Groups.Messaging]: Sending chatterbox invite instant message");
                    }

                    UUID fromAgent = new UUID(msg.fromAgentID);
                    // Force? open the group session dialog???
                    // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg);
                    IEventQueue eq = activeClient.Scene.RequestModuleInterface <IEventQueue>();
                    if (eq != null)
                    {
                        eq.ChatterboxInvitation(
                            GroupID
                            , groupInfo.GroupName
                            , fromAgent
                            , msg.message
                            , AgentID
                            , msg.fromAgentName
                            , msg.dialog
                            , msg.timestamp
                            , msg.offline == 1
                            , (int)msg.ParentEstateID
                            , msg.Position
                            , 1
                            , new UUID(msg.imSessionID)
                            , msg.fromGroup
                            , OpenMetaverse.Utils.StringToBytes(groupInfo.GroupName)
                            );

                        var update  = new GroupChatListAgentUpdateData(AgentID);
                        var updates = new List <GroupChatListAgentUpdateData> {
                            update
                        };
                        eq.ChatterBoxSessionAgentListUpdates(GroupID, new UUID(msg.toAgentID), updates);
                    }
                }
            }
        }
Example #3
0
        private void ProcessMessageFromGroupSession(GridInstantMessage msg, IClientAPI client)
        {
            if (m_debugEnabled)
            {
                m_log.DebugFormat(
                    "[GROUPS-MESSAGING]: Session message from {0} going to agent {1}, sessionID {2}, type {3}",
                    msg.fromAgentName, msg.toAgentID, msg.imSessionID, (InstantMessageDialog)msg.dialog);
            }

            UUID        fromAgentID = new UUID(msg.fromAgentID);
            UUID        GroupID     = new UUID(msg.imSessionID);
            IEventQueue eq          = client.Scene.RequestModuleInterface <IEventQueue>();

            switch (msg.dialog)
            {
            case (byte)InstantMessageDialog.SessionAdd:
                m_groupData.AgentInvitedToGroupChatSession(fromAgentID, GroupID);
                if (eq != null)
                {
                    var update  = new GroupChatListAgentUpdateData(fromAgentID);
                    var updates = new List <GroupChatListAgentUpdateData>()
                    {
                        update
                    };
                    eq.ChatterBoxSessionAgentListUpdates(GroupID, client.AgentId, updates);
                }
                break;

            case (byte)InstantMessageDialog.SessionDrop:
                m_groupData.AgentDroppedFromGroupChatSession(fromAgentID, GroupID);
                if (eq != null)
                {
                    var update  = new GroupChatListAgentUpdateData(fromAgentID, false);
                    var updates = new List <GroupChatListAgentUpdateData>()
                    {
                        update
                    };
                    eq.ChatterBoxSessionAgentListUpdates(GroupID, client.AgentId, updates);
                }
                break;

            case (byte)InstantMessageDialog.SessionSend:
                if (!m_groupData.hasAgentDroppedGroupChatSession(client.AgentId, GroupID))
                {
                    if (!m_groupData.hasAgentBeenInvitedToGroupChatSession(client.AgentId, GroupID))
                    {
                        GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
                        if (groupInfo != null)
                        {
                            if (m_debugEnabled)
                            {
                                m_log.DebugFormat("[GROUPS-MESSAGING]: Sending chatterbox invite instant message");
                            }

                            eq?.ChatterboxInvitation(
                                GroupID
                                , groupInfo.GroupName
                                , fromAgentID
                                , msg.message
                                , client.AgentId
                                , msg.fromAgentName
                                , msg.dialog
                                , msg.timestamp
                                , msg.offline == 1
                                , (int)msg.ParentEstateID
                                , msg.Position
                                , 1
                                , new UUID(msg.imSessionID)
                                , msg.fromGroup
                                , Utils.StringToBytes(groupInfo.GroupName)
                                );
                        }
                    }
                    else
                    {
                        client.SendInstantMessage(msg);
                    }

                    //                        if (!m_groupData.hasAgentBeenInvitedToGroupChatSession(fromAgentID, GroupID))
                    {
                        m_groupData.AgentInvitedToGroupChatSession(fromAgentID, GroupID);
                        if (eq != null)
                        {
                            var update  = new GroupChatListAgentUpdateData(fromAgentID);
                            var updates = new List <GroupChatListAgentUpdateData>()
                            {
                                update
                            };
                            eq.ChatterBoxSessionAgentListUpdates(GroupID, client.AgentId, updates);
                        }
                    }
                }
                break;

            default:
                client.SendInstantMessage(msg);
                break;;
            }
        }