diff options
Diffstat (limited to 'OpenSim/Services/Connectors')
6 files changed, 948 insertions, 125 deletions
diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs index 50e817e..19bb3e2 100644 --- a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs | |||
@@ -84,7 +84,7 @@ namespace OpenSim.Services.Connectors | |||
84 | 84 | ||
85 | public string Authenticate(UUID principalID, string password, int lifetime) | 85 | public string Authenticate(UUID principalID, string password, int lifetime) |
86 | { | 86 | { |
87 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 87 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
88 | sendData["LIFETIME"] = lifetime.ToString(); | 88 | sendData["LIFETIME"] = lifetime.ToString(); |
89 | sendData["PRINCIPAL"] = principalID.ToString(); | 89 | sendData["PRINCIPAL"] = principalID.ToString(); |
90 | sendData["PASSWORD"] = password; | 90 | sendData["PASSWORD"] = password; |
@@ -106,7 +106,7 @@ namespace OpenSim.Services.Connectors | |||
106 | 106 | ||
107 | public bool Verify(UUID principalID, string token, int lifetime) | 107 | public bool Verify(UUID principalID, string token, int lifetime) |
108 | { | 108 | { |
109 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 109 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
110 | sendData["LIFETIME"] = lifetime.ToString(); | 110 | sendData["LIFETIME"] = lifetime.ToString(); |
111 | sendData["PRINCIPAL"] = principalID.ToString(); | 111 | sendData["PRINCIPAL"] = principalID.ToString(); |
112 | sendData["TOKEN"] = token; | 112 | sendData["TOKEN"] = token; |
@@ -128,7 +128,7 @@ namespace OpenSim.Services.Connectors | |||
128 | 128 | ||
129 | public bool Release(UUID principalID, string token) | 129 | public bool Release(UUID principalID, string token) |
130 | { | 130 | { |
131 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 131 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
132 | sendData["PRINCIPAL"] = principalID.ToString(); | 132 | sendData["PRINCIPAL"] = principalID.ToString(); |
133 | sendData["TOKEN"] = token; | 133 | sendData["TOKEN"] = token; |
134 | 134 | ||
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 02f2b79..99aa3fb 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | |||
@@ -89,7 +89,7 @@ namespace OpenSim.Services.Connectors | |||
89 | public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo) | 89 | public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo) |
90 | { | 90 | { |
91 | Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); | 91 | Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); |
92 | Dictionary<string, string> sendData = new Dictionary<string,string>(); | 92 | Dictionary<string, object> sendData = new Dictionary<string,object>(); |
93 | foreach (KeyValuePair<string, object> kvp in rinfo) | 93 | foreach (KeyValuePair<string, object> kvp in rinfo) |
94 | sendData[kvp.Key] = (string)kvp.Value; | 94 | sendData[kvp.Key] = (string)kvp.Value; |
95 | 95 | ||
@@ -130,7 +130,7 @@ namespace OpenSim.Services.Connectors | |||
130 | 130 | ||
131 | public virtual bool DeregisterRegion(UUID regionID) | 131 | public virtual bool DeregisterRegion(UUID regionID) |
132 | { | 132 | { |
133 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 133 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
134 | 134 | ||
135 | sendData["REGIONID"] = regionID.ToString(); | 135 | sendData["REGIONID"] = regionID.ToString(); |
136 | 136 | ||
@@ -162,7 +162,7 @@ namespace OpenSim.Services.Connectors | |||
162 | 162 | ||
163 | public virtual List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | 163 | public virtual List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) |
164 | { | 164 | { |
165 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 165 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
166 | 166 | ||
167 | sendData["SCOPEID"] = scopeID.ToString(); | 167 | sendData["SCOPEID"] = scopeID.ToString(); |
168 | sendData["REGIONID"] = regionID.ToString(); | 168 | sendData["REGIONID"] = regionID.ToString(); |
@@ -212,7 +212,7 @@ namespace OpenSim.Services.Connectors | |||
212 | 212 | ||
213 | public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | 213 | public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
214 | { | 214 | { |
215 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 215 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
216 | 216 | ||
217 | sendData["SCOPEID"] = scopeID.ToString(); | 217 | sendData["SCOPEID"] = scopeID.ToString(); |
218 | sendData["REGIONID"] = regionID.ToString(); | 218 | sendData["REGIONID"] = regionID.ToString(); |
@@ -258,7 +258,7 @@ namespace OpenSim.Services.Connectors | |||
258 | 258 | ||
259 | public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | 259 | public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y) |
260 | { | 260 | { |
261 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 261 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
262 | 262 | ||
263 | sendData["SCOPEID"] = scopeID.ToString(); | 263 | sendData["SCOPEID"] = scopeID.ToString(); |
264 | sendData["X"] = x.ToString(); | 264 | sendData["X"] = x.ToString(); |
@@ -303,7 +303,7 @@ namespace OpenSim.Services.Connectors | |||
303 | 303 | ||
304 | public virtual GridRegion GetRegionByName(UUID scopeID, string regionName) | 304 | public virtual GridRegion GetRegionByName(UUID scopeID, string regionName) |
305 | { | 305 | { |
306 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 306 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
307 | 307 | ||
308 | sendData["SCOPEID"] = scopeID.ToString(); | 308 | sendData["SCOPEID"] = scopeID.ToString(); |
309 | sendData["NAME"] = regionName; | 309 | sendData["NAME"] = regionName; |
@@ -344,7 +344,7 @@ namespace OpenSim.Services.Connectors | |||
344 | 344 | ||
345 | public virtual List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) | 345 | public virtual List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) |
346 | { | 346 | { |
347 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 347 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
348 | 348 | ||
349 | sendData["SCOPEID"] = scopeID.ToString(); | 349 | sendData["SCOPEID"] = scopeID.ToString(); |
350 | sendData["NAME"] = name; | 350 | sendData["NAME"] = name; |
@@ -396,7 +396,7 @@ namespace OpenSim.Services.Connectors | |||
396 | 396 | ||
397 | public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) | 397 | public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) |
398 | { | 398 | { |
399 | Dictionary<string, string> sendData = new Dictionary<string, string>(); | 399 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
400 | 400 | ||
401 | sendData["SCOPEID"] = scopeID.ToString(); | 401 | sendData["SCOPEID"] = scopeID.ToString(); |
402 | sendData["XMIN"] = xmin.ToString(); | 402 | sendData["XMIN"] = xmin.ToString(); |
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs new file mode 100644 index 0000000..29cfd6e --- /dev/null +++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs | |||
@@ -0,0 +1,421 @@ | |||
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 OpenSimulator 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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class PresenceServicesConnector : IPresenceService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private string m_ServerURI = String.Empty; | ||
51 | |||
52 | public PresenceServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public PresenceServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public PresenceServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["PresenceService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); | ||
72 | throw new Exception("Presence connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("PresenceServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService"); | ||
81 | throw new Exception("Presence connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IPresenceService | ||
88 | |||
89 | public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
93 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
94 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
95 | sendData["METHOD"] = "login"; | ||
96 | |||
97 | sendData["UserID"] = userID; | ||
98 | sendData["SessionID"] = sessionID.ToString(); | ||
99 | sendData["SecureSessionID"] = secureSessionID.ToString(); | ||
100 | |||
101 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
102 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
106 | m_ServerURI + "/presence", | ||
107 | reqString); | ||
108 | if (reply != string.Empty) | ||
109 | { | ||
110 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
111 | |||
112 | if (replyData.ContainsKey("result")) | ||
113 | { | ||
114 | if (replyData["result"].ToString().ToLower() == "success") | ||
115 | return true; | ||
116 | else | ||
117 | return false; | ||
118 | } | ||
119 | else | ||
120 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field"); | ||
121 | |||
122 | } | ||
123 | else | ||
124 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply"); | ||
125 | } | ||
126 | catch (Exception e) | ||
127 | { | ||
128 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
129 | } | ||
130 | |||
131 | return false; | ||
132 | |||
133 | } | ||
134 | |||
135 | public bool LogoutAgent(UUID sessionID) | ||
136 | { | ||
137 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
138 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
139 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
140 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
141 | sendData["METHOD"] = "logout"; | ||
142 | |||
143 | sendData["SessionID"] = sessionID.ToString(); | ||
144 | |||
145 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
146 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
147 | try | ||
148 | { | ||
149 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
150 | m_ServerURI + "/presence", | ||
151 | reqString); | ||
152 | if (reply != string.Empty) | ||
153 | { | ||
154 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
155 | |||
156 | if (replyData.ContainsKey("result")) | ||
157 | { | ||
158 | if (replyData["result"].ToString().ToLower() == "success") | ||
159 | return true; | ||
160 | else | ||
161 | return false; | ||
162 | } | ||
163 | else | ||
164 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field"); | ||
165 | |||
166 | } | ||
167 | else | ||
168 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply"); | ||
169 | } | ||
170 | catch (Exception e) | ||
171 | { | ||
172 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
173 | } | ||
174 | |||
175 | return false; | ||
176 | } | ||
177 | |||
178 | public bool LogoutRegionAgents(UUID regionID) | ||
179 | { | ||
180 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
181 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
182 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
183 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
184 | sendData["METHOD"] = "logoutregion"; | ||
185 | |||
186 | sendData["RegionID"] = regionID.ToString(); | ||
187 | |||
188 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
189 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
190 | try | ||
191 | { | ||
192 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
193 | m_ServerURI + "/presence", | ||
194 | reqString); | ||
195 | if (reply != string.Empty) | ||
196 | { | ||
197 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
198 | |||
199 | if (replyData.ContainsKey("result")) | ||
200 | { | ||
201 | if (replyData["result"].ToString().ToLower() == "success") | ||
202 | return true; | ||
203 | else | ||
204 | return false; | ||
205 | } | ||
206 | else | ||
207 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field"); | ||
208 | |||
209 | } | ||
210 | else | ||
211 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply"); | ||
212 | } | ||
213 | catch (Exception e) | ||
214 | { | ||
215 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
216 | } | ||
217 | |||
218 | return false; | ||
219 | } | ||
220 | |||
221 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
222 | { | ||
223 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
224 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
225 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
226 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
227 | sendData["METHOD"] = "report"; | ||
228 | |||
229 | sendData["SessionID"] = sessionID.ToString(); | ||
230 | sendData["RegionID"] = regionID.ToString(); | ||
231 | sendData["position"] = position.ToString(); | ||
232 | sendData["lookAt"] = lookAt.ToString(); | ||
233 | |||
234 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
235 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
236 | try | ||
237 | { | ||
238 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
239 | m_ServerURI + "/presence", | ||
240 | reqString); | ||
241 | if (reply != string.Empty) | ||
242 | { | ||
243 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
244 | |||
245 | if (replyData.ContainsKey("result")) | ||
246 | { | ||
247 | if (replyData["result"].ToString().ToLower() == "success") | ||
248 | return true; | ||
249 | else | ||
250 | return false; | ||
251 | } | ||
252 | else | ||
253 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field"); | ||
254 | |||
255 | } | ||
256 | else | ||
257 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply"); | ||
258 | } | ||
259 | catch (Exception e) | ||
260 | { | ||
261 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
262 | } | ||
263 | |||
264 | return false; | ||
265 | } | ||
266 | |||
267 | public PresenceInfo GetAgent(UUID sessionID) | ||
268 | { | ||
269 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
270 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
271 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
272 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
273 | sendData["METHOD"] = "getagent"; | ||
274 | |||
275 | sendData["SessionID"] = sessionID.ToString(); | ||
276 | |||
277 | string reply = string.Empty; | ||
278 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
279 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
280 | try | ||
281 | { | ||
282 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
283 | m_ServerURI + "/presence", | ||
284 | reqString); | ||
285 | if (reply == null || (reply != null && reply == string.Empty)) | ||
286 | { | ||
287 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
288 | return null; | ||
289 | } | ||
290 | } | ||
291 | catch (Exception e) | ||
292 | { | ||
293 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
294 | } | ||
295 | |||
296 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
297 | PresenceInfo pinfo = null; | ||
298 | |||
299 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
300 | { | ||
301 | if (replyData["result"] is Dictionary<string, object>) | ||
302 | { | ||
303 | pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]); | ||
304 | } | ||
305 | } | ||
306 | |||
307 | return pinfo; | ||
308 | } | ||
309 | |||
310 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
311 | { | ||
312 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
313 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
314 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
315 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
316 | sendData["METHOD"] = "getagents"; | ||
317 | |||
318 | sendData["uuids"] = new List<string>(userIDs); | ||
319 | |||
320 | string reply = string.Empty; | ||
321 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
322 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
323 | try | ||
324 | { | ||
325 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
326 | m_ServerURI + "/presence", | ||
327 | reqString); | ||
328 | if (reply == null || (reply != null && reply == string.Empty)) | ||
329 | { | ||
330 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
331 | return null; | ||
332 | } | ||
333 | } | ||
334 | catch (Exception e) | ||
335 | { | ||
336 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
337 | } | ||
338 | |||
339 | List<PresenceInfo> rinfos = new List<PresenceInfo>(); | ||
340 | |||
341 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
342 | |||
343 | if (replyData != null) | ||
344 | { | ||
345 | if (replyData.ContainsKey("result") && | ||
346 | (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) | ||
347 | { | ||
348 | return new PresenceInfo[0]; | ||
349 | } | ||
350 | |||
351 | Dictionary<string, object>.ValueCollection pinfosList = replyData.Values; | ||
352 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
353 | foreach (object presence in pinfosList) | ||
354 | { | ||
355 | if (presence is Dictionary<string, object>) | ||
356 | { | ||
357 | PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence); | ||
358 | rinfos.Add(pinfo); | ||
359 | } | ||
360 | else | ||
361 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}", | ||
362 | presence.GetType()); | ||
363 | } | ||
364 | } | ||
365 | else | ||
366 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response"); | ||
367 | |||
368 | return rinfos.ToArray(); | ||
369 | } | ||
370 | |||
371 | |||
372 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
373 | { | ||
374 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
375 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
376 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
377 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
378 | sendData["METHOD"] = "sethome"; | ||
379 | |||
380 | sendData["UserID"] = userID; | ||
381 | sendData["RegionID"] = regionID.ToString(); | ||
382 | sendData["position"] = position.ToString(); | ||
383 | sendData["lookAt"] = lookAt.ToString(); | ||
384 | |||
385 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
386 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
387 | try | ||
388 | { | ||
389 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
390 | m_ServerURI + "/presence", | ||
391 | reqString); | ||
392 | if (reply != string.Empty) | ||
393 | { | ||
394 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
395 | |||
396 | if (replyData.ContainsKey("result")) | ||
397 | { | ||
398 | if (replyData["result"].ToString().ToLower() == "success") | ||
399 | return true; | ||
400 | else | ||
401 | return false; | ||
402 | } | ||
403 | else | ||
404 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field"); | ||
405 | |||
406 | } | ||
407 | else | ||
408 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply"); | ||
409 | } | ||
410 | catch (Exception e) | ||
411 | { | ||
412 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
413 | } | ||
414 | |||
415 | return false; | ||
416 | } | ||
417 | |||
418 | #endregion | ||
419 | |||
420 | } | ||
421 | } | ||
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs new file mode 100644 index 0000000..6f71197 --- /dev/null +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | |||
@@ -0,0 +1,242 @@ | |||
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 OpenSimulator 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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using log4net; | ||
42 | |||
43 | namespace OpenSim.Services.Connectors.Simulation | ||
44 | { | ||
45 | public class SimulationServiceConnector : ISimulationService | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private GridRegion m_Region; | ||
50 | |||
51 | public SimulationServiceConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public SimulationServiceConnector(GridRegion region) | ||
56 | { | ||
57 | m_Region = region; | ||
58 | } | ||
59 | |||
60 | public IScene GetScene(ulong regionHandle) | ||
61 | { | ||
62 | return null; | ||
63 | } | ||
64 | |||
65 | #region Agents | ||
66 | |||
67 | public bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, uint flags, out string reason) | ||
68 | { | ||
69 | reason = String.Empty; | ||
70 | |||
71 | // Eventually, we want to use a caps url instead of the agentID | ||
72 | string uri = string.Empty; | ||
73 | try | ||
74 | { | ||
75 | uri = "http://" + m_Region.ExternalEndPoint.Address + ":" + m_Region.HttpPort + "/agent/" + aCircuit.AgentID + "/"; | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent create. Reason: " + e.Message); | ||
80 | reason = e.Message; | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
85 | |||
86 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
87 | AgentCreateRequest.Method = "POST"; | ||
88 | AgentCreateRequest.ContentType = "application/json"; | ||
89 | AgentCreateRequest.Timeout = 10000; | ||
90 | //AgentCreateRequest.KeepAlive = false; | ||
91 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
92 | |||
93 | // Fill it in | ||
94 | OSDMap args = null; | ||
95 | try | ||
96 | { | ||
97 | args = aCircuit.PackAgentCircuitData(); | ||
98 | } | ||
99 | catch (Exception e) | ||
100 | { | ||
101 | m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message); | ||
102 | } | ||
103 | // Add the regionhandle and the name of the destination region | ||
104 | args["destination_handle"] = OSD.FromString(m_Region.RegionHandle.ToString()); | ||
105 | args["destination_name"] = OSD.FromString(m_Region.RegionName); | ||
106 | args["teleport_flags"] = OSD.FromString(flags.ToString()); | ||
107 | |||
108 | string strBuffer = ""; | ||
109 | byte[] buffer = new byte[1]; | ||
110 | try | ||
111 | { | ||
112 | strBuffer = OSDParser.SerializeJsonString(args); | ||
113 | Encoding str = Util.UTF8; | ||
114 | buffer = str.GetBytes(strBuffer); | ||
115 | |||
116 | } | ||
117 | catch (Exception e) | ||
118 | { | ||
119 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
120 | // ignore. buffer will be empty, caller should check. | ||
121 | } | ||
122 | |||
123 | Stream os = null; | ||
124 | try | ||
125 | { // send the Post | ||
126 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
127 | os = AgentCreateRequest.GetRequestStream(); | ||
128 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
129 | //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri); | ||
130 | } | ||
131 | //catch (WebException ex) | ||
132 | catch | ||
133 | { | ||
134 | //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
135 | reason = "cannot contact remote region"; | ||
136 | return false; | ||
137 | } | ||
138 | finally | ||
139 | { | ||
140 | if (os != null) | ||
141 | os.Close(); | ||
142 | } | ||
143 | |||
144 | // Let's wait for the response | ||
145 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); | ||
146 | |||
147 | WebResponse webResponse = null; | ||
148 | StreamReader sr = null; | ||
149 | try | ||
150 | { | ||
151 | webResponse = AgentCreateRequest.GetResponse(); | ||
152 | if (webResponse == null) | ||
153 | { | ||
154 | m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post"); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | |||
159 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
160 | string response = sr.ReadToEnd().Trim(); | ||
161 | m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response); | ||
162 | |||
163 | if (!String.IsNullOrEmpty(response)) | ||
164 | { | ||
165 | try | ||
166 | { | ||
167 | // we assume we got an OSDMap back | ||
168 | OSDMap r = Util.GetOSDMap(response); | ||
169 | bool success = r["success"].AsBoolean(); | ||
170 | reason = r["reason"].AsString(); | ||
171 | return success; | ||
172 | } | ||
173 | catch (NullReferenceException e) | ||
174 | { | ||
175 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
176 | |||
177 | // check for old style response | ||
178 | if (response.ToLower().StartsWith("true")) | ||
179 | return true; | ||
180 | |||
181 | return false; | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | catch (WebException ex) | ||
187 | { | ||
188 | m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
189 | // ignore, really | ||
190 | } | ||
191 | finally | ||
192 | { | ||
193 | if (sr != null) | ||
194 | sr.Close(); | ||
195 | } | ||
196 | |||
197 | return true; | ||
198 | } | ||
199 | |||
200 | public bool UpdateAgent(ulong regionHandle, AgentData data) | ||
201 | { | ||
202 | return false; | ||
203 | } | ||
204 | |||
205 | public bool UpdateAgent(ulong regionHandle, AgentPosition data) | ||
206 | { | ||
207 | return false; | ||
208 | } | ||
209 | |||
210 | public bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent) | ||
211 | { | ||
212 | agent = null; | ||
213 | return false; | ||
214 | } | ||
215 | |||
216 | public bool ReleaseAgent(ulong regionHandle, UUID id, string uri) | ||
217 | { | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | public bool CloseAgent(ulong regionHandle, UUID id) | ||
222 | { | ||
223 | return false; | ||
224 | } | ||
225 | |||
226 | #endregion Agents | ||
227 | |||
228 | #region Objects | ||
229 | |||
230 | public bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall) | ||
231 | { | ||
232 | return false; | ||
233 | } | ||
234 | |||
235 | public bool CreateObject(ulong regionHandle, UUID userID, UUID itemID) | ||
236 | { | ||
237 | return false; | ||
238 | } | ||
239 | |||
240 | #endregion Objects | ||
241 | } | ||
242 | } | ||
diff --git a/OpenSim/Services/Connectors/User/UserServiceConnector.cs b/OpenSim/Services/Connectors/User/UserServiceConnector.cs deleted file mode 100644 index 683990f..0000000 --- a/OpenSim/Services/Connectors/User/UserServiceConnector.cs +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
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 OpenSimulator 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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace OpenSim.Services.Connectors | ||
41 | { | ||
42 | public class UserServicesConnector : IUserAccountService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | // private string m_ServerURI = String.Empty; | ||
49 | |||
50 | public UserServicesConnector() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | public UserServicesConnector(string serverURI) | ||
55 | { | ||
56 | // m_ServerURI = serverURI.TrimEnd('/'); | ||
57 | } | ||
58 | |||
59 | public UserServicesConnector(IConfigSource source) | ||
60 | { | ||
61 | Initialise(source); | ||
62 | } | ||
63 | |||
64 | public virtual void Initialise(IConfigSource source) | ||
65 | { | ||
66 | IConfig assetConfig = source.Configs["UserService"]; | ||
67 | if (assetConfig == null) | ||
68 | { | ||
69 | m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini"); | ||
70 | throw new Exception("User connector init error"); | ||
71 | } | ||
72 | |||
73 | string serviceURI = assetConfig.GetString("UserServerURI", | ||
74 | String.Empty); | ||
75 | |||
76 | if (serviceURI == String.Empty) | ||
77 | { | ||
78 | m_log.Error("[USER CONNECTOR]: No Server URI named in section UserService"); | ||
79 | throw new Exception("User connector init error"); | ||
80 | } | ||
81 | //m_ServerURI = serviceURI; | ||
82 | } | ||
83 | |||
84 | public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | ||
85 | { | ||
86 | return null; | ||
87 | } | ||
88 | |||
89 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
90 | { | ||
91 | return null; | ||
92 | } | ||
93 | |||
94 | public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) | ||
95 | { | ||
96 | return false; | ||
97 | } | ||
98 | |||
99 | public bool SetUserAccount(UserAccount data, UUID principalID, string token) | ||
100 | { | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | public bool CreateUserAccount(UserAccount data, UUID principalID, string token) | ||
105 | { | ||
106 | return false; | ||
107 | } | ||
108 | |||
109 | public List<UserAccount> GetUserAccount(UUID scopeID, string query) | ||
110 | { | ||
111 | return null; | ||
112 | } | ||
113 | } | ||
114 | } | ||
diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs new file mode 100644 index 0000000..46313d9 --- /dev/null +++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs | |||
@@ -0,0 +1,274 @@ | |||
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 OpenSimulator 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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class UserAccountServicesConnector : IUserAccountService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | |||
51 | public UserAccountServicesConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public UserAccountServicesConnector(string serverURI) | ||
56 | { | ||
57 | m_ServerURI = serverURI.TrimEnd('/'); | ||
58 | } | ||
59 | |||
60 | public UserAccountServicesConnector(IConfigSource source) | ||
61 | { | ||
62 | Initialise(source); | ||
63 | } | ||
64 | |||
65 | public virtual void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig assetConfig = source.Configs["UserAccountService"]; | ||
68 | if (assetConfig == null) | ||
69 | { | ||
70 | m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini"); | ||
71 | throw new Exception("User account connector init error"); | ||
72 | } | ||
73 | |||
74 | string serviceURI = assetConfig.GetString("UserAccountServerURI", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceURI == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService"); | ||
80 | throw new Exception("User account connector init error"); | ||
81 | } | ||
82 | m_ServerURI = serviceURI; | ||
83 | } | ||
84 | |||
85 | public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | ||
86 | { | ||
87 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
88 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
89 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
90 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
91 | sendData["METHOD"] = "getaccount"; | ||
92 | |||
93 | sendData["ScopeID"] = scopeID; | ||
94 | sendData["FirstName"] = firstName.ToString(); | ||
95 | sendData["LastName"] = lastName.ToString(); | ||
96 | |||
97 | return SendAndGetReply(sendData); | ||
98 | } | ||
99 | |||
100 | public UserAccount GetUserAccount(UUID scopeID, string email) | ||
101 | { | ||
102 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
103 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
104 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
105 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
106 | sendData["METHOD"] = "getaccount"; | ||
107 | |||
108 | sendData["ScopeID"] = scopeID; | ||
109 | sendData["Email"] = email; | ||
110 | |||
111 | return SendAndGetReply(sendData); | ||
112 | } | ||
113 | |||
114 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
115 | { | ||
116 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
117 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
118 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
119 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
120 | sendData["METHOD"] = "getaccount"; | ||
121 | |||
122 | sendData["ScopeID"] = scopeID; | ||
123 | sendData["UserID"] = userID.ToString(); | ||
124 | |||
125 | return SendAndGetReply(sendData); | ||
126 | } | ||
127 | |||
128 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
129 | { | ||
130 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
131 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
132 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
133 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
134 | sendData["METHOD"] = "getagents"; | ||
135 | |||
136 | sendData["ScopeID"] = scopeID.ToString(); | ||
137 | sendData["query"] = query; | ||
138 | |||
139 | string reply = string.Empty; | ||
140 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
141 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
142 | try | ||
143 | { | ||
144 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
145 | m_ServerURI + "/accounts", | ||
146 | reqString); | ||
147 | if (reply == null || (reply != null && reply == string.Empty)) | ||
148 | { | ||
149 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply"); | ||
150 | return null; | ||
151 | } | ||
152 | } | ||
153 | catch (Exception e) | ||
154 | { | ||
155 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting accounts server: {0}", e.Message); | ||
156 | } | ||
157 | |||
158 | List<UserAccount> accounts = new List<UserAccount>(); | ||
159 | |||
160 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
161 | |||
162 | if (replyData != null) | ||
163 | { | ||
164 | if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null") | ||
165 | { | ||
166 | return accounts; | ||
167 | } | ||
168 | |||
169 | Dictionary<string, object>.ValueCollection accountList = replyData.Values; | ||
170 | //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
171 | foreach (object acc in accountList) | ||
172 | { | ||
173 | if (acc is Dictionary<string, object>) | ||
174 | { | ||
175 | UserAccount pinfo = new UserAccount((Dictionary<string, object>)acc); | ||
176 | accounts.Add(pinfo); | ||
177 | } | ||
178 | else | ||
179 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}", | ||
180 | acc.GetType()); | ||
181 | } | ||
182 | } | ||
183 | else | ||
184 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response"); | ||
185 | |||
186 | return accounts; | ||
187 | } | ||
188 | |||
189 | public bool StoreUserAccount(UserAccount data) | ||
190 | { | ||
191 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
192 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
193 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
194 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
195 | sendData["METHOD"] = "setaccount"; | ||
196 | |||
197 | sendData["account"] = data.ToKeyValuePairs(); | ||
198 | |||
199 | return SendAndGetBoolReply(sendData); | ||
200 | } | ||
201 | |||
202 | private UserAccount SendAndGetReply(Dictionary<string, object> sendData) | ||
203 | { | ||
204 | string reply = string.Empty; | ||
205 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
206 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
207 | try | ||
208 | { | ||
209 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
210 | m_ServerURI + "/accounts", | ||
211 | reqString); | ||
212 | if (reply == null || (reply != null && reply == string.Empty)) | ||
213 | { | ||
214 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply"); | ||
215 | return null; | ||
216 | } | ||
217 | } | ||
218 | catch (Exception e) | ||
219 | { | ||
220 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user account server: {0}", e.Message); | ||
221 | } | ||
222 | |||
223 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
224 | UserAccount account = null; | ||
225 | |||
226 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
227 | { | ||
228 | if (replyData["result"] is Dictionary<string, object>) | ||
229 | { | ||
230 | account = new UserAccount((Dictionary<string, object>)replyData["result"]); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | return account; | ||
235 | |||
236 | } | ||
237 | |||
238 | private bool SendAndGetBoolReply(Dictionary<string, object> sendData) | ||
239 | { | ||
240 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
241 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
242 | try | ||
243 | { | ||
244 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
245 | m_ServerURI + "/accounts", | ||
246 | reqString); | ||
247 | if (reply != string.Empty) | ||
248 | { | ||
249 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
250 | |||
251 | if (replyData.ContainsKey("result")) | ||
252 | { | ||
253 | if (replyData["result"].ToString().ToLower() == "success") | ||
254 | return true; | ||
255 | else | ||
256 | return false; | ||
257 | } | ||
258 | else | ||
259 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field"); | ||
260 | |||
261 | } | ||
262 | else | ||
263 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply"); | ||
264 | } | ||
265 | catch (Exception e) | ||
266 | { | ||
267 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Exception when contacting user account server: {0}", e.Message); | ||
268 | } | ||
269 | |||
270 | return false; | ||
271 | } | ||
272 | |||
273 | } | ||
274 | } | ||