aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs625
1 files changed, 625 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
new file mode 100644
index 0000000..8abd046
--- /dev/null
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -0,0 +1,625 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.IO;
32using System.Net;
33using System.Reflection;
34using System.Text;
35using OpenSim.Framework;
36using OpenSim.Services.Interfaces;
37using OpenSim.Services.Connectors.Simulation;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
41using log4net;
42using Nwc.XmlRpc;
43using Nini.Config;
44
45namespace OpenSim.Services.Connectors.Hypergrid
46{
47 public class UserAgentServiceConnector : SimulationServiceConnector, IUserAgentService
48 {
49 private static readonly ILog m_log =
50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 private string m_ServerURLHost;
54 private string m_ServerURL;
55 private GridRegion m_Gatekeeper;
56
57 public UserAgentServiceConnector(string url) : this(url, true)
58 {
59 }
60
61 public UserAgentServiceConnector(string url, bool dnsLookup)
62 {
63 m_ServerURL = m_ServerURLHost = url;
64
65 if (dnsLookup)
66 {
67 // Doing this here, because XML-RPC or mono have some strong ideas about
68 // caching DNS translations.
69 try
70 {
71 Uri m_Uri = new Uri(m_ServerURL);
72 IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
73 m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString());
74 if (!m_ServerURL.EndsWith("/"))
75 m_ServerURL += "/";
76 }
77 catch (Exception e)
78 {
79 m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", url, e.Message);
80 }
81 }
82
83 //m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL);
84 }
85
86 public UserAgentServiceConnector(IConfigSource config)
87 {
88 IConfig serviceConfig = config.Configs["UserAgentService"];
89 if (serviceConfig == null)
90 {
91 m_log.Error("[USER AGENT CONNECTOR]: UserAgentService missing from ini");
92 throw new Exception("UserAgent connector init error");
93 }
94
95 string serviceURI = serviceConfig.GetString("UserAgentServerURI",
96 String.Empty);
97
98 if (serviceURI == String.Empty)
99 {
100 m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService");
101 throw new Exception("UserAgent connector init error");
102 }
103
104 m_ServerURL = m_ServerURLHost = serviceURI;
105 if (!m_ServerURL.EndsWith("/"))
106 m_ServerURL += "/";
107
108 //m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0}", m_ServerURL);
109 }
110
111 protected override string AgentPath()
112 {
113 return "homeagent/";
114 }
115
116 // The Login service calls this interface with fromLogin=true
117 // Sims call it with fromLogin=false
118 // Either way, this is verified by the handler
119 public bool LoginAgentToGrid(GridRegion source, AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, bool fromLogin, out string reason)
120 {
121 reason = String.Empty;
122
123 if (destination == null)
124 {
125 reason = "Destination is null";
126 m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null");
127 return false;
128 }
129
130 GridRegion home = new GridRegion();
131 home.ServerURI = m_ServerURL;
132 home.RegionID = destination.RegionID;
133 home.RegionLocX = destination.RegionLocX;
134 home.RegionLocY = destination.RegionLocY;
135
136 m_Gatekeeper = gatekeeper;
137
138 Console.WriteLine(" >>> LoginAgentToGrid <<< " + home.ServerURI);
139
140 uint flags = fromLogin ? (uint)TeleportFlags.ViaLogin : (uint)TeleportFlags.ViaHome;
141 return CreateAgent(source, home, aCircuit, flags, out reason);
142 }
143
144
145 // The simulators call this interface
146 public bool LoginAgentToGrid(GridRegion source, AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason)
147 {
148 return LoginAgentToGrid(source, aCircuit, gatekeeper, destination, false, out reason);
149 }
150
151 protected override void PackData(OSDMap args, GridRegion source, AgentCircuitData aCircuit, GridRegion destination, uint flags)
152 {
153 base.PackData(args, source, aCircuit, destination, flags);
154 args["gatekeeper_serveruri"] = OSD.FromString(m_Gatekeeper.ServerURI);
155 args["gatekeeper_host"] = OSD.FromString(m_Gatekeeper.ExternalHostName);
156 args["gatekeeper_port"] = OSD.FromString(m_Gatekeeper.HttpPort.ToString());
157 args["destination_serveruri"] = OSD.FromString(destination.ServerURI);
158 }
159
160 public void SetClientToken(UUID sessionID, string token)
161 {
162 // no-op
163 }
164
165 private Hashtable CallServer(string methodName, Hashtable hash)
166 {
167 IList paramList = new ArrayList();
168 paramList.Add(hash);
169
170 XmlRpcRequest request = new XmlRpcRequest(methodName, paramList);
171
172 // Send and get reply
173 XmlRpcResponse response = null;
174 try
175 {
176 response = request.Send(m_ServerURL, 10000);
177 }
178 catch (Exception e)
179 {
180 m_log.DebugFormat("[USER AGENT CONNECTOR]: {0} call to {1} failed: {2}", methodName, m_ServerURLHost, e.Message);
181 throw;
182 }
183
184 if (response.IsFault)
185 {
186 throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned an error: {2}", methodName, m_ServerURLHost, response.FaultString));
187 }
188
189 hash = (Hashtable)response.Value;
190
191 if (hash == null)
192 {
193 throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned null", methodName, m_ServerURLHost));
194 }
195
196 return hash;
197 }
198
199 public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt)
200 {
201 position = Vector3.UnitY; lookAt = Vector3.UnitY;
202
203 Hashtable hash = new Hashtable();
204 hash["userID"] = userID.ToString();
205
206 hash = CallServer("get_home_region", hash);
207
208 bool success;
209 if (!Boolean.TryParse((string)hash["result"], out success) || !success)
210 return null;
211
212 GridRegion region = new GridRegion();
213
214 UUID.TryParse((string)hash["uuid"], out region.RegionID);
215 //m_log.Debug(">> HERE, uuid: " + region.RegionID);
216 int n = 0;
217 if (hash["x"] != null)
218 {
219 Int32.TryParse((string)hash["x"], out n);
220 region.RegionLocX = n;
221 //m_log.Debug(">> HERE, x: " + region.RegionLocX);
222 }
223 if (hash["y"] != null)
224 {
225 Int32.TryParse((string)hash["y"], out n);
226 region.RegionLocY = n;
227 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
228 }
229 if (hash["size_x"] != null)
230 {
231 Int32.TryParse((string)hash["size_x"], out n);
232 region.RegionSizeX = n;
233 //m_log.Debug(">> HERE, x: " + region.RegionLocX);
234 }
235 if (hash["size_y"] != null)
236 {
237 Int32.TryParse((string)hash["size_y"], out n);
238 region.RegionSizeY = n;
239 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
240 }
241 if (hash["region_name"] != null)
242 {
243 region.RegionName = (string)hash["region_name"];
244 //m_log.Debug(">> HERE, name: " + region.RegionName);
245 }
246 if (hash["hostname"] != null)
247 region.ExternalHostName = (string)hash["hostname"];
248 if (hash["http_port"] != null)
249 {
250 uint p = 0;
251 UInt32.TryParse((string)hash["http_port"], out p);
252 region.HttpPort = p;
253 }
254 if (hash.ContainsKey("server_uri") && hash["server_uri"] != null)
255 region.ServerURI = (string)hash["server_uri"];
256
257 if (hash["internal_port"] != null)
258 {
259 int p = 0;
260 Int32.TryParse((string)hash["internal_port"], out p);
261 region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
262 }
263 if (hash["position"] != null)
264 Vector3.TryParse((string)hash["position"], out position);
265 if (hash["lookAt"] != null)
266 Vector3.TryParse((string)hash["lookAt"], out lookAt);
267
268 // Successful return
269 return region;
270 }
271
272 public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
273 {
274 Hashtable hash = new Hashtable();
275 hash["sessionID"] = sessionID.ToString();
276 hash["externalName"] = thisGridExternalName;
277
278 IList paramList = new ArrayList();
279 paramList.Add(hash);
280
281 XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList);
282 string reason = string.Empty;
283 return GetBoolResponse(request, out reason);
284 }
285
286 public bool VerifyAgent(UUID sessionID, string token)
287 {
288 Hashtable hash = new Hashtable();
289 hash["sessionID"] = sessionID.ToString();
290 hash["token"] = token;
291
292 IList paramList = new ArrayList();
293 paramList.Add(hash);
294
295 XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList);
296 string reason = string.Empty;
297 return GetBoolResponse(request, out reason);
298 }
299
300 public bool VerifyClient(UUID sessionID, string token)
301 {
302 Hashtable hash = new Hashtable();
303 hash["sessionID"] = sessionID.ToString();
304 hash["token"] = token;
305
306 IList paramList = new ArrayList();
307 paramList.Add(hash);
308
309 XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList);
310 string reason = string.Empty;
311 return GetBoolResponse(request, out reason);
312 }
313
314 public void LogoutAgent(UUID userID, UUID sessionID)
315 {
316 Hashtable hash = new Hashtable();
317 hash["sessionID"] = sessionID.ToString();
318 hash["userID"] = userID.ToString();
319
320 IList paramList = new ArrayList();
321 paramList.Add(hash);
322
323 XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList);
324 string reason = string.Empty;
325 GetBoolResponse(request, out reason);
326 }
327
328 [Obsolete]
329 public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
330 {
331 Hashtable hash = new Hashtable();
332 hash["userID"] = userID.ToString();
333 hash["online"] = online.ToString();
334 int i = 0;
335 foreach (string s in friends)
336 {
337 hash["friend_" + i.ToString()] = s;
338 i++;
339 }
340
341 IList paramList = new ArrayList();
342 paramList.Add(hash);
343
344 XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
345// string reason = string.Empty;
346
347 // Send and get reply
348 List<UUID> friendsOnline = new List<UUID>();
349 XmlRpcResponse response = null;
350 try
351 {
352 response = request.Send(m_ServerURL, 6000);
353 }
354 catch
355 {
356 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURLHost);
357// reason = "Exception: " + e.Message;
358 return friendsOnline;
359 }
360
361 if (response.IsFault)
362 {
363 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURLHost, response.FaultString);
364// reason = "XMLRPC Fault";
365 return friendsOnline;
366 }
367
368 hash = (Hashtable)response.Value;
369 //foreach (Object o in hash)
370 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
371 try
372 {
373 if (hash == null)
374 {
375 m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost);
376// reason = "Internal error 1";
377 return friendsOnline;
378 }
379
380 // Here is the actual response
381 foreach (object key in hash.Keys)
382 {
383 if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
384 {
385 UUID uuid;
386 if (UUID.TryParse(hash[key].ToString(), out uuid))
387 friendsOnline.Add(uuid);
388 }
389 }
390
391 }
392 catch
393 {
394 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
395// reason = "Exception: " + e.Message;
396 }
397
398 return friendsOnline;
399 }
400
401 [Obsolete]
402 public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
403 {
404 Hashtable hash = new Hashtable();
405 hash["userID"] = userID.ToString();
406 int i = 0;
407 foreach (string s in friends)
408 {
409 hash["friend_" + i.ToString()] = s;
410 i++;
411 }
412
413 IList paramList = new ArrayList();
414 paramList.Add(hash);
415
416 XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
417// string reason = string.Empty;
418
419 // Send and get reply
420 List<UUID> online = new List<UUID>();
421 XmlRpcResponse response = null;
422 try
423 {
424 response = request.Send(m_ServerURL, 10000);
425 }
426 catch
427 {
428 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURLHost);
429// reason = "Exception: " + e.Message;
430 return online;
431 }
432
433 if (response.IsFault)
434 {
435 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURLHost, response.FaultString);
436// reason = "XMLRPC Fault";
437 return online;
438 }
439
440 hash = (Hashtable)response.Value;
441 //foreach (Object o in hash)
442 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
443 try
444 {
445 if (hash == null)
446 {
447 m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost);
448// reason = "Internal error 1";
449 return online;
450 }
451
452 // Here is the actual response
453 foreach (object key in hash.Keys)
454 {
455 if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
456 {
457 UUID uuid;
458 if (UUID.TryParse(hash[key].ToString(), out uuid))
459 online.Add(uuid);
460 }
461 }
462
463 }
464 catch
465 {
466 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
467// reason = "Exception: " + e.Message;
468 }
469
470 return online;
471 }
472
473 public Dictionary<string,object> GetUserInfo (UUID userID)
474 {
475 Hashtable hash = new Hashtable();
476 hash["userID"] = userID.ToString();
477
478 hash = CallServer("get_user_info", hash);
479
480 Dictionary<string, object> info = new Dictionary<string, object>();
481
482 foreach (object key in hash.Keys)
483 {
484 if (hash[key] != null)
485 {
486 info.Add(key.ToString(), hash[key]);
487 }
488 }
489
490 return info;
491 }
492
493 public Dictionary<string, object> GetServerURLs(UUID userID)
494 {
495 Hashtable hash = new Hashtable();
496 hash["userID"] = userID.ToString();
497
498 hash = CallServer("get_server_urls", hash);
499
500 Dictionary<string, object> serverURLs = new Dictionary<string, object>();
501 foreach (object key in hash.Keys)
502 {
503 if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null)
504 {
505 string serverType = key.ToString().Substring(4); // remove "SRV_"
506 serverURLs.Add(serverType, hash[key].ToString());
507 }
508 }
509
510 return serverURLs;
511 }
512
513 public string LocateUser(UUID userID)
514 {
515 Hashtable hash = new Hashtable();
516 hash["userID"] = userID.ToString();
517
518 hash = CallServer("locate_user", hash);
519
520 string url = string.Empty;
521
522 // Here's the actual response
523 if (hash.ContainsKey("URL"))
524 url = hash["URL"].ToString();
525
526 return url;
527 }
528
529 public string GetUUI(UUID userID, UUID targetUserID)
530 {
531 Hashtable hash = new Hashtable();
532 hash["userID"] = userID.ToString();
533 hash["targetUserID"] = targetUserID.ToString();
534
535 hash = CallServer("get_uui", hash);
536
537 string uui = string.Empty;
538
539 // Here's the actual response
540 if (hash.ContainsKey("UUI"))
541 uui = hash["UUI"].ToString();
542
543 return uui;
544 }
545
546 public UUID GetUUID(String first, String last)
547 {
548 Hashtable hash = new Hashtable();
549 hash["first"] = first;
550 hash["last"] = last;
551
552 hash = CallServer("get_uuid", hash);
553
554 if (!hash.ContainsKey("UUID"))
555 {
556 throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} didn't return a UUID", m_ServerURLHost));
557 }
558
559 UUID uuid;
560 if (!UUID.TryParse(hash["UUID"].ToString(), out uuid))
561 {
562 throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} returned an invalid UUID: {1}", m_ServerURLHost, hash["UUID"].ToString()));
563 }
564
565 return uuid;
566 }
567
568 private bool GetBoolResponse(XmlRpcRequest request, out string reason)
569 {
570 //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURLHost);
571 XmlRpcResponse response = null;
572 try
573 {
574 response = request.Send(m_ServerURL, 10000);
575 }
576 catch (Exception e)
577 {
578 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURLHost);
579 reason = "Exception: " + e.Message;
580 return false;
581 }
582
583 if (response.IsFault)
584 {
585 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURLHost, response.FaultString);
586 reason = "XMLRPC Fault";
587 return false;
588 }
589
590 Hashtable hash = (Hashtable)response.Value;
591 //foreach (Object o in hash)
592 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
593 try
594 {
595 if (hash == null)
596 {
597 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost);
598 reason = "Internal error 1";
599 return false;
600 }
601 bool success = false;
602 reason = string.Empty;
603 if (hash.ContainsKey("result"))
604 Boolean.TryParse((string)hash["result"], out success);
605 else
606 {
607 reason = "Internal error 2";
608 m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURLHost);
609 }
610
611 return success;
612 }
613 catch (Exception e)
614 {
615 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response.");
616 if (hash.ContainsKey("result") && hash["result"] != null)
617 m_log.ErrorFormat("Reply was ", (string)hash["result"]);
618 reason = "Exception: " + e.Message;
619 return false;
620 }
621
622 }
623
624 }
625}