diff options
author | MW | 2007-04-25 13:03:48 +0000 |
---|---|---|
committer | MW | 2007-04-25 13:03:48 +0000 |
commit | f7b51d63a87a6703d7cb8f376d1f3f7ec6ede8a0 (patch) | |
tree | b9f8f1dac346906f1333aa3fc8da704466eda005 /OpenGridServices.GridServer | |
parent | * Added try{}catch{} to RunTerrainCmd (diff) | |
download | opensim-SC_OLD-f7b51d63a87a6703d7cb8f376d1f3f7ec6ede8a0.zip opensim-SC_OLD-f7b51d63a87a6703d7cb8f376d1f3f7ec6ede8a0.tar.gz opensim-SC_OLD-f7b51d63a87a6703d7cb8f376d1f3f7ec6ede8a0.tar.bz2 opensim-SC_OLD-f7b51d63a87a6703d7cb8f376d1f3f7ec6ede8a0.tar.xz |
Small clean up of files and directories
Diffstat (limited to 'OpenGridServices.GridServer')
-rw-r--r-- | OpenGridServices.GridServer/SimProfiles.cs | 341 |
1 files changed, 182 insertions, 159 deletions
diff --git a/OpenGridServices.GridServer/SimProfiles.cs b/OpenGridServices.GridServer/SimProfiles.cs index bd91d5b..ae40133 100644 --- a/OpenGridServices.GridServer/SimProfiles.cs +++ b/OpenGridServices.GridServer/SimProfiles.cs | |||
@@ -41,88 +41,105 @@ using System.Xml; | |||
41 | 41 | ||
42 | namespace OpenGridServices.GridServer | 42 | namespace OpenGridServices.GridServer |
43 | { | 43 | { |
44 | /// <summary> | 44 | /// <summary> |
45 | /// </summary> | 45 | /// </summary> |
46 | public class SimProfileManager { | 46 | public class SimProfileManager |
47 | 47 | { | |
48 | public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>(); | 48 | |
49 | private OpenGrid_Main m_gridManager; | 49 | public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>(); |
50 | 50 | private OpenGrid_Main m_gridManager; | |
51 | public SimProfileManager(OpenGrid_Main gridManager) { | 51 | |
52 | m_gridManager = gridManager; | 52 | public SimProfileManager(OpenGrid_Main gridManager) |
53 | } | 53 | { |
54 | 54 | m_gridManager = gridManager; | |
55 | public void LoadProfiles() { // should abstract this out | 55 | } |
56 | IObjectContainer db; | 56 | |
57 | db = Db4oFactory.OpenFile("simprofiles.yap"); | 57 | public void LoadProfiles() |
58 | IObjectSet result = db.Get(typeof(SimProfileBase)); | 58 | { // should abstract this out |
59 | foreach (SimProfileBase simprof in result) { | 59 | IObjectContainer db; |
60 | SimProfiles.Add(simprof.UUID, simprof); | 60 | db = Db4oFactory.OpenFile("simprofiles.yap"); |
61 | } | 61 | IObjectSet result = db.Get(typeof(SimProfileBase)); |
62 | MainConsole.Instance.WriteLine("SimProfiles.Cs:LoadProfiles() - Successfully loaded " + result.Count.ToString() + " from database"); | 62 | foreach (SimProfileBase simprof in result) |
63 | db.Close(); | 63 | { |
64 | } | 64 | SimProfiles.Add(simprof.UUID, simprof); |
65 | 65 | } | |
66 | public SimProfileBase GetProfileByHandle(ulong reqhandle) { | 66 | MainConsole.Instance.WriteLine("SimProfiles.Cs:LoadProfiles() - Successfully loaded " + result.Count.ToString() + " from database"); |
67 | foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) { | 67 | db.Close(); |
68 | if(SimProfiles[UUID].regionhandle==reqhandle) return SimProfiles[UUID]; | 68 | } |
69 | } | 69 | |
70 | return null; | 70 | public SimProfileBase GetProfileByHandle(ulong reqhandle) |
71 | } | 71 | { |
72 | 72 | foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) | |
73 | public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID) { | 73 | { |
74 | foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) { | 74 | if (SimProfiles[UUID].regionhandle == reqhandle) return SimProfiles[UUID]; |
75 | if(SimProfiles[UUID].UUID==ProfileLLUUID) return SimProfiles[UUID]; | 75 | } |
76 | } | 76 | return null; |
77 | return null; | 77 | } |
78 | } | 78 | |
79 | 79 | public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID) | |
80 | public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey) { | 80 | { |
81 | SimProfileBase TheSim=GetProfileByHandle(regionhandle); | 81 | foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) |
82 | if(TheSim != null) | 82 | { |
83 | if(TheSim.recvkey==simrecvkey) { | 83 | if (SimProfiles[UUID].UUID == ProfileLLUUID) return SimProfiles[UUID]; |
84 | return true; | 84 | } |
85 | } else { | 85 | return null; |
86 | return false; | 86 | } |
87 | } else return false; | 87 | |
88 | 88 | public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey) | |
89 | } | 89 | { |
90 | 90 | SimProfileBase TheSim = GetProfileByHandle(regionhandle); | |
91 | public string GetXMLNeighbours(ulong reqhandle) { | 91 | if (TheSim != null) |
92 | string response=""; | 92 | if (TheSim.recvkey == simrecvkey) |
93 | SimProfileBase central_region = GetProfileByHandle(reqhandle); | 93 | { |
94 | SimProfileBase neighbour; | 94 | return true; |
95 | for(int x=-1; x<2; x++) for(int y=-1; y<2; y++) { | 95 | } |
96 | if(GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX+x)*256), (uint)(central_region.RegionLocY+y)*256))!=null) { | 96 | else |
97 | neighbour=GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX+x)*256), (uint)(central_region.RegionLocY+y)*256)); | 97 | { |
98 | response+="<neighbour>"; | 98 | return false; |
99 | response+="<sim_ip>" + neighbour.sim_ip + "</sim_ip>"; | 99 | } |
100 | response+="<sim_port>" + neighbour.sim_port.ToString() + "</sim_port>"; | 100 | else return false; |
101 | response+="<locx>" + neighbour.RegionLocX.ToString() + "</locx>"; | 101 | |
102 | response+="<locy>" + neighbour.RegionLocY.ToString() + "</locy>"; | 102 | } |
103 | response+="<regionhandle>" + neighbour.regionhandle.ToString() + "</regionhandle>"; | 103 | |
104 | response+="</neighbour>"; | 104 | public string GetXMLNeighbours(ulong reqhandle) |
105 | 105 | { | |
106 | } | 106 | string response = ""; |
107 | } | 107 | SimProfileBase central_region = GetProfileByHandle(reqhandle); |
108 | return response; | 108 | SimProfileBase neighbour; |
109 | } | 109 | for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) |
110 | 110 | { | |
111 | public SimProfileBase CreateNewProfile(string regionname, string caps_url, string sim_ip, uint sim_port, uint RegionLocX, uint RegionLocY, string sendkey, string recvkey) { | 111 | if (GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256)) != null) |
112 | SimProfileBase newprofile = new SimProfileBase(); | 112 | { |
113 | newprofile.regionname=regionname; | 113 | neighbour = GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256)); |
114 | newprofile.sim_ip=sim_ip; | 114 | response += "<neighbour>"; |
115 | newprofile.sim_port=sim_port; | 115 | response += "<sim_ip>" + neighbour.sim_ip + "</sim_ip>"; |
116 | newprofile.RegionLocX=RegionLocX; | 116 | response += "<sim_port>" + neighbour.sim_port.ToString() + "</sim_port>"; |
117 | newprofile.RegionLocY=RegionLocY; | 117 | response += "<locx>" + neighbour.RegionLocX.ToString() + "</locx>"; |
118 | newprofile.caps_url="http://" + sim_ip + ":9000/"; | 118 | response += "<locy>" + neighbour.RegionLocY.ToString() + "</locy>"; |
119 | newprofile.sendkey=sendkey; | 119 | response += "<regionhandle>" + neighbour.regionhandle.ToString() + "</regionhandle>"; |
120 | newprofile.recvkey=recvkey; | 120 | response += "</neighbour>"; |
121 | newprofile.regionhandle=Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); | 121 | |
122 | newprofile.UUID=LLUUID.Random(); | 122 | } |
123 | this.SimProfiles.Add(newprofile.UUID,newprofile); | 123 | } |
124 | return newprofile; | 124 | return response; |
125 | } | 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 | } | ||
126 | 143 | ||
127 | public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request) | 144 | public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request) |
128 | { | 145 | { |
@@ -158,15 +175,15 @@ namespace OpenGridServices.GridServer | |||
158 | if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null) | 175 | if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null) |
159 | { | 176 | { |
160 | neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)); | 177 | neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)); |
161 | 178 | ||
162 | NeighbourBlock = new Hashtable(); | 179 | NeighbourBlock = new Hashtable(); |
163 | NeighbourBlock["sim_ip"] = neighbour.sim_ip; | 180 | NeighbourBlock["sim_ip"] = neighbour.sim_ip; |
164 | NeighbourBlock["sim_port"] = neighbour.sim_port.ToString(); | 181 | NeighbourBlock["sim_port"] = neighbour.sim_port.ToString(); |
165 | NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString(); | 182 | NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString(); |
166 | NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString(); | 183 | NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString(); |
167 | NeighbourBlock["UUID"] = neighbour.UUID.ToString(); | 184 | NeighbourBlock["UUID"] = neighbour.UUID.ToString(); |
168 | 185 | ||
169 | if(neighbour.UUID!=TheSim.UUID) SimNeighboursData.Add(NeighbourBlock); | 186 | if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock); |
170 | } | 187 | } |
171 | } | 188 | } |
172 | 189 | ||
@@ -176,9 +193,9 @@ namespace OpenGridServices.GridServer | |||
176 | responseData["regionname"] = TheSim.regionname; | 193 | responseData["regionname"] = TheSim.regionname; |
177 | responseData["estate_id"] = "1"; | 194 | responseData["estate_id"] = "1"; |
178 | responseData["neighbours"] = SimNeighboursData; | 195 | responseData["neighbours"] = SimNeighboursData; |
179 | 196 | ||
180 | responseData["sim_ip"] = TheSim.sim_ip; | 197 | responseData["sim_ip"] = TheSim.sim_ip; |
181 | responseData["sim_port"] = TheSim.sim_port.ToString(); | 198 | responseData["sim_port"] = TheSim.sim_port.ToString(); |
182 | responseData["asset_url"] = m_gridManager.Cfg.DefaultAssetServer; | 199 | responseData["asset_url"] = m_gridManager.Cfg.DefaultAssetServer; |
183 | responseData["asset_sendkey"] = m_gridManager.Cfg.AssetSendKey; | 200 | responseData["asset_sendkey"] = m_gridManager.Cfg.AssetSendKey; |
184 | responseData["asset_recvkey"] = m_gridManager.Cfg.AssetRecvKey; | 201 | responseData["asset_recvkey"] = m_gridManager.Cfg.AssetRecvKey; |
@@ -193,97 +210,103 @@ namespace OpenGridServices.GridServer | |||
193 | 210 | ||
194 | public string RestSetSimMethod(string request, string path, string param) | 211 | public string RestSetSimMethod(string request, string path, string param) |
195 | { | 212 | { |
196 | Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......"); | 213 | Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......"); |
197 | SimProfileBase TheSim; | 214 | SimProfileBase TheSim; |
198 | TheSim = GetProfileByLLUUID(new LLUUID(param)); | 215 | TheSim = GetProfileByLLUUID(new LLUUID(param)); |
199 | if ((TheSim) == null) { | 216 | if ((TheSim) == null) |
200 | TheSim = new SimProfileBase(); | 217 | { |
201 | LLUUID UUID = new LLUUID(param); | 218 | TheSim = new SimProfileBase(); |
202 | TheSim.UUID=UUID; | 219 | LLUUID UUID = new LLUUID(param); |
203 | } | 220 | TheSim.UUID = UUID; |
204 | 221 | } | |
222 | |||
205 | XmlDocument doc = new XmlDocument(); | 223 | XmlDocument doc = new XmlDocument(); |
206 | doc.LoadXml(request); | 224 | doc.LoadXml(request); |
207 | XmlNode rootnode=doc.FirstChild; | 225 | XmlNode rootnode = doc.FirstChild; |
208 | XmlNode authkeynode = rootnode.ChildNodes[0]; | 226 | XmlNode authkeynode = rootnode.ChildNodes[0]; |
209 | if (authkeynode.Name != "authkey") | 227 | if (authkeynode.Name != "authkey") |
210 | { | 228 | { |
211 | return "ERROR! bad XML - expected authkey tag"; | 229 | return "ERROR! bad XML - expected authkey tag"; |
212 | } | 230 | } |
213 | 231 | ||
214 | XmlNode simnode = rootnode.ChildNodes[1]; | 232 | XmlNode simnode = rootnode.ChildNodes[1]; |
215 | if (simnode.Name != "sim") | 233 | if (simnode.Name != "sim") |
216 | { | 234 | { |
217 | return "ERROR! bad XML - expected sim tag"; | 235 | return "ERROR! bad XML - expected sim tag"; |
218 | } | 236 | } |
219 | 237 | ||
220 | if (authkeynode.InnerText != m_gridManager.Cfg.SimRecvKey) | 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) | ||
221 | { | 245 | { |
222 | return "ERROR! invalid key"; | 246 | case "regionname": |
223 | } | 247 | TheSim.regionname = simnode.ChildNodes[i].InnerText; |
224 | for (int i = 0; i < simnode.ChildNodes.Count; i++) { | 248 | break; |
225 | switch (simnode.ChildNodes[i].Name) { | 249 | |
226 | case "regionname": | 250 | case "sim_ip": |
227 | TheSim.regionname = simnode.ChildNodes[i].InnerText; | 251 | TheSim.sim_ip = simnode.ChildNodes[i].InnerText; |
228 | break; | 252 | break; |
229 | 253 | ||
230 | case "sim_ip": | 254 | case "sim_port": |
231 | TheSim.sim_ip = simnode.ChildNodes[i].InnerText; | 255 | TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); |
232 | break; | 256 | break; |
233 | 257 | ||
234 | case "sim_port": | 258 | case "region_locx": |
235 | TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); | 259 | TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); |
236 | break; | 260 | TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); |
237 | 261 | break; | |
238 | case "region_locx": | 262 | |
239 | TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | 263 | case "region_locy": |
240 | TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); | ||
241 | break; | ||
242 | |||
243 | case "region_locy": | ||
244 | TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | 264 | TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); |
245 | TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); | 265 | TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); |
246 | break; | 266 | break; |
247 | } | 267 | } |
248 | } | 268 | } |
249 | 269 | ||
250 | try { | 270 | try |
251 | SimProfiles.Add(TheSim.UUID, TheSim); | 271 | { |
252 | IObjectContainer db; | 272 | SimProfiles.Add(TheSim.UUID, TheSim); |
253 | db = Db4oFactory.OpenFile("simprofiles.yap"); | 273 | IObjectContainer db; |
254 | db.Set(TheSim); | 274 | db = Db4oFactory.OpenFile("simprofiles.yap"); |
255 | db.Close(); | 275 | db.Set(TheSim); |
256 | return "OK"; | 276 | db.Close(); |
257 | } catch(Exception e) { | 277 | return "OK"; |
258 | return "ERROR! could not save to database!"; | 278 | } |
259 | } | 279 | catch (Exception e) |
280 | { | ||
281 | return "ERROR! could not save to database!"; | ||
282 | } | ||
260 | 283 | ||
261 | } | 284 | } |
262 | 285 | ||
263 | public string RestGetRegionMethod(string request, string path, string param ) | 286 | public string RestGetRegionMethod(string request, string path, string param) |
264 | { | 287 | { |
265 | SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param)); | 288 | SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param)); |
266 | return RestGetSimMethod("", "/sims/", param); | 289 | return RestGetSimMethod("", "/sims/", param); |
267 | } | 290 | } |
268 | 291 | ||
269 | public string RestSetRegionMethod(string request, string path, string param ) | 292 | public string RestSetRegionMethod(string request, string path, string param) |
270 | { | 293 | { |
271 | SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param)); | 294 | SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param)); |
272 | return RestSetSimMethod("", "/sims/", param); | 295 | return RestSetSimMethod("", "/sims/", param); |
273 | } | 296 | } |
274 | 297 | ||
275 | public string RestGetSimMethod(string request, string path, string param ) | 298 | public string RestGetSimMethod(string request, string path, string param) |
276 | { | 299 | { |
277 | string respstring = String.Empty; | 300 | string respstring = String.Empty; |
278 | 301 | ||
279 | SimProfileBase TheSim; | 302 | SimProfileBase TheSim; |
280 | LLUUID UUID = new LLUUID(param); | 303 | LLUUID UUID = new LLUUID(param); |
281 | TheSim = GetProfileByLLUUID(UUID); | 304 | TheSim = GetProfileByLLUUID(UUID); |
282 | 305 | ||
283 | if (!(TheSim == null)) | 306 | if (!(TheSim == null)) |
284 | { | 307 | { |
285 | respstring = "<Root>"; | 308 | respstring = "<Root>"; |
286 | respstring += "<authkey>" + m_gridManager.Cfg.SimSendKey + "</authkey>"; | 309 | respstring += "<authkey>" + m_gridManager.Cfg.SimSendKey + "</authkey>"; |
287 | respstring += "<sim>"; | 310 | respstring += "<sim>"; |
288 | respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>"; | 311 | respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>"; |
289 | respstring += "<regionname>" + TheSim.regionname + "</regionname>"; | 312 | respstring += "<regionname>" + TheSim.regionname + "</regionname>"; |
@@ -293,13 +316,13 @@ namespace OpenGridServices.GridServer | |||
293 | respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>"; | 316 | respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>"; |
294 | respstring += "<estate_id>1</estate_id>"; | 317 | respstring += "<estate_id>1</estate_id>"; |
295 | respstring += "</sim>"; | 318 | respstring += "</sim>"; |
296 | respstring += "</Root>"; | 319 | respstring += "</Root>"; |
297 | } | 320 | } |
298 | 321 | ||
299 | return respstring; | 322 | return respstring; |
300 | } | 323 | } |
301 | 324 | ||
302 | } | 325 | } |
303 | 326 | ||
304 | 327 | ||
305 | } | 328 | } |