aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Application/OpenSim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Application/OpenSim.cs')
-rw-r--r--OpenSim/Region/Application/OpenSim.cs680
1 files changed, 680 insertions, 0 deletions
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
new file mode 100644
index 0000000..1bed036
--- /dev/null
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -0,0 +1,680 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.IO;
32using System.Net;
33using System.Reflection;
34using System.Threading;
35using libsecondlife;
36using log4net;
37using Nini.Config;
38using OpenSim.Framework;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Statistics;
41using OpenSim.Region.Environment.Interfaces;
42using OpenSim.Region.Environment.Scenes;
43using Timer=System.Timers.Timer;
44
45namespace OpenSim
46{
47 public delegate void ConsoleCommand(string[] comParams);
48
49 /// <summary>
50 /// Interactive OpenSim region server
51 /// </summary>
52 public class OpenSim : OpenSimBase, conscmd_callback
53 {
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55
56 protected string m_startupCommandsFile;
57 protected string m_shutdownCommandsFile;
58
59 private string m_timedScript = "disabled";
60 private Timer m_scriptTimer;
61
62 public OpenSim(IConfigSource configSource) : base(configSource)
63 {
64 }
65
66 protected override void ReadConfigSettings()
67 {
68 IConfig startupConfig = m_config.Configs["Startup"];
69
70 if (startupConfig != null)
71 {
72 m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", String.Empty);
73 m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", String.Empty);
74
75 m_timedScript = startupConfig.GetString("timer_Script", "disabled");
76 }
77 base.ReadConfigSettings();
78 }
79
80 /// <summary>
81 /// Performs initialisation of the scene, such as loading configuration from disk.
82 /// </summary>
83 public override void StartUp()
84 {
85 //
86 // Called from app startup (OpenSim.Application)
87 //
88
89 m_log.Info("====================================================================");
90 m_log.Info("========================= STARTING OPENSIM =========================");
91 m_log.Info("====================================================================");
92 m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (m_sandbox ? "sandbox" : "grid"));
93
94 m_console = CreateConsole();
95 MainConsole.Instance = m_console;
96 InternalStartUp();
97
98 //Run Startup Commands
99 if (m_startupCommandsFile != String.Empty)
100 {
101 RunCommandScript(m_startupCommandsFile);
102 }
103 else
104 {
105 m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
106 }
107
108 // Start timer script (run a script every xx seconds)
109 if (m_timedScript != "disabled")
110 {
111 m_scriptTimer = new Timer();
112 m_scriptTimer.Enabled = true;
113 m_scriptTimer.Interval = 1200 * 1000;
114 m_scriptTimer.Elapsed += RunAutoTimerScript;
115 }
116
117 PrintFileToConsole("startuplogo.txt");
118 }
119
120 protected ConsoleBase CreateConsole()
121 {
122 return new ConsoleBase("Region", this);
123 }
124
125 private void RunAutoTimerScript(object sender, EventArgs e)
126 {
127 if (m_timedScript != "disabled")
128 {
129 RunCommandScript(m_timedScript);
130 }
131 }
132
133 #region Console Commands
134
135 /// <summary>
136 ///
137 /// </summary>
138 /// <param name="fileName"></param>
139 private void RunCommandScript(string fileName)
140 {
141 m_log.Info("[COMMANDFILE]: Running " + fileName);
142 if (File.Exists(fileName))
143 {
144 StreamReader readFile = File.OpenText(fileName);
145 string currentCommand;
146 while ((currentCommand = readFile.ReadLine()) != null)
147 {
148 if (currentCommand != String.Empty)
149 {
150 m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
151 m_console.RunCommand(currentCommand);
152 }
153 }
154 }
155 else
156 {
157 m_log.Error("[COMMANDFILE]: Command script missing. Can not run commands");
158 }
159 }
160
161 private static void PrintFileToConsole(string fileName)
162 {
163 if (File.Exists(fileName))
164 {
165 StreamReader readFile = File.OpenText(fileName);
166 string currentLine;
167 while ((currentLine = readFile.ReadLine()) != null)
168 {
169 m_log.Info("[!]" + currentLine);
170 }
171 }
172 }
173
174
175 /// <summary>
176 /// Runs commands issued by the server console from the operator
177 /// </summary>
178 /// <param name="command">The first argument of the parameter (the command)</param>
179 /// <param name="cmdparams">Additional arguments passed to the command</param>
180 public override void RunCmd(string command, string[] cmdparams)
181 {
182 base.RunCmd(command, cmdparams);
183
184 switch (command)
185 {
186 case "clear-assets":
187 m_assetCache.Clear();
188 break;
189
190 case "set-time":
191 m_sceneManager.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
192 break;
193
194 case "force-update":
195 m_console.Notice("Updating all clients");
196 m_sceneManager.ForceCurrentSceneClientUpdate();
197 break;
198
199 case "edit-scale":
200 if (cmdparams.Length == 4)
201 {
202 m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
203 }
204 break;
205
206 case "debug":
207 if (cmdparams.Length > 0)
208 {
209 Debug(cmdparams);
210 }
211 break;
212
213 case "scene-debug":
214 if (cmdparams.Length == 3)
215 {
216 if (m_sceneManager.CurrentScene == null)
217 {
218 m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
219 }
220 else
221 {
222 m_sceneManager.CurrentScene.SetSceneCoreDebug(!Convert.ToBoolean(cmdparams[0]), !Convert.ToBoolean(cmdparams[1]), !Convert.ToBoolean(cmdparams[2]));
223 }
224 }
225 else
226 {
227 m_console.Error("scene-debug <scripting> <collisions> <physics> (where inside <> is true/false)");
228 }
229 break;
230
231 case "help":
232 m_console.Notice("alert - send alert to a designated user or all users.");
233 m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
234 m_console.Notice(" alert general [Message] - send an alert to all users.");
235 m_console.Notice("backup - trigger a simulator backup");
236 m_console.Notice("clear-assets - clear asset cache");
237 m_console.Notice("create-region <name> <regionfile.xml> - creates a new region");
238 m_console.Notice("create user - adds a new user.");
239 m_console.Notice("change-region [name] - sets the region that many of these commands affect.");
240 m_console.Notice("command-script [filename] - Execute command in a file.");
241 m_console.Notice("debug - debugging commands");
242 m_console.Notice(" packet 0..255 - print incoming/outgoing packets (0=off)");
243 m_console.Notice("scene-debug [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
244 m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
245 m_console.Notice("export-map [filename] - save image of world map");
246 m_console.Notice("force-update - force an update of prims in the scene");
247 m_console.Notice("load-xml [filename] - load prims from XML (DEPRECATED)");
248 m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
249 m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
250 m_console.Notice("remove-region [name] - remove a region");
251 m_console.Notice("save-xml [filename] - save prims to XML (DEPRECATED)");
252 m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
253 m_console.Notice("script - manually trigger scripts? or script commands?");
254 m_console.Notice("set-time [x] - set the current scene time phase");
255 m_console.Notice("show assets - show state of asset cache.");
256 m_console.Notice("show users - show info about connected users.");
257 m_console.Notice("show modules - shows info about loaded modules.");
258 m_console.Notice("show regions - show running region information.");
259 m_console.Notice("threads - list threads");
260 m_console.Notice("config set section field value - set a config value");
261 m_console.Notice("config get section field - get a config value");
262 m_console.Notice("config save - save OpenSim.ini");
263 m_console.Notice("terrain help - show help for terrain commands.");
264 break;
265
266 case "threads":
267// m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:");
268// int _tc = 0;
269
270// foreach (ProcessThread pt in Process.GetCurrentProcess().Threads)
271// {
272// _tc++;
273// m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString());
274// }
275
276 List<Thread> threads = ThreadTracker.GetThreads();
277 if (threads == null)
278 {
279 m_console.Notice("THREAD", "Thread tracking is only enabled in DEBUG mode.");
280 }
281 else
282 {
283 int _tc = 0;
284 m_console.Notice("THREAD", threads.Count + " threads are being tracked:");
285 foreach (Thread t in threads)
286 {
287 _tc++;
288 m_console.Notice("THREAD", _tc + ": ID: " + t.ManagedThreadId.ToString() + ", Name: " + t.Name + ", Alive: " + t.IsAlive.ToString() + ", Pri: " + t.Priority.ToString() + ", State: " + t.ThreadState.ToString());
289 }
290 }
291
292 break;
293 case "save-xml":
294 m_log.Error("[CONSOLE]: PLEASE NOTE, save-xml is DEPRECATED and may be REMOVED soon. If you are using this and there is some reason you can't use save-xml2, please file a mantis detailing the reason.");
295
296 if (cmdparams.Length > 0)
297 {
298 m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
299 }
300 else
301 {
302 m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
303 }
304 break;
305
306 case "load-xml":
307 m_log.Error("[CONSOLE]: PLEASE NOTE, load-xml is DEPRECATED and may be REMOVED soon. If you are using this and there is some reason you can't use load-xml2, please file a mantis detailing the reason.");
308
309 LLVector3 loadOffset = new LLVector3(0, 0, 0);
310 if (cmdparams.Length > 0)
311 {
312 bool generateNewIDS = false;
313 if (cmdparams.Length > 1)
314 {
315 if (cmdparams[1] == "-newUID")
316 {
317 generateNewIDS = true;
318 }
319 if (cmdparams.Length > 2)
320 {
321 loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
322 if (cmdparams.Length > 3)
323 {
324 loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
325 }
326 if (cmdparams.Length > 4)
327 {
328 loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
329 }
330 m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
331 loadOffset.Z + ">");
332 }
333 }
334 m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
335 }
336 else
337 {
338 m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
339 }
340 break;
341
342 case "save-xml2":
343 if (cmdparams.Length > 0)
344 {
345 m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
346 }
347 else
348 {
349 m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
350 }
351 break;
352
353 case "load-xml2":
354 if (cmdparams.Length > 0)
355 {
356 m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
357 }
358 else
359 {
360 m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
361 }
362 break;
363
364 case "load-oar":
365 m_log.Error("[CONSOLE]: Don't use me - I haven't yet been sufficiently implemented!");
366
367 if (cmdparams.Length > 0)
368 {
369 m_sceneManager.LoadArchiveToCurrentScene(cmdparams[0]);
370 }
371 else
372 {
373 m_sceneManager.LoadArchiveToCurrentScene(DEFAULT_OAR_BACKUP_FILENAME);
374 }
375 break;
376
377 case "save-oar":
378 m_log.Error("[CONSOLE]: Don't use me - I haven't yet been sufficiently implemented!");
379
380 if (cmdparams.Length > 0)
381 {
382 m_sceneManager.SaveCurrentSceneToArchive(cmdparams[0]);
383 }
384 else
385 {
386 m_sceneManager.SaveCurrentSceneToArchive(DEFAULT_OAR_BACKUP_FILENAME);
387 }
388 break;
389
390 case "plugin":
391 m_sceneManager.SendCommandToPluginModules(cmdparams);
392 break;
393
394 case "command-script":
395 if (cmdparams.Length > 0)
396 {
397 RunCommandScript(cmdparams[0]);
398 }
399 break;
400
401 case "backup":
402 m_sceneManager.BackupCurrentScene();
403 break;
404
405 case "alert":
406 m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
407 break;
408
409 case "create":
410 CreateAccount(cmdparams);
411 break;
412
413 case "create-region":
414 CreateRegion(new RegionInfo(cmdparams[0], "Regions/" + cmdparams[1],false), true);
415 break;
416 case "remove-region":
417 string regName = CombineParams(cmdparams, 0);
418
419 Scene killScene;
420 if (m_sceneManager.TryGetScene(regName, out killScene))
421 {
422 // only need to check this if we are not at the
423 // root level
424 if ((m_sceneManager.CurrentScene != null) &&
425 (m_sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
426 {
427 m_sceneManager.TrySetCurrentScene("..");
428 }
429 m_regionData.Remove(killScene.RegionInfo);
430 m_sceneManager.CloseScene(killScene);
431 }
432 break;
433
434 case "restart":
435 m_sceneManager.RestartCurrentScene();
436 break;
437
438 case "change-region":
439 if (cmdparams.Length > 0)
440 {
441 string regionName = CombineParams(cmdparams, 0);
442
443 if (!m_sceneManager.TrySetCurrentScene(regionName))
444 {
445 m_console.Error("Couldn't set current region to: " + regionName);
446 }
447 }
448
449 if (m_sceneManager.CurrentScene == null)
450 {
451 m_console.Error("CONSOLE", "Currently at Root level. To change region please use 'change-region <regioname>'");
452 }
453 else
454 {
455 m_console.Error("CONSOLE", "Current Region: " + m_sceneManager.CurrentScene.RegionInfo.RegionName +
456 ". To change region please use 'change-region <regioname>'");
457 }
458
459 break;
460
461 case "export-map":
462 if (cmdparams.Length > 0)
463 {
464 m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
465 }
466 else
467 {
468 m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
469 }
470 break;
471
472 case "config":
473 string n = command.ToUpper();
474 if (cmdparams.Length > 0)
475 {
476 switch (cmdparams[0].ToLower())
477 {
478 case "set":
479 if (cmdparams.Length < 4)
480 {
481 m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
482 m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
483 }
484 else
485 {
486 IConfig c = DefaultConfig().Configs[cmdparams[1]];
487 if (c == null)
488 c = DefaultConfig().AddConfig(cmdparams[1]);
489 string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
490 c.Set(cmdparams[2], _value);
491 m_config.Merge(c.ConfigSource);
492
493 m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
494 _value);
495 }
496 break;
497 case "get":
498 if (cmdparams.Length < 3)
499 {
500 m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
501 m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
502 }
503 else
504 {
505 IConfig c = DefaultConfig().Configs[cmdparams[1]];
506 if (c == null)
507 {
508 m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
509 break;
510 }
511 else
512 {
513 m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
514 c.GetString(cmdparams[2]));
515 }
516 }
517
518 break;
519 case "save":
520 m_console.Notice("Saving configuration file: " + Application.iniFilePath);
521 m_config.Save(Application.iniFilePath);
522 break;
523 }
524 }
525 break;
526 case "modules":
527 if (cmdparams.Length > 0)
528 {
529 switch (cmdparams[0].ToLower())
530 {
531 case "list":
532 foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
533 {
534 m_console.Notice("Shared region module: " + irm.Name);
535 }
536 break;
537 case "unload":
538 if (cmdparams.Length > 1)
539 {
540 foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
541 {
542 if (rm.Name.ToLower() == cmdparams[1].ToLower())
543 {
544 m_console.Notice("Unloading module: " + rm.Name);
545 m_moduleLoader.UnloadModule(rm);
546 }
547 }
548 }
549 break;
550 case "load":
551 if (cmdparams.Length > 1)
552 {
553 foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
554 {
555
556 m_console.Notice("Loading module: " + cmdparams[1]);
557 m_moduleLoader.LoadRegionModules(cmdparams[1], s);
558 }
559 }
560 break;
561 }
562 }
563
564 break;
565 default:
566 string[] tmpPluginArgs = new string[cmdparams.Length + 1];
567 cmdparams.CopyTo(tmpPluginArgs, 1);
568 tmpPluginArgs[0] = command;
569
570 m_sceneManager.SendCommandToPluginModules(tmpPluginArgs);
571 break;
572 }
573 }
574
575 public void Debug(string[] args)
576 {
577 switch (args[0])
578 {
579 case "packet":
580 if (args.Length > 1)
581 {
582 int newDebug;
583 if (int.TryParse(args[1], out newDebug))
584 {
585 m_sceneManager.SetDebugPacketOnCurrentScene(newDebug);
586 }
587 else
588 {
589 m_console.Error("packet debug should be 0..2");
590 }
591 m_console.Notice("New packet debug: " + newDebug.ToString());
592 }
593
594 break;
595 default:
596 m_console.Error("Unknown debug");
597 break;
598 }
599 }
600
601 // see BaseOpenSimServer
602 public override void Show(string ShowWhat)
603 {
604 base.Show(ShowWhat);
605
606 switch (ShowWhat)
607 {
608 case "assets":
609 m_assetCache.ShowState();
610 break;
611
612 case "users":
613 IList agents = m_sceneManager.GetCurrentSceneAvatars();
614
615 m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
616
617 m_console.Notice(
618 String.Format("{0,-16}{1,-16}{2,-37}{3,-16}", "Firstname", "Lastname",
619 "Agent ID","Region"));
620
621 foreach (ScenePresence presence in agents)
622 {
623 RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
624 string regionName;
625
626 if (regionInfo == null)
627 {
628 regionName = "Unresolvable";
629 }
630 else
631 {
632 regionName = regionInfo.RegionName;
633 }
634
635 m_console.Notice(
636 String.Format(
637 "{0,-16}{1,-16}{2,-37}{3,-16}",
638 presence.Firstname,
639 presence.Lastname,
640 presence.UUID,
641 regionName));
642 }
643
644 m_console.Notice("");
645 break;
646
647 case "modules":
648 m_console.Notice("The currently loaded shared modules are:");
649 foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
650 {
651 m_console.Notice("Shared Module: " + module.Name);
652 }
653 break;
654
655 case "regions":
656 m_sceneManager.ForEachScene(
657 delegate(Scene scene)
658 {
659 m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
660 scene.RegionInfo.RegionLocX + " , Region YLoc: " +
661 scene.RegionInfo.RegionLocY);
662 });
663 break;
664 }
665 }
666
667 private static string CombineParams(string[] commandParams, int pos)
668 {
669 string result = String.Empty;
670 for (int i = pos; i < commandParams.Length; i++)
671 {
672 result += commandParams[i] + " ";
673 }
674 result = result.TrimEnd(' ');
675 return result;
676 }
677
678 #endregion
679 }
680}