diff options
author | MW | 2007-06-27 15:28:52 +0000 |
---|---|---|
committer | MW | 2007-06-27 15:28:52 +0000 |
commit | 646bbbc84b8010e0dacbeed5342cdb045f46cc49 (patch) | |
tree | 770b34d19855363c3c113ab9a0af9a56d821d887 /OpenSim/Region/Application/OpenSimMain.cs | |
download | opensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.zip opensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.gz opensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.bz2 opensim-SC_OLD-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/Region/Application/OpenSimMain.cs')
-rw-r--r-- | OpenSim/Region/Application/OpenSimMain.cs | 476 |
1 files changed, 476 insertions, 0 deletions
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs new file mode 100644 index 0000000..7da2263 --- /dev/null +++ b/OpenSim/Region/Application/OpenSimMain.cs | |||
@@ -0,0 +1,476 @@ | |||
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 | |||
29 | using System; | ||
30 | using System.Text; | ||
31 | using System.IO; | ||
32 | using System.Threading; | ||
33 | using System.Net; | ||
34 | using System.Net.Sockets; | ||
35 | using System.Timers; | ||
36 | using System.Reflection; | ||
37 | using System.Collections; | ||
38 | using System.Collections.Generic; | ||
39 | using libsecondlife; | ||
40 | using libsecondlife.Packets; | ||
41 | using OpenSim.Region; | ||
42 | using OpenSim.Region.Scenes; | ||
43 | using OpenSim.Terrain; | ||
44 | using OpenSim.Framework.Interfaces; | ||
45 | using OpenSim.Framework.Types; | ||
46 | using OpenSim.Framework; | ||
47 | using OpenSim.Assets; | ||
48 | using OpenSim.Caches; | ||
49 | using OpenSim.Framework.Console; | ||
50 | using OpenSim.Physics.Manager; | ||
51 | using Nwc.XmlRpc; | ||
52 | using OpenSim.Servers; | ||
53 | using OpenSim.GenericConfig; | ||
54 | using OpenGrid.Framework.Communications; | ||
55 | using OpenSim.LocalCommunications; | ||
56 | using OpenGrid.Framework.Communications.OGS1; | ||
57 | |||
58 | namespace OpenSim | ||
59 | { | ||
60 | |||
61 | public class OpenSimMain : RegionApplicationBase, conscmd_callback | ||
62 | { | ||
63 | // private CheckSumServer checkServer; | ||
64 | protected CommunicationsManager commsManager; | ||
65 | |||
66 | private bool m_silent; | ||
67 | private string m_logFilename = "region-console-" + Guid.NewGuid().ToString() + ".log"; | ||
68 | |||
69 | public OpenSimMain(bool sandBoxMode, bool startLoginServer, string physicsEngine, bool useConfigFile, bool silent, string configFile) | ||
70 | { | ||
71 | this.configFileSetup = useConfigFile; | ||
72 | m_sandbox = sandBoxMode; | ||
73 | m_loginserver = startLoginServer; | ||
74 | m_physicsEngine = physicsEngine; | ||
75 | m_config = configFile; | ||
76 | m_silent = silent; | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Performs initialisation of the world, such as loading configuration from disk. | ||
81 | /// </summary> | ||
82 | public override void StartUp() | ||
83 | { | ||
84 | this.serversData = new NetworkServersInfo(); | ||
85 | |||
86 | this.localConfig = new XmlConfig(m_config); | ||
87 | this.localConfig.LoadData(); | ||
88 | |||
89 | if (this.configFileSetup) | ||
90 | { | ||
91 | this.SetupFromConfigFile(this.localConfig); | ||
92 | } | ||
93 | |||
94 | m_log = new LogBase(m_logFilename, "Region", this, m_silent); | ||
95 | OpenSim.Framework.Console.MainLog.Instance = m_log; | ||
96 | |||
97 | m_log.Verbose( "Main.cs:Startup() - Loading configuration"); | ||
98 | this.serversData.InitConfig(this.m_sandbox, this.localConfig); | ||
99 | this.localConfig.Close();//for now we can close it as no other classes read from it , but this should change | ||
100 | |||
101 | ScenePresence.LoadTextureFile("avatar-texture.dat"); | ||
102 | |||
103 | ClientView.TerrainManager = new TerrainManager(new SecondLife()); | ||
104 | |||
105 | CommunicationsLocal sandboxCommunications = null; | ||
106 | if (m_sandbox) | ||
107 | { | ||
108 | this.SetupLocalGridServers(); | ||
109 | // this.checkServer = new CheckSumServer(12036); | ||
110 | // this.checkServer.ServerListener(); | ||
111 | sandboxCommunications = new CommunicationsLocal(this.serversData); | ||
112 | this.commsManager = sandboxCommunications; | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | this.SetupRemoteGridServers(); | ||
117 | this.commsManager = new GridCommsManager(this.serversData); | ||
118 | } | ||
119 | |||
120 | startuptime = DateTime.Now; | ||
121 | |||
122 | this.physManager = new OpenSim.Physics.Manager.PhysicsManager(); | ||
123 | this.physManager.LoadPlugins(); | ||
124 | |||
125 | this.SetupHttpListener(); | ||
126 | |||
127 | this.SetupWorld(); | ||
128 | |||
129 | m_log.Verbose( "Main.cs:Startup() - Initialising HTTP server"); | ||
130 | |||
131 | |||
132 | |||
133 | if (m_sandbox) | ||
134 | { | ||
135 | httpServer.AddXmlRPCHandler("login_to_simulator", sandboxCommunications.UserServices.XmlRpcLoginMethod); | ||
136 | } | ||
137 | |||
138 | //Start http server | ||
139 | m_log.Verbose( "Main.cs:Startup() - Starting HTTP server"); | ||
140 | httpServer.Start(); | ||
141 | |||
142 | // Start UDP servers | ||
143 | for (int i = 0; i < m_udpServer.Count; i++) | ||
144 | { | ||
145 | this.m_udpServer[i].ServerListener(); | ||
146 | } | ||
147 | |||
148 | } | ||
149 | |||
150 | # region Setup methods | ||
151 | protected override void SetupLocalGridServers() | ||
152 | { | ||
153 | try | ||
154 | { | ||
155 | AssetCache = new AssetCache("OpenSim.GridInterfaces.Local.dll", this.serversData.AssetURL, this.serversData.AssetSendKey); | ||
156 | InventoryCache = new InventoryCache(); | ||
157 | } | ||
158 | catch (Exception e) | ||
159 | { | ||
160 | m_log.Error( e.Message + "\nSorry, could not setup local cache"); | ||
161 | Environment.Exit(1); | ||
162 | } | ||
163 | |||
164 | } | ||
165 | |||
166 | protected override void SetupRemoteGridServers() | ||
167 | { | ||
168 | try | ||
169 | { | ||
170 | AssetCache = new AssetCache("OpenSim.GridInterfaces.Remote.dll", this.serversData.AssetURL, this.serversData.AssetSendKey); | ||
171 | InventoryCache = new InventoryCache(); | ||
172 | } | ||
173 | catch (Exception e) | ||
174 | { | ||
175 | m_log.Error( e.Message + "\nSorry, could not setup remote cache"); | ||
176 | Environment.Exit(1); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | protected override void SetupWorld() | ||
181 | { | ||
182 | IGenericConfig regionConfig; | ||
183 | Scene LocalWorld; | ||
184 | UDPServer udpServer; | ||
185 | RegionInfo regionDat = new RegionInfo(); | ||
186 | AuthenticateSessionsBase authenBase; | ||
187 | |||
188 | string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Regions"); | ||
189 | string[] configFiles = Directory.GetFiles(path, "*.xml"); | ||
190 | |||
191 | if (configFiles.Length == 0) | ||
192 | { | ||
193 | string path2 = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Regions"); | ||
194 | string path3 = Path.Combine(path2, "default.xml"); | ||
195 | Console.WriteLine("Creating default region config file"); | ||
196 | //TODO create default region | ||
197 | IGenericConfig defaultConfig = new XmlConfig(path3); | ||
198 | defaultConfig.LoadData(); | ||
199 | defaultConfig.Commit(); | ||
200 | defaultConfig.Close(); | ||
201 | defaultConfig = null; | ||
202 | configFiles = Directory.GetFiles(path, "*.xml"); | ||
203 | } | ||
204 | |||
205 | for (int i = 0; i < configFiles.Length; i++) | ||
206 | { | ||
207 | regionDat = new RegionInfo(); | ||
208 | if (m_sandbox) | ||
209 | { | ||
210 | AuthenticateSessionsBase authen = new AuthenticateSessionsBase(); // new AuthenticateSessionsLocal(); | ||
211 | this.AuthenticateSessionsHandler.Add(authen); | ||
212 | authenBase = authen; | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | AuthenticateSessionsBase authen = new AuthenticateSessionsBase(); //new AuthenticateSessionsRemote(); | ||
217 | this.AuthenticateSessionsHandler.Add(authen); | ||
218 | authenBase = authen; | ||
219 | } | ||
220 | Console.WriteLine("Loading region config file"); | ||
221 | regionConfig = new XmlConfig(configFiles[i]); | ||
222 | regionConfig.LoadData(); | ||
223 | regionDat.InitConfig(this.m_sandbox, regionConfig); | ||
224 | regionConfig.Close(); | ||
225 | |||
226 | udpServer = new UDPServer(regionDat.CommsIPListenPort, this.AssetCache, this.InventoryCache, this.m_log, authenBase); | ||
227 | |||
228 | m_udpServer.Add(udpServer); | ||
229 | this.regionData.Add(regionDat); | ||
230 | |||
231 | /* | ||
232 | m_log.WriteLine(OpenSim.Framework.Console.LogPriority.NORMAL, "Main.cs:Startup() - We are " + regionData.RegionName + " at " + regionData.RegionLocX.ToString() + "," + regionData.RegionLocY.ToString()); | ||
233 | m_log.Verbose( "Initialising world"); | ||
234 | m_log.componentname = "Region " + regionData.RegionName; | ||
235 | */ | ||
236 | |||
237 | LocalWorld = new Scene(udpServer.PacketServer.ClientAPIs, regionDat, authenBase, commsManager, this.AssetCache, httpServer); | ||
238 | this.m_localWorld.Add(LocalWorld); | ||
239 | //LocalWorld.InventoryCache = InventoryCache; | ||
240 | //LocalWorld.AssetCache = AssetCache; | ||
241 | |||
242 | udpServer.LocalWorld = LocalWorld; | ||
243 | |||
244 | LocalWorld.LoadStorageDLL("OpenSim.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded. | ||
245 | LocalWorld.LoadWorldMap(); | ||
246 | |||
247 | m_log.Verbose( "Main.cs:Startup() - Starting up messaging system"); | ||
248 | LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this.m_physicsEngine); | ||
249 | LocalWorld.PhysScene.SetTerrain(LocalWorld.Terrain.getHeights1D()); | ||
250 | LocalWorld.LoadPrimsFromStorage(); | ||
251 | LocalWorld.localStorage.LoadParcels((ILocalStorageParcelReceiver)LocalWorld.parcelManager); | ||
252 | |||
253 | |||
254 | LocalWorld.StartTimer(); | ||
255 | } | ||
256 | } | ||
257 | |||
258 | protected override void SetupHttpListener() | ||
259 | { | ||
260 | httpServer = new BaseHttpServer(this.serversData.HttpListenerPort); //regionData[0].IPListenPort); | ||
261 | |||
262 | if (!this.m_sandbox) | ||
263 | { | ||
264 | |||
265 | // we are in Grid mode so set a XmlRpc handler to handle "expect_user" calls from the user server | ||
266 | |||
267 | |||
268 | httpServer.AddRestHandler("GET", "/simstatus/", | ||
269 | delegate(string request, string path, string param) | ||
270 | { | ||
271 | return "OK"; | ||
272 | }); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | protected override void ConnectToRemoteGridServer() | ||
277 | { | ||
278 | |||
279 | } | ||
280 | |||
281 | #endregion | ||
282 | |||
283 | private void SetupFromConfigFile(IGenericConfig configData) | ||
284 | { | ||
285 | // Log filename | ||
286 | string attri = ""; | ||
287 | attri = configData.GetAttribute("LogFilename"); | ||
288 | if (String.IsNullOrEmpty(attri)) | ||
289 | { | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | m_logFilename = attri; | ||
294 | } | ||
295 | |||
296 | // SandBoxMode | ||
297 | attri = ""; | ||
298 | attri = configData.GetAttribute("SandBox"); | ||
299 | if ((attri == "") || ((attri != "false") && (attri != "true"))) | ||
300 | { | ||
301 | this.m_sandbox = false; | ||
302 | configData.SetAttribute("SandBox", "false"); | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | this.m_sandbox = Convert.ToBoolean(attri); | ||
307 | } | ||
308 | |||
309 | // LoginServer | ||
310 | attri = ""; | ||
311 | attri = configData.GetAttribute("LoginServer"); | ||
312 | if ((attri == "") || ((attri != "false") && (attri != "true"))) | ||
313 | { | ||
314 | this.m_loginserver = false; | ||
315 | configData.SetAttribute("LoginServer", "false"); | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | this.m_loginserver = Convert.ToBoolean(attri); | ||
320 | } | ||
321 | |||
322 | // Sandbox User accounts | ||
323 | attri = ""; | ||
324 | attri = configData.GetAttribute("UserAccount"); | ||
325 | if ((attri == "") || ((attri != "false") && (attri != "true"))) | ||
326 | { | ||
327 | this.user_accounts = false; | ||
328 | configData.SetAttribute("UserAccounts", "false"); | ||
329 | } | ||
330 | else if (attri == "true") | ||
331 | { | ||
332 | this.user_accounts = Convert.ToBoolean(attri); | ||
333 | } | ||
334 | |||
335 | // Grid mode hack to use local asset server | ||
336 | attri = ""; | ||
337 | attri = configData.GetAttribute("LocalAssets"); | ||
338 | if ((attri == "") || ((attri != "false") && (attri != "true"))) | ||
339 | { | ||
340 | this.gridLocalAsset = false; | ||
341 | configData.SetAttribute("LocalAssets", "false"); | ||
342 | } | ||
343 | else if (attri == "true") | ||
344 | { | ||
345 | this.gridLocalAsset = Convert.ToBoolean(attri); | ||
346 | } | ||
347 | |||
348 | |||
349 | attri = ""; | ||
350 | attri = configData.GetAttribute("PhysicsEngine"); | ||
351 | switch (attri) | ||
352 | { | ||
353 | default: | ||
354 | m_log.Warn( "Main.cs: SetupFromConfig() - Invalid value for PhysicsEngine attribute, terminating"); | ||
355 | Environment.Exit(1); | ||
356 | break; | ||
357 | |||
358 | case "": | ||
359 | this.m_physicsEngine = "basicphysics"; | ||
360 | configData.SetAttribute("PhysicsEngine", "basicphysics"); | ||
361 | OpenSim.Region.Scenes.ScenePresence.PhysicsEngineFlying = false; | ||
362 | break; | ||
363 | |||
364 | case "basicphysics": | ||
365 | this.m_physicsEngine = "basicphysics"; | ||
366 | configData.SetAttribute("PhysicsEngine", "basicphysics"); | ||
367 | OpenSim.Region.Scenes.ScenePresence.PhysicsEngineFlying = false; | ||
368 | break; | ||
369 | |||
370 | case "RealPhysX": | ||
371 | this.m_physicsEngine = "RealPhysX"; | ||
372 | OpenSim.Region.Scenes.ScenePresence.PhysicsEngineFlying = true; | ||
373 | break; | ||
374 | |||
375 | case "OpenDynamicsEngine": | ||
376 | this.m_physicsEngine = "OpenDynamicsEngine"; | ||
377 | OpenSim.Region.Scenes.ScenePresence.PhysicsEngineFlying = true; | ||
378 | break; | ||
379 | } | ||
380 | |||
381 | configData.Commit(); | ||
382 | |||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Performs any last-minute sanity checking and shuts down the region server | ||
387 | /// </summary> | ||
388 | public virtual void Shutdown() | ||
389 | { | ||
390 | m_log.Verbose( "Main.cs:Shutdown() - Closing all threads"); | ||
391 | m_log.Verbose( "Main.cs:Shutdown() - Killing listener thread"); | ||
392 | m_log.Verbose( "Main.cs:Shutdown() - Killing clients"); | ||
393 | // IMPLEMENT THIS | ||
394 | m_log.Verbose( "Main.cs:Shutdown() - Closing console and terminating"); | ||
395 | for (int i = 0; i < m_localWorld.Count; i++) | ||
396 | { | ||
397 | ((Scene)m_localWorld[i]).Close(); | ||
398 | } | ||
399 | m_log.Close(); | ||
400 | Environment.Exit(0); | ||
401 | } | ||
402 | |||
403 | #region Console Commands | ||
404 | /// <summary> | ||
405 | /// Runs commands issued by the server console from the operator | ||
406 | /// </summary> | ||
407 | /// <param name="command">The first argument of the parameter (the command)</param> | ||
408 | /// <param name="cmdparams">Additional arguments passed to the command</param> | ||
409 | public void RunCmd(string command, string[] cmdparams) | ||
410 | { | ||
411 | switch (command) | ||
412 | { | ||
413 | case "help": | ||
414 | m_log.Error( "show users - show info about connected users"); | ||
415 | m_log.Error( "shutdown - disconnect all clients and shutdown"); | ||
416 | break; | ||
417 | |||
418 | case "show": | ||
419 | if (cmdparams.Length > 0) | ||
420 | { | ||
421 | Show(cmdparams[0]); | ||
422 | } | ||
423 | break; | ||
424 | |||
425 | case "terrain": | ||
426 | string result = ""; | ||
427 | for (int i = 0; i < m_localWorld.Count; i++) | ||
428 | { | ||
429 | if (!((Scene)m_localWorld[i]).Terrain.RunTerrainCmd(cmdparams, ref result)) | ||
430 | { | ||
431 | m_log.Error(result); | ||
432 | } | ||
433 | } | ||
434 | break; | ||
435 | |||
436 | case "shutdown": | ||
437 | Shutdown(); | ||
438 | break; | ||
439 | |||
440 | default: | ||
441 | m_log.Error( "Unknown command"); | ||
442 | break; | ||
443 | } | ||
444 | } | ||
445 | |||
446 | /// <summary> | ||
447 | /// Outputs to the console information about the region | ||
448 | /// </summary> | ||
449 | /// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param> | ||
450 | public void Show(string ShowWhat) | ||
451 | { | ||
452 | switch (ShowWhat) | ||
453 | { | ||
454 | case "uptime": | ||
455 | m_log.Error( "OpenSim has been running since " + startuptime.ToString()); | ||
456 | m_log.Error( "That is " + (DateTime.Now - startuptime).ToString()); | ||
457 | break; | ||
458 | case "users": | ||
459 | OpenSim.Region.Scenes.ScenePresence TempAv; | ||
460 | m_log.Error( String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP")); | ||
461 | /* foreach (libsecondlife.LLUUID UUID in LocalWorld.Entities.Keys) | ||
462 | { | ||
463 | if (LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar") | ||
464 | { | ||
465 | TempAv = (OpenSim.world.Avatar)LocalWorld.Entities[UUID]; | ||
466 | m_log.Error( String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString())); | ||
467 | } | ||
468 | }*/ | ||
469 | break; | ||
470 | } | ||
471 | } | ||
472 | #endregion | ||
473 | } | ||
474 | |||
475 | |||
476 | } \ No newline at end of file | ||