From 042cd57e948f6e3695d1d5b2b2a473ee77a1e9c4 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 3 Apr 2008 15:44:20 +0000 Subject: * From: Dr Scofield * This patch removes voice code into a region module. This required the implementation of events and other code to allow region modules to register their own caps handlers, and should allow different voice module implementations. * CAVEAT: This does not provide complete voice support, it merely provides the hooks so that it can be plugged in. --- OpenSim/Region/Environment/Modules/VoiceModule.cs | 196 ++++++++++++++++++++++ OpenSim/Region/Environment/Scenes/Scene.cs | 6 +- OpenSim/Region/Environment/Scenes/SceneEvents.cs | 34 ++++ 3 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 OpenSim/Region/Environment/Modules/VoiceModule.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Environment/Modules/VoiceModule.cs b/OpenSim/Region/Environment/Modules/VoiceModule.cs new file mode 100644 index 0000000..b254507 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/VoiceModule.cs @@ -0,0 +1,196 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using libsecondlife; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Servers; +using OpenSim.Region.Capabilities; +using Caps = OpenSim.Region.Capabilities.Caps; +using OpenSim.Region.Environment.Interfaces; +using OpenSim.Region.Environment.Scenes; + +namespace OpenSim.Region.Environment.Modules +{ + public class VoiceModule : IRegionModule + { + private static readonly log4net.ILog m_log = + log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; + private IConfig m_config; + private string m_sipDomain; + + private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; + private static readonly string m_provisionVoiceAccountRequestPath = "0008/"; + + public void Initialise(Scene scene, IConfigSource config) + { + m_scene = scene; + m_config = config.Configs["Voice"]; + + if (null == m_config || !m_config.GetBoolean("enabled", false)) + { + m_log.Info("[VOICE] plugin disabled"); + return; + } + m_log.Info("[VOICE] plugin enabled"); + + m_sipDomain = m_config.GetString("sip_domain", String.Empty); + if (String.IsNullOrEmpty(m_sipDomain)) + { + m_log.Error("[VOICE] plugin mis-configured: missing sip_domain configuration"); + m_log.Info("[VOICE] plugin disabled"); + return; + } + m_log.InfoFormat("[VOICE] using SIP domain {0}", m_sipDomain); + + scene.EventManager.OnRegisterCaps += OnRegisterCaps; + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return "VoiceModule"; } + } + + public bool IsSharedModule + { + get { return false; } + } + + public void OnRegisterCaps(LLUUID agentID, Caps caps) + { + m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); + string capsBase = "/CAPS/" + caps.CapsObjectPath; + caps.RegisterHandler("ParcelVoiceInfoRequest", + new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, + delegate(string request, string path, string param) + { + return ParcelVoiceInfoRequest(request, path, param, + agentID, caps); + })); + caps.RegisterHandler("ProvisionVoiceAccountRequest", + new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, + delegate(string request, string path, string param) + { + return ProvisionVoiceAccountRequest(request, path, param, + agentID, caps); + })); + } + + /// + /// Callback for a client request for ParcelVoiceInfo + /// + /// + /// + /// + /// + /// + /// + public string ParcelVoiceInfoRequest(string request, string path, string param, + LLUUID agentID, Caps caps) + { + try + { + m_log.DebugFormat("[VOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", request, path, param); + + // FIXME: get the creds from region file or from config + Hashtable creds = new Hashtable(); + + creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID.ToString(), m_sipDomain); + + string regionName = m_scene.RegionInfo.RegionName; + ScenePresence avatar = m_scene.GetScenePresence(agentID); + if (null == m_scene.LandChannel) throw new Exception("land data not yet available"); + LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); + + LLSDParcelVoiceInfoResponse parcelVoiceInfo = + new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); + + string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); + m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r); + + return r; + } + catch (Exception e) + { + m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString()); + } + + return null; + } + + /// + /// Callback for a client request for Voice Account Details + /// + /// + /// + /// + /// + /// + /// + public string ProvisionVoiceAccountRequest(string request, string path, string param, + LLUUID agentID, Caps caps) + { + try + { + m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", + request, path, param); + + string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes()); + voiceUser = voiceUser.Replace('+', '-').Replace('/', '_'); + + CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); + if (null == userInfo) throw new Exception("cannot get user details"); + + LLSDVoiceAccountResponse voiceAccountResponse = + new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.passwordHash); + string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); + m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); + return r; + } + catch (Exception e) + { + m_log.ErrorFormat("[CAPS][PROVISIONVOICE]: {0}, retry later", e.Message); + } + + return null; + } + } +} diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 2237922..64c443d 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1737,14 +1737,14 @@ namespace OpenSim.Region.Environment.Scenes Caps cap = new Caps(AssetCache, m_httpListener, m_regInfo.ExternalHostName, m_httpListener.Port, capsObjectPath, agentId, m_dumpAssetsToFile); - cap.RegisterHandlers(); + + EventManager.TriggerOnRegisterCaps(agentId, cap); cap.AddNewInventoryItem = AddInventoryItem; cap.ItemUpdatedCall = CapsUpdateInventoryItemAsset; cap.TaskScriptUpdatedCall = CapsUpdateTaskInventoryScriptAsset; cap.CAPSFetchInventoryDescendents = CommsManager.UserProfileCacheService.HandleFetchInventoryDescendentsCAPS; - cap.CAPSGetUserDetails = CommsManager.UserProfileCacheService.GetUserDetails; m_capsHandlers[agentId] = cap; } @@ -1764,6 +1764,8 @@ namespace OpenSim.Region.Environment.Scenes agentId, RegionInfo.RegionName); m_capsHandlers[agentId].DeregisterHandlers(); + EventManager.TriggerOnDeregisterCaps(agentId, m_capsHandlers[agentId]); + m_capsHandlers.Remove(agentId); } else diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs index 809507c..c916009 100644 --- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs +++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs @@ -29,6 +29,7 @@ using libsecondlife; using System; using OpenSim.Framework; using OpenSim.Region.Environment.Interfaces; +using Caps = OpenSim.Region.Capabilities.Caps; namespace OpenSim.Region.Environment.Scenes { @@ -136,6 +137,19 @@ namespace OpenSim.Region.Environment.Scenes public event OnNewPresenceDelegate OnMakeChildAgent; + /// + /// RegisterCapsEvent is called by Scene after the Caps object + /// has been instantiated and before it is return to the + /// client and provides region modules to add their caps. + /// + public delegate void RegisterCapsEvent(LLUUID agentID, Caps caps); + public event RegisterCapsEvent OnRegisterCaps; + /// + /// DeregisterCapsEvent is called by Scene when the caps + /// handler for an agent are removed. + /// + public delegate void DeregisterCapsEvent(LLUUID agentID, Caps caps); + public event DeregisterCapsEvent OnDeregisterCaps; public class MoneyTransferArgs : System.EventArgs { @@ -191,6 +205,8 @@ namespace OpenSim.Region.Environment.Scenes private ClientClosed handlerClientClosed = null; //OnClientClosed; private OnNewPresenceDelegate handlerMakeChildAgent = null; //OnMakeChildAgent; private OnTerrainTickDelegate handlerTerrainTick = null; // OnTerainTick; + private RegisterCapsEvent handlerRegisterCaps = null; // OnRegisterCaps; + private DeregisterCapsEvent handlerDeregisterCaps = null; // OnDeregisterCaps; public void TriggerOnScriptChangedEvent(uint localID, uint change) { @@ -428,5 +444,23 @@ namespace OpenSim.Region.Environment.Scenes handlerMakeChildAgent(presence); } } + + public void TriggerOnRegisterCaps(LLUUID agentID, Caps caps) + { + handlerRegisterCaps = OnRegisterCaps; + if (handlerRegisterCaps != null) + { + handlerRegisterCaps(agentID, caps); + } + } + + public void TriggerOnDeregisterCaps(LLUUID agentID, Caps caps) + { + handlerDeregisterCaps = OnDeregisterCaps; + if (handlerDeregisterCaps != null) + { + handlerDeregisterCaps(agentID, caps); + } + } } } -- cgit v1.1