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