opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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; |
||
30 | using System.Collections.Generic; |
||
31 | using System.Net; |
||
32 | using System.Reflection; |
||
33 | |||
34 | using Nini.Config; |
||
35 | using OpenSim.Framework; |
||
36 | using OpenSim.Server.Base; |
||
37 | using OpenSim.Services.Interfaces; |
||
38 | using OpenSim.Framework.Servers.HttpServer; |
||
39 | using OpenSim.Server.Handlers.Base; |
||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
41 | |||
42 | using log4net; |
||
43 | using Nwc.XmlRpc; |
||
44 | using OpenMetaverse; |
||
45 | |||
46 | namespace OpenSim.Server.Handlers.Hypergrid |
||
47 | { |
||
48 | public class UserAgentServerConnector : ServiceConnector |
||
49 | { |
||
50 | // private static readonly ILog m_log = |
||
51 | // LogManager.GetLogger( |
||
52 | // MethodBase.GetCurrentMethod().DeclaringType); |
||
53 | |||
54 | private IUserAgentService m_HomeUsersService; |
||
55 | public IUserAgentService HomeUsersService |
||
56 | { |
||
57 | get { return m_HomeUsersService; } |
||
58 | } |
||
59 | |||
60 | private string[] m_AuthorizedCallers; |
||
61 | |||
62 | private bool m_VerifyCallers = false; |
||
63 | |||
64 | public UserAgentServerConnector(IConfigSource config, IHttpServer server) : |
||
65 | this(config, server, (IFriendsSimConnector)null) |
||
66 | { |
||
67 | } |
||
68 | |||
69 | public UserAgentServerConnector(IConfigSource config, IHttpServer server, string configName) : |
||
70 | this(config, server) |
||
71 | { |
||
72 | } |
||
73 | |||
74 | public UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector) : |
||
75 | base(config, server, String.Empty) |
||
76 | { |
||
77 | IConfig gridConfig = config.Configs["UserAgentService"]; |
||
78 | if (gridConfig != null) |
||
79 | { |
||
80 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); |
||
81 | |||
82 | Object[] args = new Object[] { config, friendsConnector }; |
||
83 | m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args); |
||
84 | } |
||
85 | if (m_HomeUsersService == null) |
||
86 | throw new Exception("UserAgent server connector cannot proceed because of missing service"); |
||
87 | |||
88 | string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); |
||
89 | bool proxy = gridConfig.GetBoolean("HasProxy", false); |
||
90 | |||
91 | m_VerifyCallers = gridConfig.GetBoolean("VerifyCallers", false); |
||
92 | string csv = gridConfig.GetString("AuthorizedCallers", "127.0.0.1"); |
||
93 | csv = csv.Replace(" ", ""); |
||
94 | m_AuthorizedCallers = csv.Split(','); |
||
95 | |||
96 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); |
||
97 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); |
||
98 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); |
||
99 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); |
||
100 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); |
||
101 | |||
102 | server.AddXmlRPCHandler("status_notification", StatusNotification, false); |
||
103 | server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false); |
||
104 | server.AddXmlRPCHandler("get_user_info", GetUserInfo, false); |
||
105 | server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false); |
||
106 | |||
107 | server.AddXmlRPCHandler("locate_user", LocateUser, false); |
||
108 | server.AddXmlRPCHandler("get_uui", GetUUI, false); |
||
109 | server.AddXmlRPCHandler("get_uuid", GetUUID, false); |
||
110 | |||
111 | server.AddStreamHandler(new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy)); |
||
112 | } |
||
113 | |||
114 | public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) |
||
115 | { |
||
116 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
117 | //string host = (string)requestData["host"]; |
||
118 | //string portstr = (string)requestData["port"]; |
||
119 | string userID_str = (string)requestData["userID"]; |
||
120 | UUID userID = UUID.Zero; |
||
121 | UUID.TryParse(userID_str, out userID); |
||
122 | |||
123 | Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; |
||
124 | GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt); |
||
125 | |||
126 | Hashtable hash = new Hashtable(); |
||
127 | if (regInfo == null) |
||
128 | hash["result"] = "false"; |
||
129 | else |
||
130 | { |
||
131 | hash["result"] = "true"; |
||
132 | hash["uuid"] = regInfo.RegionID.ToString(); |
||
133 | hash["x"] = regInfo.RegionLocX.ToString(); |
||
134 | hash["y"] = regInfo.RegionLocY.ToString(); |
||
135 | hash["size_x"] = regInfo.RegionSizeX.ToString(); |
||
136 | hash["size_y"] = regInfo.RegionSizeY.ToString(); |
||
137 | hash["region_name"] = regInfo.RegionName; |
||
138 | hash["hostname"] = regInfo.ExternalHostName; |
||
139 | hash["http_port"] = regInfo.HttpPort.ToString(); |
||
140 | hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); |
||
141 | hash["position"] = position.ToString(); |
||
142 | hash["lookAt"] = lookAt.ToString(); |
||
143 | } |
||
144 | XmlRpcResponse response = new XmlRpcResponse(); |
||
145 | response.Value = hash; |
||
146 | return response; |
||
147 | |||
148 | } |
||
149 | |||
150 | public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient) |
||
151 | { |
||
152 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
153 | //string host = (string)requestData["host"]; |
||
154 | //string portstr = (string)requestData["port"]; |
||
155 | string sessionID_str = (string)requestData["sessionID"]; |
||
156 | UUID sessionID = UUID.Zero; |
||
157 | UUID.TryParse(sessionID_str, out sessionID); |
||
158 | string gridName = (string)requestData["externalName"]; |
||
159 | |||
160 | bool success = m_HomeUsersService.IsAgentComingHome(sessionID, gridName); |
||
161 | |||
162 | Hashtable hash = new Hashtable(); |
||
163 | hash["result"] = success.ToString(); |
||
164 | XmlRpcResponse response = new XmlRpcResponse(); |
||
165 | response.Value = hash; |
||
166 | return response; |
||
167 | |||
168 | } |
||
169 | |||
170 | public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient) |
||
171 | { |
||
172 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
173 | //string host = (string)requestData["host"]; |
||
174 | //string portstr = (string)requestData["port"]; |
||
175 | string sessionID_str = (string)requestData["sessionID"]; |
||
176 | UUID sessionID = UUID.Zero; |
||
177 | UUID.TryParse(sessionID_str, out sessionID); |
||
178 | string token = (string)requestData["token"]; |
||
179 | |||
180 | bool success = m_HomeUsersService.VerifyAgent(sessionID, token); |
||
181 | |||
182 | Hashtable hash = new Hashtable(); |
||
183 | hash["result"] = success.ToString(); |
||
184 | XmlRpcResponse response = new XmlRpcResponse(); |
||
185 | response.Value = hash; |
||
186 | return response; |
||
187 | |||
188 | } |
||
189 | |||
190 | public XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient) |
||
191 | { |
||
192 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
193 | //string host = (string)requestData["host"]; |
||
194 | //string portstr = (string)requestData["port"]; |
||
195 | string sessionID_str = (string)requestData["sessionID"]; |
||
196 | UUID sessionID = UUID.Zero; |
||
197 | UUID.TryParse(sessionID_str, out sessionID); |
||
198 | string token = (string)requestData["token"]; |
||
199 | |||
200 | bool success = m_HomeUsersService.VerifyClient(sessionID, token); |
||
201 | |||
202 | Hashtable hash = new Hashtable(); |
||
203 | hash["result"] = success.ToString(); |
||
204 | XmlRpcResponse response = new XmlRpcResponse(); |
||
205 | response.Value = hash; |
||
206 | return response; |
||
207 | |||
208 | } |
||
209 | |||
210 | public XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient) |
||
211 | { |
||
212 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
213 | //string host = (string)requestData["host"]; |
||
214 | //string portstr = (string)requestData["port"]; |
||
215 | string sessionID_str = (string)requestData["sessionID"]; |
||
216 | UUID sessionID = UUID.Zero; |
||
217 | UUID.TryParse(sessionID_str, out sessionID); |
||
218 | string userID_str = (string)requestData["userID"]; |
||
219 | UUID userID = UUID.Zero; |
||
220 | UUID.TryParse(userID_str, out userID); |
||
221 | |||
222 | m_HomeUsersService.LogoutAgent(userID, sessionID); |
||
223 | |||
224 | Hashtable hash = new Hashtable(); |
||
225 | hash["result"] = "true"; |
||
226 | XmlRpcResponse response = new XmlRpcResponse(); |
||
227 | response.Value = hash; |
||
228 | return response; |
||
229 | |||
230 | } |
||
231 | |||
232 | [Obsolete] |
||
233 | public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient) |
||
234 | { |
||
235 | Hashtable hash = new Hashtable(); |
||
236 | hash["result"] = "false"; |
||
237 | |||
238 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
239 | //string host = (string)requestData["host"]; |
||
240 | //string portstr = (string)requestData["port"]; |
||
241 | if (requestData.ContainsKey("userID") && requestData.ContainsKey("online")) |
||
242 | { |
||
243 | string userID_str = (string)requestData["userID"]; |
||
244 | UUID userID = UUID.Zero; |
||
245 | UUID.TryParse(userID_str, out userID); |
||
246 | List<string> ids = new List<string>(); |
||
247 | foreach (object key in requestData.Keys) |
||
248 | { |
||
249 | if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null) |
||
250 | ids.Add(requestData[key].ToString()); |
||
251 | } |
||
252 | bool online = false; |
||
253 | bool.TryParse(requestData["online"].ToString(), out online); |
||
254 | |||
255 | // let's spawn a thread for this, because it may take a long time... |
||
256 | List<UUID> friendsOnline = m_HomeUsersService.StatusNotification(ids, userID, online); |
||
257 | if (friendsOnline.Count > 0) |
||
258 | { |
||
259 | int i = 0; |
||
260 | foreach (UUID id in friendsOnline) |
||
261 | { |
||
262 | hash["friend_" + i.ToString()] = id.ToString(); |
||
263 | i++; |
||
264 | } |
||
265 | } |
||
266 | else |
||
267 | hash["result"] = "No Friends Online"; |
||
268 | |||
269 | } |
||
270 | |||
271 | XmlRpcResponse response = new XmlRpcResponse(); |
||
272 | response.Value = hash; |
||
273 | return response; |
||
274 | |||
275 | } |
||
276 | |||
277 | [Obsolete] |
||
278 | public XmlRpcResponse GetOnlineFriends(XmlRpcRequest request, IPEndPoint remoteClient) |
||
279 | { |
||
280 | Hashtable hash = new Hashtable(); |
||
281 | |||
282 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
283 | //string host = (string)requestData["host"]; |
||
284 | //string portstr = (string)requestData["port"]; |
||
285 | if (requestData.ContainsKey("userID")) |
||
286 | { |
||
287 | string userID_str = (string)requestData["userID"]; |
||
288 | UUID userID = UUID.Zero; |
||
289 | UUID.TryParse(userID_str, out userID); |
||
290 | List<string> ids = new List<string>(); |
||
291 | foreach (object key in requestData.Keys) |
||
292 | { |
||
293 | if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null) |
||
294 | ids.Add(requestData[key].ToString()); |
||
295 | } |
||
296 | |||
297 | //List<UUID> online = m_HomeUsersService.GetOnlineFriends(userID, ids); |
||
298 | //if (online.Count > 0) |
||
299 | //{ |
||
300 | // int i = 0; |
||
301 | // foreach (UUID id in online) |
||
302 | // { |
||
303 | // hash["friend_" + i.ToString()] = id.ToString(); |
||
304 | // i++; |
||
305 | // } |
||
306 | //} |
||
307 | //else |
||
308 | // hash["result"] = "No Friends Online"; |
||
309 | } |
||
310 | |||
311 | XmlRpcResponse response = new XmlRpcResponse(); |
||
312 | response.Value = hash; |
||
313 | return response; |
||
314 | |||
315 | } |
||
316 | |||
317 | public XmlRpcResponse GetUserInfo(XmlRpcRequest request, IPEndPoint remoteClient) |
||
318 | { |
||
319 | Hashtable hash = new Hashtable(); |
||
320 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
321 | |||
322 | // This needs checking! |
||
323 | if (requestData.ContainsKey("userID")) |
||
324 | { |
||
325 | string userID_str = (string)requestData["userID"]; |
||
326 | UUID userID = UUID.Zero; |
||
327 | UUID.TryParse(userID_str, out userID); |
||
328 | |||
329 | //int userFlags = m_HomeUsersService.GetUserFlags(userID); |
||
330 | Dictionary<string,object> userInfo = m_HomeUsersService.GetUserInfo(userID); |
||
331 | if (userInfo.Count > 0) |
||
332 | { |
||
333 | foreach (KeyValuePair<string, object> kvp in userInfo) |
||
334 | { |
||
335 | hash[kvp.Key] = kvp.Value; |
||
336 | } |
||
337 | } |
||
338 | else |
||
339 | { |
||
340 | hash["result"] = "failure"; |
||
341 | } |
||
342 | } |
||
343 | |||
344 | XmlRpcResponse response = new XmlRpcResponse(); |
||
345 | response.Value = hash; |
||
346 | return response; |
||
347 | } |
||
348 | |||
349 | public XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient) |
||
350 | { |
||
351 | Hashtable hash = new Hashtable(); |
||
352 | |||
353 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
354 | //string host = (string)requestData["host"]; |
||
355 | //string portstr = (string)requestData["port"]; |
||
356 | if (requestData.ContainsKey("userID")) |
||
357 | { |
||
358 | string userID_str = (string)requestData["userID"]; |
||
359 | UUID userID = UUID.Zero; |
||
360 | UUID.TryParse(userID_str, out userID); |
||
361 | |||
362 | Dictionary<string, object> serverURLs = m_HomeUsersService.GetServerURLs(userID); |
||
363 | if (serverURLs.Count > 0) |
||
364 | { |
||
365 | foreach (KeyValuePair<string, object> kvp in serverURLs) |
||
366 | hash["SRV_" + kvp.Key] = kvp.Value.ToString(); |
||
367 | } |
||
368 | else |
||
369 | hash["result"] = "No Service URLs"; |
||
370 | } |
||
371 | |||
372 | XmlRpcResponse response = new XmlRpcResponse(); |
||
373 | response.Value = hash; |
||
374 | return response; |
||
375 | |||
376 | } |
||
377 | |||
378 | /// <summary> |
||
379 | /// Locates the user. |
||
380 | /// This is a sensitive operation, only authorized IP addresses can perform it. |
||
381 | /// </summary> |
||
382 | /// <param name="request"></param> |
||
383 | /// <param name="remoteClient"></param> |
||
384 | /// <returns></returns> |
||
385 | public XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient) |
||
386 | { |
||
387 | Hashtable hash = new Hashtable(); |
||
388 | |||
389 | bool authorized = true; |
||
390 | if (m_VerifyCallers) |
||
391 | { |
||
392 | authorized = false; |
||
393 | foreach (string s in m_AuthorizedCallers) |
||
394 | if (s == remoteClient.Address.ToString()) |
||
395 | { |
||
396 | authorized = true; |
||
397 | break; |
||
398 | } |
||
399 | } |
||
400 | |||
401 | if (authorized) |
||
402 | { |
||
403 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
404 | //string host = (string)requestData["host"]; |
||
405 | //string portstr = (string)requestData["port"]; |
||
406 | if (requestData.ContainsKey("userID")) |
||
407 | { |
||
408 | string userID_str = (string)requestData["userID"]; |
||
409 | UUID userID = UUID.Zero; |
||
410 | UUID.TryParse(userID_str, out userID); |
||
411 | |||
412 | string url = m_HomeUsersService.LocateUser(userID); |
||
413 | if (url != string.Empty) |
||
414 | hash["URL"] = url; |
||
415 | else |
||
416 | hash["result"] = "Unable to locate user"; |
||
417 | } |
||
418 | } |
||
419 | |||
420 | XmlRpcResponse response = new XmlRpcResponse(); |
||
421 | response.Value = hash; |
||
422 | return response; |
||
423 | |||
424 | } |
||
425 | |||
426 | /// <summary> |
||
427 | /// Returns the UUI of a user given a UUID. |
||
428 | /// </summary> |
||
429 | /// <param name="request"></param> |
||
430 | /// <param name="remoteClient"></param> |
||
431 | /// <returns></returns> |
||
432 | public XmlRpcResponse GetUUI(XmlRpcRequest request, IPEndPoint remoteClient) |
||
433 | { |
||
434 | Hashtable hash = new Hashtable(); |
||
435 | |||
436 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
437 | //string host = (string)requestData["host"]; |
||
438 | //string portstr = (string)requestData["port"]; |
||
439 | if (requestData.ContainsKey("userID") && requestData.ContainsKey("targetUserID")) |
||
440 | { |
||
441 | string userID_str = (string)requestData["userID"]; |
||
442 | UUID userID = UUID.Zero; |
||
443 | UUID.TryParse(userID_str, out userID); |
||
444 | |||
445 | string tuserID_str = (string)requestData["targetUserID"]; |
||
446 | UUID targetUserID = UUID.Zero; |
||
447 | UUID.TryParse(tuserID_str, out targetUserID); |
||
448 | string uui = m_HomeUsersService.GetUUI(userID, targetUserID); |
||
449 | if (uui != string.Empty) |
||
450 | hash["UUI"] = uui; |
||
451 | else |
||
452 | hash["result"] = "User unknown"; |
||
453 | } |
||
454 | |||
455 | XmlRpcResponse response = new XmlRpcResponse(); |
||
456 | response.Value = hash; |
||
457 | return response; |
||
458 | } |
||
459 | |||
460 | /// <summary> |
||
461 | /// Gets the UUID of a user given First name, Last name. |
||
462 | /// </summary> |
||
463 | /// <param name="request"></param> |
||
464 | /// <param name="remoteClient"></param> |
||
465 | /// <returns></returns> |
||
466 | public XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient) |
||
467 | { |
||
468 | Hashtable hash = new Hashtable(); |
||
469 | |||
470 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
471 | //string host = (string)requestData["host"]; |
||
472 | //string portstr = (string)requestData["port"]; |
||
473 | if (requestData.ContainsKey("first") && requestData.ContainsKey("last")) |
||
474 | { |
||
475 | string first = (string)requestData["first"]; |
||
476 | string last = (string)requestData["last"]; |
||
477 | UUID uuid = m_HomeUsersService.GetUUID(first, last); |
||
478 | hash["UUID"] = uuid.ToString(); |
||
479 | } |
||
480 | |||
481 | XmlRpcResponse response = new XmlRpcResponse(); |
||
482 | response.Value = hash; |
||
483 | return response; |
||
484 | } |
||
485 | } |
||
486 | } |