diff options
Diffstat (limited to '')
-rw-r--r-- | OpenGridServices.GridServer/SimProfiles.cs | 196 |
1 files changed, 175 insertions, 21 deletions
diff --git a/OpenGridServices.GridServer/SimProfiles.cs b/OpenGridServices.GridServer/SimProfiles.cs index 7aff434..fd4ba99 100644 --- a/OpenGridServices.GridServer/SimProfiles.cs +++ b/OpenGridServices.GridServer/SimProfiles.cs | |||
@@ -36,6 +36,8 @@ using OpenSim.Framework.Utilities; | |||
36 | using OpenSim.Framework.Console; | 36 | using OpenSim.Framework.Console; |
37 | using OpenSim.Framework.Sims; | 37 | using OpenSim.Framework.Sims; |
38 | using Db4objects.Db4o; | 38 | using Db4objects.Db4o; |
39 | using Nwc.XmlRpc; | ||
40 | using System.Xml; | ||
39 | 41 | ||
40 | namespace OpenGridServices.GridServer | 42 | namespace OpenGridServices.GridServer |
41 | { | 43 | { |
@@ -44,9 +46,11 @@ namespace OpenGridServices.GridServer | |||
44 | public class SimProfileManager { | 46 | public class SimProfileManager { |
45 | 47 | ||
46 | public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>(); | 48 | public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>(); |
49 | private OpenGrid_Main m_gridManager; | ||
47 | 50 | ||
48 | public SimProfileManager() { | 51 | public SimProfileManager(OpenGrid_Main gridManager) { |
49 | } | 52 | m_gridManager = gridManager; |
53 | } | ||
50 | 54 | ||
51 | public void LoadProfiles() { // should abstract this out | 55 | public void LoadProfiles() { // should abstract this out |
52 | IObjectContainer db; | 56 | IObjectContainer db; |
@@ -117,26 +121,176 @@ namespace OpenGridServices.GridServer | |||
117 | return newprofile; | 121 | return newprofile; |
118 | } | 122 | } |
119 | 123 | ||
124 | public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request) | ||
125 | { | ||
126 | XmlRpcResponse response = new XmlRpcResponse(); | ||
127 | Hashtable responseData = new Hashtable(); | ||
128 | response.Value = responseData; | ||
129 | |||
130 | SimProfileBase TheSim = null; | ||
131 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
132 | |||
133 | if (requestData.ContainsKey("UUID")) | ||
134 | { | ||
135 | TheSim = GetProfileByLLUUID(new LLUUID((string)requestData["UUID"])); | ||
136 | } | ||
137 | else if (requestData.ContainsKey("region_handle")) | ||
138 | { | ||
139 | TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"])); | ||
140 | } | ||
141 | |||
142 | if (TheSim == null) | ||
143 | { | ||
144 | responseData["error"] = "sim not found"; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | |||
149 | ArrayList SimNeighboursData = new ArrayList(); | ||
150 | |||
151 | SimProfileBase neighbour; | ||
152 | Hashtable NeighbourBlock; | ||
153 | for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) | ||
154 | { | ||
155 | if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null) | ||
156 | { | ||
157 | neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)); | ||
158 | NeighbourBlock = new Hashtable(); | ||
159 | NeighbourBlock["sim_ip"] = neighbour.sim_ip; | ||
160 | NeighbourBlock["sim_port"] = neighbour.sim_port.ToString(); | ||
161 | NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString(); | ||
162 | NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString(); | ||
163 | NeighbourBlock["UUID"] = neighbour.UUID.ToString(); | ||
164 | SimNeighboursData.Add(NeighbourBlock); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | responseData["UUID"] = TheSim.UUID; | ||
169 | responseData["region_locx"] = TheSim.RegionLocX.ToString(); | ||
170 | responseData["region_locy"] = TheSim.RegionLocY.ToString(); | ||
171 | responseData["regionname"] = TheSim.regionname; | ||
172 | responseData["estate_id"] = "1"; | ||
173 | responseData["neighbours"] = SimNeighboursData; | ||
174 | |||
175 | responseData["asset_url"] = m_gridManager.DefaultAssetServer; | ||
176 | responseData["asset_sendkey"] = m_gridManager.AssetSendKey; | ||
177 | responseData["asset_recvkey"] = m_gridManager.AssetRecvKey; | ||
178 | responseData["user_url"] = m_gridManager.DefaultUserServer; | ||
179 | responseData["user_sendkey"] = m_gridManager.UserSendKey; | ||
180 | responseData["user_recvkey"] = m_gridManager.UserRecvKey; | ||
181 | responseData["authkey"] = m_gridManager.SimSendKey; | ||
182 | } | ||
183 | |||
184 | return response; | ||
185 | } | ||
186 | |||
187 | public string RestSetSimMethod(string request, string path, string param) | ||
188 | { | ||
189 | string respstring = String.Empty; | ||
190 | |||
191 | SimProfileBase TheSim; | ||
192 | LLUUID UUID = new LLUUID(param); | ||
193 | TheSim = GetProfileByLLUUID(UUID); | ||
194 | |||
195 | if (!(TheSim == null)) | ||
196 | { | ||
197 | Console.WriteLine("Updating sim details....."); | ||
198 | XmlDocument doc = new XmlDocument(); | ||
199 | doc.LoadXml(request); | ||
200 | XmlNode authkeynode = doc.FirstChild; | ||
201 | if (authkeynode.Name != "authkey") | ||
202 | { | ||
203 | respstring = "ERROR! bad XML - expected authkey tag"; | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | XmlNode simnode = doc.ChildNodes[1]; | ||
208 | if (simnode.Name != "sim") | ||
209 | { | ||
210 | respstring = "ERROR! bad XML - expected sim tag"; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | if (authkeynode.Name != m_gridManager.SimRecvKey) | ||
215 | { | ||
216 | respstring = "ERROR! invalid key"; | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | if (TheSim == null) | ||
221 | { | ||
222 | respstring = "ERROR! sim not found"; | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | for (int i = 0; i <= simnode.ChildNodes.Count; i++) | ||
227 | { | ||
228 | switch (simnode.ChildNodes[i].Name) | ||
229 | { | ||
230 | case "uuid": | ||
231 | // should a sim be able to update it's own UUID? To be decided | ||
232 | // watch next week for the exciting conclusion in "the adventures of OpenGridServices.GridServer/GridHttp.cs:ParseREST() at line 190! | ||
233 | break; // and line 190's arch-enemy - THE BREAK STATEMENT! OH NOES!!!!! (this code written at 6:57AM, no sleep, lots of caffeine) | ||
234 | |||
235 | case "regionname": | ||
236 | TheSim.regionname = simnode.ChildNodes[i].InnerText; | ||
237 | break; | ||
238 | |||
239 | case "sim_ip": | ||
240 | TheSim.sim_ip = simnode.ChildNodes[i].InnerText; | ||
241 | break; | ||
242 | |||
243 | case "sim_port": | ||
244 | TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); | ||
245 | break; | ||
246 | |||
247 | case "region_locx": | ||
248 | TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
249 | TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); | ||
250 | break; | ||
251 | |||
252 | case "region_locy": | ||
253 | TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
254 | TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); | ||
255 | break; | ||
256 | } | ||
257 | } | ||
258 | respstring = "OK"; | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | } | ||
263 | } | ||
264 | |||
265 | return respstring; | ||
266 | } | ||
267 | |||
268 | public string RestGetSimMethod(string request, string path, string param ) | ||
269 | { | ||
270 | string respstring = String.Empty; | ||
271 | |||
272 | SimProfileBase TheSim; | ||
273 | LLUUID UUID = new LLUUID(param); | ||
274 | TheSim = GetProfileByLLUUID(UUID); | ||
275 | |||
276 | if (!(TheSim == null)) | ||
277 | { | ||
278 | respstring = "<authkey>" + m_gridManager.SimSendKey + "</authkey>"; | ||
279 | respstring += "<sim>"; | ||
280 | respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>"; | ||
281 | respstring += "<regionname>" + TheSim.regionname + "</regionname>"; | ||
282 | respstring += "<sim_ip>" + TheSim.sim_ip + "</sim_ip>"; | ||
283 | respstring += "<sim_port>" + TheSim.sim_port.ToString() + "</sim_port>"; | ||
284 | respstring += "<region_locx>" + TheSim.RegionLocX.ToString() + "</region_locx>"; | ||
285 | respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>"; | ||
286 | respstring += "<estate_id>1</estate_id>"; | ||
287 | respstring += "</sim>"; | ||
288 | } | ||
289 | |||
290 | return respstring; | ||
291 | } | ||
292 | |||
120 | } | 293 | } |
121 | 294 | ||
122 | /* is in OpenSim.Framework | ||
123 | public class SimProfileBase { | ||
124 | public LLUUID UUID; | ||
125 | public ulong regionhandle; | ||
126 | public string regionname; | ||
127 | public string sim_ip; | ||
128 | public uint sim_port; | ||
129 | public string caps_url; | ||
130 | public uint RegionLocX; | ||
131 | public uint RegionLocY; | ||
132 | public string sendkey; | ||
133 | public string recvkey; | ||
134 | |||
135 | |||
136 | public SimProfileBase() { | ||
137 | } | ||
138 | |||
139 | |||
140 | }*/ | ||
141 | 295 | ||
142 | } | 296 | } |