/// <summary>
        /// Return a decoded capabilities message as a strongly typed object
        /// </summary>
        /// <param name="eventName">A string containing the name of the capabilities message key</param>
        /// <param name="map">An <see cref="OSDMap"/> to decode</param>
        /// <returns>A strongly typed object containing the decoded information from the capabilities message, or null
        /// if no existing Message object exists for the specified event</returns>
        public static IMessage DecodeEvent(string eventName, OSDMap map)
        {
            IMessage message = null;

            switch (eventName)
            {
                case "AgentGroupDataUpdate": message = new AgentGroupDataUpdateMessage(); break;
                case "AvatarGroupsReply": message = new AgentGroupDataUpdateMessage(); break; // OpenSim sends the above with the wrong? key
                case "ParcelProperties": message = new ParcelPropertiesMessage(); break;
                case "ParcelObjectOwnersReply": message = new ParcelObjectOwnersReplyMessage(); break;
                case "TeleportFinish": message = new TeleportFinishMessage(); break;
                case "EnableSimulator": message = new EnableSimulatorMessage(); break;
                case "ParcelPropertiesUpdate": message = new ParcelPropertiesUpdateMessage(); break;
                case "EstablishAgentCommunication": message = new EstablishAgentCommunicationMessage(); break;
                case "ChatterBoxInvitation": message = new ChatterBoxInvitationMessage(); break;
                case "ChatterBoxSessionEventReply": message = new ChatterboxSessionEventReplyMessage(); break;
                case "ChatterBoxSessionStartReply": message = new ChatterBoxSessionStartReplyMessage(); break;
                case "ChatterBoxSessionAgentListUpdates": message = new ChatterBoxSessionAgentListUpdatesMessage(); break;
                case "RequiredVoiceVersion": message = new RequiredVoiceVersionMessage(); break;
                case "MapLayer": message = new MapLayerMessage(); break;
                case "ChatSessionRequest": message = new ChatSessionRequestMessage(); break;
                case "CopyInventoryFromNotecard": message = new CopyInventoryFromNotecardMessage(); break;
                case "ProvisionVoiceAccountRequest": message = new ProvisionVoiceAccountRequestMessage(); break;
                case "Viewerstats": message = new ViewerStatsMessage(); break;
                case "UpdateAgentLanguage": message = new UpdateAgentLanguageMessage(); break;
                case "RemoteParcelRequest": message = new RemoteParcelRequestMessage(); break;
                case "UpdateScriptTask": message = new UpdateScriptTaskMessage(); break;
                case "UpdateScriptAgent": message = new UpdateScriptAgentMessage(); break;
                case "SendPostcard": message = new SendPostcardMessage(); break;
                case "UpdateGestureAgentInventory": message = new UpdateGestureAgentInventoryMessage(); break;
                case "UpdateNotecardAgentInventory": message = new UpdateNotecardAgentInventoryMessage(); break;
                case "LandStatReply": message = new LandStatReplyMessage(); break;
                case "ParcelVoiceInfoRequest": message = new ParcelVoiceInfoRequestMessage(); break;
                case "ViewerStats": message = new ViewerStatsMessage(); break;
                case "EventQueueGet": message = new EventQueueGetMessage(); break;
                case "CrossedRegion": message = new CrossedRegionMessage(); break;
                case "TeleportFailed": message = new TeleportFailedMessage(); break;
                case "PlacesReply": message = new PlacesReplyMessage(); break;
                case "UpdateAgentInformation": message = new UpdateAgentInformationMessage(); break;
                case "DirLandReply": message = new DirLandReplyMessage(); break;
                case "ScriptRunningReply": message = new ScriptRunningReplyMessage(); break;
                case "SearchStatRequest": message = new SearchStatRequestMessage(); break;
                case "AgentDropGroup": message = new AgentDropGroupMessage(); break;
                case "AgentStateUpdate": message = new AgentStateUpdateMessage(); break;
                case "ForceCloseChatterBoxSession": message = new ForceCloseChatterBoxSessionMessage(); break;
                case "UploadBakedTexture": message = new UploadBakedTextureMessage(); break;
                case "RegionInfo": message = new RegionInfoMessage(); break;
                case "ObjectMediaNavigate": message = new ObjectMediaNavigateMessage(); break;
                case "ObjectMedia": message = new ObjectMediaMessage(); break;
                case "AttachmentResources": message = AttachmentResourcesMessage.GetMessageHandler(map); break;
                case "LandResources": message = LandResourcesMessage.GetMessageHandler(map); break;
                case "GetDisplayNames": message = new GetDisplayNamesMessage(); break;
                case "SetDisplayName": message = new SetDisplayNameMessage(); break;
                case "SetDisplayNameReply": message = new SetDisplayNameReplyMessage(); break;
                case "DisplayNameUpdate": message = new DisplayNameUpdateMessage(); break;
                //case "ProductInfoRequest": message = new ProductInfoRequestMessage(); break;
                case "ObjectPhysicsProperties": message = new ObjectPhysicsPropertiesMessage(); break;
                case "BulkUpdateInventory": message = new BulkUpdateInventoryMessage(); break;
                case "RenderMaterials": message = new RenderMaterialsMessage(); break;
                case "GetObjectCost": message = GetObjectCostMessage.GetMessageHandler(map); break;

                // Capabilities TODO:
                // DispatchRegionInfo
                // EstateChangeInfo
                // EventQueueGet
                // FetchInventoryDescendents
                // GroupProposalBallot
                // MapLayerGod
                // NewFileAgentInventory
                // RequestTextureDownload
                // SearchStatTracking
                // SendUserReport
                // SendUserReportWithScreenshot
                // ServerReleaseNotes
                // StartGroupProposal
                // UpdateGestureTaskInventory
                // UpdateNotecardTaskInventory
                // ViewerStartAuction
                // UntrustedSimulatorMessage
            }

            if (message != null)
            {
                try
                {
                    message.Deserialize(map);
                    return message;
                }
                catch (Exception e)
                {
                    Logger.Log("Exception while trying to Deserialize " + eventName + ":" + e.Message + ": " + e.StackTrace, Helpers.LogLevel.Error);
                }

                return null;
            }
            else
            {
                return null;
            }
        }
        public string ChatSessionRequest(IRegionClientCapsService caps, OSDMap req)
        {
            string method = req["method"].AsString();

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

            switch (method)
            {
                case "start conference":
                    {
                        if (SessionExists(sessionid))
                            return ""; //No duplicate sessions
                        //Create the session.
                        CreateSession(new ChatSession
                                          {
                                              Members = new List<ChatSessionMember>(),
                                              SessionID = sessionid,
                                              Name = caps.ClientCaps.AccountInfo.Name + " Conference"
                                          });

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

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

                        //Inform us about our room
                        ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block =
                            new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock
                                {
                                    AgentID = caps.AgentID,
                                    CanVoiceChat = true,
                                    IsModerator = true,
                                    MuteText = false,
                                    MuteVoice = false,
                                    Transition = "ENTER"
                                };
                        m_eventQueueService.ChatterBoxSessionAgentListUpdates(sessionid, new[] {block}, caps.AgentID,
                                                                              "ENTER",
                                                                              caps.RegionID);

                        ChatterBoxSessionStartReplyMessage cs = new ChatterBoxSessionStartReplyMessage
                                                                    {
                                                                        VoiceEnabled = true,
                                                                        TempSessionID = sessionid,
                                                                        Type = 1,
                                                                        Success = true,
                                                                        SessionID = sessionid,
                                                                        SessionName =
                                                                            caps.ClientCaps.AccountInfo.Name +
                                                                            " Conference",
                                                                        ModeratedVoice = true
                                                                    };
                        return OSDParser.SerializeLLSDXmlString(cs.Serialize());
                    }
                case "accept invitation":
                    {
                        //They would like added to the group conversation
                        List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> Us =
                            new List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();
                        List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> NotUsAgents =
                            new List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();

                        ChatSession session = GetSession(sessionid);
                        if (session != null)
                        {
                            ChatSessionMember thismember = FindMember(sessionid, caps.AgentID);
                            //Tell all the other members about the incoming member
                            foreach (ChatSessionMember sessionMember in session.Members)
                            {
                                ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block =
                                    new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock
                                        {
                                            AgentID = sessionMember.AvatarKey,
                                            CanVoiceChat = sessionMember.CanVoiceChat,
                                            IsModerator = sessionMember.IsModerator,
                                            MuteText = sessionMember.MuteText,
                                            MuteVoice = sessionMember.MuteVoice,
                                            Transition = "ENTER"
                                        };
                                if (sessionMember.AvatarKey == thismember.AvatarKey)
                                {
                                    Us.Add(block);
                                    NotUsAgents.Add(block);
                                }
                                else
                                {
                                    if (sessionMember.HasBeenAdded)
                                        // Don't add not joined yet agents. They don't want to be here.
                                        NotUsAgents.Add(block);
                                }
                            }
                            thismember.HasBeenAdded = true;
                            foreach (ChatSessionMember member in session.Members)
                            {
                                if (member.HasBeenAdded) //Only send to those in the group
                                {
                                    UUID regionID = FindRegionID(member.AvatarKey);
                                    if (regionID != UUID.Zero)
                                    {
                                        m_eventQueueService.ChatterBoxSessionAgentListUpdates(session.SessionID,
                                                                                              member.AvatarKey ==
                                                                                              thismember.AvatarKey
                                                                                                  ? NotUsAgents.ToArray()
                                                                                                  : Us.ToArray(),
                                                                                              member.AvatarKey, "ENTER",
                                                                                              regionID);
                                    }
                                }
                            }
                            return "Accepted";
                        }
                        else
                            return ""; //no session exists?
                    }
                case "mute update":
                    {
                        //Check if the user is a moderator
                        if (!CheckModeratorPermission(caps.AgentID, sessionid))
                            return "";

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

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

                        ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block =
                            new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock
                                {
                                    AgentID = thismember.AvatarKey,
                                    CanVoiceChat = thismember.CanVoiceChat,
                                    IsModerator = thismember.IsModerator,
                                    MuteText = thismember.MuteText,
                                    MuteVoice = thismember.MuteVoice,
                                    Transition = "ENTER"
                                };

                        ChatSession session = GetSession(sessionid);
                        // Send an update to all users so that they show the correct permissions
                        foreach (ChatSessionMember member in session.Members)
                        {
                            if (member.HasBeenAdded) //Only send to those in the group
                            {
                                UUID regionID = FindRegionID(member.AvatarKey);
                                if (regionID != UUID.Zero)
                                {
                                    m_eventQueueService.ChatterBoxSessionAgentListUpdates(sessionid, new[] {block},
                                                                                          member.AvatarKey, "",
                                                                                          regionID);
                                }
                            }
                        }

                        return "Accepted";
                    }
                case "call":
                    {
                        //Implement voice chat for conferences...

                        IVoiceService voiceService = m_registry.RequestModuleInterface<IVoiceService>();
                        if (voiceService == null)
                            return "";

                        OSDMap resp = voiceService.GroupConferenceCallRequest(caps, sessionid);
                        return OSDParser.SerializeLLSDXmlString(resp);
                    }
                default:
                    MainConsole.Instance.Warn("ChatSessionRequest : " + method);
                    return "";
            }
        }
Пример #3
0
        private string OnChatSessionRequest(UUID Agent, OSDMap rm)
        {
            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
                ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block =
                    new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock
                        {
                            AgentID = Agent,
                            CanVoiceChat = true,
                            IsModerator = true,
                            MuteText = false,
                            MuteVoice = false,
                            Transition = "ENTER"
                        };
                eq.ChatterBoxSessionAgentListUpdates(sessionid, new[] {block}, Agent, "ENTER",
                                                     findScene(Agent).RegionInfo.RegionHandle);

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

                return cs.Serialize().ToString();
            }
            else if (method == "accept invitation")
            {
                //They would like added to the group conversation
                List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> Us =
                    new List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock>();
                List<ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock> NotUsAgents =
                    new List<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)
                    {
                        ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block =
                            new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock
                                {
                                    AgentID = sessionMember.AvatarKey,
                                    CanVoiceChat = sessionMember.CanVoiceChat,
                                    IsModerator = sessionMember.IsModerator,
                                    MuteText = sessionMember.MuteText,
                                    MuteVoice = sessionMember.MuteVoice,
                                    Transition = "ENTER"
                                };
                        if (sessionMember.AvatarKey == thismember.AvatarKey)
                            Us.Add(block);
                        else
                        {
                            if (sessionMember.HasBeenAdded)
                                // Don't add not joined yet agents. They don't want to be here.
                                NotUsAgents.Add(block);
                        }
                    }
                    thismember.HasBeenAdded = true;
                    foreach (ChatSessionMember member in session.Members)
                    {
                        eq.ChatterBoxSessionAgentListUpdates(session.SessionID,
                                                             member.AvatarKey == thismember.AvatarKey
                                                                 ? NotUsAgents.ToArray()
                                                                 : Us.ToArray(),
                                                             member.AvatarKey, "ENTER",
                                                             findScene(Agent).RegionInfo.RegionHandle);
                    }
                    return "Accepted";
                }
                else
                    return ""; //not this type of session
            }
            else if (method == "mute update")
            {
                //Check if the user is a moderator
                Hashtable responsedata = new Hashtable();
                if (!CheckModeratorPermission(Agent, sessionid))
                {
                    return "";
                }

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

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

                ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block =
                    new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock
                        {
                            AgentID = thismember.AvatarKey,
                            CanVoiceChat = thismember.CanVoiceChat,
                            IsModerator = thismember.IsModerator,
                            MuteText = thismember.MuteText,
                            MuteVoice = thismember.MuteVoice,
                            Transition = "ENTER"
                        };

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

                return "Accepted";
            }
            else
            {
                MainConsole.Instance.Warn("ChatSessionRequest : " + method);
                return "";
            }
        }
        public void ChatterBoxSessionStartReplyMessage()
        {
            ChatterBoxSessionStartReplyMessage s = new ChatterBoxSessionStartReplyMessage();
            s.ModeratedVoice = true;
            s.SessionID = UUID.Random();
            s.SessionName = "Test Session";
            s.Success = true;
            s.TempSessionID = UUID.Random();
            s.Type = 1;
            s.VoiceEnabled = true;

            OSDMap map = s.Serialize();

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

            Assert.AreEqual(s.ModeratedVoice, t.ModeratedVoice);
            Assert.AreEqual(s.SessionID, t.SessionID);
            Assert.AreEqual(s.SessionName, t.SessionName);
            Assert.AreEqual(s.Success, t.Success);
            Assert.AreEqual(s.TempSessionID, t.TempSessionID);
            Assert.AreEqual(s.Type, t.Type);
            Assert.AreEqual(s.VoiceEnabled, t.VoiceEnabled);
        }