OpenMetaverse.Messages.Linden.ChatterBoxSessionAgentListUpdatesMessage.Deserialize C# (CSharp) Method

Deserialize() public method

Deserialize the message
public Deserialize ( OSDMap map ) : void
map OSDMap An containing the data
return void
        public void Deserialize(OSDMap map)
        {

            OSDMap agent_updates = (OSDMap)map["agent_updates"];
            SessionID = map["session_id"].AsUUID();

            List<AgentUpdatesBlock> updatesList = new List<AgentUpdatesBlock>();

            foreach (KeyValuePair<string, OSD> kvp in agent_updates)
            {

                if (kvp.Key == "updates")
                {
                    // This appears to be redundant and duplicated by the info block, more dumps will confirm this
                    /* <key>32939971-a520-4b52-8ca5-6085d0e39933</key>
                            <string>ENTER</string> */
                }
                else if (kvp.Key == "session_id")
                {
                    // I am making the assumption that each osdmap will contain the information for a 
                    // single session. This is how the map appears to read however more dumps should be taken
                    // to confirm this.
                    /* <key>session_id</key>
                            <string>984f6a1e-4ceb-6366-8d5e-a18c6819c6f7</string> */

                }
                else  // key is an agent uuid (we hope!)
                {
                    // should be the agents uuid as the key, and "info" as the datablock
                    /* <key>32939971-a520-4b52-8ca5-6085d0e39933</key>
                            <map>
                                <key>info</key>
                                    <map>
                                        <key>can_voice_chat</key>
                                            <boolean>1</boolean>
                                        <key>is_moderator</key>
                                            <boolean>1</boolean>
                                    </map>
                                <key>transition</key>
                                    <string>ENTER</string>
                            </map>*/
                    AgentUpdatesBlock block = new AgentUpdatesBlock();
                    block.AgentID = UUID.Parse(kvp.Key);

                    OSDMap infoMap = (OSDMap)agent_updates[kvp.Key];

                    OSDMap agentPermsMap = (OSDMap)infoMap["info"];

                    block.CanVoiceChat = agentPermsMap["can_voice_chat"].AsBoolean();
                    block.IsModerator = agentPermsMap["is_moderator"].AsBoolean();

                    block.Transition = infoMap["transition"].AsString();

                    if (agentPermsMap.ContainsKey("mutes"))
                    {
                        OSDMap mutesMap = (OSDMap)agentPermsMap["mutes"];
                        block.MuteText = mutesMap["text"].AsBoolean();
                        block.MuteVoice = mutesMap["voice"].AsBoolean();
                    }
                    updatesList.Add(block);
                }
            }

            Updates = new AgentUpdatesBlock[updatesList.Count];

            for (int i = 0; i < updatesList.Count; i++)
            {
                AgentUpdatesBlock block = new AgentUpdatesBlock();
                block.AgentID = updatesList[i].AgentID;
                block.CanVoiceChat = updatesList[i].CanVoiceChat;
                block.IsModerator = updatesList[i].IsModerator;
                block.MuteText = updatesList[i].MuteText;
                block.MuteVoice = updatesList[i].MuteVoice;
                block.Transition = updatesList[i].Transition;
                Updates[i] = block;
            }
        }
    }

Usage Example

        public void ChatterBoxSessionAgentListUpdatesMessage()
        {
            ChatterBoxSessionAgentListUpdatesMessage s = new ChatterBoxSessionAgentListUpdatesMessage();
            s.SessionID = UUID.Random();
            s.Updates = new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[1];

            ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block1 = new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
            block1.AgentID = UUID.Random();
            block1.CanVoiceChat = true;
            block1.IsModerator = true;
            block1.MuteText = true;
            block1.MuteVoice = true;
            block1.Transition = "ENTER";

            ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block2 = new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock();
            block2.AgentID = UUID.Random();
            block2.CanVoiceChat = true;
            block2.IsModerator = true;
            block2.MuteText = true;
            block2.MuteVoice = true;
            block2.Transition = "LEAVE";

            s.Updates[0] = block1;

            OSDMap map = s.Serialize();

            ChatterBoxSessionAgentListUpdatesMessage t = new ChatterBoxSessionAgentListUpdatesMessage();
            t.Deserialize(map);

            Assert.AreEqual(s.SessionID, t.SessionID);
            for (int i = 0; i < t.Updates.Length; i++)
            {
                Assert.AreEqual(s.Updates[i].AgentID, t.Updates[i].AgentID);
                Assert.AreEqual(s.Updates[i].CanVoiceChat, t.Updates[i].CanVoiceChat);
                Assert.AreEqual(s.Updates[i].IsModerator, t.Updates[i].IsModerator);
                Assert.AreEqual(s.Updates[i].MuteText, t.Updates[i].MuteText);
                Assert.AreEqual(s.Updates[i].MuteVoice, t.Updates[i].MuteVoice);
                Assert.AreEqual(s.Updates[i].Transition, t.Updates[i].Transition);
            }
        }
ChatterBoxSessionAgentListUpdatesMessage