aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Simulation
diff options
context:
space:
mode:
authorDiva Canto2009-12-31 11:42:33 -0800
committerDiva Canto2009-12-31 11:42:33 -0800
commitf4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9 (patch)
treee6874f6f3d74249308a058375481f6516d877086 /OpenSim/Services/Connectors/Simulation
parentSimulation handlers (agents & objects) completed. (diff)
downloadopensim-SC-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.zip
opensim-SC-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.tar.gz
opensim-SC-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.tar.bz2
opensim-SC-f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9.tar.xz
More progress on both the Simulation service and the Login service. Both still unfinished.
Diffstat (limited to 'OpenSim/Services/Connectors/Simulation')
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs242
1 files changed, 242 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
new file mode 100644
index 0000000..6f71197
--- /dev/null
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -0,0 +1,242 @@
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.Generic;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34
35using OpenSim.Framework;
36using OpenSim.Services.Interfaces;
37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38
39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
41using log4net;
42
43namespace OpenSim.Services.Connectors.Simulation
44{
45 public class SimulationServiceConnector : ISimulationService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private GridRegion m_Region;
50
51 public SimulationServiceConnector()
52 {
53 }
54
55 public SimulationServiceConnector(GridRegion region)
56 {
57 m_Region = region;
58 }
59
60 public IScene GetScene(ulong regionHandle)
61 {
62 return null;
63 }
64
65 #region Agents
66
67 public bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, uint flags, out string reason)
68 {
69 reason = String.Empty;
70
71 // Eventually, we want to use a caps url instead of the agentID
72 string uri = string.Empty;
73 try
74 {
75 uri = "http://" + m_Region.ExternalEndPoint.Address + ":" + m_Region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
76 }
77 catch (Exception e)
78 {
79 m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent create. Reason: " + e.Message);
80 reason = e.Message;
81 return false;
82 }
83
84 //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
85
86 HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
87 AgentCreateRequest.Method = "POST";
88 AgentCreateRequest.ContentType = "application/json";
89 AgentCreateRequest.Timeout = 10000;
90 //AgentCreateRequest.KeepAlive = false;
91 //AgentCreateRequest.Headers.Add("Authorization", authKey);
92
93 // Fill it in
94 OSDMap args = null;
95 try
96 {
97 args = aCircuit.PackAgentCircuitData();
98 }
99 catch (Exception e)
100 {
101 m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
102 }
103 // Add the regionhandle and the name of the destination region
104 args["destination_handle"] = OSD.FromString(m_Region.RegionHandle.ToString());
105 args["destination_name"] = OSD.FromString(m_Region.RegionName);
106 args["teleport_flags"] = OSD.FromString(flags.ToString());
107
108 string strBuffer = "";
109 byte[] buffer = new byte[1];
110 try
111 {
112 strBuffer = OSDParser.SerializeJsonString(args);
113 Encoding str = Util.UTF8;
114 buffer = str.GetBytes(strBuffer);
115
116 }
117 catch (Exception e)
118 {
119 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
120 // ignore. buffer will be empty, caller should check.
121 }
122
123 Stream os = null;
124 try
125 { // send the Post
126 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
127 os = AgentCreateRequest.GetRequestStream();
128 os.Write(buffer, 0, strBuffer.Length); //Send it
129 //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
130 }
131 //catch (WebException ex)
132 catch
133 {
134 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
135 reason = "cannot contact remote region";
136 return false;
137 }
138 finally
139 {
140 if (os != null)
141 os.Close();
142 }
143
144 // Let's wait for the response
145 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
146
147 WebResponse webResponse = null;
148 StreamReader sr = null;
149 try
150 {
151 webResponse = AgentCreateRequest.GetResponse();
152 if (webResponse == null)
153 {
154 m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
155 }
156 else
157 {
158
159 sr = new StreamReader(webResponse.GetResponseStream());
160 string response = sr.ReadToEnd().Trim();
161 m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
162
163 if (!String.IsNullOrEmpty(response))
164 {
165 try
166 {
167 // we assume we got an OSDMap back
168 OSDMap r = Util.GetOSDMap(response);
169 bool success = r["success"].AsBoolean();
170 reason = r["reason"].AsString();
171 return success;
172 }
173 catch (NullReferenceException e)
174 {
175 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
176
177 // check for old style response
178 if (response.ToLower().StartsWith("true"))
179 return true;
180
181 return false;
182 }
183 }
184 }
185 }
186 catch (WebException ex)
187 {
188 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
189 // ignore, really
190 }
191 finally
192 {
193 if (sr != null)
194 sr.Close();
195 }
196
197 return true;
198 }
199
200 public bool UpdateAgent(ulong regionHandle, AgentData data)
201 {
202 return false;
203 }
204
205 public bool UpdateAgent(ulong regionHandle, AgentPosition data)
206 {
207 return false;
208 }
209
210 public bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent)
211 {
212 agent = null;
213 return false;
214 }
215
216 public bool ReleaseAgent(ulong regionHandle, UUID id, string uri)
217 {
218 return false;
219 }
220
221 public bool CloseAgent(ulong regionHandle, UUID id)
222 {
223 return false;
224 }
225
226 #endregion Agents
227
228 #region Objects
229
230 public bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall)
231 {
232 return false;
233 }
234
235 public bool CreateObject(ulong regionHandle, UUID userID, UUID itemID)
236 {
237 return false;
238 }
239
240 #endregion Objects
241 }
242}