29 using System.Collections.Generic;
32 using System.Reflection;
34 using System.Collections;
36 using OpenSim.Framework;
37 using OpenSim.Services.Interfaces;
41 using OpenMetaverse.StructuredData;
45 namespace OpenSim.Services.Connectors.Simulation
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private Dictionary<string,AgentPosition> m_updateAgentQueue =
new Dictionary<string,AgentPosition>();
86 args[
"source_x"] = OSD.FromString(source.RegionLocX.ToString());
87 args[
"source_y"] = OSD.FromString(source.RegionLocY.ToString());
88 args[
"source_name"] = OSD.FromString(source.RegionName);
89 args[
"source_uuid"] = OSD.FromString(source.RegionID.ToString());
94 args[
"destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
95 args[
"destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
96 args[
"destination_name"] = OSD.FromString(destination.RegionName);
97 args[
"destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
98 args[
"teleport_flags"] = OSD.FromString(flags.ToString());
103 string tmp = String.Empty;
104 return CreateAgent(source, destination, aCircuit, flags, ctx, out tmp, out reason);
109 m_log.DebugFormat(
"[REMOTE SIMULATION CONNECTOR]: Creating agent at {0}", destination.ServerURI);
110 reason = String.Empty;
111 myipaddress = String.Empty;
113 if (destination == null)
115 reason =
"Destination not found";
116 m_log.Debug(
"[REMOTE SIMULATION CONNECTOR]: Given destination is null");
120 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID +
"/";
124 OSDMap args = aCircuit.PackAgentCircuitData(ctx);
125 args[
"context"] = ctx.Pack();
126 PackData(args, source, aCircuit, destination, flags);
128 OSDMap result = WebUtil.PostToServiceCompressed(uri, args, 30000);
129 bool success = result[
"success"].AsBoolean();
130 if (success && result.ContainsKey(
"_Result"))
134 reason = data[
"reason"].AsString();
135 success = data[
"success"].AsBoolean();
136 myipaddress = data[
"your_ip"].AsString();
141 result = WebUtil.PostToService(uri, args, 30000,
false);
143 if (result[
"Success"].AsBoolean())
145 if (result.ContainsKey(
"_Result"))
149 reason = data[
"reason"].AsString();
150 success = data[
"success"].AsBoolean();
151 myipaddress = data[
"your_ip"].AsString();
153 "[REMOTE SIMULATION CONNECTOR]: Remote simulator {0} did not accept compressed transfer, suggest updating it.", destination.RegionName);
159 "[REMOTE SIMULATION CONNECTOR]: Failed to create agent {0} {1} at remote simulator {2}",
160 aCircuit.firstname, aCircuit.lastname, destination.RegionName);
161 reason = result[
"Message"] != null ? result[
"Message"].AsString() :
"error";
166 m_log.Warn(
"[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
181 private ExpiringCache<string, bool> _failedSims =
new ExpiringCache<string, bool>();
190 if (_failedSims.TryGetValue(destination.
ServerURI, out v))
199 string uri = destination.ServerURI + AgentPath() + data.AgentID +
"/";
200 lock (m_updateAgentQueue)
202 if (m_updateAgentQueue.ContainsKey(uri))
209 m_updateAgentQueue[uri] = data;
214 m_updateAgentQueue[uri] = data;
221 lock (m_updateAgentQueue)
226 pos = m_updateAgentQueue[uri];
234 m_updateAgentQueue.Remove(uri);
244 lock (m_updateAgentQueue)
246 _failedSims.AddOrUpdate(destination.ServerURI,
true, 120);
247 m_updateAgentQueue.Remove(uri);
260 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID +
"/";
264 OSDMap args = cAgentData.Pack(ctx);
266 args[
"destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
267 args[
"destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
268 args[
"destination_name"] = OSD.FromString(destination.RegionName);
269 args[
"destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
270 args[
"context"] = ctx.Pack();
272 OSDMap result = WebUtil.PutToServiceCompressed(uri, args, timeout);
273 if (result[
"Success"].AsBoolean())
276 result = WebUtil.PutToService(uri, args, timeout);
278 return result[
"Success"].AsBoolean();
282 m_log.Warn(
"[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
291 reason =
"Failed to contact destination";
295 IPEndPoint ext = destination.ExternalEndPoint;
296 if (ext == null)
return false;
299 string uri = destination.ServerURI + AgentPath() + agentID +
"/" + destination.RegionID.ToString() +
"/";
302 request.Add(
"viaTeleport", OSD.FromBoolean(viaTeleport));
303 request.Add(
"position", OSD.FromString(position.ToString()));
313 request.Add(
"context", ctx.Pack());
316 foreach (UUID feature
in featuresAvailable)
317 features.Add(OSD.FromString(feature.ToString()));
319 request.Add(
"features", features);
321 if (agentHomeURI != null)
322 request.Add(
"agent_home_uri", OSD.FromString(agentHomeURI));
326 OSDMap result = WebUtil.ServiceOSDRequest(uri, request,
"QUERYACCESS", 30000,
false,
false);
327 bool success = result[
"success"].AsBoolean();
328 if (result.ContainsKey(
"_Result"))
334 success = data[
"success"];
336 reason = data[
"reason"].AsString();
339 if (data.ContainsKey(
"negotiated_inbound_version") && data[
"negotiated_inbound_version"] != null)
341 ctx.InboundVersion = (float)data[
"negotiated_inbound_version"].AsReal();
342 ctx.OutboundVersion = (float)data[
"negotiated_outbound_version"].AsReal();
344 else if (data[
"version"] != null && data[
"version"].AsString() != string.Empty)
346 string versionString = data[
"version"].AsString();
347 String[] parts = versionString.Split(
new char[] {
'/'});
348 if (parts.Length > 1)
350 ctx.InboundVersion = float.Parse(parts[1]);
351 ctx.OutboundVersion = float.Parse(parts[1]);
356 "[REMOTE SIMULATION CONNECTOR]: QueryAccess to {0} returned {1}, reason {2}, version {3}/{4}",
357 uri, success, reason, ctx.InboundVersion, ctx.OutboundVersion);
360 if (!success || ctx.InboundVersion == 0f || ctx.OutboundVersion == 0f)
364 if (!result.ContainsKey(
"_Result"))
366 if (result.ContainsKey(
"Message"))
368 string message = result[
"Message"].AsString();
369 if (message ==
"Service request failed: [MethodNotAllowed] MethodNotAllowed")
371 m_log.Info(
"[REMOTE SIMULATION CONNECTOR]: The above web util error was caused by a TP to a sim that doesn't support QUERYACCESS and can be ignored");
375 reason = result[
"Message"];
379 reason =
"Communications failure";
386 featuresAvailable.Clear();
388 if (result.ContainsKey(
"features"))
392 foreach (
OSD o
in array)
393 featuresAvailable.Add(
new UUID(o.AsString()));
397 if (ctx.OutboundVersion < 0.5)
398 ctx.WearablesCount = AvatarWearable.LEGACY_VERSION_MAX_WEARABLES;
399 else if (ctx.OutboundVersion < 0.6)
400 ctx.WearablesCount = AvatarWearable.LEGACY_VERSION_MAX_WEARABLES + 1;
402 ctx.WearablesCount = -1;
408 m_log.WarnFormat(
"[REMOTE SIMULATION CONNECTOR] QueryAcesss failed with exception; {0}",e.ToString());
422 WebUtil.ServiceOSDRequest(uri, null,
"DELETE", 10000,
false,
false);
426 m_log.WarnFormat(
"[REMOTE SIMULATION CONNECTOR] ReleaseAgent failed with exception; {0}",e.ToString());
436 string uri = destination.ServerURI + AgentPath() +
id +
"/" + destination.RegionID.ToString() +
"/?auth=" + auth_code;
437 m_log.DebugFormat(
"[REMOTE SIMULATION CONNECTOR]: CloseAgent {0}", uri);
441 WebUtil.ServiceOSDRequest(uri, null,
"DELETE", 10000,
false,
false);
445 m_log.WarnFormat(
"[REMOTE SIMULATION CONNECTOR] CloseAgent failed with exception; {0}",e.ToString());
467 string uri = destination.ServerURI + ObjectPath() + sog.UUID +
"/";
473 args[
"sog"] = OSD.FromString(sog.ToXml2());
474 args[
"extra"] = OSD.FromString(sog.ExtraToXmlString());
475 args[
"modified"] = OSD.FromBoolean(sog.HasGroupChanged);
476 args[
"new_position"] = newPosition.ToString();
478 string state = sog.GetStateSnapshot();
479 if (state.Length > 0)
480 args[
"state"] = OSD.FromString(state);
483 args[
"destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
484 args[
"destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
485 args[
"destination_name"] = OSD.FromString(destination.RegionName);
486 args[
"destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
488 OSDMap result = WebUtil.PostToService(uri, args, 40000,
false);
492 bool success = result[
"success"].AsBoolean();
498 m_log.WarnFormat(
"[REMOTE SIMULATION CONNECTOR] CreateObject failed with exception; {0}",e.ToString());
bool ReleaseAgent(UUID origin, UUID id, string uri)
bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, List< UUID > featuresAvailable, EntityTransferContext ctx, out string reason)
Returns whether a propspective user is allowed to visit the region.
OpenMetaverse.StructuredData.OSDArray OSDArray
virtual void PackData(OSDMap args, GridRegion source, AgentCircuitData aCircuit, GridRegion destination, uint flags)
bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint flags, EntityTransferContext ctx, out string reason)
Ask the simulator hosting the destination to create an agent on that region.
OpenMetaverse.StructuredData.OSDMap OSDMap
static readonly float SimulationServiceVersionAcceptedMax
static readonly float SimulationServiceVersionSupportedMin
bool UpdateAgent(GridRegion destination, AgentData data, EntityTransferContext ctx)
Send complete data about an agent in this region to a neighbor
SimulationServiceConnector(IConfigSource config)
string RawServerURI
Provides direct access to the 'm_serverURI' field, without returning a generated URL if m_serverURI i...
SimulationServiceConnector()
bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint flags, EntityTransferContext ctx, out string myipaddress, out string reason)
OpenSim.Services.Interfaces.GridRegion GridRegion
bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog, bool isLocalCall)
static readonly float SimulationServiceVersionSupportedMax
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
OpenMetaverse.StructuredData.OSD OSD
delegate void UpdateAgent(IClientAPI remoteClient, AgentUpdateArgs agentData)
Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms.
bool CloseAgent(GridRegion destination, UUID id, string auth_code)
string ServerURI
A well-formed URI for the host region server (namely "http://" + ExternalHostName) ...
static readonly float SimulationServiceVersionAcceptedMin
This rules versioning regarding teleports, and compatibility between simulators in that regard...
virtual string AgentPath()
Interactive OpenSim region server
IScene GetScene(UUID regionId)
Retrieve the scene with the given region ID.
bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
ISimulationService GetInnerService()
virtual string ObjectPath()
bool UpdateAgent(GridRegion destination, AgentPosition data)
Send updated position information about an agent in this region to a neighbor This operation may be c...