aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Config.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Config.cs')
-rw-r--r--src/Config.cs140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/Config.cs b/src/Config.cs
new file mode 100644
index 0000000..44e0689
--- /dev/null
+++ b/src/Config.cs
@@ -0,0 +1,140 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4* Copyright (c) <year>, <copyright holder>
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.Collections.Generic;
32using System.IO;
33using Db4objects.Db4o;
34using libsecondlife;
35using OpenSim.world;
36
37namespace OpenSim
38{
39 /// <summary>
40 /// This class handles connection to the underlying database used for configuration of the region.
41 /// Region content is also stored by this class. The main entry point is InitConfig() which attempts to locate
42 /// opensim.yap in the current working directory. If opensim.yap can not be found, default settings are loaded from
43 /// what is hardcoded here and then saved into opensim.yap for future startups.
44 /// </summary>
45 public class SimConfig
46 {
47 public string RegionName;
48
49 public uint RegionLocX;
50 public uint RegionLocY;
51 public ulong RegionHandle;
52
53 public int IPListenPort;
54 public string IPListenAddr;
55
56 public string AssetURL;
57 public string AssetSendKey;
58
59 public string GridURL;
60 public string GridSendKey;
61
62 private IObjectContainer db;
63
64 public void LoadDefaults() {
65 this.RegionName = "OpenSim test\0";
66 this.RegionLocX = 997;
67 this.RegionLocY = 996;
68 this.RegionHandle = Helpers.UIntsToLong((RegionLocX*256), (RegionLocY*256));
69 this.IPListenPort = 9000;
70 this.IPListenAddr = "4.78.190.75";
71 this.AssetURL = "http://osgrid.org/ogs/assetserver/";
72 this.AssetSendKey = "1234";
73 this.GridURL = "http://osgrid.org/ogs/gridserver/";
74 this.GridSendKey = "1234";
75 }
76
77 public void InitConfig() {
78 try {
79 db = Db4oFactory.OpenFile("opensim.yap");
80 IObjectSet result = db.Get(typeof(SimConfig));
81 if(result.Count==1) {
82 Console.WriteLine("Config.cs:InitConfig() - Found a SimConfig object in the local database, loading");
83 foreach (SimConfig cfg in result) {
84 this.RegionName = cfg.RegionName;
85 this.RegionLocX = cfg.RegionLocX;
86 this.RegionLocY = cfg.RegionLocY;
87 this.RegionHandle = Helpers.UIntsToLong((RegionLocX*256), (RegionLocY*256));
88 this.IPListenPort = cfg.IPListenPort;
89 this.IPListenAddr = cfg.IPListenAddr;
90 this.AssetURL = cfg.AssetURL;
91 this.AssetSendKey = cfg.AssetSendKey;
92 this.GridURL = cfg.GridURL;
93 this.GridSendKey = cfg.GridSendKey;
94 }
95 } else {
96 Console.WriteLine("Config.cs:InitConfig() - Could not find object in database, loading precompiled defaults");
97 LoadDefaults();
98 Console.WriteLine("Writing out default settings to local database");
99 db.Set(this);
100 }
101 } catch(Exception e) {
102 db.Close();
103 Console.WriteLine("Config.cs:InitConfig() - Exception occured");
104 Console.WriteLine(e.ToString());
105 }
106 }
107
108 public World LoadWorld() {
109 IObjectSet world_result = db.Get(typeof(OpenSim.world.World));
110 if(world_result.Count==1) {
111 Console.WriteLine("Config.cs:LoadWorld() - Found an OpenSim.world.World object in local database, loading");
112 return (World)world_result.Next();
113 } else {
114 Console.WriteLine("Config.cs:LoadWorld() - Could not find the world or too many worlds! Constructing blank one");
115 World blank = new World();
116 Console.WriteLine("Config.cs:LoadWorld() - Saving initial world state to disk");
117 db.Set(blank);
118 db.Commit();
119 return blank;
120 }
121 }
122
123 public void LoadFromGrid() {
124 Console.WriteLine("Config.cs:LoadFromGrid() - dummy function, DOING ABSOLUTELY NOTHING AT ALL!!!");
125 // TODO: Make this crap work
126 /* WebRequest GridLogin = WebRequest.Create(this.GridURL + "regions/" + this.RegionHandle.ToString() + "/login");
127 WebResponse GridResponse = GridLogin.GetResponse();
128 byte[] idata = new byte[(int)GridResponse.ContentLength];
129 BinaryReader br = new BinaryReader(GridResponse.GetResponseStream());
130
131 br.Close();
132 GridResponse.Close();
133 */
134 }
135
136 public void Shutdown() {
137 db.Close();
138 }
139 }
140}