clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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.ServiceAuth;
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 GridUserServicesConnector : BaseServiceConnector, IGridUserService
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 GridUserServicesConnector()
53 {
54 }
55  
56 public GridUserServicesConnector(string serverURI)
57 {
58 m_ServerURI = serverURI.TrimEnd('/');
59 }
60  
61 public GridUserServicesConnector(IConfigSource source)
62 {
63 Initialise(source);
64 }
65  
66 public virtual void Initialise(IConfigSource source)
67 {
68 IConfig gridConfig = source.Configs["GridUserService"];
69 if (gridConfig == null)
70 {
71 m_log.Error("[GRID USER CONNECTOR]: GridUserService missing from OpenSim.ini");
72 throw new Exception("GridUser connector init error");
73 }
74  
75 string serviceURI = gridConfig.GetString("GridUserServerURI",
76 String.Empty);
77  
78 if (serviceURI == String.Empty)
79 {
80 m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService");
81 throw new Exception("GridUser connector init error");
82 }
83 m_ServerURI = serviceURI;
84 base.Initialise(source, "GridUserService");
85 }
86  
87  
88 #region IGridUserService
89  
90  
91 public GridUserInfo LoggedIn(string userID)
92 {
93 Dictionary<string, object> sendData = new Dictionary<string, object>();
94 //sendData["SCOPEID"] = scopeID.ToString();
95 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
96 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
97 sendData["METHOD"] = "loggedin";
98  
99 sendData["UserID"] = userID;
100  
101 return Get(sendData);
102  
103 }
104  
105 public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat)
106 {
107 Dictionary<string, object> sendData = new Dictionary<string, object>();
108 //sendData["SCOPEID"] = scopeID.ToString();
109 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
110 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
111 sendData["METHOD"] = "loggedout";
112  
113 return Set(sendData, userID, region, position, lookat);
114 }
115  
116 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
117 {
118 Dictionary<string, object> sendData = new Dictionary<string, object>();
119 //sendData["SCOPEID"] = scopeID.ToString();
120 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
121 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
122 sendData["METHOD"] = "sethome";
123  
124 return Set(sendData, userID, regionID, position, lookAt);
125 }
126  
127 public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
128 {
129 Dictionary<string, object> sendData = new Dictionary<string, object>();
130 //sendData["SCOPEID"] = scopeID.ToString();
131 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
132 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
133 sendData["METHOD"] = "setposition";
134  
135 return Set(sendData, userID, regionID, position, lookAt);
136 }
137  
138 public GridUserInfo GetGridUserInfo(string userID)
139 {
140 Dictionary<string, object> sendData = new Dictionary<string, object>();
141 //sendData["SCOPEID"] = scopeID.ToString();
142 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
143 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
144 sendData["METHOD"] = "getgriduserinfo";
145  
146 sendData["UserID"] = userID;
147  
148 return Get(sendData);
149 }
150  
151 #endregion
152  
153 protected bool Set(Dictionary<string, object> sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt)
154 {
155 sendData["UserID"] = userID;
156 sendData["RegionID"] = regionID.ToString();
157 sendData["Position"] = position.ToString();
158 sendData["LookAt"] = lookAt.ToString();
159  
160 string reqString = ServerUtils.BuildQueryString(sendData);
161 string uri = m_ServerURI + "/griduser";
162 // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString);
163 try
164 {
165 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
166 uri,
167 reqString,
168 m_Auth);
169 if (reply != string.Empty)
170 {
171 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
172  
173 if (replyData.ContainsKey("result"))
174 {
175 if (replyData["result"].ToString().ToLower() == "success")
176 return true;
177 else
178 return false;
179 }
180 else
181 m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition reply data does not contain result field");
182  
183 }
184 else
185 m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition received empty reply");
186 }
187 catch (Exception e)
188 {
189 m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message);
190 }
191  
192 return false;
193 }
194  
195 protected GridUserInfo Get(Dictionary<string, object> sendData)
196 {
197 string reqString = ServerUtils.BuildQueryString(sendData);
198 string uri = m_ServerURI + "/griduser";
199 // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString);
200 try
201 {
202 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
203 uri,
204 reqString,
205 m_Auth);
206 if (reply != string.Empty)
207 {
208 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
209 GridUserInfo guinfo = null;
210  
211 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
212 {
213 if (replyData["result"] is Dictionary<string, object>)
214 guinfo = Create((Dictionary<string, object>)replyData["result"]);
215 }
216  
217 return guinfo;
218  
219 }
220 else
221 m_log.DebugFormat("[GRID USER CONNECTOR]: Get received empty reply");
222 }
223 catch (Exception e)
224 {
225 m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message);
226 }
227  
228 return null;
229  
230 }
231  
232 public GridUserInfo[] GetGridUserInfo(string[] userIDs)
233 {
234 Dictionary<string, object> sendData = new Dictionary<string, object>();
235 //sendData["SCOPEID"] = scopeID.ToString();
236 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
237 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
238 sendData["METHOD"] = "getgriduserinfos";
239  
240 sendData["AgentIDs"] = new List<string>(userIDs);
241  
242 string reply = string.Empty;
243 string reqString = ServerUtils.BuildQueryString(sendData);
244 string uri = m_ServerURI + "/griduser";
245 //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
246 try
247 {
248 reply = SynchronousRestFormsRequester.MakeRequest("POST",
249 uri,
250 reqString,
251 m_Auth);
252 if (reply == null || (reply != null && reply == string.Empty))
253 {
254 m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null or empty reply");
255 return null;
256 }
257 }
258 catch (Exception e)
259 {
260 m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message);
261 }
262  
263 List<GridUserInfo> rinfos = new List<GridUserInfo>();
264  
265 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
266  
267 if (replyData != null)
268 {
269 if (replyData.ContainsKey("result") &&
270 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
271 {
272 return new GridUserInfo[0];
273 }
274  
275 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
276 //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
277 foreach (object griduser in pinfosList)
278 {
279 if (griduser is Dictionary<string, object>)
280 {
281 GridUserInfo pinfo = Create((Dictionary<string, object>)griduser);
282 rinfos.Add(pinfo);
283 }
284 else
285 m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received invalid response type {0}",
286 griduser.GetType());
287 }
288 }
289 else
290 m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null response");
291  
292 return rinfos.ToArray();
293 }
294  
295 protected virtual GridUserInfo Create(Dictionary<string, object> griduser)
296 {
297 return new GridUserInfo(griduser);
298 }
299 }
300 }