aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.AssetServer/SimProfiles.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenGridServices.AssetServer/SimProfiles.cs')
-rw-r--r--OpenGridServices.AssetServer/SimProfiles.cs328
1 files changed, 0 insertions, 328 deletions
diff --git a/OpenGridServices.AssetServer/SimProfiles.cs b/OpenGridServices.AssetServer/SimProfiles.cs
deleted file mode 100644
index ae40133..0000000
--- a/OpenGridServices.AssetServer/SimProfiles.cs
+++ /dev/null
@@ -1,328 +0,0 @@
1/*
2Copyright (c) OpenGrid project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Text;
32using System.Collections;
33using System.Collections.Generic;
34using libsecondlife;
35using OpenSim.Framework.Utilities;
36using OpenSim.Framework.Console;
37using OpenSim.Framework.Sims;
38using Db4objects.Db4o;
39using Nwc.XmlRpc;
40using System.Xml;
41
42namespace OpenGridServices.GridServer
43{
44 /// <summary>
45 /// </summary>
46 public class SimProfileManager
47 {
48
49 public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>();
50 private OpenGrid_Main m_gridManager;
51
52 public SimProfileManager(OpenGrid_Main gridManager)
53 {
54 m_gridManager = gridManager;
55 }
56
57 public void LoadProfiles()
58 { // should abstract this out
59 IObjectContainer db;
60 db = Db4oFactory.OpenFile("simprofiles.yap");
61 IObjectSet result = db.Get(typeof(SimProfileBase));
62 foreach (SimProfileBase simprof in result)
63 {
64 SimProfiles.Add(simprof.UUID, simprof);
65 }
66 MainConsole.Instance.WriteLine("SimProfiles.Cs:LoadProfiles() - Successfully loaded " + result.Count.ToString() + " from database");
67 db.Close();
68 }
69
70 public SimProfileBase GetProfileByHandle(ulong reqhandle)
71 {
72 foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys)
73 {
74 if (SimProfiles[UUID].regionhandle == reqhandle) return SimProfiles[UUID];
75 }
76 return null;
77 }
78
79 public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID)
80 {
81 foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys)
82 {
83 if (SimProfiles[UUID].UUID == ProfileLLUUID) return SimProfiles[UUID];
84 }
85 return null;
86 }
87
88 public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey)
89 {
90 SimProfileBase TheSim = GetProfileByHandle(regionhandle);
91 if (TheSim != null)
92 if (TheSim.recvkey == simrecvkey)
93 {
94 return true;
95 }
96 else
97 {
98 return false;
99 }
100 else return false;
101
102 }
103
104 public string GetXMLNeighbours(ulong reqhandle)
105 {
106 string response = "";
107 SimProfileBase central_region = GetProfileByHandle(reqhandle);
108 SimProfileBase neighbour;
109 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
110 {
111 if (GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256)) != null)
112 {
113 neighbour = GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256));
114 response += "<neighbour>";
115 response += "<sim_ip>" + neighbour.sim_ip + "</sim_ip>";
116 response += "<sim_port>" + neighbour.sim_port.ToString() + "</sim_port>";
117 response += "<locx>" + neighbour.RegionLocX.ToString() + "</locx>";
118 response += "<locy>" + neighbour.RegionLocY.ToString() + "</locy>";
119 response += "<regionhandle>" + neighbour.regionhandle.ToString() + "</regionhandle>";
120 response += "</neighbour>";
121
122 }
123 }
124 return response;
125 }
126
127 public SimProfileBase CreateNewProfile(string regionname, string caps_url, string sim_ip, uint sim_port, uint RegionLocX, uint RegionLocY, string sendkey, string recvkey)
128 {
129 SimProfileBase newprofile = new SimProfileBase();
130 newprofile.regionname = regionname;
131 newprofile.sim_ip = sim_ip;
132 newprofile.sim_port = sim_port;
133 newprofile.RegionLocX = RegionLocX;
134 newprofile.RegionLocY = RegionLocY;
135 newprofile.caps_url = "http://" + sim_ip + ":9000/";
136 newprofile.sendkey = sendkey;
137 newprofile.recvkey = recvkey;
138 newprofile.regionhandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256));
139 newprofile.UUID = LLUUID.Random();
140 this.SimProfiles.Add(newprofile.UUID, newprofile);
141 return newprofile;
142 }
143
144 public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request)
145 {
146 XmlRpcResponse response = new XmlRpcResponse();
147 Hashtable responseData = new Hashtable();
148 response.Value = responseData;
149
150 SimProfileBase TheSim = null;
151 Hashtable requestData = (Hashtable)request.Params[0];
152
153 if (requestData.ContainsKey("UUID"))
154 {
155 TheSim = GetProfileByLLUUID(new LLUUID((string)requestData["UUID"]));
156 }
157 else if (requestData.ContainsKey("region_handle"))
158 {
159 TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"]));
160 }
161
162 if (TheSim == null)
163 {
164 responseData["error"] = "sim not found";
165 }
166 else
167 {
168
169 ArrayList SimNeighboursData = new ArrayList();
170
171 SimProfileBase neighbour;
172 Hashtable NeighbourBlock;
173 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
174 {
175 if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null)
176 {
177 neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256));
178
179 NeighbourBlock = new Hashtable();
180 NeighbourBlock["sim_ip"] = neighbour.sim_ip;
181 NeighbourBlock["sim_port"] = neighbour.sim_port.ToString();
182 NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString();
183 NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString();
184 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
185
186 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
187 }
188 }
189
190 responseData["UUID"] = TheSim.UUID.ToString();
191 responseData["region_locx"] = TheSim.RegionLocX.ToString();
192 responseData["region_locy"] = TheSim.RegionLocY.ToString();
193 responseData["regionname"] = TheSim.regionname;
194 responseData["estate_id"] = "1";
195 responseData["neighbours"] = SimNeighboursData;
196
197 responseData["sim_ip"] = TheSim.sim_ip;
198 responseData["sim_port"] = TheSim.sim_port.ToString();
199 responseData["asset_url"] = m_gridManager.Cfg.DefaultAssetServer;
200 responseData["asset_sendkey"] = m_gridManager.Cfg.AssetSendKey;
201 responseData["asset_recvkey"] = m_gridManager.Cfg.AssetRecvKey;
202 responseData["user_url"] = m_gridManager.Cfg.DefaultUserServer;
203 responseData["user_sendkey"] = m_gridManager.Cfg.UserSendKey;
204 responseData["user_recvkey"] = m_gridManager.Cfg.UserRecvKey;
205 responseData["authkey"] = m_gridManager.Cfg.SimSendKey;
206 }
207
208 return response;
209 }
210
211 public string RestSetSimMethod(string request, string path, string param)
212 {
213 Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......");
214 SimProfileBase TheSim;
215 TheSim = GetProfileByLLUUID(new LLUUID(param));
216 if ((TheSim) == null)
217 {
218 TheSim = new SimProfileBase();
219 LLUUID UUID = new LLUUID(param);
220 TheSim.UUID = UUID;
221 }
222
223 XmlDocument doc = new XmlDocument();
224 doc.LoadXml(request);
225 XmlNode rootnode = doc.FirstChild;
226 XmlNode authkeynode = rootnode.ChildNodes[0];
227 if (authkeynode.Name != "authkey")
228 {
229 return "ERROR! bad XML - expected authkey tag";
230 }
231
232 XmlNode simnode = rootnode.ChildNodes[1];
233 if (simnode.Name != "sim")
234 {
235 return "ERROR! bad XML - expected sim tag";
236 }
237
238 if (authkeynode.InnerText != m_gridManager.Cfg.SimRecvKey)
239 {
240 return "ERROR! invalid key";
241 }
242 for (int i = 0; i < simnode.ChildNodes.Count; i++)
243 {
244 switch (simnode.ChildNodes[i].Name)
245 {
246 case "regionname":
247 TheSim.regionname = simnode.ChildNodes[i].InnerText;
248 break;
249
250 case "sim_ip":
251 TheSim.sim_ip = simnode.ChildNodes[i].InnerText;
252 break;
253
254 case "sim_port":
255 TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
256 break;
257
258 case "region_locx":
259 TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
260 TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
261 break;
262
263 case "region_locy":
264 TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
265 TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
266 break;
267 }
268 }
269
270 try
271 {
272 SimProfiles.Add(TheSim.UUID, TheSim);
273 IObjectContainer db;
274 db = Db4oFactory.OpenFile("simprofiles.yap");
275 db.Set(TheSim);
276 db.Close();
277 return "OK";
278 }
279 catch (Exception e)
280 {
281 return "ERROR! could not save to database!";
282 }
283
284 }
285
286 public string RestGetRegionMethod(string request, string path, string param)
287 {
288 SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param));
289 return RestGetSimMethod("", "/sims/", param);
290 }
291
292 public string RestSetRegionMethod(string request, string path, string param)
293 {
294 SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param));
295 return RestSetSimMethod("", "/sims/", param);
296 }
297
298 public string RestGetSimMethod(string request, string path, string param)
299 {
300 string respstring = String.Empty;
301
302 SimProfileBase TheSim;
303 LLUUID UUID = new LLUUID(param);
304 TheSim = GetProfileByLLUUID(UUID);
305
306 if (!(TheSim == null))
307 {
308 respstring = "<Root>";
309 respstring += "<authkey>" + m_gridManager.Cfg.SimSendKey + "</authkey>";
310 respstring += "<sim>";
311 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
312 respstring += "<regionname>" + TheSim.regionname + "</regionname>";
313 respstring += "<sim_ip>" + TheSim.sim_ip + "</sim_ip>";
314 respstring += "<sim_port>" + TheSim.sim_port.ToString() + "</sim_port>";
315 respstring += "<region_locx>" + TheSim.RegionLocX.ToString() + "</region_locx>";
316 respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
317 respstring += "<estate_id>1</estate_id>";
318 respstring += "</sim>";
319 respstring += "</Root>";
320 }
321
322 return respstring;
323 }
324
325 }
326
327
328}