Struct representing a member of a group chat session and their settings
Exemple #1
0
        /// <summary>
        /// Someone joined or left group chat
        /// </summary>
        /// <param name="capsKey"></param>
        /// <param name="message">IMessage object containing decoded data from OSD</param>
        /// <param name="simulator"></param>
        private void ChatterBoxSessionAgentListUpdatesEventHandler(string capsKey, IMessage message, Simulator simulator)
        {
            ChatterBoxSessionAgentListUpdatesMessage msg = (ChatterBoxSessionAgentListUpdatesMessage)message;

            lock (GroupChatSessions.Dictionary)
                if (!GroupChatSessions.ContainsKey(msg.SessionID))
                    GroupChatSessions.Add(msg.SessionID, new List<ChatSessionMember>());

            for (int i = 0; i < msg.Updates.Length; i++)
            {
                ChatSessionMember fndMbr;
                lock (GroupChatSessions.Dictionary)
                {
                    fndMbr = GroupChatSessions[msg.SessionID].Find(delegate(ChatSessionMember member)
                    {
                        return member.AvatarKey == msg.Updates[i].AgentID;
                    });
                }

                if (msg.Updates[i].Transition != null)
                {
                    if (msg.Updates[i].Transition.Equals("ENTER"))
                    {
                        if (fndMbr.AvatarKey == UUID.Zero)
                        {
                            fndMbr = new ChatSessionMember();
                            fndMbr.AvatarKey = msg.Updates[i].AgentID;

                            lock (GroupChatSessions.Dictionary)
                                GroupChatSessions[msg.SessionID].Add(fndMbr);

                            if (m_ChatSessionMemberAdded != null)
                            {
                                OnChatSessionMemberAdded(new ChatSessionMemberAddedEventArgs(msg.SessionID, fndMbr.AvatarKey));
                            }
                        }
                    }
                    else if (msg.Updates[i].Transition.Equals("LEAVE"))
                    {
                        if (fndMbr.AvatarKey != UUID.Zero)
                            lock (GroupChatSessions.Dictionary)
                                GroupChatSessions[msg.SessionID].Remove(fndMbr);

                        if (m_ChatSessionMemberLeft != null)
                        {
                            OnChatSessionMemberLeft(new ChatSessionMemberLeftEventArgs(msg.SessionID, msg.Updates[i].AgentID));
                        }
                    }
                }

                // handle updates
                ChatSessionMember update_member = GroupChatSessions.Dictionary[msg.SessionID].Find(delegate(ChatSessionMember m)
                {
                    return m.AvatarKey == msg.Updates[i].AgentID;
                });


                update_member.MuteText = msg.Updates[i].MuteText;
                update_member.MuteVoice = msg.Updates[i].MuteVoice;

                update_member.CanVoiceChat = msg.Updates[i].CanVoiceChat;
                update_member.IsModerator = msg.Updates[i].IsModerator;

                // replace existing member record
                lock (GroupChatSessions.Dictionary)
                {
                    int found = GroupChatSessions.Dictionary[msg.SessionID].FindIndex(delegate(ChatSessionMember m)
                    {
                        return m.AvatarKey == msg.Updates[i].AgentID;
                    });

                    if (found >= 0)
                        GroupChatSessions.Dictionary[msg.SessionID][found] = update_member;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Someone joined or left group chat
        /// </summary>
        /// <param name="capsKey"></param>
        /// <param name="llsd"></param>
        /// <param name="simulator"></param>
        private void ChatterBoxSessionAgentListReplyHandler(string capsKey, LLSD llsd, Simulator simulator)
        {
            // parse the LLSD
            LLSDMap map = (LLSDMap)llsd;

            // verify sessions exists, if not add it
            UUID sessionID;
            if (map.ContainsKey("session_id"))
            {
                sessionID = map["session_id"].AsUUID();
                lock (GroupChatSessions)
                    if (!GroupChatSessions.ContainsKey(sessionID))
                        GroupChatSessions.Add(sessionID, new List<ChatSessionMember>());
            }
            else
            {
                return;
            }

            //string errormsg = map["error"].AsString();
            //LLSDMap updates = (LLSDMap)map["updates"];

            // Handle any agent data updates
            LLSDMap agent_updates = (LLSDMap)map["agent_updates"];

            foreach (KeyValuePair<string, LLSD> kvp in agent_updates)
            {
                UUID agent_key = UUID.Parse(kvp.Key);
                LLSDMap record = (LLSDMap)kvp.Value;

                // handle joins/parts first
                if (record.ContainsKey("transition"))
                {
                    // find existing record if any
                    ChatSessionMember fndMbr;
                    lock (GroupChatSessions.Dictionary)
                    {
                        fndMbr = GroupChatSessions[sessionID].Find(delegate(ChatSessionMember member)
                           {
                               return member.AvatarKey == agent_key;
                           });
                    }

                    // handle joins
                    if (record["transition"].AsString().Equals("ENTER"))
                    {
                        if (fndMbr.AvatarKey == UUID.Zero)
                        {
                            fndMbr = new ChatSessionMember();
                            fndMbr.AvatarKey = agent_key;

                            lock (GroupChatSessions.Dictionary)
                                GroupChatSessions[sessionID].Add(fndMbr);

                            if (OnChatSessionMemberAdded != null)
                            {
                                try { OnChatSessionMemberAdded(sessionID, agent_key); }
                                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                            }
                        }

                    }
                    // handle parts
                    else if (record["transition"].AsString().Equals("LEAVE"))
                    {
                        if (fndMbr.AvatarKey != UUID.Zero)
                            lock (GroupChatSessions.Dictionary)
                                GroupChatSessions[sessionID].Remove(fndMbr);

                        if (OnChatSessionMemberLeft != null)
                        {
                            try { OnChatSessionMemberLeft(sessionID, agent_key); }
                            catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                        }

                        if (agent_key == Client.Self.AgentID)
                        {
                            try { OnGroupChatLeft(sessionID); }
                            catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                        }

                        // no need to process anything else in this record
                        continue;
                    }
                    // this should only fire if LL adds a new transition but doesn't tell anyone
                    else
                    {
                        Logger.Log("Unknown transition action " + record["transition"], Helpers.LogLevel.Warning, Client);
                    }
                }

                // Handle any updates

                // search for member to update
                ChatSessionMember update_member = GroupChatSessions.Dictionary[sessionID].Find(delegate(ChatSessionMember m)
                {
                    return m.AvatarKey == agent_key;
                });

                LLSDMap record_info = (LLSDMap)record["info"];

                lock (GroupChatSessions.Dictionary)
                {

                    if (record_info.ContainsKey("mutes"))
                    {
                        LLSDMap mutes = (LLSDMap)record_info["mutes"];
                        foreach (KeyValuePair<string, LLSD> muteEntry in mutes)
                        {
                            if (muteEntry.Key == "text")
                            {
                                update_member.MuteText = muteEntry.Value.AsBoolean();
                            }
                            else if (muteEntry.Key == "voice")
                            {
                                update_member.MuteVoice = muteEntry.Value.AsBoolean();
                            }
                        }
                    }

                    if (record_info.ContainsKey("can_voice_chat"))
                    {
                        update_member.CanVoiceChat = record_info["can_voice_chat"].AsBoolean();
                    }

                    if (record_info.ContainsKey("is_moderator"))
                    {
                        update_member.IsModerator = record_info["is_moderator"].AsBoolean();
                    }
                }

                // replace existing member record
                lock (GroupChatSessions.Dictionary)
                {
                    int found = GroupChatSessions.Dictionary[sessionID].FindIndex(delegate(ChatSessionMember m)
                    {
                        return m.AvatarKey == agent_key;
                    });

                    if (found >= 0)
                        GroupChatSessions.Dictionary[sessionID][found] = update_member;
                }

            }

            //foreach (KeyValuePair<string, LLSD> kvp in updates)
            //{
            //    if (kvp.Value.Equals("ENTER"))
            //    {
            //        lock (GroupChatSessions.Dictionary)
            //        {
            //            if (!GroupChatSessions.Dictionary[sessionID].Contains((UUID)kvp.Key))
            //                GroupChatSessions.Dictionary[sessionID].Add((UUID)kvp.Key);
            //        }
            //    }
            //    else if (kvp.Value.Equals("LEAVE"))
            //    {
            //        lock (GroupChatSessions.Dictionary)
            //        {
            //            if (GroupChatSessions.Dictionary[sessionID].Contains((UUID)kvp.Key))
            //                GroupChatSessions.Dictionary[sessionID].Remove((UUID)kvp.Key);

            //            // we left session, remove from dictionary
            //            if (kvp.Key.Equals(Client.Self.id) && OnGroupChatLeft != null)
            //            {
            //                GroupChatSessions.Dictionary.Remove(sessionID);
            //                OnGroupChatLeft(sessionID);
            //            }
            //        }
            //    }
            //}
        }