aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs215
1 files changed, 189 insertions, 26 deletions
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
index 6f71197..fcf07c7 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -46,7 +46,7 @@ namespace OpenSim.Services.Connectors.Simulation
46 { 46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 private GridRegion m_Region; 49 //private GridRegion m_Region;
50 50
51 public SimulationServiceConnector() 51 public SimulationServiceConnector()
52 { 52 {
@@ -54,7 +54,7 @@ namespace OpenSim.Services.Connectors.Simulation
54 54
55 public SimulationServiceConnector(GridRegion region) 55 public SimulationServiceConnector(GridRegion region)
56 { 56 {
57 m_Region = region; 57 //m_Region = region;
58 } 58 }
59 59
60 public IScene GetScene(ulong regionHandle) 60 public IScene GetScene(ulong regionHandle)
@@ -64,7 +64,7 @@ namespace OpenSim.Services.Connectors.Simulation
64 64
65 #region Agents 65 #region Agents
66 66
67 public bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, uint flags, out string reason) 67 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason)
68 { 68 {
69 reason = String.Empty; 69 reason = String.Empty;
70 70
@@ -72,11 +72,11 @@ namespace OpenSim.Services.Connectors.Simulation
72 string uri = string.Empty; 72 string uri = string.Empty;
73 try 73 try
74 { 74 {
75 uri = "http://" + m_Region.ExternalEndPoint.Address + ":" + m_Region.HttpPort + "/agent/" + aCircuit.AgentID + "/"; 75 uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + aCircuit.AgentID + "/";
76 } 76 }
77 catch (Exception e) 77 catch (Exception e)
78 { 78 {
79 m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent create. Reason: " + e.Message); 79 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent create. Reason: " + e.Message);
80 reason = e.Message; 80 reason = e.Message;
81 return false; 81 return false;
82 } 82 }
@@ -98,11 +98,13 @@ namespace OpenSim.Services.Connectors.Simulation
98 } 98 }
99 catch (Exception e) 99 catch (Exception e)
100 { 100 {
101 m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message); 101 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message);
102 } 102 }
103 // Add the regionhandle and the name of the destination region 103 // Add the input arguments
104 args["destination_handle"] = OSD.FromString(m_Region.RegionHandle.ToString()); 104 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
105 args["destination_name"] = OSD.FromString(m_Region.RegionName); 105 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
106 args["destination_name"] = OSD.FromString(destination.RegionName);
107 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
106 args["teleport_flags"] = OSD.FromString(flags.ToString()); 108 args["teleport_flags"] = OSD.FromString(flags.ToString());
107 109
108 string strBuffer = ""; 110 string strBuffer = "";
@@ -116,7 +118,7 @@ namespace OpenSim.Services.Connectors.Simulation
116 } 118 }
117 catch (Exception e) 119 catch (Exception e)
118 { 120 {
119 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message); 121 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
120 // ignore. buffer will be empty, caller should check. 122 // ignore. buffer will be empty, caller should check.
121 } 123 }
122 124
@@ -126,12 +128,12 @@ namespace OpenSim.Services.Connectors.Simulation
126 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send 128 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
127 os = AgentCreateRequest.GetRequestStream(); 129 os = AgentCreateRequest.GetRequestStream();
128 os.Write(buffer, 0, strBuffer.Length); //Send it 130 os.Write(buffer, 0, strBuffer.Length); //Send it
129 //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri); 131 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateChildAgent request to remote sim {0}", uri);
130 } 132 }
131 //catch (WebException ex) 133 //catch (WebException ex)
132 catch 134 catch
133 { 135 {
134 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message); 136 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
135 reason = "cannot contact remote region"; 137 reason = "cannot contact remote region";
136 return false; 138 return false;
137 } 139 }
@@ -142,7 +144,7 @@ namespace OpenSim.Services.Connectors.Simulation
142 } 144 }
143 145
144 // Let's wait for the response 146 // Let's wait for the response
145 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); 147 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall");
146 148
147 WebResponse webResponse = null; 149 WebResponse webResponse = null;
148 StreamReader sr = null; 150 StreamReader sr = null;
@@ -151,14 +153,14 @@ namespace OpenSim.Services.Connectors.Simulation
151 webResponse = AgentCreateRequest.GetResponse(); 153 webResponse = AgentCreateRequest.GetResponse();
152 if (webResponse == null) 154 if (webResponse == null)
153 { 155 {
154 m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post"); 156 m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post");
155 } 157 }
156 else 158 else
157 { 159 {
158 160
159 sr = new StreamReader(webResponse.GetResponseStream()); 161 sr = new StreamReader(webResponse.GetResponseStream());
160 string response = sr.ReadToEnd().Trim(); 162 string response = sr.ReadToEnd().Trim();
161 m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response); 163 m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
162 164
163 if (!String.IsNullOrEmpty(response)) 165 if (!String.IsNullOrEmpty(response))
164 { 166 {
@@ -172,7 +174,7 @@ namespace OpenSim.Services.Connectors.Simulation
172 } 174 }
173 catch (NullReferenceException e) 175 catch (NullReferenceException e)
174 { 176 {
175 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message); 177 m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
176 178
177 // check for old style response 179 // check for old style response
178 if (response.ToLower().StartsWith("true")) 180 if (response.ToLower().StartsWith("true"))
@@ -185,7 +187,7 @@ namespace OpenSim.Services.Connectors.Simulation
185 } 187 }
186 catch (WebException ex) 188 catch (WebException ex)
187 { 189 {
188 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); 190 m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
189 // ignore, really 191 // ignore, really
190 } 192 }
191 finally 193 finally
@@ -197,28 +199,189 @@ namespace OpenSim.Services.Connectors.Simulation
197 return true; 199 return true;
198 } 200 }
199 201
200 public bool UpdateAgent(ulong regionHandle, AgentData data) 202 public bool UpdateAgent(GridRegion destination, AgentData data)
201 { 203 {
202 return false; 204 return UpdateAgent(destination, data);
203 } 205 }
204 206
205 public bool UpdateAgent(ulong regionHandle, AgentPosition data) 207 public bool UpdateAgent(GridRegion destination, AgentPosition data)
206 { 208 {
207 return false; 209 return UpdateAgent(destination, data);
208 } 210 }
209 211
210 public bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent) 212 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
213 {
214 // Eventually, we want to use a caps url instead of the agentID
215 string uri = string.Empty;
216 try
217 {
218 uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + cAgentData.AgentID + "/";
219 }
220 catch (Exception e)
221 {
222 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent update. Reason: " + e.Message);
223 return false;
224 }
225 //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri);
226
227 HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
228 ChildUpdateRequest.Method = "PUT";
229 ChildUpdateRequest.ContentType = "application/json";
230 ChildUpdateRequest.Timeout = 10000;
231 //ChildUpdateRequest.KeepAlive = false;
232
233 // Fill it in
234 OSDMap args = null;
235 try
236 {
237 args = cAgentData.Pack();
238 }
239 catch (Exception e)
240 {
241 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message);
242 }
243 // Add the input arguments
244 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
245 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
246 args["destination_name"] = OSD.FromString(destination.RegionName);
247 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
248
249 string strBuffer = "";
250 byte[] buffer = new byte[1];
251 try
252 {
253 strBuffer = OSDParser.SerializeJsonString(args);
254 Encoding str = Util.UTF8;
255 buffer = str.GetBytes(strBuffer);
256
257 }
258 catch (Exception e)
259 {
260 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
261 // ignore. buffer will be empty, caller should check.
262 }
263
264 Stream os = null;
265 try
266 { // send the Post
267 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
268 os = ChildUpdateRequest.GetRequestStream();
269 os.Write(buffer, 0, strBuffer.Length); //Send it
270 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted ChildAgentUpdate request to remote sim {0}", uri);
271 }
272 //catch (WebException ex)
273 catch
274 {
275 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
276
277 return false;
278 }
279 finally
280 {
281 if (os != null)
282 os.Close();
283 }
284
285 // Let's wait for the response
286 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate");
287
288 WebResponse webResponse = null;
289 StreamReader sr = null;
290 try
291 {
292 webResponse = ChildUpdateRequest.GetResponse();
293 if (webResponse == null)
294 {
295 m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post");
296 }
297
298 sr = new StreamReader(webResponse.GetResponseStream());
299 //reply = sr.ReadToEnd().Trim();
300 sr.ReadToEnd().Trim();
301 sr.Close();
302 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
303
304 }
305 catch (WebException ex)
306 {
307 m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate {0}", ex.Message);
308 // ignore, really
309 }
310 finally
311 {
312 if (sr != null)
313 sr.Close();
314 }
315
316 return true;
317 }
318
319 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
211 { 320 {
212 agent = null; 321 agent = null;
322 // Eventually, we want to use a caps url instead of the agentID
323 string uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + id + "/" + destination.RegionID.ToString() + "/";
324 //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri);
325
326 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
327 request.Method = "GET";
328 request.Timeout = 10000;
329 //request.Headers.Add("authorization", ""); // coming soon
330
331 HttpWebResponse webResponse = null;
332 string reply = string.Empty;
333 StreamReader sr = null;
334 try
335 {
336 webResponse = (HttpWebResponse)request.GetResponse();
337 if (webResponse == null)
338 {
339 m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get ");
340 }
341
342 sr = new StreamReader(webResponse.GetResponseStream());
343 reply = sr.ReadToEnd().Trim();
344
345 //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was " + reply);
346
347 }
348 catch (WebException ex)
349 {
350 m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message);
351 // ignore, really
352 return false;
353 }
354 finally
355 {
356 if (sr != null)
357 sr.Close();
358 }
359
360 if (webResponse.StatusCode == HttpStatusCode.OK)
361 {
362 // we know it's jason
363 OSDMap args = Util.GetOSDMap(reply);
364 if (args == null)
365 {
366 //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: Error getting OSDMap from reply");
367 return false;
368 }
369
370 agent = new CompleteAgentData();
371 agent.Unpack(args);
372 return true;
373 }
374
375 //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode);
213 return false; 376 return false;
214 } 377 }
215 378
216 public bool ReleaseAgent(ulong regionHandle, UUID id, string uri) 379 public bool ReleaseAgent(GridRegion destination, UUID id, string uri)
217 { 380 {
218 return false; 381 return false;
219 } 382 }
220 383
221 public bool CloseAgent(ulong regionHandle, UUID id) 384 public bool CloseAgent(GridRegion destination, UUID id)
222 { 385 {
223 return false; 386 return false;
224 } 387 }
@@ -227,12 +390,12 @@ namespace OpenSim.Services.Connectors.Simulation
227 390
228 #region Objects 391 #region Objects
229 392
230 public bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall) 393 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
231 { 394 {
232 return false; 395 return false;
233 } 396 }
234 397
235 public bool CreateObject(ulong regionHandle, UUID userID, UUID itemID) 398 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
236 { 399 {
237 return false; 400 return false;
238 } 401 }