aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/VoiceModule.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/VoiceModule.cs196
1 files changed, 196 insertions, 0 deletions
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 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using Nini.Config;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Framework.Servers;
36using OpenSim.Region.Capabilities;
37using Caps = OpenSim.Region.Capabilities.Caps;
38using OpenSim.Region.Environment.Interfaces;
39using OpenSim.Region.Environment.Scenes;
40
41namespace OpenSim.Region.Environment.Modules
42{
43 public class VoiceModule : IRegionModule
44 {
45 private static readonly log4net.ILog m_log =
46 log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
47
48 private Scene m_scene;
49 private IConfig m_config;
50 private string m_sipDomain;
51
52 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
53 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
54
55 public void Initialise(Scene scene, IConfigSource config)
56 {
57 m_scene = scene;
58 m_config = config.Configs["Voice"];
59
60 if (null == m_config || !m_config.GetBoolean("enabled", false))
61 {
62 m_log.Info("[VOICE] plugin disabled");
63 return;
64 }
65 m_log.Info("[VOICE] plugin enabled");
66
67 m_sipDomain = m_config.GetString("sip_domain", String.Empty);
68 if (String.IsNullOrEmpty(m_sipDomain))
69 {
70 m_log.Error("[VOICE] plugin mis-configured: missing sip_domain configuration");
71 m_log.Info("[VOICE] plugin disabled");
72 return;
73 }
74 m_log.InfoFormat("[VOICE] using SIP domain {0}", m_sipDomain);
75
76 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
77 }
78
79 public void PostInitialise()
80 {
81 }
82
83 public void Close()
84 {
85 }
86
87 public string Name
88 {
89 get { return "VoiceModule"; }
90 }
91
92 public bool IsSharedModule
93 {
94 get { return false; }
95 }
96
97 public void OnRegisterCaps(LLUUID agentID, Caps caps)
98 {
99 m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
100 string capsBase = "/CAPS/" + caps.CapsObjectPath;
101 caps.RegisterHandler("ParcelVoiceInfoRequest",
102 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
103 delegate(string request, string path, string param)
104 {
105 return ParcelVoiceInfoRequest(request, path, param,
106 agentID, caps);
107 }));
108 caps.RegisterHandler("ProvisionVoiceAccountRequest",
109 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath,
110 delegate(string request, string path, string param)
111 {
112 return ProvisionVoiceAccountRequest(request, path, param,
113 agentID, caps);
114 }));
115 }
116
117 /// <summary>
118 /// Callback for a client request for ParcelVoiceInfo
119 /// </summary>
120 /// <param name="request"></param>
121 /// <param name="path"></param>
122 /// <param name="param"></param>
123 /// <param name="agentID"></param>
124 /// <param name="caps"></param>
125 /// <returns></returns>
126 public string ParcelVoiceInfoRequest(string request, string path, string param,
127 LLUUID agentID, Caps caps)
128 {
129 try
130 {
131 m_log.DebugFormat("[VOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", request, path, param);
132
133 // FIXME: get the creds from region file or from config
134 Hashtable creds = new Hashtable();
135
136 creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID.ToString(), m_sipDomain);
137
138 string regionName = m_scene.RegionInfo.RegionName;
139 ScenePresence avatar = m_scene.GetScenePresence(agentID);
140 if (null == m_scene.LandChannel) throw new Exception("land data not yet available");
141 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
142
143 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
144 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
145
146 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
147 m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r);
148
149 return r;
150 }
151 catch (Exception e)
152 {
153 m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString());
154 }
155
156 return null;
157 }
158
159 /// <summary>
160 /// Callback for a client request for Voice Account Details
161 /// </summary>
162 /// <param name="request"></param>
163 /// <param name="path"></param>
164 /// <param name="param"></param>
165 /// <param name="agentID"></param>
166 /// <param name="caps"></param>
167 /// <returns></returns>
168 public string ProvisionVoiceAccountRequest(string request, string path, string param,
169 LLUUID agentID, Caps caps)
170 {
171 try
172 {
173 m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
174 request, path, param);
175
176 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes());
177 voiceUser = voiceUser.Replace('+', '-').Replace('/', '_');
178
179 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
180 if (null == userInfo) throw new Exception("cannot get user details");
181
182 LLSDVoiceAccountResponse voiceAccountResponse =
183 new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.passwordHash);
184 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
185 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);
186 return r;
187 }
188 catch (Exception e)
189 {
190 m_log.ErrorFormat("[CAPS][PROVISIONVOICE]: {0}, retry later", e.Message);
191 }
192
193 return null;
194 }
195 }
196}