aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/GridServer
diff options
context:
space:
mode:
authorMW2007-06-27 15:28:52 +0000
committerMW2007-06-27 15:28:52 +0000
commit646bbbc84b8010e0dacbeed5342cdb045f46cc49 (patch)
tree770b34d19855363c3c113ab9a0af9a56d821d887 /OpenSim/Grid/GridServer
downloadopensim-SC-646bbbc84b8010e0dacbeed5342cdb045f46cc49.zip
opensim-SC-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.gz
opensim-SC-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.bz2
opensim-SC-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.xz
Some work on restructuring the namespaces / project names. Note this doesn't compile yet as not all the code has been changed to use the new namespaces. Am committing it now for feedback on the namespaces.
Diffstat (limited to 'OpenSim/Grid/GridServer')
-rw-r--r--OpenSim/Grid/GridServer/GridManager.cs599
-rw-r--r--OpenSim/Grid/GridServer/Main.cs271
-rw-r--r--OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj134
-rw-r--r--OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj.user12
-rw-r--r--OpenSim/Grid/GridServer/Properties/AssemblyInfo.cs60
5 files changed, 1076 insertions, 0 deletions
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
new file mode 100644
index 0000000..bf80652
--- /dev/null
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -0,0 +1,599 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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;
30using System.Collections.Generic;
31using System.Text;
32using System.Reflection;
33using OpenGrid.Framework.Data;
34using OpenSim.Framework.Utilities;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Sims;
37using libsecondlife;
38using Nwc.XmlRpc;
39using System.Xml;
40
41namespace OpenGridServices.GridServer
42{
43 class GridManager
44 {
45 Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>();
46 Dictionary<string, ILogData> _logplugins = new Dictionary<string, ILogData>();
47
48 public OpenSim.Framework.Interfaces.GridConfig config;
49
50 /// <summary>
51 /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded.
52 /// </summary>
53 /// <param name="FileName">The filename to the grid server plugin DLL</param>
54 public void AddPlugin(string FileName)
55 {
56 OpenSim.Framework.Console.MainLog.Instance.Verbose("Storage: Attempting to load " + FileName);
57 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
58
59 OpenSim.Framework.Console.MainLog.Instance.Verbose("Storage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
60 foreach (Type pluginType in pluginAssembly.GetTypes())
61 {
62 if (!pluginType.IsAbstract)
63 {
64 // Regions go here
65 Type typeInterface = pluginType.GetInterface("IGridData", true);
66
67 if (typeInterface != null)
68 {
69 IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
70 plug.Initialise();
71 this._plugins.Add(plug.getName(), plug);
72 OpenSim.Framework.Console.MainLog.Instance.Verbose("Storage: Added IGridData Interface");
73 }
74
75 typeInterface = null;
76
77 // Logs go here
78 typeInterface = pluginType.GetInterface("ILogData", true);
79
80 if (typeInterface != null)
81 {
82 ILogData plug = (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
83 plug.Initialise();
84 this._logplugins.Add(plug.getName(), plug);
85 OpenSim.Framework.Console.MainLog.Instance.Verbose( "Storage: Added ILogData Interface");
86 }
87
88 typeInterface = null;
89 }
90 }
91
92 pluginAssembly = null;
93 }
94
95 /// <summary>
96 /// Logs a piece of information to the database
97 /// </summary>
98 /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param>
99 /// <param name="method">Which method is being called?</param>
100 /// <param name="args">What arguments are being passed?</param>
101 /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param>
102 /// <param name="message">The message to log</param>
103 private void logToDB(string target, string method, string args, int priority, string message)
104 {
105 foreach (KeyValuePair<string, ILogData> kvp in _logplugins)
106 {
107 try
108 {
109 kvp.Value.saveLog("Gridserver", target, method, args, priority, message);
110 }
111 catch (Exception e)
112 {
113 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: unable to write log via " + kvp.Key);
114 }
115 }
116 }
117
118 /// <summary>
119 /// Returns a region by argument
120 /// </summary>
121 /// <param name="uuid">A UUID key of the region to return</param>
122 /// <returns>A SimProfileData for the region</returns>
123 public SimProfileData getRegion(libsecondlife.LLUUID uuid)
124 {
125 foreach(KeyValuePair<string,IGridData> kvp in _plugins) {
126 try
127 {
128 return kvp.Value.GetProfileByLLUUID(uuid);
129 }
130 catch (Exception e)
131 {
132 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to find region " + uuid.ToStringHyphenated() + " via " + kvp.Key);
133 }
134 }
135 return null;
136 }
137
138 /// <summary>
139 /// Returns a region by argument
140 /// </summary>
141 /// <param name="uuid">A regionHandle of the region to return</param>
142 /// <returns>A SimProfileData for the region</returns>
143 public SimProfileData getRegion(ulong handle)
144 {
145 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
146 {
147 try
148 {
149 return kvp.Value.GetProfileByHandle(handle);
150 }
151 catch (Exception e)
152 {
153 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to find region " + handle.ToString() + " via " + kvp.Key);
154 }
155 }
156 return null;
157 }
158
159 public Dictionary<ulong, SimProfileData> getRegions(uint xmin, uint ymin, uint xmax, uint ymax)
160 {
161 Dictionary<ulong, SimProfileData> regions = new Dictionary<ulong, SimProfileData>();
162
163 SimProfileData[] neighbours;
164
165 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
166 {
167 try
168 {
169 neighbours = kvp.Value.GetProfilesInRange(xmin, ymin, xmax, ymax);
170 foreach (SimProfileData neighbour in neighbours)
171 {
172 regions[neighbour.regionHandle] = neighbour;
173 }
174 }
175 catch (Exception e)
176 {
177 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to query regionblock via " + kvp.Key);
178 }
179 }
180
181 return regions;
182 }
183
184 /// <summary>
185 /// Returns a XML String containing a list of the neighbouring regions
186 /// </summary>
187 /// <param name="reqhandle">The regionhandle for the center sim</param>
188 /// <returns>An XML string containing neighbour entities</returns>
189 public string GetXMLNeighbours(ulong reqhandle)
190 {
191 string response = "";
192 SimProfileData central_region = getRegion(reqhandle);
193 SimProfileData neighbour;
194 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
195 {
196 if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null)
197 {
198 neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256));
199 response += "<neighbour>";
200 response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>";
201 response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>";
202 response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>";
203 response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>";
204 response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>";
205 response += "</neighbour>";
206
207 }
208 }
209 return response;
210 }
211
212 /// <summary>
213 /// Performed when a region connects to the grid server initially.
214 /// </summary>
215 /// <param name="request">The XMLRPC Request</param>
216 /// <returns>Startup parameters</returns>
217 public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request)
218 {
219 XmlRpcResponse response = new XmlRpcResponse();
220 Hashtable responseData = new Hashtable();
221 response.Value = responseData;
222
223 SimProfileData TheSim = null;
224 Hashtable requestData = (Hashtable)request.Params[0];
225
226 if (requestData.ContainsKey("UUID"))
227 {
228 TheSim = getRegion(new LLUUID((string)requestData["UUID"]));
229 logToDB((new LLUUID((string)requestData["UUID"])).ToStringHyphenated(),"XmlRpcLoginToSimulatorMethod","", 5,"Region attempting login with UUID.");
230 }
231 else if (requestData.ContainsKey("region_handle"))
232 {
233 TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"]));
234 logToDB((string)requestData["region_handle"], "XmlRpcLoginToSimulatorMethod", "", 5, "Region attempting login with regionHandle.");
235 }
236 else
237 {
238 responseData["error"] = "No UUID or region_handle passed to grid server - unable to connect you";
239 return response;
240 }
241
242 if (TheSim == null)
243 {
244 responseData["error"] = "sim not found";
245 return response;
246 }
247 else
248 {
249
250 ArrayList SimNeighboursData = new ArrayList();
251
252 SimProfileData neighbour;
253 Hashtable NeighbourBlock;
254
255 bool fastMode = false; // Only compatible with MySQL right now
256
257 if (fastMode)
258 {
259 Dictionary<ulong, SimProfileData> neighbours = getRegions(TheSim.regionLocX - 1, TheSim.regionLocY - 1, TheSim.regionLocX + 1, TheSim.regionLocY + 1);
260
261 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
262 {
263 NeighbourBlock = new Hashtable();
264 NeighbourBlock["sim_ip"] = aSim.Value.serverIP.ToString();
265 NeighbourBlock["sim_port"] = aSim.Value.serverPort.ToString();
266 NeighbourBlock["region_locx"] = aSim.Value.regionLocX.ToString();
267 NeighbourBlock["region_locy"] = aSim.Value.regionLocY.ToString();
268 NeighbourBlock["UUID"] = aSim.Value.UUID.ToString();
269
270 if (aSim.Value.UUID != TheSim.UUID)
271 SimNeighboursData.Add(NeighbourBlock);
272 }
273 }
274 else
275 {
276 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
277 {
278 if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null)
279 {
280 neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256));
281
282 NeighbourBlock = new Hashtable();
283 NeighbourBlock["sim_ip"] = neighbour.serverIP;
284 NeighbourBlock["sim_port"] = neighbour.serverPort.ToString();
285 NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString();
286 NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString();
287 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
288
289 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
290 }
291 }
292 }
293
294 responseData["UUID"] = TheSim.UUID.ToString();
295 responseData["region_locx"] = TheSim.regionLocX.ToString();
296 responseData["region_locy"] = TheSim.regionLocY.ToString();
297 responseData["regionname"] = TheSim.regionName;
298 responseData["estate_id"] = "1";
299 responseData["neighbours"] = SimNeighboursData;
300
301 responseData["sim_ip"] = TheSim.serverIP;
302 responseData["sim_port"] = TheSim.serverPort.ToString();
303 responseData["asset_url"] = TheSim.regionAssetURI;
304 responseData["asset_sendkey"] = TheSim.regionAssetSendKey;
305 responseData["asset_recvkey"] = TheSim.regionAssetRecvKey;
306 responseData["user_url"] = TheSim.regionUserURI;
307 responseData["user_sendkey"] = TheSim.regionUserSendKey;
308 responseData["user_recvkey"] = TheSim.regionUserRecvKey;
309 responseData["authkey"] = TheSim.regionSecret;
310
311 // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap)
312 responseData["data_uri"] = TheSim.regionDataURI;
313 }
314
315 return response;
316 }
317
318 public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request)
319 {
320 int xmin=980, ymin=980, xmax=1020, ymax=1020;
321
322 Hashtable requestData = (Hashtable)request.Params[0];
323 if (requestData.ContainsKey("xmin"))
324 {
325 xmin = (Int32)requestData["xmin"];
326 }
327 if (requestData.ContainsKey("ymin"))
328 {
329 ymin = (Int32)requestData["ymin"];
330 }
331 if (requestData.ContainsKey("xmax"))
332 {
333 xmax = (Int32)requestData["xmax"];
334 }
335 if (requestData.ContainsKey("ymax"))
336 {
337 ymax = (Int32)requestData["ymax"];
338 }
339
340 XmlRpcResponse response = new XmlRpcResponse();
341 Hashtable responseData = new Hashtable();
342 response.Value = responseData;
343 IList simProfileList = new ArrayList();
344
345 bool fastMode = true; // MySQL Only
346
347 if (fastMode)
348 {
349 Dictionary<ulong, SimProfileData> neighbours = getRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax);
350
351 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
352 {
353 Hashtable simProfileBlock = new Hashtable();
354 simProfileBlock["x"] = aSim.Value.regionLocX.ToString();
355 simProfileBlock["y"] = aSim.Value.regionLocY.ToString();
356 simProfileBlock["name"] = aSim.Value.regionName;
357 simProfileBlock["access"] = 21;
358 simProfileBlock["region-flags"] = 512;
359 simProfileBlock["water-height"] = 0;
360 simProfileBlock["agents"] = 1;
361 simProfileBlock["map-image-id"] = aSim.Value.regionMapTextureID.ToString();
362
363 // For Sugilite compatibility
364 simProfileBlock["regionhandle"] = aSim.Value.regionHandle.ToString();
365 simProfileBlock["sim_ip"] = aSim.Value.serverIP.ToString();
366 simProfileBlock["sim_port"] = aSim.Value.serverPort.ToString();
367 simProfileBlock["sim_uri"] = aSim.Value.serverURI.ToString();
368 simProfileBlock["uuid"] = aSim.Value.UUID.ToStringHyphenated();
369
370 simProfileList.Add(simProfileBlock);
371 }
372 OpenSim.Framework.Console.MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via FastMode");
373 }
374 else
375 {
376 SimProfileData simProfile;
377 for (int x = xmin; x < xmax; x++)
378 {
379 for (int y = ymin; y < ymax; y++)
380 {
381 simProfile = getRegion(Helpers.UIntsToLong((uint)(x * 256), (uint)(y * 256)));
382 if (simProfile != null)
383 {
384 Hashtable simProfileBlock = new Hashtable();
385 simProfileBlock["x"] = x;
386 simProfileBlock["y"] = y;
387 simProfileBlock["name"] = simProfile.regionName;
388 simProfileBlock["access"] = 0;
389 simProfileBlock["region-flags"] = 0;
390 simProfileBlock["water-height"] = 20;
391 simProfileBlock["agents"] = 1;
392 simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToString();
393
394 // For Sugilite compatibility
395 simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString();
396 simProfileBlock["sim_ip"] = simProfile.serverIP.ToString();
397 simProfileBlock["sim_port"] = simProfile.serverPort.ToString();
398 simProfileBlock["sim_uri"] = simProfile.serverURI.ToString();
399 simProfileBlock["uuid"] = simProfile.UUID.ToStringHyphenated();
400
401 simProfileList.Add(simProfileBlock);
402 }
403 }
404 }
405 OpenSim.Framework.Console.MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via Standard Mode");
406 }
407
408 responseData["sim-profiles"] = simProfileList;
409
410 return response;
411 }
412
413
414
415 /// <summary>
416 /// Performs a REST Get Operation
417 /// </summary>
418 /// <param name="request"></param>
419 /// <param name="path"></param>
420 /// <param name="param"></param>
421 /// <returns></returns>
422 public string RestGetRegionMethod(string request, string path, string param)
423 {
424 return RestGetSimMethod("", "/sims/", param);
425 }
426
427 /// <summary>
428 /// Performs a REST Set Operation
429 /// </summary>
430 /// <param name="request"></param>
431 /// <param name="path"></param>
432 /// <param name="param"></param>
433 /// <returns></returns>
434 public string RestSetRegionMethod(string request, string path, string param)
435 {
436 return RestSetSimMethod("", "/sims/", param);
437 }
438
439 /// <summary>
440 /// Returns information about a sim via a REST Request
441 /// </summary>
442 /// <param name="request"></param>
443 /// <param name="path"></param>
444 /// <param name="param"></param>
445 /// <returns>Information about the sim in XML</returns>
446 public string RestGetSimMethod(string request, string path, string param)
447 {
448 string respstring = String.Empty;
449
450 SimProfileData TheSim;
451 LLUUID UUID = new LLUUID(param);
452 TheSim = getRegion(UUID);
453
454 if (!(TheSim == null))
455 {
456 respstring = "<Root>";
457 respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>";
458 respstring += "<sim>";
459 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
460 respstring += "<regionname>" + TheSim.regionName + "</regionname>";
461 respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>";
462 respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>";
463 respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>";
464 respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>";
465 respstring += "<estate_id>1</estate_id>";
466 respstring += "</sim>";
467 respstring += "</Root>";
468 }
469
470 return respstring;
471 }
472
473 /// <summary>
474 /// Creates or updates a sim via a REST Method Request
475 /// BROKEN with SQL Update
476 /// </summary>
477 /// <param name="request"></param>
478 /// <param name="path"></param>
479 /// <param name="param"></param>
480 /// <returns>"OK" or an error</returns>
481 public string RestSetSimMethod(string request, string path, string param)
482 {
483 Console.WriteLine("Processing region update");
484 SimProfileData TheSim;
485 TheSim = getRegion(new LLUUID(param));
486 if ((TheSim) == null)
487 {
488 TheSim = new SimProfileData();
489 LLUUID UUID = new LLUUID(param);
490 TheSim.UUID = UUID;
491 TheSim.regionRecvKey = config.SimRecvKey;
492 }
493
494 XmlDocument doc = new XmlDocument();
495 doc.LoadXml(request);
496 XmlNode rootnode = doc.FirstChild;
497 XmlNode authkeynode = rootnode.ChildNodes[0];
498 if (authkeynode.Name != "authkey")
499 {
500 return "ERROR! bad XML - expected authkey tag";
501 }
502
503 XmlNode simnode = rootnode.ChildNodes[1];
504 if (simnode.Name != "sim")
505 {
506 return "ERROR! bad XML - expected sim tag";
507 }
508
509 if (authkeynode.InnerText != TheSim.regionRecvKey)
510 {
511 return "ERROR! invalid key";
512 }
513
514 //TheSim.regionSendKey = Cfg;
515 TheSim.regionRecvKey = config.SimRecvKey;
516 TheSim.regionSendKey = config.SimSendKey;
517 TheSim.regionSecret = config.SimRecvKey;
518 TheSim.regionDataURI = "";
519 TheSim.regionAssetURI = config.DefaultAssetServer;
520 TheSim.regionAssetRecvKey = config.AssetRecvKey;
521 TheSim.regionAssetSendKey = config.AssetSendKey;
522 TheSim.regionUserURI = config.DefaultUserServer;
523 TheSim.regionUserSendKey = config.UserSendKey;
524 TheSim.regionUserRecvKey = config.UserRecvKey;
525
526
527 for (int i = 0; i < simnode.ChildNodes.Count; i++)
528 {
529 switch (simnode.ChildNodes[i].Name)
530 {
531 case "regionname":
532 TheSim.regionName = simnode.ChildNodes[i].InnerText;
533 break;
534
535 case "sim_ip":
536 TheSim.serverIP = simnode.ChildNodes[i].InnerText;
537 break;
538
539 case "sim_port":
540 TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
541 break;
542
543 case "region_locx":
544 TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
545 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
546 break;
547
548 case "region_locy":
549 TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
550 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
551 break;
552 }
553 }
554
555 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
556
557 bool requirePublic = false;
558
559 if (requirePublic && (TheSim.serverIP.StartsWith("172.16") || TheSim.serverIP.StartsWith("192.168") || TheSim.serverIP.StartsWith("10.") || TheSim.serverIP.StartsWith("0.") || TheSim.serverIP.StartsWith("255.")))
560 {
561 return "ERROR! Servers must register with public addresses.";
562 }
563
564
565 try
566 {
567 OpenSim.Framework.Console.MainLog.Instance.Verbose("Updating / adding via " + _plugins.Count + " storage provider(s) registered.");
568 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
569 {
570 try
571 {
572 //Check reservations
573 ReservationData reserveData = kvp.Value.GetReservationAtPoint(TheSim.regionLocX, TheSim.regionLocY);
574 if ((reserveData != null && reserveData.gridRecvKey == TheSim.regionRecvKey) || (reserveData == null))
575 {
576 kvp.Value.AddProfile(TheSim);
577 OpenSim.Framework.Console.MainLog.Instance.Verbose("New sim added to grid (" + TheSim.regionName + ")");
578 logToDB(TheSim.UUID.ToStringHyphenated(), "RestSetSimMethod", "", 5, "Region successfully updated and connected to grid.");
579 }
580 else
581 {
582 return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
583 }
584 }
585 catch (Exception e)
586 {
587 OpenSim.Framework.Console.MainLog.Instance.Verbose("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString());
588 }
589 }
590 return "OK";
591 }
592 catch (Exception e)
593 {
594 return "ERROR! Could not save to database! (" + e.ToString() + ")";
595 }
596 }
597
598 }
599}
diff --git a/OpenSim/Grid/GridServer/Main.cs b/OpenSim/Grid/GridServer/Main.cs
new file mode 100644
index 0000000..b948fd6
--- /dev/null
+++ b/OpenSim/Grid/GridServer/Main.cs
@@ -0,0 +1,271 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28
29using System;
30using System.IO;
31using System.Text;
32using System.Timers;
33using System.Net;
34using System.Threading;
35using System.Reflection;
36using libsecondlife;
37using OpenGrid.Framework.Manager;
38using OpenSim.Framework;
39using OpenSim.Framework.Sims;
40using OpenSim.Framework.Console;
41using OpenSim.Framework.Interfaces;
42using OpenSim.Servers;
43using OpenSim.GenericConfig;
44
45namespace OpenGridServices.GridServer
46{
47 /// <summary>
48 /// </summary>
49 public class OpenGrid_Main : conscmd_callback
50 {
51 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
52 private string GridDll = "OpenGrid.Framework.Data.MySQL.dll";
53 public GridConfig Cfg;
54
55 public static OpenGrid_Main thegrid;
56 protected IGenericConfig localXMLConfig;
57
58 public static bool setuponly;
59
60 //public LLUUID highestUUID;
61
62 // private SimProfileManager m_simProfileManager;
63
64 private GridManager m_gridManager;
65
66 private LogBase m_console;
67
68 [STAThread]
69 public static void Main(string[] args)
70 {
71 if (args.Length > 0)
72 {
73 if (args[0] == "-setuponly") setuponly = true;
74 }
75 Console.WriteLine("Starting...\n");
76
77 thegrid = new OpenGrid_Main();
78 thegrid.Startup();
79
80 thegrid.Work();
81 }
82
83 private void Work()
84 {
85 while (true)
86 {
87 Thread.Sleep(5000);
88 // should flush the DB etc here
89 }
90 }
91
92 private OpenGrid_Main()
93 {
94 m_console = new LogBase("opengrid-gridserver-console.log", "OpenGrid", this, false);
95 MainLog.Instance = m_console;
96
97
98 }
99
100 public void managercallback(string cmd)
101 {
102 switch (cmd)
103 {
104 case "shutdown":
105 RunCmd("shutdown", new string[0]);
106 break;
107 }
108 }
109
110
111 public void Startup()
112 {
113 this.localXMLConfig = new XmlConfig("GridServerConfig.xml");
114 this.localXMLConfig.LoadData();
115 this.ConfigDB(this.localXMLConfig);
116 this.localXMLConfig.Close();
117
118 m_console.Verbose( "Main.cs:Startup() - Loading configuration");
119 Cfg = this.LoadConfigDll(this.ConfigDll);
120 Cfg.InitConfig();
121 if (setuponly) Environment.Exit(0);
122
123 m_console.Verbose( "Main.cs:Startup() - Connecting to Storage Server");
124 m_gridManager = new GridManager();
125 m_gridManager.AddPlugin(GridDll); // Made of win
126 m_gridManager.config = Cfg;
127
128 m_console.Verbose( "Main.cs:Startup() - Starting HTTP process");
129 BaseHttpServer httpServer = new BaseHttpServer(8001);
130 //GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer, "gridserver", Cfg.SimSendKey, Cfg.SimRecvKey, managercallback);
131
132 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcLoginToSimulatorMethod);
133 httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
134
135 httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
136 httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
137 httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
138 httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
139
140
141 // lbsa71 : This code snippet taken from old http server.
142 // I have no idea what this was supposed to do - looks like an infinite recursion to me.
143 // case "regions":
144 //// DIRTY HACK ALERT
145 //Console.Notice("/regions/ accessed");
146 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
147 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
148 //break;
149
150 // lbsa71 : I guess these were never used?
151 //Listener.Prefixes.Add("http://+:8001/gods/");
152 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
153 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
154
155 httpServer.Start();
156
157 m_console.Verbose( "Main.cs:Startup() - Starting sim status checker");
158
159 System.Timers.Timer simCheckTimer = new System.Timers.Timer(3600000 * 3); // 3 Hours between updates.
160 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
161 simCheckTimer.Enabled = true;
162 }
163
164 private GridConfig LoadConfigDll(string dllName)
165 {
166 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
167 GridConfig config = null;
168
169 foreach (Type pluginType in pluginAssembly.GetTypes())
170 {
171 if (pluginType.IsPublic)
172 {
173 if (!pluginType.IsAbstract)
174 {
175 Type typeInterface = pluginType.GetInterface("IGridConfig", true);
176
177 if (typeInterface != null)
178 {
179 IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
180 config = plug.GetConfigObject();
181 break;
182 }
183
184 typeInterface = null;
185 }
186 }
187 }
188 pluginAssembly = null;
189 return config;
190 }
191
192 public void CheckSims(object sender, ElapsedEventArgs e)
193 {
194 /*
195 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
196 {
197 string SimResponse = "";
198 try
199 {
200 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
201 CheckSim.Method = "GET";
202 CheckSim.ContentType = "text/plaintext";
203 CheckSim.ContentLength = 0;
204
205 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
206 stOut.Write("");
207 stOut.Close();
208
209 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
210 SimResponse = stIn.ReadToEnd();
211 stIn.Close();
212 }
213 catch
214 {
215 }
216
217 if (SimResponse == "OK")
218 {
219 m_simProfileManager.SimProfiles[sim.UUID].online = true;
220 }
221 else
222 {
223 m_simProfileManager.SimProfiles[sim.UUID].online = false;
224 }
225 }
226 */
227 }
228
229 public void RunCmd(string cmd, string[] cmdparams)
230 {
231 switch (cmd)
232 {
233 case "help":
234 m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
235 break;
236
237 case "shutdown":
238 m_console.Close();
239 Environment.Exit(0);
240 break;
241 }
242 }
243
244 public void Show(string ShowWhat)
245 {
246 }
247
248 private void ConfigDB(IGenericConfig configData)
249 {
250 try
251 {
252 string attri = "";
253 attri = configData.GetAttribute("DataBaseProvider");
254 if (attri == "")
255 {
256 GridDll = "OpenGrid.Framework.Data.DB4o.dll";
257 configData.SetAttribute("DataBaseProvider", "OpenGrid.Framework.Data.DB4o.dll");
258 }
259 else
260 {
261 GridDll = attri;
262 }
263 configData.Commit();
264 }
265 catch (Exception e)
266 {
267
268 }
269 }
270 }
271}
diff --git a/OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj b/OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj
new file mode 100644
index 0000000..424072e
--- /dev/null
+++ b/OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj
@@ -0,0 +1,134 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{60FCC3A6-0000-0000-0000-000000000000}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon>
10 <AssemblyKeyContainerName>
11 </AssemblyKeyContainerName>
12 <AssemblyName>OpenSim.Grid.GridServer</AssemblyName>
13 <DefaultClientScript>JScript</DefaultClientScript>
14 <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
15 <DefaultTargetSchema>IE50</DefaultTargetSchema>
16 <DelaySign>false</DelaySign>
17 <OutputType>Exe</OutputType>
18 <AppDesignerFolder></AppDesignerFolder>
19 <RootNamespace>OpenSim.Grid.GridServer</RootNamespace>
20 <StartupObject></StartupObject>
21 <FileUpgradeFlags>
22 </FileUpgradeFlags>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
26 <BaseAddress>285212672</BaseAddress>
27 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
28 <ConfigurationOverrideFile>
29 </ConfigurationOverrideFile>
30 <DefineConstants>TRACE;DEBUG</DefineConstants>
31 <DocumentationFile></DocumentationFile>
32 <DebugSymbols>True</DebugSymbols>
33 <FileAlignment>4096</FileAlignment>
34 <Optimize>False</Optimize>
35 <OutputPath>..\..\..\bin\</OutputPath>
36 <RegisterForComInterop>False</RegisterForComInterop>
37 <RemoveIntegerChecks>False</RemoveIntegerChecks>
38 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
39 <WarningLevel>4</WarningLevel>
40 <NoWarn></NoWarn>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
43 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
44 <BaseAddress>285212672</BaseAddress>
45 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
46 <ConfigurationOverrideFile>
47 </ConfigurationOverrideFile>
48 <DefineConstants>TRACE</DefineConstants>
49 <DocumentationFile></DocumentationFile>
50 <DebugSymbols>False</DebugSymbols>
51 <FileAlignment>4096</FileAlignment>
52 <Optimize>True</Optimize>
53 <OutputPath>..\..\..\bin\</OutputPath>
54 <RegisterForComInterop>False</RegisterForComInterop>
55 <RemoveIntegerChecks>False</RemoveIntegerChecks>
56 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
57 <WarningLevel>4</WarningLevel>
58 <NoWarn></NoWarn>
59 </PropertyGroup>
60 <ItemGroup>
61 <Reference Include="Db4objects.Db4o.dll" >
62 <HintPath>..\..\..\bin\Db4objects.Db4o.dll</HintPath>
63 <Private>False</Private>
64 </Reference>
65 <Reference Include="libsecondlife.dll" >
66 <HintPath>..\..\..\bin\libsecondlife.dll</HintPath>
67 <Private>False</Private>
68 </Reference>
69 <Reference Include="OpenSim.Framework" >
70 <HintPath>OpenSim.Framework.dll</HintPath>
71 <Private>False</Private>
72 </Reference>
73 <Reference Include="OpenSim.Framework.Console" >
74 <HintPath>OpenSim.Framework.Console.dll</HintPath>
75 <Private>False</Private>
76 </Reference>
77 <Reference Include="OpenSim.Framework.GenericConfig.Xml" >
78 <HintPath>OpenSim.Framework.GenericConfig.Xml.dll</HintPath>
79 <Private>False</Private>
80 </Reference>
81 <Reference Include="OpenSim.Framework.Servers" >
82 <HintPath>OpenSim.Framework.Servers.dll</HintPath>
83 <Private>False</Private>
84 </Reference>
85 <Reference Include="System" >
86 <HintPath>System.dll</HintPath>
87 <Private>False</Private>
88 </Reference>
89 <Reference Include="System.Data" >
90 <HintPath>System.Data.dll</HintPath>
91 <Private>False</Private>
92 </Reference>
93 <Reference Include="System.Xml" >
94 <HintPath>System.Xml.dll</HintPath>
95 <Private>False</Private>
96 </Reference>
97 <Reference Include="XMLRPC.dll" >
98 <HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
99 <Private>False</Private>
100 </Reference>
101 </ItemGroup>
102 <ItemGroup>
103 <ProjectReference Include="..\..\Framework\Data\OpenSim.Framework.Data.csproj">
104 <Name>OpenSim.Framework.Data</Name>
105 <Project>{36B72A9B-0000-0000-0000-000000000000}</Project>
106 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
107 <Private>False</Private>
108 </ProjectReference>
109 <ProjectReference Include="..\Framework.Manager\OpenSim.Grid.Framework.Manager.csproj">
110 <Name>OpenSim.Grid.Framework.Manager</Name>
111 <Project>{4B7BFD1C-0000-0000-0000-000000000000}</Project>
112 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
113 <Private>False</Private>
114 </ProjectReference>
115 </ItemGroup>
116 <ItemGroup>
117 <Compile Include="GridManager.cs">
118 <SubType>Code</SubType>
119 </Compile>
120 <Compile Include="Main.cs">
121 <SubType>Code</SubType>
122 </Compile>
123 <Compile Include="Properties\AssemblyInfo.cs">
124 <SubType>Code</SubType>
125 </Compile>
126 </ItemGroup>
127 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
128 <PropertyGroup>
129 <PreBuildEvent>
130 </PreBuildEvent>
131 <PostBuildEvent>
132 </PostBuildEvent>
133 </PropertyGroup>
134</Project>
diff --git a/OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj.user b/OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj.user
new file mode 100644
index 0000000..6841907
--- /dev/null
+++ b/OpenSim/Grid/GridServer/OpenSim.Grid.GridServer.csproj.user
@@ -0,0 +1,12 @@
1<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5 <ReferencePath>C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-06\NameSpaceChanges\bin\</ReferencePath>
6 <LastOpenVersion>8.0.50727</LastOpenVersion>
7 <ProjectView>ProjectFiles</ProjectView>
8 <ProjectTrust>0</ProjectTrust>
9 </PropertyGroup>
10 <PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
11 <PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
12</Project>
diff --git a/OpenSim/Grid/GridServer/Properties/AssemblyInfo.cs b/OpenSim/Grid/GridServer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..303dddf
--- /dev/null
+++ b/OpenSim/Grid/GridServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,60 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Reflection;
29using System.Runtime.CompilerServices;
30using System.Runtime.InteropServices;
31
32// General Information about an assembly is controlled through the following
33// set of attributes. Change these attribute values to modify the information
34// associated with an assembly.
35[assembly: AssemblyTitle("OGS-GridServer")]
36[assembly: AssemblyDescription("")]
37[assembly: AssemblyConfiguration("")]
38[assembly: AssemblyCompany("")]
39[assembly: AssemblyProduct("OGS-GridServer")]
40[assembly: AssemblyCopyright("Copyright © 2007")]
41[assembly: AssemblyTrademark("")]
42[assembly: AssemblyCulture("")]
43
44// Setting ComVisible to false makes the types in this assembly not visible
45// to COM components. If you need to access a type in this assembly from
46// COM, set the ComVisible attribute to true on that type.
47[assembly: ComVisible(false)]
48
49// The following GUID is for the ID of the typelib if this project is exposed to COM
50[assembly: Guid("b541b244-3d1d-4625-9003-bc2a3a6a39a4")]
51
52// Version information for an assembly consists of the following four values:
53//
54// Major Version
55// Minor Version
56// Build Number
57// Revision
58//
59[assembly: AssemblyVersion("1.0.0.0")]
60[assembly: AssemblyFileVersion("1.0.0.0")]