diff options
Diffstat (limited to 'src/Config.cs')
-rw-r--r-- | src/Config.cs | 174 |
1 files changed, 0 insertions, 174 deletions
diff --git a/src/Config.cs b/src/Config.cs deleted file mode 100644 index 9bb9296..0000000 --- a/src/Config.cs +++ /dev/null | |||
@@ -1,174 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (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 | |||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.IO; | ||
33 | using Db4objects.Db4o; | ||
34 | using libsecondlife; | ||
35 | using OpenSim.world; | ||
36 | |||
37 | namespace 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 bool sandbox = true; | ||
57 | public string AssetURL = String.Empty; | ||
58 | public string AssetSendKey = String.Empty; | ||
59 | |||
60 | public string GridURL = String.Empty; | ||
61 | public string GridSendKey = String.Empty; | ||
62 | |||
63 | private IObjectContainer db; | ||
64 | |||
65 | public void LoadDefaults() | ||
66 | { | ||
67 | string tempstring; | ||
68 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadDefaults() - Please press enter to retain default or enter new settings"); | ||
69 | |||
70 | this.RegionName = OpenSim_Main.localcons.CmdPrompt("Name [OpenSim test]: ", "OpenSim test"); | ||
71 | this.RegionLocX = (uint)Convert.ToInt32(OpenSim_Main.localcons.CmdPrompt("Grid Location X [997]: ", "997")); | ||
72 | this.RegionLocY = (uint)Convert.ToInt32(OpenSim_Main.localcons.CmdPrompt("Grid Location Y [996]: ", "996")); | ||
73 | this.IPListenPort = Convert.ToInt32(OpenSim_Main.localcons.CmdPrompt("UDP port for client connections [9000]: ", "9000")); | ||
74 | this.IPListenAddr = OpenSim_Main.localcons.CmdPrompt("IP Address to listen on for client connections [127.0.0.1]: ", "127.0.0.1"); | ||
75 | |||
76 | tempstring = OpenSim_Main.localcons.CmdPrompt("Run in sandbox or grid mode? [sandbox]: ", "sandbox", "sandbox", "grid"); | ||
77 | this.sandbox = tempstring.Equals("sandbox"); | ||
78 | |||
79 | if (!this.sandbox) | ||
80 | { | ||
81 | this.AssetURL = OpenSim_Main.localcons.CmdPrompt("Asset server URL: "); | ||
82 | this.AssetSendKey = OpenSim_Main.localcons.CmdPrompt("Asset server key: "); | ||
83 | this.GridURL = OpenSim_Main.localcons.CmdPrompt("Grid server URL: "); | ||
84 | this.GridSendKey = OpenSim_Main.localcons.CmdPrompt("Grid server key: "); | ||
85 | } | ||
86 | this.RegionHandle = Helpers.UIntsToLong((RegionLocX * 256), (RegionLocY * 256)); | ||
87 | } | ||
88 | |||
89 | public void InitConfig() | ||
90 | { | ||
91 | try | ||
92 | { | ||
93 | db = Db4oFactory.OpenFile("opensim.yap"); | ||
94 | IObjectSet result = db.Get(typeof(SimConfig)); | ||
95 | if (result.Count == 1) | ||
96 | { | ||
97 | OpenSim_Main.localcons.WriteLine("Config.cs:InitConfig() - Found a SimConfig object in the local database, loading"); | ||
98 | foreach (SimConfig cfg in result) | ||
99 | { | ||
100 | this.sandbox = cfg.sandbox; | ||
101 | this.RegionName = cfg.RegionName; | ||
102 | this.RegionLocX = cfg.RegionLocX; | ||
103 | this.RegionLocY = cfg.RegionLocY; | ||
104 | this.RegionHandle = Helpers.UIntsToLong((RegionLocX * 256), (RegionLocY * 256)); | ||
105 | this.IPListenPort = cfg.IPListenPort; | ||
106 | this.IPListenAddr = cfg.IPListenAddr; | ||
107 | this.AssetURL = cfg.AssetURL; | ||
108 | this.AssetSendKey = cfg.AssetSendKey; | ||
109 | this.GridURL = cfg.GridURL; | ||
110 | this.GridSendKey = cfg.GridSendKey; | ||
111 | } | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | OpenSim_Main.localcons.WriteLine("Config.cs:InitConfig() - Could not find object in database, loading precompiled defaults"); | ||
116 | LoadDefaults(); | ||
117 | OpenSim_Main.localcons.WriteLine("Writing out default settings to local database"); | ||
118 | db.Set(this); | ||
119 | } | ||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | db.Close(); | ||
124 | OpenSim_Main.localcons.WriteLine("Config.cs:InitConfig() - Exception occured"); | ||
125 | OpenSim_Main.localcons.WriteLine(e.ToString()); | ||
126 | } | ||
127 | OpenSim_Main.localcons.WriteLine("Sim settings loaded:"); | ||
128 | OpenSim_Main.localcons.WriteLine("Name: " + this.RegionName); | ||
129 | OpenSim_Main.localcons.WriteLine("Region Location: [" + this.RegionLocX.ToString() + "," + this.RegionLocY + "]"); | ||
130 | OpenSim_Main.localcons.WriteLine("Region Handle: " + this.RegionHandle.ToString()); | ||
131 | OpenSim_Main.localcons.WriteLine("Listening on IP: " + this.IPListenAddr + ":" + this.IPListenPort); | ||
132 | OpenSim_Main.localcons.WriteLine("Sandbox Mode? " + this.sandbox.ToString()); | ||
133 | OpenSim_Main.localcons.WriteLine("Asset URL: " + this.AssetURL); | ||
134 | OpenSim_Main.localcons.WriteLine("Asset key: " + this.AssetSendKey); | ||
135 | OpenSim_Main.localcons.WriteLine("Grid URL: " + this.GridURL); | ||
136 | OpenSim_Main.localcons.WriteLine("Grid key: " + this.GridSendKey); | ||
137 | } | ||
138 | |||
139 | public World LoadWorld() | ||
140 | { | ||
141 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadWorld() - Loading world...."); | ||
142 | World blank = new World(); | ||
143 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadWorld() - Looking for a heightmap in local DB"); | ||
144 | IObjectSet world_result = db.Get(new float[65536]); | ||
145 | if (world_result.Count > 0) | ||
146 | { | ||
147 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadWorld() - Found a heightmap in local database, loading"); | ||
148 | blank.LandMap = (float[])world_result.Next(); | ||
149 | } | ||
150 | else | ||
151 | { | ||
152 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadWorld() - No heightmap found, generating new one"); | ||
153 | HeightmapGenHills hills = new HeightmapGenHills(); | ||
154 | blank.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false); | ||
155 | |||
156 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadWorld() - Saving heightmap to local database"); | ||
157 | db.Set(blank.LandMap); | ||
158 | db.Commit(); | ||
159 | } | ||
160 | return blank; | ||
161 | } | ||
162 | |||
163 | public void LoadFromGrid() | ||
164 | { | ||
165 | OpenSim_Main.localcons.WriteLine("Config.cs:LoadFromGrid() - dummy function, DOING ABSOLUTELY NOTHING AT ALL!!!"); | ||
166 | // TODO: Make this crap work | ||
167 | } | ||
168 | |||
169 | public void Shutdown() | ||
170 | { | ||
171 | db.Close(); | ||
172 | } | ||
173 | } | ||
174 | } | ||