29 using System.Collections;
30 using System.Collections.Generic;
33 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Services.Interfaces;
37 using OpenSim.Services.Connectors.Simulation;
40 using OpenMetaverse.StructuredData;
45 namespace OpenSim.Services.Connectors.Hypergrid
49 private static readonly ILog m_log =
51 MethodBase.GetCurrentMethod().DeclaringType);
53 private string m_ServerURLHost;
54 private string m_ServerURL;
63 m_ServerURL = m_ServerURLHost = url;
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(
"/"))
79 m_log.DebugFormat(
"[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", url, e.Message);
88 IConfig serviceConfig = config.Configs[
"UserAgentService"];
89 if (serviceConfig == null)
91 m_log.Error(
"[USER AGENT CONNECTOR]: UserAgentService missing from ini");
92 throw new Exception(
"UserAgent connector init error");
95 string serviceURI = serviceConfig.GetString(
"UserAgentServerURI",
98 if (serviceURI == String.Empty)
100 m_log.Error(
"[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService");
101 throw new Exception(
"UserAgent connector init error");
104 m_ServerURL = m_ServerURLHost = serviceURI;
105 if (!m_ServerURL.EndsWith(
"/"))
121 reason = String.Empty;
123 if (destination == null)
125 reason =
"Destination is null";
126 m_log.Debug(
"[USER AGENT CONNECTOR]: Given destination is null");
131 home.ServerURI = m_ServerURL;
132 home.RegionID = destination.RegionID;
133 home.RegionLocX = destination.RegionLocX;
134 home.RegionLocY = destination.RegionLocY;
136 m_Gatekeeper = gatekeeper;
138 Console.WriteLine(
" >>> LoginAgentToGrid <<< " + home.ServerURI);
140 uint flags = fromLogin ? (uint)
TeleportFlags.ViaLogin : (uint)TeleportFlags.ViaHome;
142 return CreateAgent(source, home, aCircuit, flags, ctx, out reason);
149 return LoginAgentToGrid(source, aCircuit, gatekeeper, destination,
false, out reason);
154 base.PackData(args, source, aCircuit, destination, flags);
155 args[
"gatekeeper_serveruri"] = OSD.FromString(m_Gatekeeper.ServerURI);
156 args[
"gatekeeper_host"] = OSD.FromString(m_Gatekeeper.ExternalHostName);
157 args[
"gatekeeper_port"] = OSD.FromString(m_Gatekeeper.HttpPort.ToString());
158 args[
"destination_serveruri"] = OSD.FromString(destination.ServerURI);
166 private Hashtable CallServer(
string methodName, Hashtable hash)
168 IList paramList =
new ArrayList();
171 XmlRpcRequest request =
new XmlRpcRequest(methodName, paramList);
174 XmlRpcResponse response = null;
177 response = request.Send(m_ServerURL, 10000);
181 m_log.DebugFormat(
"[USER AGENT CONNECTOR]: {0} call to {1} failed: {2}", methodName, m_ServerURLHost, e.Message);
185 if (response.IsFault)
187 throw new Exception(
string.Format(
"[USER AGENT CONNECTOR]: {0} call to {1} returned an error: {2}", methodName, m_ServerURLHost, response.FaultString));
190 hash = (Hashtable)response.Value;
194 throw new Exception(
string.Format(
"[USER AGENT CONNECTOR]: {0} call to {1} returned null", methodName, m_ServerURLHost));
202 position = Vector3.UnitY; lookAt = Vector3.UnitY;
204 Hashtable hash =
new Hashtable();
205 hash[
"userID"] = userID.ToString();
207 hash = CallServer(
"get_home_region", hash);
210 if (!Boolean.TryParse((
string)hash[
"result"], out success) || !success)
215 UUID.TryParse((string)hash[
"uuid"], out region.
RegionID);
218 if (hash[
"x"] != null)
220 Int32.TryParse((string)hash[
"x"], out n);
221 region.RegionLocX = n;
224 if (hash[
"y"] != null)
226 Int32.TryParse((string)hash[
"y"], out n);
227 region.RegionLocY = n;
230 if (hash[
"size_x"] != null)
232 Int32.TryParse((string)hash[
"size_x"], out n);
233 region.RegionSizeX = n;
236 if (hash[
"size_y"] != null)
238 Int32.TryParse((string)hash[
"size_y"], out n);
239 region.RegionSizeY = n;
242 if (hash[
"region_name"] != null)
244 region.RegionName = (string)hash[
"region_name"];
247 if (hash[
"hostname"] != null)
248 region.ExternalHostName = (string)hash[
"hostname"];
249 if (hash[
"http_port"] != null)
252 UInt32.TryParse((string)hash[
"http_port"], out p);
255 if (hash.ContainsKey(
"server_uri") && hash[
"server_uri"] != null)
256 region.
ServerURI = (
string)hash[
"server_uri"];
258 if (hash[
"internal_port"] != null)
261 Int32.TryParse((string)hash[
"internal_port"], out p);
262 region.InternalEndPoint =
new IPEndPoint(IPAddress.Parse(
"0.0.0.0"), p);
264 if (hash[
"position"] != null)
265 Vector3.TryParse((string)hash[
"position"], out position);
266 if (hash[
"lookAt"] != null)
267 Vector3.TryParse((string)hash[
"lookAt"], out lookAt);
275 Hashtable hash =
new Hashtable();
276 hash[
"sessionID"] = sessionID.ToString();
277 hash[
"externalName"] = thisGridExternalName;
279 IList paramList =
new ArrayList();
282 XmlRpcRequest request =
new XmlRpcRequest(
"agent_is_coming_home", paramList);
283 string reason = string.Empty;
284 return GetBoolResponse(request, out reason);
289 Hashtable hash =
new Hashtable();
290 hash[
"sessionID"] = sessionID.ToString();
291 hash[
"token"] = token;
293 IList paramList =
new ArrayList();
296 XmlRpcRequest request =
new XmlRpcRequest(
"verify_agent", paramList);
297 string reason = string.Empty;
298 return GetBoolResponse(request, out reason);
303 Hashtable hash =
new Hashtable();
304 hash[
"sessionID"] = sessionID.ToString();
305 hash[
"token"] = token;
307 IList paramList =
new ArrayList();
310 XmlRpcRequest request =
new XmlRpcRequest(
"verify_client", paramList);
311 string reason = string.Empty;
312 return GetBoolResponse(request, out reason);
317 Hashtable hash =
new Hashtable();
318 hash[
"sessionID"] = sessionID.ToString();
319 hash[
"userID"] = userID.ToString();
321 IList paramList =
new ArrayList();
324 XmlRpcRequest request =
new XmlRpcRequest(
"logout_agent", paramList);
325 string reason = string.Empty;
326 GetBoolResponse(request, out reason);
332 Hashtable hash =
new Hashtable();
333 hash[
"userID"] = userID.ToString();
334 hash[
"online"] = online.ToString();
336 foreach (
string s
in friends)
338 hash[
"friend_" + i.ToString()] = s;
342 IList paramList =
new ArrayList();
345 XmlRpcRequest request =
new XmlRpcRequest(
"status_notification", paramList);
349 List<UUID> friendsOnline =
new List<UUID>();
350 XmlRpcResponse response = null;
353 response = request.Send(m_ServerURL, 6000);
357 m_log.DebugFormat(
"[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURLHost);
359 return friendsOnline;
362 if (response.IsFault)
364 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURLHost, response.FaultString);
366 return friendsOnline;
369 hash = (Hashtable)response.Value;
376 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost);
378 return friendsOnline;
382 foreach (
object key in hash.Keys)
384 if (key is
string && ((
string)
key).StartsWith(
"friend_") && hash[
key] != null)
387 if (UUID.TryParse(hash[key].ToString(), out uuid))
388 friendsOnline.Add(uuid);
395 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
399 return friendsOnline;
405 Hashtable hash =
new Hashtable();
406 hash[
"userID"] = userID.ToString();
408 foreach (
string s
in friends)
410 hash[
"friend_" + i.ToString()] = s;
414 IList paramList =
new ArrayList();
417 XmlRpcRequest request =
new XmlRpcRequest(
"get_online_friends", paramList);
421 List<UUID> online =
new List<UUID>();
422 XmlRpcResponse response = null;
425 response = request.Send(m_ServerURL, 10000);
429 m_log.DebugFormat(
"[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURLHost);
434 if (response.IsFault)
436 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURLHost, response.FaultString);
441 hash = (Hashtable)response.Value;
448 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost);
454 foreach (
object key in hash.Keys)
456 if (key is
string && ((
string)
key).StartsWith(
"friend_") && hash[
key] != null)
459 if (UUID.TryParse(hash[key].ToString(), out uuid))
467 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
476 Hashtable hash =
new Hashtable();
477 hash[
"userID"] = userID.ToString();
479 hash = CallServer(
"get_user_info", hash);
481 Dictionary<string, object> info =
new Dictionary<string, object>();
483 foreach (
object key in hash.Keys)
485 if (hash[key] != null)
487 info.Add(key.ToString(), hash[key]);
496 Hashtable hash =
new Hashtable();
497 hash[
"userID"] = userID.ToString();
499 hash = CallServer(
"get_server_urls", hash);
501 Dictionary<string, object> serverURLs =
new Dictionary<string, object>();
502 foreach (
object key
in hash.Keys)
504 if (key is
string && ((
string)key).StartsWith(
"SRV_") && hash[key] != null)
506 string serverType = key.ToString().Substring(4);
507 serverURLs.Add(serverType, hash[
key].ToString());
516 Hashtable hash =
new Hashtable();
517 hash[
"userID"] = userID.ToString();
519 hash = CallServer(
"locate_user", hash);
521 string url = string.Empty;
524 if (hash.ContainsKey(
"URL"))
525 url = hash[
"URL"].ToString();
530 public string GetUUI(UUID userID, UUID targetUserID)
532 Hashtable hash =
new Hashtable();
533 hash[
"userID"] = userID.ToString();
534 hash[
"targetUserID"] = targetUserID.ToString();
536 hash = CallServer(
"get_uui", hash);
538 string uui = string.Empty;
541 if (hash.ContainsKey(
"UUI"))
542 uui = hash[
"UUI"].ToString();
547 public UUID
GetUUID(String first, String last)
549 Hashtable hash =
new Hashtable();
550 hash[
"first"] = first;
553 hash = CallServer(
"get_uuid", hash);
555 if (!hash.ContainsKey(
"UUID"))
557 throw new Exception(
string.Format(
"[USER AGENT CONNECTOR]: get_uuid call to {0} didn't return a UUID", m_ServerURLHost));
561 if (!UUID.TryParse(hash[
"UUID"].ToString(), out uuid))
563 throw new Exception(
string.Format(
"[USER AGENT CONNECTOR]: get_uuid call to {0} returned an invalid UUID: {1}", m_ServerURLHost, hash[
"UUID"].ToString()));
569 private bool GetBoolResponse(XmlRpcRequest request, out
string reason)
572 XmlRpcResponse response = null;
575 response = request.Send(m_ServerURL, 10000);
579 m_log.DebugFormat(
"[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURLHost);
580 reason =
"Exception: " + e.Message;
584 if (response.IsFault)
586 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURLHost, response.FaultString);
587 reason =
"XMLRPC Fault";
591 Hashtable hash = (Hashtable)response.Value;
598 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost);
599 reason =
"Internal error 1";
602 bool success =
false;
603 reason = string.Empty;
604 if (hash.ContainsKey(
"result"))
605 Boolean.TryParse((
string)hash[
"result"], out success);
608 reason =
"Internal error 2";
609 m_log.WarnFormat(
"[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURLHost);
616 m_log.ErrorFormat(
"[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response.");
617 if (hash.ContainsKey(
"result") && hash[
"result"] != null)
618 m_log.ErrorFormat(
"Reply was ", (
string)hash[
"result"]);
619 reason =
"Exception: " + e.Message;
bool VerifyAgent(UUID sessionID, string token)
UserAgentServiceConnector(string url)
OpenSim.Framework.Constants.TeleportFlags TeleportFlags
List< UUID > GetOnlineFriends(UUID userID, List< string > friends)
string LocateUser(UUID userID)
Returns the current location of a remote user.
UserAgentServiceConnector(string url, bool dnsLookup)
List< UUID > StatusNotification(List< string > friends, UUID userID, bool online)
bool VerifyClient(UUID sessionID, string token)
OpenMetaverse.StructuredData.OSDMap OSDMap
Dictionary< string, object > GetUserInfo(UUID userID)
Returns the UserInfo of a remote user.
UUID GetUUID(String first, String last)
Returns the remote user that has the given name.
UserAgentServiceConnector(IConfigSource config)
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
OpenSim.Services.Interfaces.GridRegion GridRegion
override string AgentPath()
bool LoginAgentToGrid(GridRegion source, AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason)
override void PackData(OSDMap args, GridRegion source, AgentCircuitData aCircuit, GridRegion destination, uint flags)
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt)
Returns the home region of a remote user.
Dictionary< string, object > GetServerURLs(UUID userID)
Returns the Server URLs of a remote user.
string GetUUI(UUID userID, UUID targetUserID)
Returns the Universal User Identifier for 'targetUserID' on behalf of 'userID'.
string ServerURI
A well-formed URI for the host region server (namely "http://" + ExternalHostName) ...
bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
bool LoginAgentToGrid(GridRegion source, AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, bool fromLogin, out string reason)
void SetClientToken(UUID sessionID, string token)
void LogoutAgent(UUID userID, UUID sessionID)