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