diff options
author | Adam Frisby | 2007-05-04 06:53:32 +0000 |
---|---|---|
committer | Adam Frisby | 2007-05-04 06:53:32 +0000 |
commit | 9804b0e5f3fd75879d8da364f1e7b03b1d672564 (patch) | |
tree | 71cfa887b5a194eeb06c92d1b50e054958cc3229 | |
parent | Grid server V2.0! Now with extra crunchy SQL support. (diff) | |
download | opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.zip opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.tar.gz opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.tar.bz2 opensim-SC_OLD-9804b0e5f3fd75879d8da364f1e7b03b1d672564.tar.xz |
* Deleted old sim profiles
* Added new grid manager replacement
-rw-r--r-- | OpenGridServices.GridServer/GridManager.cs | 286 | ||||
-rw-r--r-- | OpenGridServices.GridServer/SimProfiles.cs | 328 |
2 files changed, 286 insertions, 328 deletions
diff --git a/OpenGridServices.GridServer/GridManager.cs b/OpenGridServices.GridServer/GridManager.cs new file mode 100644 index 0000000..0569816 --- /dev/null +++ b/OpenGridServices.GridServer/GridManager.cs | |||
@@ -0,0 +1,286 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Text; | ||
5 | using System.Reflection; | ||
6 | using OpenGrid.Framework.Data; | ||
7 | using OpenSim.Framework.Utilities; | ||
8 | using OpenSim.Framework.Console; | ||
9 | using OpenSim.Framework.Sims; | ||
10 | using libsecondlife; | ||
11 | using Nwc.XmlRpc; | ||
12 | using System.Xml; | ||
13 | |||
14 | namespace OpenGridServices.GridServer | ||
15 | { | ||
16 | class GridManager | ||
17 | { | ||
18 | Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>(); | ||
19 | |||
20 | public void AddPlugin(string FileName) | ||
21 | { | ||
22 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||
23 | |||
24 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
25 | { | ||
26 | if (pluginType.IsPublic) | ||
27 | { | ||
28 | if (!pluginType.IsAbstract) | ||
29 | { | ||
30 | Type typeInterface = pluginType.GetInterface("IGridData", true); | ||
31 | |||
32 | if (typeInterface != null) | ||
33 | { | ||
34 | IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
35 | plug.Initialise(); | ||
36 | this._plugins.Add(plug.getName(),plug); | ||
37 | |||
38 | } | ||
39 | |||
40 | typeInterface = null; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | pluginAssembly = null; | ||
46 | } | ||
47 | |||
48 | public SimProfileData getRegion(libsecondlife.LLUUID uuid) | ||
49 | { | ||
50 | foreach(KeyValuePair<string,IGridData> kvp in _plugins) { | ||
51 | try | ||
52 | { | ||
53 | return kvp.Value.GetProfileByLLUUID(uuid); | ||
54 | } | ||
55 | catch (Exception e) | ||
56 | { | ||
57 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("getRegionPlugin UUID " + kvp.Key + " is made of fail: " + e.ToString()); | ||
58 | } | ||
59 | } | ||
60 | return null; | ||
61 | } | ||
62 | |||
63 | public SimProfileData getRegion(ulong handle) | ||
64 | { | ||
65 | foreach (KeyValuePair<string, IGridData> kvp in _plugins) | ||
66 | { | ||
67 | try | ||
68 | { | ||
69 | return kvp.Value.GetProfileByHandle(handle); | ||
70 | } | ||
71 | catch (Exception e) | ||
72 | { | ||
73 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("getRegionPlugin Handle " + kvp.Key + " is made of fail: " + e.ToString()); | ||
74 | } | ||
75 | } | ||
76 | return null; | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Returns a XML String containing a list of the neighbouring regions | ||
81 | /// </summary> | ||
82 | /// <param name="reqhandle">The regionhandle for the center sim</param> | ||
83 | /// <returns>An XML string containing neighbour entities</returns> | ||
84 | public string GetXMLNeighbours(ulong reqhandle) | ||
85 | { | ||
86 | string response = ""; | ||
87 | SimProfileData central_region = getRegion(reqhandle); | ||
88 | SimProfileData neighbour; | ||
89 | for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) | ||
90 | { | ||
91 | if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null) | ||
92 | { | ||
93 | neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)); | ||
94 | response += "<neighbour>"; | ||
95 | response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>"; | ||
96 | response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>"; | ||
97 | response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>"; | ||
98 | response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>"; | ||
99 | response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>"; | ||
100 | response += "</neighbour>"; | ||
101 | |||
102 | } | ||
103 | } | ||
104 | return response; | ||
105 | } | ||
106 | |||
107 | public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request) | ||
108 | { | ||
109 | XmlRpcResponse response = new XmlRpcResponse(); | ||
110 | Hashtable responseData = new Hashtable(); | ||
111 | response.Value = responseData; | ||
112 | |||
113 | SimProfileData TheSim = null; | ||
114 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
115 | |||
116 | if (requestData.ContainsKey("UUID")) | ||
117 | { | ||
118 | TheSim = getRegion(new LLUUID((string)requestData["UUID"])); | ||
119 | } | ||
120 | else if (requestData.ContainsKey("region_handle")) | ||
121 | { | ||
122 | TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"])); | ||
123 | } | ||
124 | |||
125 | if (TheSim == null) | ||
126 | { | ||
127 | responseData["error"] = "sim not found"; | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | |||
132 | ArrayList SimNeighboursData = new ArrayList(); | ||
133 | |||
134 | SimProfileData neighbour; | ||
135 | Hashtable NeighbourBlock; | ||
136 | for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) | ||
137 | { | ||
138 | if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null) | ||
139 | { | ||
140 | neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)); | ||
141 | |||
142 | NeighbourBlock = new Hashtable(); | ||
143 | NeighbourBlock["sim_ip"] = neighbour.serverIP; | ||
144 | NeighbourBlock["sim_port"] = neighbour.serverPort.ToString(); | ||
145 | NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString(); | ||
146 | NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString(); | ||
147 | NeighbourBlock["UUID"] = neighbour.UUID.ToString(); | ||
148 | |||
149 | if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | responseData["UUID"] = TheSim.UUID.ToString(); | ||
154 | responseData["region_locx"] = TheSim.regionLocX.ToString(); | ||
155 | responseData["region_locy"] = TheSim.regionLocY.ToString(); | ||
156 | responseData["regionname"] = TheSim.regionName; | ||
157 | responseData["estate_id"] = "1"; | ||
158 | responseData["neighbours"] = SimNeighboursData; | ||
159 | |||
160 | responseData["sim_ip"] = TheSim.serverIP; | ||
161 | responseData["sim_port"] = TheSim.serverPort.ToString(); | ||
162 | responseData["asset_url"] = TheSim.regionAssetURI; | ||
163 | responseData["asset_sendkey"] = TheSim.regionAssetSendKey; | ||
164 | responseData["asset_recvkey"] = TheSim.regionAssetRecvKey; | ||
165 | responseData["user_url"] = TheSim.regionUserURI; | ||
166 | responseData["user_sendkey"] = TheSim.regionUserSendKey; | ||
167 | responseData["user_recvkey"] = TheSim.regionUserRecvKey; | ||
168 | responseData["authkey"] = TheSim.regionSecret; | ||
169 | } | ||
170 | |||
171 | return response; | ||
172 | } | ||
173 | |||
174 | |||
175 | public string RestGetRegionMethod(string request, string path, string param) | ||
176 | { | ||
177 | return RestGetSimMethod("", "/sims/", param); | ||
178 | } | ||
179 | |||
180 | public string RestSetRegionMethod(string request, string path, string param) | ||
181 | { | ||
182 | return RestSetSimMethod("", "/sims/", param); | ||
183 | } | ||
184 | |||
185 | |||
186 | public string RestGetSimMethod(string request, string path, string param) | ||
187 | { | ||
188 | string respstring = String.Empty; | ||
189 | |||
190 | SimProfileData TheSim; | ||
191 | LLUUID UUID = new LLUUID(param); | ||
192 | TheSim = getRegion(UUID); | ||
193 | |||
194 | if (!(TheSim == null)) | ||
195 | { | ||
196 | respstring = "<Root>"; | ||
197 | respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>"; | ||
198 | respstring += "<sim>"; | ||
199 | respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>"; | ||
200 | respstring += "<regionname>" + TheSim.regionName + "</regionname>"; | ||
201 | respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>"; | ||
202 | respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>"; | ||
203 | respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>"; | ||
204 | respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>"; | ||
205 | respstring += "<estate_id>1</estate_id>"; | ||
206 | respstring += "</sim>"; | ||
207 | respstring += "</Root>"; | ||
208 | } | ||
209 | |||
210 | return respstring; | ||
211 | } | ||
212 | |||
213 | |||
214 | public string RestSetSimMethod(string request, string path, string param) | ||
215 | { | ||
216 | Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......"); | ||
217 | SimProfileData TheSim; | ||
218 | TheSim = getRegion(new LLUUID(param)); | ||
219 | if ((TheSim) == null) | ||
220 | { | ||
221 | TheSim = new SimProfileData(); | ||
222 | LLUUID UUID = new LLUUID(param); | ||
223 | TheSim.UUID = UUID; | ||
224 | } | ||
225 | |||
226 | XmlDocument doc = new XmlDocument(); | ||
227 | doc.LoadXml(request); | ||
228 | XmlNode rootnode = doc.FirstChild; | ||
229 | XmlNode authkeynode = rootnode.ChildNodes[0]; | ||
230 | if (authkeynode.Name != "authkey") | ||
231 | { | ||
232 | return "ERROR! bad XML - expected authkey tag"; | ||
233 | } | ||
234 | |||
235 | XmlNode simnode = rootnode.ChildNodes[1]; | ||
236 | if (simnode.Name != "sim") | ||
237 | { | ||
238 | return "ERROR! bad XML - expected sim tag"; | ||
239 | } | ||
240 | |||
241 | if (authkeynode.InnerText != TheSim.regionRecvKey) | ||
242 | { | ||
243 | return "ERROR! invalid key"; | ||
244 | } | ||
245 | for (int i = 0; i < simnode.ChildNodes.Count; i++) | ||
246 | { | ||
247 | switch (simnode.ChildNodes[i].Name) | ||
248 | { | ||
249 | case "regionname": | ||
250 | TheSim.regionName = simnode.ChildNodes[i].InnerText; | ||
251 | break; | ||
252 | |||
253 | case "sim_ip": | ||
254 | TheSim.serverIP = simnode.ChildNodes[i].InnerText; | ||
255 | break; | ||
256 | |||
257 | case "sim_port": | ||
258 | TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); | ||
259 | break; | ||
260 | |||
261 | case "region_locx": | ||
262 | TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
263 | TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); | ||
264 | break; | ||
265 | |||
266 | case "region_locy": | ||
267 | TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
268 | TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); | ||
269 | break; | ||
270 | } | ||
271 | } | ||
272 | |||
273 | try | ||
274 | { | ||
275 | // NEEDS IMPLEMENTATION. | ||
276 | return "OK"; | ||
277 | } | ||
278 | catch (Exception e) | ||
279 | { | ||
280 | return "ERROR! could not save to database! (" + e.ToString() + ")"; | ||
281 | } | ||
282 | |||
283 | } | ||
284 | |||
285 | } | ||
286 | } | ||
diff --git a/OpenGridServices.GridServer/SimProfiles.cs b/OpenGridServices.GridServer/SimProfiles.cs deleted file mode 100644 index 6e228ae..0000000 --- a/OpenGridServices.GridServer/SimProfiles.cs +++ /dev/null | |||
@@ -1,328 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (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 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | using libsecondlife; | ||
35 | using OpenSim.Framework.Utilities; | ||
36 | using OpenSim.Framework.Console; | ||
37 | using OpenSim.Framework.Sims; | ||
38 | using Db4objects.Db4o; | ||
39 | using Nwc.XmlRpc; | ||
40 | using System.Xml; | ||
41 | |||
42 | namespace 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! (" + e.ToString() + ")"; | ||
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 | } | ||