aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim/OpenSimMain.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:02:47 +0000
committerAdam Frisby2007-07-11 08:02:47 +0000
commit5c7ffdde0b9642a42e8f5987e06eb01220ff7776 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /OpenSim/OpenSim/OpenSimMain.cs
parentWho would have known that the only way of specifying utf-8 without preamble, ... (diff)
downloadopensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.zip
opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.gz
opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.bz2
opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.xz
* Wiping trunk in prep for Sugilite
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim/OpenSimMain.cs552
1 files changed, 0 insertions, 552 deletions
diff --git a/OpenSim/OpenSim/OpenSimMain.cs b/OpenSim/OpenSim/OpenSimMain.cs
deleted file mode 100644
index 0a316bd..0000000
--- a/OpenSim/OpenSim/OpenSimMain.cs
+++ /dev/null
@@ -1,552 +0,0 @@
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.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.RegionServer;
42
43using OpenSim.RegionServer.Simulator;
44using OpenSim.Terrain;
45using OpenSim.Framework.Interfaces;
46using OpenSim.Framework.Types;
47using OpenSim.UserServer;
48using OpenSim.RegionServer.Assets;
49using OpenSim.RegionServer.CAPS;
50using OpenSim.Framework.Console;
51using OpenSim.Physics.Manager;
52using Nwc.XmlRpc;
53using OpenSim.Servers;
54using OpenSim.GenericConfig;
55
56namespace OpenSim
57{
58
59 public class OpenSimMain : OpenSim.RegionServer.RegionServerBase, conscmd_callback
60 {
61 private CheckSumServer checkServer;
62
63 public OpenSimMain(bool sandBoxMode, bool startLoginServer, string physicsEngine, bool useConfigFile, bool silent, string configFile)
64 {
65 this.configFileSetup = useConfigFile;
66 m_sandbox = sandBoxMode;
67 m_loginserver = startLoginServer;
68 m_physicsEngine = physicsEngine;
69 m_config = configFile;
70
71 m_console = new ConsoleBase("region-console-" + Guid.NewGuid().ToString() + ".log", "Region", this, silent);
72 OpenSim.Framework.Console.MainConsole.Instance = m_console;
73 }
74
75 /// <summary>
76 /// Performs initialisation of the world, such as loading configuration from disk.
77 /// </summary>
78 public override void StartUp()
79 {
80 this.regionData = new RegionInfo();
81
82 this.localConfig = new XmlConfig(m_config);
83 this.localConfig.LoadData();
84
85 if (this.configFileSetup)
86 {
87 this.SetupFromConfigFile(this.localConfig);
88 }
89 m_console.Notice("Main.cs:Startup() - Loading configuration");
90 this.regionData.InitConfig(this.m_sandbox, this.localConfig);
91 this.localConfig.Close();//for now we can close it as no other classes read from it , but this should change
92
93 GridServers = new Grid();
94 if (m_sandbox)
95 {
96 this.SetupLocalGridServers();
97 //Authenticate Session Handler
98 AuthenticateSessionsLocal authen = new AuthenticateSessionsLocal();
99 this.AuthenticateSessionsHandler = authen;
100 this.checkServer = new CheckSumServer(12036);
101 this.checkServer.ServerListener();
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
114 AssetCache = new AssetCache(GridServers.AssetServer);
115 InventoryCache = new InventoryCache();
116
117
118 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);
119
120 //should be passing a IGenericConfig object to these so they can read the config data they want from it
121 GridServers.AssetServer.SetServerInfo(regionData.AssetURL, regionData.AssetSendKey);
122 IGridServer gridServer = GridServers.GridServer;
123 gridServer.SetServerInfo(regionData.GridURL, regionData.GridSendKey, regionData.GridRecvKey);
124
125 if (!m_sandbox)
126 {
127 this.ConnectToRemoteGridServer();
128 }
129
130 this.SetupLocalWorld();
131
132 if (m_sandbox)
133 {
134 AssetCache.LoadDefaultTextureSet();
135 }
136
137 m_console.Notice("Main.cs:Startup() - Initialising HTTP server");
138
139 this.SetupHttpListener();
140
141 //Login server setup
142 LoginServer loginServer = null;
143 LoginServer adminLoginServer = null;
144
145 bool sandBoxWithLoginServer = m_loginserver && m_sandbox;
146 if (sandBoxWithLoginServer)
147 {
148 loginServer = new LoginServer(regionData.IPListenAddr, regionData.IPListenPort, regionData.RegionLocX, regionData.RegionLocY, this.user_accounts);
149 loginServer.Startup();
150 loginServer.SetSessionHandler(((AuthenticateSessionsLocal)this.AuthenticateSessionsHandler).AddNewSession);
151
152 if (user_accounts)
153 {
154 //sandbox mode with loginserver using accounts
155 this.GridServers.UserServer = loginServer;
156 adminLoginServer = loginServer;
157
158 httpServer.AddXmlRPCHandler("login_to_simulator", loginServer.LocalUserManager.XmlRpcLoginMethod);
159 }
160 else
161 {
162 //sandbox mode with loginserver not using accounts
163 httpServer.AddXmlRPCHandler("login_to_simulator", loginServer.XmlRpcLoginMethod);
164 }
165 }
166
167 //Web front end setup
168 AdminWebFront adminWebFront = new AdminWebFront("Admin", LocalWorld, InventoryCache, adminLoginServer);
169 adminWebFront.LoadMethods(httpServer);
170
171 //Start http server
172 m_console.Notice("Main.cs:Startup() - Starting HTTP server");
173 httpServer.Start();
174
175 // Start UDP server
176 this.m_udpServer.ServerListener();
177
178 //Setup Master Avatar
179 m_console.Notice("Main.cs:Startup() - Setting up Master Avatar");
180 if (this.m_sandbox)
181 {
182 OpenSim.Framework.User.UserProfile masterUser = adminLoginServer.LocalUserManager.GetProfileByName(this.regionData.MasterAvatarFirstName, this.regionData.MasterAvatarLastName);
183 if (masterUser == null)
184 {
185 m_console.Notice("Main.cs:Startup() - Sandbox Mode; Master Avatar is a new user; creating account.");
186 adminLoginServer.CreateUserAccount(this.regionData.MasterAvatarFirstName, this.regionData.MasterAvatarLastName, this.regionData.MasterAvatarSandboxPassword);
187 masterUser = adminLoginServer.LocalUserManager.GetProfileByName(this.regionData.MasterAvatarFirstName, this.regionData.MasterAvatarLastName);
188 if (masterUser == null) //Still NULL?!!?! OMG FAIL!
189 {
190 throw new Exception("Failure to create master user account");
191 }
192 }
193 m_console.Notice("Main.cs:Startup() - Master User UUID: " + masterUser.UUID.ToStringHyphenated());
194 regionData.MasterAvatarAssignedUUID = masterUser.UUID;
195
196 }
197 else
198 {
199 m_console.Warn("Main.cs:Startup() - Grid Mode; Do not know how to get the user's master key yet!");
200 }
201
202 m_console.Notice("Creating Estate Manager");
203 LocalWorld.estateManager = new OpenSim.RegionServer.Estate.EstateManager(this.LocalWorld);
204
205 m_console.Notice("Creating Parcel Manager");
206 LocalWorld.parcelManager = new OpenSim.RegionServer.Simulator.ParcelManager(this.LocalWorld);
207
208 m_console.Notice("Loading Parcels from DB...");
209 LocalWorld.localStorage.LoadParcels((ILocalStorageParcelReceiver)LocalWorld.parcelManager);
210
211 m_heartbeatTimer.Enabled = true;
212 m_heartbeatTimer.Interval = 100;
213 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
214 }
215
216 # region Setup methods
217 protected override void SetupLocalGridServers()
218 {
219 GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll";
220 GridServers.GridDll = "OpenSim.GridInterfaces.Local.dll";
221
222 m_console.Notice("Starting in Sandbox mode");
223
224 GridServers.Initialise();
225 }
226
227 protected override void SetupRemoteGridServers()
228 {
229 if (this.gridLocalAsset)
230 {
231 GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll";
232 }
233 else
234 {
235 GridServers.AssetDll = "OpenSim.GridInterfaces.Remote.dll";
236 }
237 GridServers.GridDll = "OpenSim.GridInterfaces.Remote.dll";
238
239 m_console.Notice("Starting in Grid mode");
240
241
242 GridServers.Initialise();
243
244 }
245
246 protected override void SetupLocalWorld()
247 {
248 m_console.Status("Main.cs:Startup() - We are " + regionData.RegionName + " at " + regionData.RegionLocX.ToString() + "," + regionData.RegionLocY.ToString());
249 m_console.Notice("Initialising world");
250 m_console.componentname = "Region " + regionData.RegionName;
251
252 m_localWorld = new World(this.m_udpServer.PacketServer.ClientThreads, regionData, regionData.RegionHandle, regionData.RegionName);
253 LocalWorld.InventoryCache = InventoryCache;
254 LocalWorld.AssetCache = AssetCache;
255
256 this.m_udpServer.LocalWorld = LocalWorld;
257 this.m_udpServer.PacketServer.RegisterClientPacketHandlers();
258
259 this.physManager = new OpenSim.Physics.Manager.PhysicsManager();
260 this.physManager.LoadPlugins();
261
262 LocalWorld.m_datastore = this.regionData.DataStore;
263
264 LocalWorld.LoadStorageDLL("OpenSim.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded.
265 LocalWorld.LoadWorldMap();
266
267 m_console.Notice("Main.cs:Startup() - Starting up messaging system");
268 LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this.m_physicsEngine);
269 LocalWorld.PhysScene.SetTerrain(LocalWorld.Terrain.getHeights1D());
270 LocalWorld.LoadPrimsFromStorage();
271 }
272
273 protected override void SetupHttpListener()
274 {
275 httpServer = new BaseHttpServer(regionData.IPListenPort);
276
277 if (this.GridServers.GridServer.GetName() == "Remote")
278 {
279
280 // we are in Grid mode so set a XmlRpc handler to handle "expect_user" calls from the user server
281 httpServer.AddXmlRPCHandler("expect_user", ((AuthenticateSessionsRemote)this.AuthenticateSessionsHandler).ExpectUser);
282
283 httpServer.AddXmlRPCHandler("agent_crossing",
284 delegate(XmlRpcRequest request)
285 {
286 Hashtable requestData = (Hashtable)request.Params[0];
287 uint circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
288
289 AgentCircuitData agent_data = new AgentCircuitData();
290 agent_data.firstname = (string)requestData["firstname"];
291 agent_data.lastname = (string)requestData["lastname"];
292 agent_data.circuitcode = circuitcode;
293 agent_data.startpos = new LLVector3(Single.Parse((string)requestData["pos_x"]), Single.Parse((string)requestData["pos_y"]), Single.Parse((string)requestData["pos_z"]));
294
295 AuthenticateSessionsHandler.UpdateAgentData(agent_data);
296
297 return new XmlRpcResponse();
298 });
299
300 httpServer.AddRestHandler("GET", "/simstatus/",
301 delegate(string request, string path, string param)
302 {
303 return "OK";
304 });
305 }
306 }
307
308 protected override void ConnectToRemoteGridServer()
309 {
310 if (GridServers.GridServer.RequestConnection(regionData.SimUUID, regionData.IPListenAddr, (uint)regionData.IPListenPort))
311 {
312 m_console.Notice("Main.cs:Startup() - Success: Got a grid connection OK!");
313 }
314 else
315 {
316 m_console.Error("Main.cs:Startup() - FAILED: Unable to get connection to grid. Shutting down.");
317 Shutdown();
318 }
319
320 GridServers.AssetServer.SetServerInfo((string)((RemoteGridBase)GridServers.GridServer).GridData["asset_url"], (string)((RemoteGridBase)GridServers.GridServer).GridData["asset_sendkey"]);
321
322 // If we are being told to load a file, load it.
323 string dataUri = (string)((RemoteGridBase)GridServers.GridServer).GridData["data_uri"];
324
325 if (!String.IsNullOrEmpty(dataUri))
326 {
327 this.LocalWorld.m_datastore = dataUri;
328 }
329
330 if (((RemoteGridBase)(GridServers.GridServer)).GridData["regionname"].ToString() != "")
331 {
332 // The grid server has told us who we are
333 // We must obey the grid server.
334
335 regionData.RegionLocX = Convert.ToUInt32(((RemoteGridBase)(GridServers.GridServer)).GridData["region_locx"].ToString());
336 regionData.RegionLocY = Convert.ToUInt32(((RemoteGridBase)(GridServers.GridServer)).GridData["region_locy"].ToString());
337 regionData.RegionName = ((RemoteGridBase)(GridServers.GridServer)).GridData["regionname"].ToString();
338
339
340 }
341 }
342
343 #endregion
344
345 private void SetupFromConfigFile(IGenericConfig configData)
346 {
347
348 // SandBoxMode
349 string attri = "";
350 attri = configData.GetAttribute("SandBox");
351 if ((attri == "") || ((attri != "false") && (attri != "true")))
352 {
353 this.m_sandbox = false;
354 configData.SetAttribute("SandBox", "false");
355 }
356 else
357 {
358 this.m_sandbox = Convert.ToBoolean(attri);
359 }
360
361 // LoginServer
362 attri = "";
363 attri = configData.GetAttribute("LoginServer");
364 if ((attri == "") || ((attri != "false") && (attri != "true")))
365 {
366 this.m_loginserver = false;
367 configData.SetAttribute("LoginServer", "false");
368 }
369 else
370 {
371 this.m_loginserver = Convert.ToBoolean(attri);
372 }
373
374 // Sandbox User accounts
375 attri = "";
376 attri = configData.GetAttribute("UserAccount");
377 if ((attri == "") || ((attri != "false") && (attri != "true")))
378 {
379 this.user_accounts = false;
380 configData.SetAttribute("UserAccounts", "false");
381 }
382 else if (attri == "true")
383 {
384 this.user_accounts = Convert.ToBoolean(attri);
385 }
386
387 // Grid mode hack to use local asset server
388 attri = "";
389 attri = configData.GetAttribute("LocalAssets");
390 if ((attri == "") || ((attri != "false") && (attri != "true")))
391 {
392 this.gridLocalAsset = false;
393 configData.SetAttribute("LocalAssets", "false");
394 }
395 else if (attri == "true")
396 {
397 this.gridLocalAsset = Convert.ToBoolean(attri);
398 }
399
400
401 attri = "";
402 attri = configData.GetAttribute("PhysicsEngine");
403 switch (attri)
404 {
405 default:
406 m_console.Warn("Main.cs: SetupFromConfig() - Invalid value for PhysicsEngine attribute, terminating");
407 Environment.Exit(1);
408 break;
409
410 case "":
411 this.m_physicsEngine = "basicphysics";
412 configData.SetAttribute("PhysicsEngine", "basicphysics");
413 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = false;
414 break;
415
416 case "basicphysics":
417 this.m_physicsEngine = "basicphysics";
418 configData.SetAttribute("PhysicsEngine", "basicphysics");
419 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = false;
420 break;
421
422 case "RealPhysX":
423 this.m_physicsEngine = "RealPhysX";
424 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = true;
425 break;
426
427 case "OpenDynamicsEngine":
428 this.m_physicsEngine = "OpenDynamicsEngine";
429 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = true;
430 break;
431 }
432
433 configData.Commit();
434 }
435
436 /// <summary>
437 /// Performs any last-minute sanity checking and shuts down the region server
438 /// </summary>
439 public virtual void Shutdown()
440 {
441 m_console.Notice("Main.cs:Shutdown() - Closing all threads");
442 m_console.Notice("Main.cs:Shutdown() - Killing listener thread");
443 m_console.Notice("Main.cs:Shutdown() - Killing clients");
444 // IMPLEMENT THIS
445 m_console.Notice("Main.cs:Shutdown() - Closing console and terminating");
446 LocalWorld.Close();
447 GridServers.Close();
448 m_console.Close();
449 Environment.Exit(0);
450 }
451
452 /// <summary>
453 /// Performs per-frame updates regularly
454 /// </summary>
455 /// <param name="sender"></param>
456 /// <param name="e"></param>
457 void Heartbeat(object sender, System.EventArgs e)
458 {
459 LocalWorld.Update();
460 }
461
462 #region Console Commands
463 /// <summary>
464 /// Runs commands issued by the server console from the operator
465 /// </summary>
466 /// <param name="command">The first argument of the parameter (the command)</param>
467 /// <param name="cmdparams">Additional arguments passed to the command</param>
468 public void RunCmd(string command, string[] cmdparams)
469 {
470 switch (command)
471 {
472 case "help":
473 m_console.Error("show users - show info about connected users");
474 m_console.Error("shutdown - disconnect all clients and shutdown");
475 m_console.Error("backup - start a backup manually");
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.Error(result);
487 }
488 break;
489
490 case "shutdown":
491 Shutdown();
492 break;
493
494 case "backup":
495 LocalWorld.Backup();
496 break;
497
498 case "reset":
499 if (cmdparams[0] == "parcels")
500 {
501 LocalWorld.localStorage.RemoveAllParcels();
502 LocalWorld.localStorage.LoadParcels((ILocalStorageParcelReceiver)LocalWorld.parcelManager);
503 }
504 break;
505
506 default:
507 m_console.Error("Unknown command");
508 break;
509 }
510 }
511
512 /// <summary>
513 /// Outputs to the console information about the region
514 /// </summary>
515 /// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param>
516 public void Show(string ShowWhat)
517 {
518 switch (ShowWhat)
519 {
520 case "uptime":
521 m_console.Error("OpenSim has been running since " + startuptime.ToString());
522 m_console.Error("That is " + (DateTime.Now - startuptime).ToString());
523 break;
524 case "users":
525 OpenSim.RegionServer.Simulator.Avatar TempAv;
526 m_console.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP"));
527 foreach (libsecondlife.LLUUID UUID in LocalWorld.Entities.Keys)
528 {
529 if (LocalWorld.Entities[UUID].ToString() == "OpenSim.RegionServer.Simulator.Avatar")
530 {
531 TempAv = (OpenSim.RegionServer.Simulator.Avatar)LocalWorld.Entities[UUID];
532 m_console.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()));
533 }
534 }
535 break;
536 case "parcels":
537 foreach (OpenSim.RegionServer.Simulator.Parcel parcel in LocalWorld.parcelManager.parcelList.Values)
538 {
539 m_console.Error("Parcel ID#" + parcel.parcelData.localID + "(Global UUID: " + parcel.parcelData.globalID + "):");
540 m_console.Error("\tParcel Name: " + parcel.parcelData.parcelName);
541 m_console.Error("\tParcel Owner UUID: " + parcel.parcelData.ownerID);
542 m_console.Error("\tParcel Area: " + parcel.parcelData.area + "sqm");
543 m_console.Error(" ");
544 }
545 break;
546 }
547 }
548 #endregion
549 }
550
551
552} \ No newline at end of file