diff options
Diffstat (limited to 'ConvertToPlugins/src/Config/SimConfig/Db4SimConfig.cs')
-rw-r--r-- | ConvertToPlugins/src/Config/SimConfig/Db4SimConfig.cs | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/ConvertToPlugins/src/Config/SimConfig/Db4SimConfig.cs b/ConvertToPlugins/src/Config/SimConfig/Db4SimConfig.cs new file mode 100644 index 0000000..cc31328 --- /dev/null +++ b/ConvertToPlugins/src/Config/SimConfig/Db4SimConfig.cs | |||
@@ -0,0 +1,146 @@ | |||
1 | /* | ||
2 | * Copyright (c) OpenSim project, http://sim.opensecondlife.org/ | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * Neither the name of the <organization> nor the | ||
12 | * names of its contributors may be used to endorse or promote products | ||
13 | * derived from this software without specific prior written permission. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
18 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | * | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using OpenSim; | ||
30 | using OpenSim.world; | ||
31 | using Db4objects.Db4o; | ||
32 | |||
33 | namespace Db40SimConfig | ||
34 | { | ||
35 | public class Db40ConfigPlugin: ISimConfig | ||
36 | { | ||
37 | public SimConfig GetConfigObject() | ||
38 | { | ||
39 | ServerConsole.MainConsole.Instance.WriteLine("Loading Db40Config dll"); | ||
40 | return ( new DbSimConfig()); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | public class DbSimConfig :SimConfig | ||
45 | { | ||
46 | private IObjectContainer db; | ||
47 | |||
48 | public void LoadDefaults() { | ||
49 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadDefaults() - Please press enter to retain default or enter new settings"); | ||
50 | |||
51 | this.RegionName=ServerConsole.MainConsole.Instance.CmdPrompt("Name [OpenSim test]: ","OpenSim test"); | ||
52 | this.RegionLocX=(uint)Convert.ToInt32(ServerConsole.MainConsole.Instance.CmdPrompt("Grid Location X [997]: ","997")); | ||
53 | this.RegionLocY=(uint)Convert.ToInt32(ServerConsole.MainConsole.Instance.CmdPrompt("Grid Location Y [996]: ","996")); | ||
54 | this.IPListenPort=Convert.ToInt32(ServerConsole.MainConsole.Instance.CmdPrompt("UDP port for client connections [9000]: ","9000")); | ||
55 | this.IPListenAddr=ServerConsole.MainConsole.Instance.CmdPrompt("IP Address to listen on for client connections [127.0.0.1]: ","127.0.0.1"); | ||
56 | |||
57 | if(!OpenSim_Main.sim.sandbox) | ||
58 | { | ||
59 | this.AssetURL=ServerConsole.MainConsole.Instance.CmdPrompt("Asset server URL: "); | ||
60 | this.AssetSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Asset server key: "); | ||
61 | this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid server URL: "); | ||
62 | this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Grid server key: "); | ||
63 | } | ||
64 | this.RegionHandle = Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); | ||
65 | } | ||
66 | |||
67 | public override void InitConfig() { | ||
68 | try { | ||
69 | db = Db4oFactory.OpenFile("opensim.yap"); | ||
70 | IObjectSet result = db.Get(typeof(DbSimConfig)); | ||
71 | if(result.Count==1) { | ||
72 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:InitConfig() - Found a SimConfig object in the local database, loading"); | ||
73 | foreach (DbSimConfig cfg in result) { | ||
74 | this.RegionName = cfg.RegionName; | ||
75 | this.RegionLocX = cfg.RegionLocX; | ||
76 | this.RegionLocY = cfg.RegionLocY; | ||
77 | this.RegionHandle = Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); | ||
78 | this.IPListenPort = cfg.IPListenPort; | ||
79 | this.IPListenAddr = cfg.IPListenAddr; | ||
80 | this.AssetURL = cfg.AssetURL; | ||
81 | this.AssetSendKey = cfg.AssetSendKey; | ||
82 | this.GridURL = cfg.GridURL; | ||
83 | this.GridSendKey = cfg.GridSendKey; | ||
84 | } | ||
85 | } else { | ||
86 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:InitConfig() - Could not find object in database, loading precompiled defaults"); | ||
87 | LoadDefaults(); | ||
88 | ServerConsole.MainConsole.Instance.WriteLine("Writing out default settings to local database"); | ||
89 | db.Set(this); | ||
90 | } | ||
91 | } catch(Exception e) { | ||
92 | db.Close(); | ||
93 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:InitConfig() - Exception occured"); | ||
94 | ServerConsole.MainConsole.Instance.WriteLine(e.ToString()); | ||
95 | } | ||
96 | |||
97 | ServerConsole.MainConsole.Instance.WriteLine("Sim settings loaded:"); | ||
98 | ServerConsole.MainConsole.Instance.WriteLine("Name: " + this.RegionName); | ||
99 | ServerConsole.MainConsole.Instance.WriteLine("Region Location: [" + this.RegionLocX.ToString() + "," + this.RegionLocY + "]"); | ||
100 | ServerConsole.MainConsole.Instance.WriteLine("Region Handle: " + this.RegionHandle.ToString()); | ||
101 | ServerConsole.MainConsole.Instance.WriteLine("Listening on IP: " + this.IPListenAddr + ":" + this.IPListenPort); | ||
102 | ServerConsole.MainConsole.Instance.WriteLine("Sandbox Mode? " + OpenSim_Main.sim.sandbox.ToString()); | ||
103 | ServerConsole.MainConsole.Instance.WriteLine("Asset URL: " + this.AssetURL); | ||
104 | ServerConsole.MainConsole.Instance.WriteLine("Asset key: " + this.AssetSendKey); | ||
105 | ServerConsole.MainConsole.Instance.WriteLine("Grid URL: " + this.GridURL); | ||
106 | ServerConsole.MainConsole.Instance.WriteLine("Grid key: " + this.GridSendKey); | ||
107 | } | ||
108 | |||
109 | public override World LoadWorld() | ||
110 | { | ||
111 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - Loading world...."); | ||
112 | World blank = new World(); | ||
113 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - Looking for a heightmap in local DB"); | ||
114 | IObjectSet world_result = db.Get(new float[65536]); | ||
115 | if(world_result.Count>0) { | ||
116 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - Found a heightmap in local database, loading"); | ||
117 | blank.LandMap=(float[])world_result.Next(); | ||
118 | } else { | ||
119 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - No heightmap found, generating new one"); | ||
120 | HeightmapGenHills hills = new HeightmapGenHills(); | ||
121 | blank.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false); | ||
122 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - Saving heightmap to local database"); | ||
123 | db.Set(blank.LandMap); | ||
124 | db.Commit(); | ||
125 | } | ||
126 | return blank; | ||
127 | } | ||
128 | |||
129 | public override void LoadFromGrid() { | ||
130 | ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadFromGrid() - dummy function, DOING ABSOLUTELY NOTHING AT ALL!!!"); | ||
131 | // TODO: Make this crap work | ||
132 | /* WebRequest GridLogin = WebRequest.Create(this.GridURL + "regions/" + this.RegionHandle.ToString() + "/login"); | ||
133 | WebResponse GridResponse = GridLogin.GetResponse(); | ||
134 | byte[] idata = new byte[(int)GridResponse.ContentLength]; | ||
135 | BinaryReader br = new BinaryReader(GridResponse.GetResponseStream()); | ||
136 | |||
137 | br.Close(); | ||
138 | GridResponse.Close(); | ||
139 | */ | ||
140 | } | ||
141 | |||
142 | public void Shutdown() { | ||
143 | db.Close(); | ||
144 | } | ||
145 | } | ||
146 | } | ||