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