aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs2
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs2
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs200
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs2
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs76
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs68
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs138
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs29
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs12
-rw-r--r--OpenSim/Services/Interfaces/IHypergridServices.cs5
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs2
11 files changed, 171 insertions, 365 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
index 02ed1a0..0715324 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
@@ -273,7 +273,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
273 { 273 {
274 string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString(); 274 string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString();
275 IUserAgentService connector = new UserAgentServiceConnector(userAgentDriver); 275 IUserAgentService connector = new UserAgentServiceConnector(userAgentDriver);
276 bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason); 276 bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, false, out reason);
277 logout = success; // flag for later logout from this grid; this is an HG TP 277 logout = success; // flag for later logout from this grid; this is an HG TP
278 278
279 if (success) 279 if (success)
diff --git a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs
index cf1af15..adc2fbc 100644
--- a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs
@@ -61,7 +61,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
61 m_Proxy = proxy; 61 m_Proxy = proxy;
62 } 62 }
63 63
64 protected override bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 64 protected override bool CreateAgent(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
65 { 65 {
66 return m_GatekeeperService.LoginAgent(aCircuit, destination, out reason); 66 return m_GatekeeperService.LoginAgent(aCircuit, destination, out reason);
67 } 67 }
diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
index 968c1e6..df875af 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
@@ -49,191 +49,87 @@ using log4net;
49 49
50namespace OpenSim.Server.Handlers.Hypergrid 50namespace OpenSim.Server.Handlers.Hypergrid
51{ 51{
52 public class HomeAgentHandler 52 public class HomeAgentHandler : AgentPostHandler
53 { 53 {
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 private IUserAgentService m_UserAgentService; 55 private IUserAgentService m_UserAgentService;
56 56
57 private string m_LoginServerIP; 57 private string m_LoginServerIP;
58 private bool m_Proxy = false;
59 58
60 public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP, bool proxy) 59 public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP, bool proxy) :
60 base("/homeagent")
61 { 61 {
62 m_UserAgentService = userAgentService; 62 m_UserAgentService = userAgentService;
63 m_LoginServerIP = loginServerIP; 63 m_LoginServerIP = loginServerIP;
64 m_Proxy = proxy; 64 m_Proxy = proxy;
65 } 65 }
66 66
67 public Hashtable Handler(Hashtable request) 67 protected override AgentDestinationData CreateAgentDestinationData()
68 { 68 {
69// m_log.Debug("[CONNECTION DEBUGGING]: HomeAgentHandler Called"); 69 return new ExtendedAgentDestinationData();
70// 70 }
71// m_log.Debug("---------------------------"); 71 protected override void UnpackData(OSDMap args, AgentDestinationData d, Hashtable request)
72// m_log.Debug(" >> uri=" + request["uri"]); 72 {
73// m_log.Debug(" >> content-type=" + request["content-type"]); 73 base.UnpackData(args, d, request);
74// m_log.Debug(" >> http-method=" + request["http-method"]); 74 ExtendedAgentDestinationData data = (ExtendedAgentDestinationData)d;
75// m_log.Debug("---------------------------\n"); 75 try
76
77 Hashtable responsedata = new Hashtable();
78 responsedata["content_type"] = "text/html";
79 responsedata["keepalive"] = false;
80
81
82 UUID agentID;
83 UUID regionID;
84 string action;
85 if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action))
86 { 76 {
87 m_log.InfoFormat("[HOME AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); 77 if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
88 responsedata["int_response_code"] = 404; 78 data.host = args["gatekeeper_host"].AsString();
89 responsedata["str_response_string"] = "false"; 79 if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
80 Int32.TryParse(args["gatekeeper_port"].AsString(), out data.port);
81 if (args.ContainsKey("gatekeeper_serveruri") && args["gatekeeper_serveruri"] != null)
82 data.gatekeeperServerURI = args["gatekeeper_serveruri"];
83 if (args.ContainsKey("destination_serveruri") && args["destination_serveruri"] != null)
84 data.destinationServerURI = args["destination_serveruri"];
90 85
91 return responsedata;
92 } 86 }
93 87 catch (InvalidCastException e)
94 // Next, let's parse the verb
95 string method = (string)request["http-method"];
96 if (method.Equals("POST"))
97 { 88 {
98 DoAgentPost(request, responsedata, agentID); 89 m_log.ErrorFormat("[HOME AGENT HANDLER]: Bad cast in UnpackData");
99 return responsedata;
100 } 90 }
101 else
102 {
103 m_log.InfoFormat("[HOME AGENT HANDLER]: method {0} not supported in agent message", method);
104 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
105 responsedata["str_response_string"] = "Method not allowed";
106 91
107 return responsedata; 92 string callerIP = GetCallerIP(request);
108 } 93 // Verify if this call came from the login server
94 if (callerIP == m_LoginServerIP)
95 data.fromLogin = true;
109 96
110 } 97 }
111 98
112 protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) 99 protected override GridRegion ExtractGatekeeper(AgentDestinationData d)
113 { 100 {
114 OSDMap args = Utils.GetOSDMap((string)request["body"]); 101 if (d is ExtendedAgentDestinationData)
115 if (args == null)
116 { 102 {
117 responsedata["int_response_code"] = HttpStatusCode.BadRequest; 103 ExtendedAgentDestinationData data = (ExtendedAgentDestinationData)d;
118 responsedata["str_response_string"] = "Bad request"; 104 GridRegion gatekeeper = new GridRegion();
119 return; 105 gatekeeper.ServerURI = data.gatekeeperServerURI;
106 gatekeeper.ExternalHostName = data.host;
107 gatekeeper.HttpPort = (uint)data.port;
108 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
109
110 return gatekeeper;
120 } 111 }
121
122 // retrieve the input arguments
123 int x = 0, y = 0;
124 UUID uuid = UUID.Zero;
125 string regionname = string.Empty;
126 string gatekeeper_host = string.Empty;
127 string gatekeeper_serveruri = string.Empty;
128 string destination_serveruri = string.Empty;
129 int gatekeeper_port = 0;
130 IPEndPoint client_ipaddress = null;
131
132 if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
133 gatekeeper_host = args["gatekeeper_host"].AsString();
134 if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
135 Int32.TryParse(args["gatekeeper_port"].AsString(), out gatekeeper_port);
136 if (args.ContainsKey("gatekeeper_serveruri") && args["gatekeeper_serveruri"] !=null)
137 gatekeeper_serveruri = args["gatekeeper_serveruri"];
138 if (args.ContainsKey("destination_serveruri") && args["destination_serveruri"] !=null)
139 destination_serveruri = args["destination_serveruri"];
140
141 GridRegion gatekeeper = new GridRegion();
142 gatekeeper.ServerURI = gatekeeper_serveruri;
143 gatekeeper.ExternalHostName = gatekeeper_host;
144 gatekeeper.HttpPort = (uint)gatekeeper_port;
145 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
146
147 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
148 Int32.TryParse(args["destination_x"].AsString(), out x);
149 else 112 else
150 m_log.WarnFormat(" -- request didn't have destination_x"); 113 m_log.WarnFormat("[HOME AGENT HANDLER]: Wrong data type");
151 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
152 Int32.TryParse(args["destination_y"].AsString(), out y);
153 else
154 m_log.WarnFormat(" -- request didn't have destination_y");
155 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
156 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
157 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
158 regionname = args["destination_name"].ToString();
159
160 if (args.ContainsKey("client_ip") && args["client_ip"] != null)
161 {
162 string ip_str = args["client_ip"].ToString();
163 try
164 {
165 string callerIP = GetCallerIP(request);
166 // Verify if this caller has authority to send the client IP
167 if (callerIP == m_LoginServerIP)
168 client_ipaddress = new IPEndPoint(IPAddress.Parse(ip_str), 0);
169 else // leaving this for now, but this warning should be removed
170 m_log.WarnFormat("[HOME AGENT HANDLER]: Unauthorized machine {0} tried to set client ip to {1}", callerIP, ip_str);
171 }
172 catch
173 {
174 m_log.DebugFormat("[HOME AGENT HANDLER]: Exception parsing client ip address from {0}", ip_str);
175 }
176 }
177
178 GridRegion destination = new GridRegion();
179 destination.RegionID = uuid;
180 destination.RegionLocX = x;
181 destination.RegionLocY = y;
182 destination.RegionName = regionname;
183 destination.ServerURI = destination_serveruri;
184
185 AgentCircuitData aCircuit = new AgentCircuitData();
186 try
187 {
188 aCircuit.UnpackAgentCircuitData(args);
189 }
190 catch (Exception ex)
191 {
192 m_log.InfoFormat("[HOME AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
193 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
194 responsedata["str_response_string"] = "Bad request";
195 return;
196 }
197
198 OSDMap resp = new OSDMap(2);
199 string reason = String.Empty;
200 114
201 bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, client_ipaddress, out reason); 115 return null;
202
203 resp["reason"] = OSD.FromString(reason);
204 resp["success"] = OSD.FromBoolean(result);
205
206 // TODO: add reason if not String.Empty?
207 responsedata["int_response_code"] = HttpStatusCode.OK;
208 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
209 } 116 }
210 117
211 private string GetCallerIP(Hashtable request)
212 {
213 if (!m_Proxy)
214 return Util.GetCallerIP(request);
215
216 // We're behind a proxy
217 Hashtable headers = (Hashtable)request["headers"];
218 string xff = "X-Forwarded-For";
219 if (headers.ContainsKey(xff.ToLower()))
220 xff = xff.ToLower();
221 118
222 if (!headers.ContainsKey(xff) || headers[xff] == null) 119 protected override bool CreateAgent(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
223 { 120 {
224 m_log.WarnFormat("[AGENT HANDLER]: No XFF header"); 121 return m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, fromLogin, out reason);
225 return Util.GetCallerIP(request); 122 }
226 }
227 123
228 m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]); 124 }
229 125
230 IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]); 126 public class ExtendedAgentDestinationData : AgentDestinationData
231 if (ep != null) 127 {
232 return ep.Address.ToString(); 128 public string host;
129 public int port;
130 public string gatekeeperServerURI;
131 public string destinationServerURI;
233 132
234 // Oops
235 return Util.GetCallerIP(request);
236 }
237 } 133 }
238 134
239} 135}
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
index b20f467..d9c1bd3 100644
--- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
@@ -108,7 +108,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
108 server.AddXmlRPCHandler("get_uui", GetUUI, false); 108 server.AddXmlRPCHandler("get_uui", GetUUI, false);
109 server.AddXmlRPCHandler("get_uuid", GetUUID, false); 109 server.AddXmlRPCHandler("get_uuid", GetUUID, false);
110 110
111 server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); 111 server.AddStreamHandler(new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy));
112 } 112 }
113 113
114 public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) 114 public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index ae37ca7..334d313 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -328,31 +328,16 @@ namespace OpenSim.Server.Handlers.Simulation
328 return; 328 return;
329 } 329 }
330 330
331 // retrieve the input arguments 331 AgentDestinationData data = CreateAgentDestinationData();
332 int x = 0, y = 0; 332 UnpackData(args, data, request);
333 UUID uuid = UUID.Zero;
334 string regionname = string.Empty;
335 uint teleportFlags = 0;
336 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
337 Int32.TryParse(args["destination_x"].AsString(), out x);
338 else
339 m_log.WarnFormat(" -- request didn't have destination_x");
340 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
341 Int32.TryParse(args["destination_y"].AsString(), out y);
342 else
343 m_log.WarnFormat(" -- request didn't have destination_y");
344 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
345 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
346 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
347 regionname = args["destination_name"].ToString();
348 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
349 teleportFlags = args["teleport_flags"].AsUInteger();
350 333
351 GridRegion destination = new GridRegion(); 334 GridRegion destination = new GridRegion();
352 destination.RegionID = uuid; 335 destination.RegionID = data.uuid;
353 destination.RegionLocX = x; 336 destination.RegionLocX = data.x;
354 destination.RegionLocY = y; 337 destination.RegionLocY = data.y;
355 destination.RegionName = regionname; 338 destination.RegionName = data.name;
339
340 GridRegion gatekeeper = ExtractGatekeeper(data);
356 341
357 AgentCircuitData aCircuit = new AgentCircuitData(); 342 AgentCircuitData aCircuit = new AgentCircuitData();
358 try 343 try
@@ -373,7 +358,7 @@ namespace OpenSim.Server.Handlers.Simulation
373 // This is the meaning of POST agent 358 // This is the meaning of POST agent
374 //m_regionClient.AdjustUserInformation(aCircuit); 359 //m_regionClient.AdjustUserInformation(aCircuit);
375 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); 360 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
376 bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); 361 bool result = CreateAgent(gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason);
377 362
378 resp["reason"] = OSD.FromString(reason); 363 resp["reason"] = OSD.FromString(reason);
379 resp["success"] = OSD.FromBoolean(result); 364 resp["success"] = OSD.FromBoolean(result);
@@ -385,7 +370,36 @@ namespace OpenSim.Server.Handlers.Simulation
385 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); 370 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
386 } 371 }
387 372
388 private string GetCallerIP(Hashtable request) 373 protected virtual AgentDestinationData CreateAgentDestinationData()
374 {
375 return new AgentDestinationData();
376 }
377
378 protected virtual void UnpackData(OSDMap args, AgentDestinationData data, Hashtable request)
379 {
380 // retrieve the input arguments
381 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
382 Int32.TryParse(args["destination_x"].AsString(), out data.x);
383 else
384 m_log.WarnFormat(" -- request didn't have destination_x");
385 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
386 Int32.TryParse(args["destination_y"].AsString(), out data.y);
387 else
388 m_log.WarnFormat(" -- request didn't have destination_y");
389 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
390 UUID.TryParse(args["destination_uuid"].AsString(), out data.uuid);
391 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
392 data.name = args["destination_name"].ToString();
393 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
394 data.flags = args["teleport_flags"].AsUInteger();
395 }
396
397 protected virtual GridRegion ExtractGatekeeper(AgentDestinationData data)
398 {
399 return null;
400 }
401
402 protected string GetCallerIP(Hashtable request)
389 { 403 {
390 if (!m_Proxy) 404 if (!m_Proxy)
391 return Util.GetCallerIP(request); 405 return Util.GetCallerIP(request);
@@ -418,7 +432,7 @@ namespace OpenSim.Server.Handlers.Simulation
418 } 432 }
419 433
420 // subclasses can override this 434 // subclasses can override this
421 protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 435 protected virtual bool CreateAgent(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
422 { 436 {
423 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); 437 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
424 } 438 }
@@ -593,4 +607,14 @@ namespace OpenSim.Server.Handlers.Simulation
593 return m_SimulationService.UpdateAgent(destination, agent); 607 return m_SimulationService.UpdateAgent(destination, agent);
594 } 608 }
595 } 609 }
610
611 public class AgentDestinationData
612 {
613 public int x;
614 public int y;
615 public string name;
616 public UUID uuid;
617 public uint flags;
618 public bool fromLogin;
619 }
596} 620}
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
index 5bcff48..c9c6c31 100644
--- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -53,7 +53,8 @@ namespace OpenSim.Services.Connectors.Hypergrid
53 53
54 private IAssetService m_AssetService; 54 private IAssetService m_AssetService;
55 55
56 public GatekeeperServiceConnector() : base() 56 public GatekeeperServiceConnector()
57 : base()
57 { 58 {
58 } 59 }
59 60
@@ -123,11 +124,13 @@ namespace OpenSim.Services.Connectors.Hypergrid
123 realHandle = Convert.ToUInt64((string)hash["handle"]); 124 realHandle = Convert.ToUInt64((string)hash["handle"]);
124 //m_log.Debug(">> HERE, realHandle: " + realHandle); 125 //m_log.Debug(">> HERE, realHandle: " + realHandle);
125 } 126 }
126 if (hash["region_image"] != null) { 127 if (hash["region_image"] != null)
128 {
127 imageURL = (string)hash["region_image"]; 129 imageURL = (string)hash["region_image"];
128 //m_log.Debug(">> HERE, imageURL: " + imageURL); 130 //m_log.Debug(">> HERE, imageURL: " + imageURL);
129 } 131 }
130 if (hash["external_name"] != null) { 132 if (hash["external_name"] != null)
133 {
131 externalName = (string)hash["external_name"]; 134 externalName = (string)hash["external_name"];
132 //m_log.Debug(">> HERE, externalName: " + externalName); 135 //m_log.Debug(">> HERE, externalName: " + externalName);
133 } 136 }
@@ -178,7 +181,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
178 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); 181 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
179 imageData = OpenJPEG.EncodeFromImage(bitmap, true); 182 imageData = OpenJPEG.EncodeFromImage(bitmap, true);
180 } 183 }
181 184
182 AssetBase ass = new AssetBase(UUID.Random(), "region " + name, (sbyte)AssetType.Texture, regionID.ToString()); 185 AssetBase ass = new AssetBase(UUID.Random(), "region " + name, (sbyte)AssetType.Texture, regionID.ToString());
183 186
184 // !!! for now 187 // !!! for now
@@ -257,7 +260,8 @@ namespace OpenSim.Services.Connectors.Hypergrid
257 region.RegionName = (string)hash["region_name"]; 260 region.RegionName = (string)hash["region_name"];
258 //m_log.Debug(">> HERE, region_name: " + region.RegionName); 261 //m_log.Debug(">> HERE, region_name: " + region.RegionName);
259 } 262 }
260 if (hash["hostname"] != null) { 263 if (hash["hostname"] != null)
264 {
261 region.ExternalHostName = (string)hash["hostname"]; 265 region.ExternalHostName = (string)hash["hostname"];
262 //m_log.Debug(">> HERE, hostname: " + region.ExternalHostName); 266 //m_log.Debug(">> HERE, hostname: " + region.ExternalHostName);
263 } 267 }
@@ -275,10 +279,10 @@ namespace OpenSim.Services.Connectors.Hypergrid
275 region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); 279 region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
276 //m_log.Debug(">> HERE, internal_port: " + region.InternalEndPoint); 280 //m_log.Debug(">> HERE, internal_port: " + region.InternalEndPoint);
277 } 281 }
278 282
279 if (hash["server_uri"] != null) 283 if (hash["server_uri"] != null)
280 { 284 {
281 region.ServerURI = (string) hash["server_uri"]; 285 region.ServerURI = (string)hash["server_uri"];
282 //m_log.Debug(">> HERE, server_uri: " + region.ServerURI); 286 //m_log.Debug(">> HERE, server_uri: " + region.ServerURI);
283 } 287 }
284 288
@@ -295,55 +299,5 @@ namespace OpenSim.Services.Connectors.Hypergrid
295 299
296 return null; 300 return null;
297 } 301 }
298
299 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
300 {
301 // m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");
302
303 myipaddress = String.Empty;
304 reason = String.Empty;
305
306 if (destination == null)
307 {
308 m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
309 return false;
310 }
311
312 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
313
314 try
315 {
316 OSDMap args = aCircuit.PackAgentCircuitData();
317
318 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
319 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
320 args["destination_name"] = OSD.FromString(destination.RegionName);
321 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
322 args["teleport_flags"] = OSD.FromString(flags.ToString());
323
324 OSDMap result = WebUtil.PostToService(uri, args, 80000);
325 if (result["Success"].AsBoolean())
326 {
327 OSDMap unpacked = (OSDMap)result["_Result"];
328
329 if (unpacked != null)
330 {
331 reason = unpacked["reason"].AsString();
332 myipaddress = unpacked["your_ip"].AsString();
333 return unpacked["success"].AsBoolean();
334 }
335 }
336
337 reason = result["Message"] != null ? result["Message"].AsString() : "error";
338 return false;
339 }
340 catch (Exception e)
341 {
342 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
343 reason = e.Message;
344 }
345
346 return false;
347 }
348 } 302 }
349} 303}
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
index 47d0cce..d8a3184 100644
--- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -44,13 +44,14 @@ using Nini.Config;
44 44
45namespace OpenSim.Services.Connectors.Hypergrid 45namespace OpenSim.Services.Connectors.Hypergrid
46{ 46{
47 public class UserAgentServiceConnector : IUserAgentService 47 public class UserAgentServiceConnector : SimulationServiceConnector, IUserAgentService
48 { 48 {
49 private static readonly ILog m_log = 49 private static readonly ILog m_log =
50 LogManager.GetLogger( 50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType); 51 MethodBase.GetCurrentMethod().DeclaringType);
52 52
53 string m_ServerURL; 53 private string m_ServerURL;
54 private GridRegion m_Gatekeeper;
54 55
55 public UserAgentServiceConnector(string url) : this(url, true) 56 public UserAgentServiceConnector(string url) : this(url, true)
56 { 57 {
@@ -104,9 +105,15 @@ namespace OpenSim.Services.Connectors.Hypergrid
104 m_log.DebugFormat("[USER AGENT CONNECTOR]: UserAgentServiceConnector started for {0}", m_ServerURL); 105 m_log.DebugFormat("[USER AGENT CONNECTOR]: UserAgentServiceConnector started for {0}", m_ServerURL);
105 } 106 }
106 107
108 protected override string AgentPath()
109 {
110 return "homeagent/";
111 }
107 112
108 // The Login service calls this interface with a non-null [client] ipaddress 113 // The Login service calls this interface with fromLogin=true
109 public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress, out string reason) 114 // Sims call it with fromLogin=false
115 // Either way, this is verified by the handler
116 public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, bool fromLogin, out string reason)
110 { 117 {
111 reason = String.Empty; 118 reason = String.Empty;
112 119
@@ -117,119 +124,34 @@ namespace OpenSim.Services.Connectors.Hypergrid
117 return false; 124 return false;
118 } 125 }
119 126
120 string uri = m_ServerURL + "homeagent/" + aCircuit.AgentID + "/"; 127 GridRegion home = new GridRegion();
121 128 home.ServerURI = m_ServerURL;
122 Console.WriteLine(" >>> LoginAgentToGrid <<< " + uri); 129 home.RegionID = destination.RegionID;
123 130 home.RegionLocX = destination.RegionLocX;
124 HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); 131 home.RegionLocY = destination.RegionLocY;
125 AgentCreateRequest.Method = "POST";
126 AgentCreateRequest.ContentType = "application/json";
127 AgentCreateRequest.Timeout = 10000;
128 //AgentCreateRequest.KeepAlive = false;
129 //AgentCreateRequest.Headers.Add("Authorization", authKey);
130
131 // Fill it in
132 OSDMap args = PackCreateAgentArguments(aCircuit, gatekeeper, destination, ipaddress);
133
134 string strBuffer = "";
135 byte[] buffer = new byte[1];
136 try
137 {
138 strBuffer = OSDParser.SerializeJsonString(args);
139 Encoding str = Util.UTF8;
140 buffer = str.GetBytes(strBuffer);
141
142 }
143 catch (Exception e)
144 {
145 m_log.WarnFormat("[USER AGENT CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
146 // ignore. buffer will be empty, caller should check.
147 }
148
149 Stream os = null;
150 try
151 { // send the Post
152 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
153 os = AgentCreateRequest.GetRequestStream();
154 os.Write(buffer, 0, strBuffer.Length); //Send it
155 m_log.InfoFormat("[USER AGENT CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}",
156 uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY);
157 }
158 //catch (WebException ex)
159 catch
160 {
161 //m_log.InfoFormat("[USER AGENT CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
162 reason = "cannot contact remote region";
163 return false;
164 }
165 finally
166 {
167 if (os != null)
168 os.Close();
169 }
170
171 // Let's wait for the response
172 //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall");
173 132
174 try 133 m_Gatekeeper = gatekeeper;
175 {
176 using (WebResponse webResponse = AgentCreateRequest.GetResponse())
177 {
178 if (webResponse == null)
179 {
180 m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post");
181 }
182 else
183 {
184 using (Stream s = webResponse.GetResponseStream())
185 {
186 using (StreamReader sr = new StreamReader(s))
187 {
188 string response = sr.ReadToEnd().Trim();
189 m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
190
191 if (!String.IsNullOrEmpty(response))
192 {
193 try
194 {
195 // we assume we got an OSDMap back
196 OSDMap r = Util.GetOSDMap(response);
197 bool success = r["success"].AsBoolean();
198 reason = r["reason"].AsString();
199 return success;
200 }
201 catch (NullReferenceException e)
202 {
203 m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
204
205 // check for old style response
206 if (response.ToLower().StartsWith("true"))
207 return true;
208
209 return false;
210 }
211 }
212 }
213 }
214 }
215 }
216 }
217 catch (WebException ex)
218 {
219 m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
220 reason = "Destination did not reply";
221 return false;
222 }
223 134
224 return true; 135 Console.WriteLine(" >>> LoginAgentToGrid <<< " + home.ServerURI);
225 136
137 uint flags = fromLogin ? (uint)TeleportFlags.ViaLogin : (uint)TeleportFlags.ViaHome;
138 return CreateAgent(home, aCircuit, flags, out reason);
226 } 139 }
227 140
228 141
229 // The simulators call this interface 142 // The simulators call this interface
230 public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason) 143 public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason)
231 { 144 {
232 return LoginAgentToGrid(aCircuit, gatekeeper, destination, null, out reason); 145 return LoginAgentToGrid(aCircuit, gatekeeper, destination, false, out reason);
146 }
147
148 protected override void PackData(OSDMap args, AgentCircuitData aCircuit, GridRegion destination, uint flags)
149 {
150 base.PackData(args, aCircuit, destination, flags);
151 args["gatekeeper_serveruri"] = OSD.FromString(m_Gatekeeper.ServerURI);
152 args["gatekeeper_host"] = OSD.FromString(m_Gatekeeper.ExternalHostName);
153 args["gatekeeper_port"] = OSD.FromString(m_Gatekeeper.HttpPort.ToString());
154 args["destination_serveruri"] = OSD.FromString(destination.ServerURI);
233 } 155 }
234 156
235 protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress) 157 protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress)
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
index 57f2ffa..e247008 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -79,11 +79,27 @@ namespace OpenSim.Services.Connectors.Simulation
79 return "agent/"; 79 return "agent/";
80 } 80 }
81 81
82 protected virtual void PackData(OSDMap args, AgentCircuitData aCircuit, GridRegion destination, uint flags)
83 {
84 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
85 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
86 args["destination_name"] = OSD.FromString(destination.RegionName);
87 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
88 args["teleport_flags"] = OSD.FromString(flags.ToString());
89 }
90
82 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) 91 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason)
83 { 92 {
84 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent start"); 93 string tmp = String.Empty;
85 94 return CreateAgent(destination, aCircuit, flags, out tmp, out reason);
95 }
96
97 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
98 {
99 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Creating agent at {0}", destination.ServerURI);
86 reason = String.Empty; 100 reason = String.Empty;
101 myipaddress = String.Empty;
102
87 if (destination == null) 103 if (destination == null)
88 { 104 {
89 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); 105 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
@@ -95,12 +111,7 @@ namespace OpenSim.Services.Connectors.Simulation
95 try 111 try
96 { 112 {
97 OSDMap args = aCircuit.PackAgentCircuitData(); 113 OSDMap args = aCircuit.PackAgentCircuitData();
98 114 PackData(args, aCircuit, destination, flags);
99 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
100 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
101 args["destination_name"] = OSD.FromString(destination.RegionName);
102 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
103 args["teleport_flags"] = OSD.FromString(flags.ToString());
104 115
105 OSDMap result = WebUtil.PostToServiceCompressed(uri, args, 30000); 116 OSDMap result = WebUtil.PostToServiceCompressed(uri, args, 30000);
106 bool success = result["success"].AsBoolean(); 117 bool success = result["success"].AsBoolean();
@@ -110,6 +121,7 @@ namespace OpenSim.Services.Connectors.Simulation
110 121
111 reason = data["reason"].AsString(); 122 reason = data["reason"].AsString();
112 success = data["success"].AsBoolean(); 123 success = data["success"].AsBoolean();
124 myipaddress = data["your_ip"].AsString();
113 return success; 125 return success;
114 } 126 }
115 127
@@ -124,6 +136,7 @@ namespace OpenSim.Services.Connectors.Simulation
124 136
125 reason = data["reason"].AsString(); 137 reason = data["reason"].AsString();
126 success = data["success"].AsBoolean(); 138 success = data["success"].AsBoolean();
139 myipaddress = data["your_ip"].AsString();
127 m_log.WarnFormat( 140 m_log.WarnFormat(
128 "[REMOTE SIMULATION CONNECTOR]: Remote simulator {0} did not accept compressed transfer, suggest updating it.", destination.RegionName); 141 "[REMOTE SIMULATION CONNECTOR]: Remote simulator {0} did not accept compressed transfer, suggest updating it.", destination.RegionName);
129 return success; 142 return success;
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index 737e9c9..733993f 100644
--- a/OpenSim/Services/HypergridService/UserAgentService.cs
+++ b/OpenSim/Services/HypergridService/UserAgentService.cs
@@ -210,10 +210,10 @@ namespace OpenSim.Services.HypergridService
210 return home; 210 return home;
211 } 211 }
212 212
213 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, IPEndPoint clientIP, out string reason) 213 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, bool fromLogin, out string reason)
214 { 214 {
215 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}", 215 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}",
216 agentCircuit.firstname, agentCircuit.lastname, ((clientIP == null) ? "stored IP" : clientIP.Address.ToString()), gatekeeper.ServerURI); 216 agentCircuit.firstname, agentCircuit.lastname, (fromLogin ? agentCircuit.IPAddress : "stored IP"), gatekeeper.ServerURI);
217 217
218 string gridName = gatekeeper.ServerURI; 218 string gridName = gatekeeper.ServerURI;
219 219
@@ -265,7 +265,7 @@ namespace OpenSim.Services.HypergridService
265 bool success = false; 265 bool success = false;
266 string myExternalIP = string.Empty; 266 string myExternalIP = string.Empty;
267 267
268 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName); 268 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}, desired region: {2}", m_GridName, gridName, region.RegionID);
269 269
270 if (m_GridName == gridName) 270 if (m_GridName == gridName)
271 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason); 271 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason);
@@ -296,8 +296,8 @@ namespace OpenSim.Services.HypergridService
296 296
297 m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP); 297 m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP);
298 // else set the IP addresses associated with this client 298 // else set the IP addresses associated with this client
299 if (clientIP != null) 299 if (fromLogin)
300 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); 300 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = agentCircuit.IPAddress;
301 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; 301 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
302 302
303 return true; 303 return true;
@@ -306,7 +306,7 @@ namespace OpenSim.Services.HypergridService
306 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason) 306 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason)
307 { 307 {
308 reason = string.Empty; 308 reason = string.Empty;
309 return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, null, out reason); 309 return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, false, out reason);
310 } 310 }
311 311
312 private void SetClientIP(UUID sessionID, string ip) 312 private void SetClientIP(UUID sessionID, string ip)
diff --git a/OpenSim/Services/Interfaces/IHypergridServices.cs b/OpenSim/Services/Interfaces/IHypergridServices.cs
index 3dc877a..f9e7f08 100644
--- a/OpenSim/Services/Interfaces/IHypergridServices.cs
+++ b/OpenSim/Services/Interfaces/IHypergridServices.cs
@@ -48,10 +48,7 @@ namespace OpenSim.Services.Interfaces
48 /// </summary> 48 /// </summary>
49 public interface IUserAgentService 49 public interface IUserAgentService
50 { 50 {
51 // called by login service only 51 bool LoginAgentToGrid(AgentCircuitData agent, GridRegion gatekeeper, GridRegion finalDestination, bool fromLogin, out string reason);
52 bool LoginAgentToGrid(AgentCircuitData agent, GridRegion gatekeeper, GridRegion finalDestination, IPEndPoint clientIP, out string reason);
53 // called by simulators
54 bool LoginAgentToGrid(AgentCircuitData agent, GridRegion gatekeeper, GridRegion finalDestination, out string reason);
55 void LogoutAgent(UUID userID, UUID sessionID); 52 void LogoutAgent(UUID userID, UUID sessionID);
56 GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); 53 GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt);
57 Dictionary<string, object> GetServerURLs(UUID userID); 54 Dictionary<string, object> GetServerURLs(UUID userID);
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index 10cf90f..fe43582 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -933,7 +933,7 @@ namespace OpenSim.Services.LLLoginService
933 private bool LaunchAgentIndirectly(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, IPEndPoint clientIP, out string reason) 933 private bool LaunchAgentIndirectly(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, IPEndPoint clientIP, out string reason)
934 { 934 {
935 m_log.Debug("[LLOGIN SERVICE] Launching agent at " + destination.RegionName); 935 m_log.Debug("[LLOGIN SERVICE] Launching agent at " + destination.RegionName);
936 if (m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, clientIP, out reason)) 936 if (m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, true, out reason))
937 return true; 937 return true;
938 return false; 938 return false;
939 } 939 }