aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSimMain.cs
diff options
context:
space:
mode:
authorMW2007-05-16 18:59:51 +0000
committerMW2007-05-16 18:59:51 +0000
commit2a6d69b2b8ab84eec58bf8d0fb786ac6fdfba73f (patch)
tree638f3d03f5ba5184dca03b8cf60211e90976eee3 /OpenSim/OpenSimMain.cs
parentAdded OpenSimApplication as a base class to OpenSimMain (diff)
downloadopensim-SC_OLD-2a6d69b2b8ab84eec58bf8d0fb786ac6fdfba73f.zip
opensim-SC_OLD-2a6d69b2b8ab84eec58bf8d0fb786ac6fdfba73f.tar.gz
opensim-SC_OLD-2a6d69b2b8ab84eec58bf8d0fb786ac6fdfba73f.tar.bz2
opensim-SC_OLD-2a6d69b2b8ab84eec58bf8d0fb786ac6fdfba73f.tar.xz
Moved the OpenSimMain class into the OpenSim.exe project
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSimMain.cs530
1 files changed, 530 insertions, 0 deletions
diff --git a/OpenSim/OpenSimMain.cs b/OpenSim/OpenSimMain.cs
new file mode 100644
index 0000000..b7c8bef
--- /dev/null
+++ b/OpenSim/OpenSimMain.cs
@@ -0,0 +1,530 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4* All rights reserved.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the <organization> nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29using System;
30using System.Text;
31using System.IO;
32using System.Threading;
33using System.Net;
34using System.Net.Sockets;
35using System.Timers;
36using System.Reflection;
37using System.Collections;
38using System.Collections.Generic;
39using libsecondlife;
40using libsecondlife.Packets;
41using OpenSim.world;
42using OpenSim.Terrain;
43using OpenSim.Framework.Interfaces;
44using OpenSim.Framework.Types;
45using OpenSim.UserServer;
46using OpenSim.Assets;
47using OpenSim.CAPS;
48using OpenSim.Framework.Console;
49using OpenSim.Physics.Manager;
50using Nwc.XmlRpc;
51using OpenSim.Servers;
52using OpenSim.GenericConfig;
53
54namespace OpenSim
55{
56
57 public class OpenSimMain : OpenSimApplicationBase, conscmd_callback
58 {
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
68 m_console = new ConsoleBase("region-console-" + Guid.NewGuid().ToString() + ".log", "Region", this, silent);
69 OpenSim.Framework.Console.MainConsole.Instance = m_console;
70 }
71
72 /// <summary>
73 /// Performs initialisation of the world, such as loading configuration from disk.
74 /// </summary>
75 public override void StartUp()
76 {
77 this.regionData = new RegionInfo();
78 try
79 {
80 this.localConfig = new XmlConfig(m_config);
81 this.localConfig.LoadData();
82 }
83 catch (Exception e)
84 {
85 Console.WriteLine(e.Message);
86 }
87 if (this.configFileSetup)
88 {
89 this.SetupFromConfigFile(this.localConfig);
90 }
91 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Loading configuration");
92 this.regionData.InitConfig(this.m_sandbox, this.localConfig);
93 this.localConfig.Close();//for now we can close it as no other classes read from it , but this should change
94
95 GridServers = new Grid();
96 if (m_sandbox)
97 {
98 this.SetupLocalGridServers();
99 //Authenticate Session Handler
100 AuthenticateSessionsLocal authen = new AuthenticateSessionsLocal();
101 this.AuthenticateSessionsHandler = authen;
102 }
103 else
104 {
105 this.SetupRemoteGridServers();
106 //Authenticate Session Handler
107 AuthenticateSessionsRemote authen = new AuthenticateSessionsRemote();
108 this.AuthenticateSessionsHandler = authen;
109 }
110
111 startuptime = DateTime.Now;
112
113 try
114 {
115 AssetCache = new AssetCache(GridServers.AssetServer);
116 InventoryCache = new InventoryCache();
117 }
118 catch (Exception e)
119 {
120 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, e.Message + "\nSorry, could not setup local cache");
121 Environment.Exit(1);
122 }
123
124 m_udpServer = new UDPServer(this.regionData.IPListenPort, this.GridServers, this.AssetCache, this.InventoryCache, this.regionData, this.m_sandbox, this.user_accounts, this.m_console, this.AuthenticateSessionsHandler);
125
126 //should be passing a IGenericConfig object to these so they can read the config data they want from it
127 GridServers.AssetServer.SetServerInfo(regionData.AssetURL, regionData.AssetSendKey);
128 IGridServer gridServer = GridServers.GridServer;
129 gridServer.SetServerInfo(regionData.GridURL, regionData.GridSendKey, regionData.GridRecvKey);
130
131 if (!m_sandbox)
132 {
133 this.ConnectToRemoteGridServer();
134 }
135
136 this.SetupLocalWorld();
137
138 if (m_sandbox)
139 {
140 AssetCache.LoadDefaultTextureSet();
141 }
142
143 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Initialising HTTP server");
144
145 this.SetupHttpListener();
146
147 LoginServer loginServer = null;
148 LoginServer adminLoginServer = null;
149
150 bool sandBoxWithLoginServer = m_loginserver && m_sandbox;
151 if (sandBoxWithLoginServer)
152 {
153 loginServer = new LoginServer(regionData.IPListenAddr, regionData.IPListenPort, regionData.RegionLocX, regionData.RegionLocY, this.user_accounts);
154 loginServer.Startup();
155 loginServer.SetSessionHandler(((AuthenticateSessionsLocal)this.AuthenticateSessionsHandler).AddNewSession);
156
157 if (user_accounts)
158 {
159 //sandbox mode with loginserver using accounts
160 this.GridServers.UserServer = loginServer;
161 adminLoginServer = loginServer;
162
163 httpServer.AddXmlRPCHandler("login_to_simulator", loginServer.LocalUserManager.XmlRpcLoginMethod);
164 }
165 else
166 {
167 //sandbox mode with loginserver not using accounts
168 httpServer.AddXmlRPCHandler("login_to_simulator", loginServer.XmlRpcLoginMethod);
169 }
170 }
171
172 AdminWebFront adminWebFront = new AdminWebFront("Admin", LocalWorld, InventoryCache, adminLoginServer);
173 adminWebFront.LoadMethods(httpServer);
174
175 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP server");
176 httpServer.Start();
177
178 //MainServerListener();
179 this.m_udpServer.ServerListener();
180
181 m_heartbeatTimer.Enabled = true;
182 m_heartbeatTimer.Interval = 100;
183 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
184 }
185
186 # region Setup methods
187 protected virtual void SetupLocalGridServers()
188 {
189 GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll";
190 GridServers.GridDll = "OpenSim.GridInterfaces.Local.dll";
191
192 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Starting in Sandbox mode");
193
194 try
195 {
196 GridServers.Initialise();
197 }
198 catch (Exception e)
199 {
200 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, e.Message + "\nSorry, could not setup the grid interface");
201 Environment.Exit(1);
202 }
203 }
204
205 protected virtual void SetupRemoteGridServers()
206 {
207 if (this.gridLocalAsset)
208 {
209 GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll";
210 }
211 else
212 {
213 GridServers.AssetDll = "OpenSim.GridInterfaces.Remote.dll";
214 }
215 GridServers.GridDll = "OpenSim.GridInterfaces.Remote.dll";
216
217 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Starting in Grid mode");
218
219 try
220 {
221 GridServers.Initialise();
222 }
223 catch (Exception e)
224 {
225 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, e.Message + "\nSorry, could not setup the grid interface");
226 Environment.Exit(1);
227 }
228 }
229
230 protected virtual void SetupLocalWorld()
231 {
232 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.NORMAL, "Main.cs:Startup() - We are " + regionData.RegionName + " at " + regionData.RegionLocX.ToString() + "," + regionData.RegionLocY.ToString());
233 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Initialising world");
234 m_console.componentname = "Region " + regionData.RegionName;
235
236 m_localWorld = new World(this.m_udpServer.PacketServer.ClientThreads, regionData, regionData.RegionHandle, regionData.RegionName);
237 LocalWorld.InventoryCache = InventoryCache;
238 LocalWorld.AssetCache = AssetCache;
239
240 this.m_udpServer.LocalWorld = LocalWorld;
241 this.m_udpServer.PacketServer.RegisterClientPacketHandlers();
242
243 this.physManager = new OpenSim.Physics.Manager.PhysicsManager();
244 this.physManager.LoadPlugins();
245
246 LocalWorld.m_datastore = this.regionData.DataStore;
247
248 LocalWorld.LoadStorageDLL("OpenSim.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded.
249 LocalWorld.LoadWorldMap();
250
251 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting up messaging system");
252 LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this.m_physicsEngine);
253 LocalWorld.PhysScene.SetTerrain(LocalWorld.Terrain.getHeights1D());
254 LocalWorld.LoadPrimsFromStorage();
255 }
256
257 protected virtual void SetupHttpListener()
258 {
259 httpServer = new BaseHttpServer(regionData.IPListenPort);
260
261 if (this.GridServers.GridServer.GetName() == "Remote")
262 {
263
264 // we are in Grid mode so set a XmlRpc handler to handle "expect_user" calls from the user server
265 httpServer.AddXmlRPCHandler("expect_user", ((AuthenticateSessionsRemote)this.AuthenticateSessionsHandler).ExpectUser);
266
267 httpServer.AddXmlRPCHandler("agent_crossing",
268 delegate(XmlRpcRequest request)
269 {
270 Hashtable requestData = (Hashtable)request.Params[0];
271 AgentCircuitData agent_data = new AgentCircuitData();
272 agent_data.firstname = (string)requestData["firstname"];
273 agent_data.lastname = (string)requestData["lastname"];
274 agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
275 agent_data.startpos = new LLVector3(Single.Parse((string)requestData["pos_x"]), Single.Parse((string)requestData["pos_y"]), Single.Parse((string)requestData["pos_z"]));
276
277 if (((RemoteGridBase)this.GridServers.GridServer).agentcircuits.ContainsKey((uint)agent_data.circuitcode))
278 {
279 ((RemoteGridBase)this.GridServers.GridServer).agentcircuits[(uint)agent_data.circuitcode].firstname = agent_data.firstname;
280 ((RemoteGridBase)this.GridServers.GridServer).agentcircuits[(uint)agent_data.circuitcode].lastname = agent_data.lastname;
281 ((RemoteGridBase)this.GridServers.GridServer).agentcircuits[(uint)agent_data.circuitcode].startpos = agent_data.startpos;
282 }
283
284 return new XmlRpcResponse();
285 });
286
287 httpServer.AddRestHandler("GET", "/simstatus/",
288 delegate(string request, string path, string param)
289 {
290 return "OK";
291 });
292 }
293 }
294
295 protected virtual void ConnectToRemoteGridServer()
296 {
297 if (GridServers.GridServer.RequestConnection(regionData.SimUUID, regionData.IPListenAddr, (uint)regionData.IPListenPort))
298 {
299 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Success: Got a grid connection OK!");
300 }
301 else
302 {
303 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL, "Main.cs:Startup() - FAILED: Unable to get connection to grid. Shutting down.");
304 Shutdown();
305 }
306
307 GridServers.AssetServer.SetServerInfo((string)((RemoteGridBase)GridServers.GridServer).GridData["asset_url"], (string)((RemoteGridBase)GridServers.GridServer).GridData["asset_sendkey"]);
308
309 // If we are being told to load a file, load it.
310 string dataUri = (string)((RemoteGridBase)GridServers.GridServer).GridData["data_uri"];
311
312 if (!String.IsNullOrEmpty(dataUri))
313 {
314 this.LocalWorld.m_datastore = dataUri;
315 }
316
317 if (((RemoteGridBase)(GridServers.GridServer)).GridData["regionname"].ToString() != "")
318 {
319 // The grid server has told us who we are
320 // We must obey the grid server.
321 try
322 {
323 regionData.RegionLocX = Convert.ToUInt32(((RemoteGridBase)(GridServers.GridServer)).GridData["region_locx"].ToString());
324 regionData.RegionLocY = Convert.ToUInt32(((RemoteGridBase)(GridServers.GridServer)).GridData["region_locy"].ToString());
325 regionData.RegionName = ((RemoteGridBase)(GridServers.GridServer)).GridData["regionname"].ToString();
326 }
327 catch (Exception e)
328 {
329 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL, e.Message + "\nBAD ERROR! THIS SHOULD NOT HAPPEN! Bad GridData from the grid interface!!!! ZOMG!!!");
330 Environment.Exit(1);
331 }
332 }
333 }
334
335 #endregion
336
337 private void SetupFromConfigFile(IGenericConfig configData)
338 {
339 try
340 {
341 // SandBoxMode
342 string attri = "";
343 attri = configData.GetAttribute("SandBox");
344 if ((attri == "") || ((attri != "false") && (attri != "true")))
345 {
346 this.m_sandbox = false;
347 configData.SetAttribute("SandBox", "false");
348 }
349 else
350 {
351 this.m_sandbox = Convert.ToBoolean(attri);
352 }
353
354 // LoginServer
355 attri = "";
356 attri = configData.GetAttribute("LoginServer");
357 if ((attri == "") || ((attri != "false") && (attri != "true")))
358 {
359 this.m_loginserver = false;
360 configData.SetAttribute("LoginServer", "false");
361 }
362 else
363 {
364 this.m_loginserver = Convert.ToBoolean(attri);
365 }
366
367 // Sandbox User accounts
368 attri = "";
369 attri = configData.GetAttribute("UserAccount");
370 if ((attri == "") || ((attri != "false") && (attri != "true")))
371 {
372 this.user_accounts = false;
373 configData.SetAttribute("UserAccounts", "false");
374 }
375 else if (attri == "true")
376 {
377 this.user_accounts = Convert.ToBoolean(attri);
378 }
379
380 // Grid mode hack to use local asset server
381 attri = "";
382 attri = configData.GetAttribute("LocalAssets");
383 if ((attri == "") || ((attri != "false") && (attri != "true")))
384 {
385 this.gridLocalAsset = false;
386 configData.SetAttribute("LocalAssets", "false");
387 }
388 else if (attri == "true")
389 {
390 this.gridLocalAsset = Convert.ToBoolean(attri);
391 }
392
393
394 attri = "";
395 attri = configData.GetAttribute("PhysicsEngine");
396 switch (attri)
397 {
398 default:
399 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "Main.cs: SetupFromConfig() - Invalid value for PhysicsEngine attribute, terminating");
400 Environment.Exit(1);
401 break;
402
403 case "":
404 this.m_physicsEngine = "basicphysics";
405 configData.SetAttribute("PhysicsEngine", "basicphysics");
406 OpenSim.world.Avatar.PhysicsEngineFlying = false;
407 break;
408
409 case "basicphysics":
410 this.m_physicsEngine = "basicphysics";
411 configData.SetAttribute("PhysicsEngine", "basicphysics");
412 OpenSim.world.Avatar.PhysicsEngineFlying = false;
413 break;
414
415 case "RealPhysX":
416 this.m_physicsEngine = "RealPhysX";
417 OpenSim.world.Avatar.PhysicsEngineFlying = true;
418 break;
419
420 case "OpenDynamicsEngine":
421 this.m_physicsEngine = "OpenDynamicsEngine";
422 OpenSim.world.Avatar.PhysicsEngineFlying = true;
423 break;
424 }
425
426 configData.Commit();
427 }
428 catch (Exception e)
429 {
430 Console.WriteLine(e.Message);
431 Console.WriteLine("\nSorry, a fatal error occurred while trying to initialise the configuration data");
432 Console.WriteLine("Can not continue starting up");
433 Environment.Exit(1);
434 }
435 }
436
437 /// <summary>
438 /// Performs any last-minute sanity checking and shuts down the region server
439 /// </summary>
440 public virtual void Shutdown()
441 {
442 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Shutdown() - Closing all threads");
443 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Shutdown() - Killing listener thread");
444 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Shutdown() - Killing clients");
445 // IMPLEMENT THIS
446 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Shutdown() - Closing console and terminating");
447 LocalWorld.Close();
448 GridServers.Close();
449 m_console.Close();
450 Environment.Exit(0);
451 }
452
453 /// <summary>
454 /// Performs per-frame updates regularly
455 /// </summary>
456 /// <param name="sender"></param>
457 /// <param name="e"></param>
458 void Heartbeat(object sender, System.EventArgs e)
459 {
460 LocalWorld.Update();
461 }
462
463 #region Console Commands
464 /// <summary>
465 /// Runs commands issued by the server console from the operator
466 /// </summary>
467 /// <param name="command">The first argument of the parameter (the command)</param>
468 /// <param name="cmdparams">Additional arguments passed to the command</param>
469 public void RunCmd(string command, string[] cmdparams)
470 {
471 switch (command)
472 {
473 case "help":
474 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "show users - show info about connected users");
475 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "shutdown - disconnect all clients and shutdown");
476 break;
477
478 case "show":
479 Show(cmdparams[0]);
480 break;
481
482 case "terrain":
483 string result = "";
484 if (!LocalWorld.Terrain.RunTerrainCmd(cmdparams, ref result))
485 {
486 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, result);
487 }
488 break;
489
490 case "shutdown":
491 Shutdown();
492 break;
493
494 default:
495 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "Unknown command");
496 break;
497 }
498 }
499
500 /// <summary>
501 /// Outputs to the console information about the region
502 /// </summary>
503 /// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param>
504 public void Show(string ShowWhat)
505 {
506 switch (ShowWhat)
507 {
508 case "uptime":
509 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "OpenSim has been running since " + startuptime.ToString());
510 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "That is " + (DateTime.Now - startuptime).ToString());
511 break;
512 case "users":
513 OpenSim.world.Avatar TempAv;
514 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP"));
515 foreach (libsecondlife.LLUUID UUID in LocalWorld.Entities.Keys)
516 {
517 if (LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
518 {
519 TempAv = (OpenSim.world.Avatar)LocalWorld.Entities[UUID];
520 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, 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()));
521 }
522 }
523 break;
524 }
525 }
526 #endregion
527 }
528
529
530} \ No newline at end of file