aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Application
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Application')
-rw-r--r--OpenSim/Region/Application/Application.cs26
-rw-r--r--OpenSim/Region/Application/OpenSimMain.cs725
-rw-r--r--OpenSim/Region/Application/OpenSimMainConsole.cs716
3 files changed, 785 insertions, 682 deletions
diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs
index eaa4788..828490a 100644
--- a/OpenSim/Region/Application/Application.cs
+++ b/OpenSim/Region/Application/Application.cs
@@ -65,6 +65,12 @@ namespace OpenSim
65 65
66 ArgvConfigSource configSource = new ArgvConfigSource(args); 66 ArgvConfigSource configSource = new ArgvConfigSource(args);
67 67
68 configSource.Alias.AddAlias("On", true);
69 configSource.Alias.AddAlias("Off", false);
70 configSource.Alias.AddAlias("True", true);
71 configSource.Alias.AddAlias("False", false);
72
73 configSource.AddSwitch("Startup", "background");
68 configSource.AddSwitch("Startup", "inifile"); 74 configSource.AddSwitch("Startup", "inifile");
69 configSource.AddSwitch("Startup", "gridmode"); 75 configSource.AddSwitch("Startup", "gridmode");
70 configSource.AddSwitch("Startup", "physics"); 76 configSource.AddSwitch("Startup", "physics");
@@ -73,13 +79,23 @@ namespace OpenSim
73 configSource.AddConfig("StandAlone"); 79 configSource.AddConfig("StandAlone");
74 configSource.AddConfig("Network"); 80 configSource.AddConfig("Network");
75 81
76 OpenSimMain sim = new OpenSimMain(configSource); 82 bool background = configSource.Configs["Startup"].GetBoolean("background", false);
77
78 sim.StartUp();
79 83
80 while (true) 84 if (background)
85 {
86 Console.WriteLine("background mode");
87 OpenSimMain sim = new OpenSimMain(configSource);
88 sim.StartUp();
89 }
90 else
81 { 91 {
82 MainConsole.Instance.Prompt(); 92 OpenSimMain sim = new OpenSimMainConsole(configSource);
93 sim.StartUp();
94
95 while (true)
96 {
97 MainConsole.Instance.Prompt();
98 }
83 } 99 }
84 } 100 }
85 101
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs
index 93d6f56..3bee7f3 100644
--- a/OpenSim/Region/Application/OpenSimMain.cs
+++ b/OpenSim/Region/Application/OpenSimMain.cs
@@ -54,15 +54,14 @@ using Timer=System.Timers.Timer;
54 54
55namespace OpenSim 55namespace OpenSim
56{ 56{
57 public delegate void ConsoleCommand(string[] comParams); 57 public class OpenSimMain : RegionApplicationBase
58
59 public class OpenSimMain : RegionApplicationBase, conscmd_callback
60 { 58 {
61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 59 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62 private string proxyUrl;
63 private int proxyOffset = 0;
64 60
65 private const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml"; 61 protected string proxyUrl;
62 protected int proxyOffset = 0;
63
64 protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
66 65
67 public string m_physicsEngine; 66 public string m_physicsEngine;
68 public string m_meshEngineName; 67 public string m_meshEngineName;
@@ -76,35 +75,29 @@ namespace OpenSim
76 75
77 protected string m_storageDll; 76 protected string m_storageDll;
78 77
79 protected string m_startupCommandsFile;
80 protected string m_shutdownCommandsFile;
81
82 protected List<UDPServer> m_udpServers = new List<UDPServer>(); 78 protected List<UDPServer> m_udpServers = new List<UDPServer>();
83 protected List<RegionInfo> m_regionData = new List<RegionInfo>(); 79 protected List<RegionInfo> m_regionData = new List<RegionInfo>();
84 80
85 private bool m_physicalPrim; 81 protected bool m_physicalPrim;
86 private bool m_permissions = false; 82 protected bool m_permissions = false;
87 83
88 private bool m_standaloneAuthenticate = false; 84 protected bool m_standaloneAuthenticate = false;
89 private string m_standaloneWelcomeMessage = null; 85 protected string m_standaloneWelcomeMessage = null;
90 private string m_standaloneInventoryPlugin; 86 protected string m_standaloneInventoryPlugin;
91 private string m_standaloneAssetPlugin; 87 protected string m_standaloneAssetPlugin;
92 private string m_standaloneUserPlugin; 88 protected string m_standaloneUserPlugin;
93 private string m_standaloneInventorySource; 89 private string m_standaloneInventorySource;
94 private string m_standaloneAssetSource; 90 private string m_standaloneAssetSource;
95 private string m_standaloneUserSource; 91 private string m_standaloneUserSource;
96 92
97 private string m_assetStorage = "local"; 93 protected string m_assetStorage = "local";
98
99 private string m_timedScript = "disabled";
100 private Timer m_scriptTimer;
101 94
102 public ConsoleCommand CreateAccount = null; 95 public ConsoleCommand CreateAccount = null;
103 private bool m_dumpAssetsToFile; 96 protected bool m_dumpAssetsToFile;
104 97
105 private List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>(); 98 protected List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
106 99
107 private IniConfigSource m_config; 100 protected IniConfigSource m_config;
108 101
109 public IniConfigSource ConfigSource 102 public IniConfigSource ConfigSource
110 { 103 {
@@ -127,7 +120,7 @@ namespace OpenSim
127 get { return m_regionData; } 120 get { return m_regionData; }
128 } 121 }
129 122
130 private ModuleLoader m_moduleLoader; 123 protected ModuleLoader m_moduleLoader;
131 124
132 public ModuleLoader ModuleLoader 125 public ModuleLoader ModuleLoader
133 { 126 {
@@ -260,7 +253,7 @@ namespace OpenSim
260 253
261 } 254 }
262 255
263 protected void ReadConfigSettings() 256 protected virtual void ReadConfigSettings()
264 { 257 {
265 m_networkServersInfo = new NetworkServersInfo(); 258 m_networkServersInfo = new NetworkServersInfo();
266 259
@@ -290,13 +283,8 @@ namespace OpenSim
290 m_storagePersistPrimInventories 283 m_storagePersistPrimInventories
291 = startupConfig.GetBoolean("storage_prim_inventories", true); 284 = startupConfig.GetBoolean("storage_prim_inventories", true);
292 285
293 m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", String.Empty);
294 m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", String.Empty);
295
296 m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll"); 286 m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
297 m_assetStorage = startupConfig.GetString("asset_database", "local"); 287 m_assetStorage = startupConfig.GetString("asset_database", "local");
298
299 m_timedScript = startupConfig.GetString("timer_Script", "disabled");
300 } 288 }
301 289
302 IConfig standaloneConfig = m_config.Configs["StandAlone"]; 290 IConfig standaloneConfig = m_config.Configs["StandAlone"];
@@ -325,6 +313,8 @@ namespace OpenSim
325 m_networkServersInfo.loadFromConfiguration(m_config); 313 m_networkServersInfo.loadFromConfiguration(m_config);
326 } 314 }
327 315
316 private ManualResetEvent WorldHasComeToAnEnd = new ManualResetEvent(false);
317
328 /// <summary> 318 /// <summary>
329 /// Performs initialisation of the scene, such as loading configuration from disk. 319 /// Performs initialisation of the scene, such as loading configuration from disk.
330 /// </summary> 320 /// </summary>
@@ -334,14 +324,30 @@ namespace OpenSim
334 // Called from app startup (OpenSim.Application) 324 // Called from app startup (OpenSim.Application)
335 // 325 //
336 326
337 m_log.Info("===================================================================="); 327 m_log.Info("[OPENSIM]: Starting Opensim");
338 m_log.Info("========================= STARTING OPENSIM =========================");
339 m_log.Info("====================================================================");
340 m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (m_sandbox ? "sandbox" : "grid")); 328 m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (m_sandbox ? "sandbox" : "grid"));
341 329
342 m_console = CreateConsole(); 330 InternalStartUp();
343 MainConsole.Instance = m_console; 331
332 // We are done with startup
333 m_log.Info("[OPENSIM MAIN]: Startup complete, serving " + m_udpServers.Count.ToString() + " region(s)");
334 WorldHasComeToAnEnd.WaitOne();
335 }
336
337
338 /// <summary>
339 /// Signal that the end of the world is now.
340 /// </summary>
341 public void ApocalypseNow()
342 {
343 WorldHasComeToAnEnd.Set();
344 }
344 345
346 /// <summary>
347 /// Performs initialisation of the scene, such as loading configuration from disk.
348 /// </summary>
349 protected void InternalStartUp()
350 {
345 StatsManager.StartCollectingSimExtraStats(); 351 StatsManager.StartCollectingSimExtraStats();
346 352
347 // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp 353 // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp
@@ -411,28 +417,6 @@ namespace OpenSim
411 // m_udpServers[i].ServerListener(); 417 // m_udpServers[i].ServerListener();
412 // } 418 // }
413 419
414 //Run Startup Commands
415 if (m_startupCommandsFile != String.Empty)
416 {
417 RunCommandScript(m_startupCommandsFile);
418 }
419 else
420 {
421 m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
422 }
423
424 // Start timer script (run a script every xx seconds)
425 if (m_timedScript != "disabled")
426 {
427 m_scriptTimer = new Timer();
428 m_scriptTimer.Enabled = true;
429 m_scriptTimer.Interval = (int)(1200 * 1000);
430 m_scriptTimer.Elapsed += new ElapsedEventHandler(RunAutoTimerScript);
431 }
432
433 // We are done with startup
434 PrintFileToConsole("startuplogo.txt");
435 m_log.Info("[OPENSIM MAIN]: Startup complete, serving " + m_udpServers.Count.ToString() + " region(s)");
436 } 420 }
437 421
438 protected override void Initialize() 422 protected override void Initialize()
@@ -644,11 +628,6 @@ namespace OpenSim
644 //m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle); 628 //m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle);
645 } 629 }
646 630
647 protected override ConsoleBase CreateConsole()
648 {
649 return new ConsoleBase("Region", this);
650 }
651
652 # region Setup methods 631 # region Setup methods
653 632
654 protected override PhysicsScene GetPhysicsScene() 633 protected override PhysicsScene GetPhysicsScene()
@@ -656,7 +635,7 @@ namespace OpenSim
656 return GetPhysicsScene(m_physicsEngine, m_meshEngineName); 635 return GetPhysicsScene(m_physicsEngine, m_meshEngineName);
657 } 636 }
658 637
659 private class SimStatusHandler : IStreamedRequestHandler 638 protected class SimStatusHandler : IStreamedRequestHandler
660 { 639 {
661 public byte[] Handle(string path, Stream request) 640 public byte[] Handle(string path, Stream request)
662 { 641 {
@@ -684,18 +663,13 @@ namespace OpenSim
684 /// <summary> 663 /// <summary>
685 /// Performs any last-minute sanity checking and shuts down the region server 664 /// Performs any last-minute sanity checking and shuts down the region server
686 /// </summary> 665 /// </summary>
687 public virtual void Shutdown() 666 protected virtual void InternalShutdown()
688 { 667 {
689 if (proxyUrl.Length > 0) 668 if (proxyUrl.Length > 0)
690 { 669 {
691 Util.XmlRpcCommand(proxyUrl, "Stop"); 670 Util.XmlRpcCommand(proxyUrl, "Stop");
692 } 671 }
693 672
694 if (m_startupCommandsFile != String.Empty)
695 {
696 RunCommandScript(m_shutdownCommandsFile);
697 }
698
699 m_log.Info("[SHUTDOWN]: Closing all threads"); 673 m_log.Info("[SHUTDOWN]: Closing all threads");
700 m_log.Info("[SHUTDOWN]: Killing listener thread"); 674 m_log.Info("[SHUTDOWN]: Killing listener thread");
701 m_log.Info("[SHUTDOWN]: Killing clients"); 675 m_log.Info("[SHUTDOWN]: Killing clients");
@@ -703,619 +677,16 @@ namespace OpenSim
703 m_log.Info("[SHUTDOWN]: Closing console and terminating"); 677 m_log.Info("[SHUTDOWN]: Closing console and terminating");
704 678
705 m_sceneManager.Close(); 679 m_sceneManager.Close();
706 680 // needs to be called by Shutdown() method
707 m_console.Close(); 681 // Environment.Exit(0);
708 Environment.Exit(0);
709 }
710
711 private void RunAutoTimerScript(object sender, EventArgs e)
712 {
713 if (m_timedScript != "disabled")
714 {
715 RunCommandScript(m_timedScript);
716 }
717 }
718
719 #region Console Commands
720
721 /// <summary>
722 ///
723 /// </summary>
724 /// <param name="fileName"></param>
725 private void RunCommandScript(string fileName)
726 {
727 m_log.Info("[COMMANDFILE]: Running " + fileName);
728 if (File.Exists(fileName))
729 {
730 StreamReader readFile = File.OpenText(fileName);
731 string currentCommand = String.Empty;
732 while ((currentCommand = readFile.ReadLine()) != null)
733 {
734 if (currentCommand != String.Empty)
735 {
736 m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
737 m_console.RunCommand(currentCommand);
738 }
739 }
740 }
741 else
742 {
743 m_log.Error("[COMMANDFILE]: Command script missing. Can not run commands");
744 }
745 }
746
747 private void PrintFileToConsole(string fileName)
748 {
749 if (File.Exists(fileName))
750 {
751 StreamReader readFile = File.OpenText(fileName);
752 string currentLine = String.Empty;
753 while ((currentLine = readFile.ReadLine()) != null)
754 {
755 m_log.Info("[!]" + currentLine);
756 }
757 }
758 } 682 }
759 683
760 684 public virtual void Shutdown()
761 /// <summary>
762 /// Runs commands issued by the server console from the operator
763 /// </summary>
764 /// <param name="command">The first argument of the parameter (the command)</param>
765 /// <param name="cmdparams">Additional arguments passed to the command</param>
766 public override void RunCmd(string command, string[] cmdparams)
767 {
768 base.RunCmd(command, cmdparams);
769
770 switch (command)
771 {
772 case "clear-assets":
773 m_assetCache.Clear();
774 break;
775
776 case "set-time":
777 m_sceneManager.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
778 break;
779
780 case "force-update":
781 m_console.Notice("Updating all clients");
782 m_sceneManager.ForceCurrentSceneClientUpdate();
783 break;
784
785 case "edit-scale":
786 if (cmdparams.Length == 4)
787 {
788 m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
789 }
790 break;
791
792 case "debug":
793 if (cmdparams.Length > 0)
794 {
795 Debug(cmdparams);
796 }
797 break;
798
799 case "scene-debug":
800 if (cmdparams.Length == 3)
801 {
802 if (m_sceneManager.CurrentScene == null)
803 {
804 m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
805 }
806 else
807 {
808 m_sceneManager.CurrentScene.SetSceneCoreDebug(!Convert.ToBoolean(cmdparams[0]), !Convert.ToBoolean(cmdparams[1]), !Convert.ToBoolean(cmdparams[2]));
809 }
810 }
811 else
812 {
813 m_console.Error("scene-debug <scripting> <collisions> <physics> (where inside <> is true/false)");
814 }
815 break;
816
817 case "help":
818 m_console.Notice("alert - send alert to a designated user or all users.");
819 m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
820 m_console.Notice(" alert general [Message] - send an alert to all users.");
821 m_console.Notice("backup - trigger a simulator backup");
822 m_console.Notice("change-region [name] - sets the region that many of these commands affect.");
823 m_console.Notice("clear-assets - clear asset cache");
824 m_console.Notice("command-script [filename] - Execute command in a file.");
825 m_console.Notice("config get section field - get a config value");
826 m_console.Notice("config save - save OpenSim.ini");
827 m_console.Notice("config set section field value - set a config value");
828 m_console.Notice("create-region <name> <regionfile.xml> - creates a new region");
829 m_console.Notice("create user - adds a new user.");
830 m_console.Notice("debug - debugging commands");
831 m_console.Notice(" packet 0..255 - print incoming/outgoing packets (0=off)");
832 m_console.Notice("scene-debug [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
833 m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
834 m_console.Notice("export-map [filename] - save image of world map");
835 m_console.Notice("force-update - force an update of prims in the scene");
836 m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
837 m_console.Notice("permissions [true/false] - turn on/off permissions on the scene");
838 m_console.Notice("quit - equivalent to shutdown.");
839 m_console.Notice("remove-region [name] - remove a region");
840 m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
841 m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
842 m_console.Notice("script - manually trigger scripts? or script commands?");
843 m_console.Notice("set-time [x] - set the current scene time phase");
844 m_console.Notice("show assets - show state of asset cache.");
845 m_console.Notice("show modules - shows info about loaded modules.");
846 m_console.Notice("show regions - shows info about active regions.");
847 m_console.Notice("show users - show info about connected users.");
848 m_console.Notice("show stats - statistical information for this server not displayed in the client");
849 m_console.Notice("shutdown - disconnect all clients and shutdown.");
850 m_console.Notice("terrain help - show help for terrain commands.");
851 m_console.Notice("threads - list threads");
852 break;
853
854 case "threads":
855// m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:");
856// int _tc = 0;
857
858// foreach (ProcessThread pt in Process.GetCurrentProcess().Threads)
859// {
860// _tc++;
861// m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString());
862// }
863
864 List<Thread> threads = ThreadTracker.GetThreads();
865 if (threads == null)
866 {
867 m_console.Notice("THREAD", "Thread tracking is only enabled in DEBUG mode.");
868 }
869 else
870 {
871 int _tc = 0;
872 m_console.Notice("THREAD", threads.Count + " threads are being tracked:");
873 foreach (Thread t in threads)
874 {
875 _tc++;
876 m_console.Notice("THREAD", _tc + ": ID: " + t.ManagedThreadId.ToString() + ", Name: " + t.Name + ", Alive: " + t.IsAlive.ToString() + ", Pri: " + t.Priority.ToString() + ", State: " + t.ThreadState.ToString());
877 }
878 }
879
880 break;
881 case "save-xml":
882 if (cmdparams.Length > 0)
883 {
884 m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
885 }
886 else
887 {
888 m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
889 }
890 break;
891
892 case "load-xml":
893 LLVector3 loadOffset = new LLVector3(0, 0, 0);
894 if (cmdparams.Length > 0)
895 {
896 bool generateNewIDS = false;
897 if (cmdparams.Length > 1)
898 {
899 if (cmdparams[1] == "-newUID")
900 {
901 generateNewIDS = true;
902 }
903 if (cmdparams.Length > 2)
904 {
905 loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
906 if (cmdparams.Length > 3)
907 {
908 loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
909 }
910 if (cmdparams.Length > 4)
911 {
912 loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
913 }
914 m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
915 loadOffset.Z + ">");
916 }
917 }
918 m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
919 }
920 else
921 {
922 m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
923 }
924 break;
925
926 case "save-xml2":
927 if (cmdparams.Length > 0)
928 {
929 m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
930 }
931 else
932 {
933 m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
934 }
935 break;
936
937 case "load-xml2":
938 if (cmdparams.Length > 0)
939 {
940 m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
941 }
942 else
943 {
944 m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
945 }
946 break;
947
948 case "plugin":
949 m_sceneManager.SendCommandToPluginModules(cmdparams);
950 break;
951
952 case "command-script":
953 if (cmdparams.Length > 0)
954 {
955 RunCommandScript(cmdparams[0]);
956 }
957 break;
958
959 case "permissions":
960 // Treats each user as a super-admin when disabled
961 bool permissions = Convert.ToBoolean(cmdparams[0]);
962 m_sceneManager.SetBypassPermissionsOnCurrentScene(!permissions);
963 break;
964
965 case "backup":
966 m_sceneManager.BackupCurrentScene();
967 break;
968
969 case "alert":
970 m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
971 break;
972
973 case "create":
974 CreateAccount(cmdparams);
975 break;
976
977 case "create-region":
978 CreateRegion(new RegionInfo(cmdparams[0], "Regions/" + cmdparams[1],false), true);
979 break;
980 case "remove-region":
981
982 string regName = CombineParams(cmdparams, 0);
983
984 Console.WriteLine("Trying to kill: " + regName);
985 Scene killScene;
986
987 /* if (m_sceneManager.TryGetScene(regName, out killScene))
988 {
989 Console.WriteLine("Returned object ID: ", killScene.RegionInfo.RegionID.ToString());
990 Console.WriteLine("Returned object Name: ", killScene.RegionInfo.RegionName);
991
992
993 if (killScene == null)
994 {
995 Console.WriteLine("Returned object is null!");
996 }
997
998 if (m_sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID)
999 {
1000 m_sceneManager.TrySetCurrentScene("..");
1001 }
1002
1003 m_regionData.Remove(killScene.RegionInfo);
1004 m_sceneManager.CloseScene(killScene);
1005
1006
1007 }*/
1008
1009
1010 /// note from John R Sohn aka XenReborn (irc.freenode.net)
1011 /// the trygetscene function does not work
1012 /// when debugging it i noticed it did indeed find the region by name
1013 /// but the OUT parameter "scene" return an empty object
1014 /// hence the reason it threw an exception
1015 /// when the server code in this block tried to kill it
1016 /// i know its not supposed to work that way... but it seems..
1017 /// that it is.. given a flaw in the langauge or concurrency error..
1018 /// i have no idea, but for some reason, performing the search here
1019 /// locally does work, as does dynamically killing the region
1020 /// however on server restart, the region returns, i dunno if this was
1021 /// intentional or not.... i suggest creating a seperate function
1022 /// which will permanently remove all data relating to the region
1023 /// as an administrative option... maybe something like "Purge Region"
1024 ///
1025 /// i made editations with debug console output in above commented code..
1026 /// and the trygetscene(string,out scene) function to show whats happening.
1027
1028 for (int x = 0; x < m_sceneManager.Scenes.Count; x++)
1029 {
1030 if (m_sceneManager.Scenes[x].RegionInfo.RegionName.CompareTo(regName) == 0)
1031 {
1032 killScene = m_sceneManager.Scenes[x];
1033 m_regionData.Remove(killScene.RegionInfo);
1034 m_sceneManager.CloseScene(killScene);
1035 }
1036 }
1037
1038 break;
1039
1040 case "exit":
1041 case "quit":
1042 case "shutdown":
1043 Shutdown();
1044 break;
1045
1046 case "restart":
1047 m_sceneManager.RestartCurrentScene();
1048 break;
1049
1050 case "change-region":
1051 if (cmdparams.Length > 0)
1052 {
1053 string regionName = CombineParams(cmdparams, 0);
1054
1055 if (!m_sceneManager.TrySetCurrentScene(regionName))
1056 {
1057 m_console.Error("Couldn't set current region to: " + regionName);
1058 }
1059 }
1060
1061 if (m_sceneManager.CurrentScene == null)
1062 {
1063 m_console.Error("CONSOLE", "Currently at Root level. To change region please use 'change-region <regioname>'");
1064 }
1065 else
1066 {
1067 m_console.Error("CONSOLE", "Current Region: " + m_sceneManager.CurrentScene.RegionInfo.RegionName +
1068 ". To change region please use 'change-region <regioname>'");
1069 }
1070
1071 break;
1072
1073 case "export-map":
1074 if (cmdparams.Length > 0)
1075 {
1076 m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
1077 }
1078 else
1079 {
1080 m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
1081 }
1082 break;
1083
1084 case "config":
1085 string n = command.ToUpper();
1086 if (cmdparams.Length > 0)
1087 {
1088 switch (cmdparams[0].ToLower())
1089 {
1090 case "set":
1091 if (cmdparams.Length < 4)
1092 {
1093 m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
1094 m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
1095 }
1096 else
1097 {
1098 IConfig c = DefaultConfig().Configs[cmdparams[1]];
1099 if (c == null)
1100 c = DefaultConfig().AddConfig(cmdparams[1]);
1101 string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
1102 c.Set(cmdparams[2], _value);
1103 m_config.Merge(c.ConfigSource);
1104
1105 m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
1106 _value);
1107 }
1108 break;
1109 case "get":
1110 if (cmdparams.Length < 3)
1111 {
1112 m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
1113 m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
1114 }
1115 else
1116 {
1117 IConfig c = DefaultConfig().Configs[cmdparams[1]];
1118 if (c == null)
1119 {
1120 m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
1121 break;
1122 }
1123 else
1124 {
1125 m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
1126 c.GetString(cmdparams[2]));
1127 }
1128 }
1129
1130 break;
1131 case "save":
1132 m_console.Notice("Saving configuration file: " + Application.iniFilePath);
1133 m_config.Save(Application.iniFilePath);
1134 break;
1135 }
1136 }
1137 break;
1138 case "modules":
1139 if (cmdparams.Length > 0)
1140 {
1141 switch (cmdparams[0].ToLower())
1142 {
1143 case "list":
1144 foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
1145 {
1146 m_console.Notice("Shared region module: " + irm.Name);
1147 }
1148 break;
1149 case "unload":
1150 if (cmdparams.Length > 1)
1151 {
1152 foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
1153 {
1154 if (rm.Name.ToLower() == cmdparams[1].ToLower())
1155 {
1156 m_console.Notice("Unloading module: " + rm.Name);
1157 m_moduleLoader.UnloadModule(rm);
1158 }
1159 }
1160 }
1161 break;
1162 case "load":
1163 if (cmdparams.Length > 1)
1164 {
1165 foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
1166 {
1167
1168 m_console.Notice("Loading module: " + cmdparams[1]);
1169 m_moduleLoader.LoadRegionModules(cmdparams[1], s);
1170 }
1171 }
1172 break;
1173 }
1174 }
1175
1176 break;
1177
1178 default:
1179 string[] tmpPluginArgs = new string[cmdparams.Length + 1];
1180 cmdparams.CopyTo(tmpPluginArgs, 1);
1181 tmpPluginArgs[0] = command;
1182
1183 m_sceneManager.SendCommandToPluginModules(tmpPluginArgs);
1184 break;
1185 }
1186 }
1187
1188 public void Debug(string[] args)
1189 {
1190 switch (args[0])
1191 {
1192 case "packet":
1193 if (args.Length > 1)
1194 {
1195 int newDebug;
1196 if (int.TryParse(args[1], out newDebug))
1197 {
1198 m_sceneManager.SetDebugPacketOnCurrentScene(newDebug);
1199 }
1200 else
1201 {
1202 m_console.Error("packet debug should be 0..2");
1203 }
1204 m_console.Notice("New packet debug: " + newDebug.ToString());
1205 }
1206
1207 break;
1208 default:
1209 m_console.Error("Unknown debug");
1210 break;
1211 }
1212 }
1213
1214 // see BaseOpenSimServer
1215 public override void Show(string ShowWhat)
1216 {
1217 base.Show(ShowWhat);
1218
1219 switch (ShowWhat)
1220 {
1221 case "assets":
1222 m_assetCache.ShowState();
1223 break;
1224
1225 case "users":
1226 IList agents = m_sceneManager.GetCurrentSceneAvatars();
1227
1228 m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
1229
1230 m_console.Notice(
1231 String.Format("{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}{6,-15}", "Firstname", "Lastname",
1232 "Agent ID", "Circuit", "IP", "Region", "Status"));
1233
1234 foreach (ScenePresence presence in agents)
1235 {
1236 RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
1237 string regionName;
1238 EndPoint ep = null;
1239
1240 if (regionInfo == null)
1241 {
1242 regionName = "Unresolvable";
1243 }
1244 else
1245 {
1246 regionName = regionInfo.RegionName;
1247 }
1248
1249 for (int i = 0; i < m_udpServers.Count; i++)
1250 {
1251 if (m_udpServers[i].RegionHandle == presence.RegionHandle)
1252 {
1253
1254 m_udpServers[i].clientCircuits_reverse.TryGetValue(presence.ControllingClient.CircuitCode, out ep);
1255 }
1256 }
1257
1258 m_console.Notice(
1259 String.Format(
1260 "{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}{6,-15}",
1261 presence.Firstname,
1262 presence.Lastname,
1263 presence.UUID,
1264 presence.ControllingClient.CircuitCode,
1265 ep,
1266 regionName,
1267 ((((ClientView)presence.ControllingClient).PacketProcessingEnabled)
1268 ?"Active client":"Standby client")));
1269 }
1270
1271 m_console.Notice("");
1272
1273 break;
1274 case "modules":
1275 m_console.Notice("The currently loaded shared modules are:");
1276 foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
1277 {
1278 m_console.Notice("Shared Module: " + module.Name);
1279 }
1280 break;
1281
1282 case "regions":
1283 m_sceneManager.ForEachScene(
1284 delegate(Scene scene)
1285 {
1286 m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
1287 scene.RegionInfo.RegionLocX + " , Region YLoc: " +
1288 scene.RegionInfo.RegionLocY);
1289 });
1290 break;
1291
1292 case "stats":
1293 if (StatsManager.SimExtraStats != null)
1294 {
1295 m_console.Notice(
1296 "STATS", Environment.NewLine + StatsManager.SimExtraStats.Report());
1297 }
1298 else
1299 {
1300 m_console.Notice("Extra sim statistics collection has not been enabled");
1301 }
1302 break;
1303 }
1304 }
1305
1306 private string CombineParams(string[] commandParams, int pos)
1307 { 685 {
1308 string result = String.Empty; 686 InternalShutdown();
1309 for (int i = pos; i < commandParams.Length; i++) 687 Environment.Exit(0);
1310 {
1311 result += commandParams[i] + " ";
1312 }
1313 result = result.TrimEnd(' ');
1314 return result;
1315 } 688 }
1316 689
1317 #endregion
1318
1319 /// <summary> 690 /// <summary>
1320 /// Get the start time and up time of Region server 691 /// Get the start time and up time of Region server
1321 /// </summary> 692 /// </summary>
diff --git a/OpenSim/Region/Application/OpenSimMainConsole.cs b/OpenSim/Region/Application/OpenSimMainConsole.cs
new file mode 100644
index 0000000..53e3583
--- /dev/null
+++ b/OpenSim/Region/Application/OpenSimMainConsole.cs
@@ -0,0 +1,716 @@
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.Generic;
30using System.Diagnostics;
31using System.IO;
32using System.Text;
33using System.Threading;
34using System.Timers;
35using Nini.Config;
36using OpenSim.Framework;
37using OpenSim.Framework.Communications.Cache;
38using OpenSim.Framework.Console;
39using OpenSim.Framework.Servers;
40using OpenSim.Framework.Statistics;
41using OpenSim.Region.ClientStack;
42using OpenSim.Region.Communications.Local;
43using OpenSim.Region.Communications.OGS1;
44using OpenSim.Region.Environment;
45using OpenSim.Region.Environment.Interfaces;
46using OpenSim.Region.Environment.Scenes;
47using OpenSim.Region.Physics.Manager;
48using Timer=System.Timers.Timer;
49using System.Net;
50using Nwc.XmlRpc;
51using System.Collections;
52using System.Reflection;
53using libsecondlife;
54using Mono.Addins;
55using Mono.Addins.Description;
56
57namespace OpenSim
58{
59 public delegate void ConsoleCommand(string[] comParams);
60
61 public class OpenSimMainConsole : OpenSimMain, conscmd_callback
62 {
63 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
64
65 protected string m_startupCommandsFile;
66 protected string m_shutdownCommandsFile;
67
68 private string m_timedScript = "disabled";
69 private Timer m_scriptTimer;
70
71
72 public OpenSimMainConsole(IConfigSource configSource)
73 : base(configSource)
74 {
75 }
76
77 protected override void ReadConfigSettings()
78 {
79 IConfig startupConfig = m_config.Configs["Startup"];
80
81 if (startupConfig != null)
82 {
83 m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", String.Empty);
84 m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", String.Empty);
85
86 m_timedScript = startupConfig.GetString("timer_Script", "disabled");
87 }
88 base.ReadConfigSettings();
89 }
90
91 /// <summary>
92 /// Performs initialisation of the scene, such as loading configuration from disk.
93 /// </summary>
94 public override void StartUp()
95 {
96 //
97 // Called from app startup (OpenSim.Application)
98 //
99
100 m_log.Info("====================================================================");
101 m_log.Info("========================= STARTING OPENSIM =========================");
102 m_log.Info("====================================================================");
103 m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (m_sandbox ? "sandbox" : "grid"));
104
105 m_console = CreateConsole();
106 MainConsole.Instance = m_console;
107 InternalStartUp();
108
109 //Run Startup Commands
110 if (m_startupCommandsFile != String.Empty)
111 {
112 RunCommandScript(m_startupCommandsFile);
113 }
114 else
115 {
116 m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
117 }
118
119 // Start timer script (run a script every xx seconds)
120 if (m_timedScript != "disabled")
121 {
122 m_scriptTimer = new Timer();
123 m_scriptTimer.Enabled = true;
124 m_scriptTimer.Interval = (int)(1200 * 1000);
125 m_scriptTimer.Elapsed += new ElapsedEventHandler(RunAutoTimerScript);
126 }
127 PrintFileToConsole("startuplogo.txt");
128 }
129
130 protected ConsoleBase CreateConsole()
131 {
132 return new ConsoleBase("Region", this);
133 }
134
135 /// <summary>
136 /// Performs any last-minute sanity checking and shuts down the region server
137 /// </summary>
138 public override void Shutdown()
139 {
140 if (m_startupCommandsFile != String.Empty)
141 {
142 RunCommandScript(m_shutdownCommandsFile);
143 }
144 InternalShutdown();
145 m_console.Close();
146 Environment.Exit(0);
147 }
148
149 private void RunAutoTimerScript(object sender, EventArgs e)
150 {
151 if (m_timedScript != "disabled")
152 {
153 RunCommandScript(m_timedScript);
154 }
155 }
156
157 #region Console Commands
158
159 /// <summary>
160 ///
161 /// </summary>
162 /// <param name="fileName"></param>
163 private void RunCommandScript(string fileName)
164 {
165 m_log.Info("[COMMANDFILE]: Running " + fileName);
166 if (File.Exists(fileName))
167 {
168 StreamReader readFile = File.OpenText(fileName);
169 string currentCommand = String.Empty;
170 while ((currentCommand = readFile.ReadLine()) != null)
171 {
172 if (currentCommand != String.Empty)
173 {
174 m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
175 m_console.RunCommand(currentCommand);
176 }
177 }
178 }
179 else
180 {
181 m_log.Error("[COMMANDFILE]: Command script missing. Can not run commands");
182 }
183 }
184
185 private void PrintFileToConsole(string fileName)
186 {
187 if (File.Exists(fileName))
188 {
189 StreamReader readFile = File.OpenText(fileName);
190 string currentLine = String.Empty;
191 while ((currentLine = readFile.ReadLine()) != null)
192 {
193 m_log.Info("[!]" + currentLine);
194 }
195 }
196 }
197
198
199 /// <summary>
200 /// Runs commands issued by the server console from the operator
201 /// </summary>
202 /// <param name="command">The first argument of the parameter (the command)</param>
203 /// <param name="cmdparams">Additional arguments passed to the command</param>
204 public override void RunCmd(string command, string[] cmdparams)
205 {
206 base.RunCmd(command, cmdparams);
207
208 switch (command)
209 {
210 case "clear-assets":
211 m_assetCache.Clear();
212 break;
213
214 case "set-time":
215 m_sceneManager.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
216 break;
217
218 case "force-update":
219 m_console.Notice("Updating all clients");
220 m_sceneManager.ForceCurrentSceneClientUpdate();
221 break;
222
223 case "edit-scale":
224 if (cmdparams.Length == 4)
225 {
226 m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
227 }
228 break;
229
230 case "debug":
231 if (cmdparams.Length > 0)
232 {
233 Debug(cmdparams);
234 }
235 break;
236
237 case "scene-debug":
238 if (cmdparams.Length == 3)
239 {
240 if (m_sceneManager.CurrentScene == null)
241 {
242 m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
243 }
244 else
245 {
246 m_sceneManager.CurrentScene.SetSceneCoreDebug(!System.Convert.ToBoolean(cmdparams[0]), !System.Convert.ToBoolean(cmdparams[1]), !System.Convert.ToBoolean(cmdparams[2]));
247 }
248 }
249 else
250 {
251 m_console.Error("scene-debug <scripting> <collisions> <physics> (where inside <> is true/false)");
252 }
253 break;
254
255 case "help":
256 m_console.Notice("alert - send alert to a designated user or all users.");
257 m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
258 m_console.Notice(" alert general [Message] - send an alert to all users.");
259 m_console.Notice("backup - trigger a simulator backup");
260 m_console.Notice("clear-assets - clear asset cache");
261 m_console.Notice("create-region <name> <regionfile.xml> - creates a new region");
262 m_console.Notice("create user - adds a new user.");
263 m_console.Notice("change-region [name] - sets the region that many of these commands affect.");
264 m_console.Notice("command-script [filename] - Execute command in a file.");
265 m_console.Notice("debug - debugging commands");
266 m_console.Notice(" packet 0..255 - print incoming/outgoing packets (0=off)");
267 m_console.Notice("scene-debug [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
268 m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
269 m_console.Notice("export-map [filename] - save image of world map");
270 m_console.Notice("force-update - force an update of prims in the scene");
271 m_console.Notice("load-xml [filename] - load prims from XML");
272 m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
273 m_console.Notice("permissions [true/false] - turn on/off permissions on the scene");
274 m_console.Notice("quit - equivalent to shutdown.");
275 m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
276 m_console.Notice("remove-region [name] - remove a region");
277 m_console.Notice("save-xml [filename] - save prims to XML");
278 m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
279 m_console.Notice("script - manually trigger scripts? or script commands?");
280 m_console.Notice("set-time [x] - set the current scene time phase");
281 m_console.Notice("show assets - show state of asset cache.");
282 m_console.Notice("show users - show info about connected users.");
283 m_console.Notice("show modules - shows info about loaded modules.");
284 m_console.Notice("show stats - statistical information for this server not displayed in the client");
285 m_console.Notice("threads - list threads");
286 m_console.Notice("shutdown - disconnect all clients and shutdown.");
287 m_console.Notice("config set section field value - set a config value");
288 m_console.Notice("config get section field - get a config value");
289 m_console.Notice("config save - save OpenSim.ini");
290 m_console.Notice("terrain help - show help for terrain commands.");
291 break;
292
293 case "threads":
294// m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:");
295// int _tc = 0;
296
297// foreach (ProcessThread pt in Process.GetCurrentProcess().Threads)
298// {
299// _tc++;
300// m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString());
301// }
302
303 List<Thread> threads = OpenSim.Framework.ThreadTracker.GetThreads();
304 if (threads == null)
305 {
306 m_console.Notice("THREAD", "Thread tracking is only enabled in DEBUG mode.");
307 }
308 else
309 {
310 int _tc = 0;
311 m_console.Notice("THREAD", threads.Count + " threads are being tracked:");
312 foreach (Thread t in threads)
313 {
314 _tc++;
315 m_console.Notice("THREAD", _tc + ": ID: " + t.ManagedThreadId.ToString() + ", Name: " + t.Name + ", Alive: " + t.IsAlive.ToString() + ", Pri: " + t.Priority.ToString() + ", State: " + t.ThreadState.ToString());
316 }
317 }
318
319 break;
320 case "save-xml":
321 if (cmdparams.Length > 0)
322 {
323 m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
324 }
325 else
326 {
327 m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
328 }
329 break;
330
331 case "load-xml":
332 LLVector3 loadOffset = new LLVector3(0, 0, 0);
333 if (cmdparams.Length > 0)
334 {
335 bool generateNewIDS = false;
336 if (cmdparams.Length > 1)
337 {
338 if (cmdparams[1] == "-newUID")
339 {
340 generateNewIDS = true;
341 }
342 if (cmdparams.Length > 2)
343 {
344 loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
345 if (cmdparams.Length > 3)
346 {
347 loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
348 }
349 if (cmdparams.Length > 4)
350 {
351 loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
352 }
353 m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
354 loadOffset.Z + ">");
355 }
356 }
357 m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
358 }
359 else
360 {
361 m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
362 }
363 break;
364
365 case "save-xml2":
366 if (cmdparams.Length > 0)
367 {
368 m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
369 }
370 else
371 {
372 m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
373 }
374 break;
375
376 case "load-xml2":
377 if (cmdparams.Length > 0)
378 {
379 m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
380 }
381 else
382 {
383 m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
384 }
385 break;
386
387 case "plugin":
388 m_sceneManager.SendCommandToPluginModules(cmdparams);
389 break;
390
391 case "command-script":
392 if (cmdparams.Length > 0)
393 {
394 RunCommandScript(cmdparams[0]);
395 }
396 break;
397
398 case "permissions":
399 // Treats each user as a super-admin when disabled
400 bool permissions = Convert.ToBoolean(cmdparams[0]);
401 m_sceneManager.SetBypassPermissionsOnCurrentScene(!permissions);
402 break;
403
404 case "backup":
405 m_sceneManager.BackupCurrentScene();
406 break;
407
408 case "alert":
409 m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
410 break;
411
412 case "create":
413 CreateAccount(cmdparams);
414 break;
415
416 case "create-region":
417 CreateRegion(new RegionInfo(cmdparams[0], "Regions/" + cmdparams[1],false), true);
418 break;
419 case "remove-region":
420 string regName = CombineParams(cmdparams, 0);
421
422 Scene killScene;
423 if (m_sceneManager.TryGetScene(regName, out killScene))
424 {
425 // only need to check this if we are not at the
426 // root level
427 if ((m_sceneManager.CurrentScene != null) &&
428 (m_sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
429 {
430 m_sceneManager.TrySetCurrentScene("..");
431 }
432 m_regionData.Remove(killScene.RegionInfo);
433 m_sceneManager.CloseScene(killScene);
434 }
435 break;
436
437 case "exit":
438 case "quit":
439 case "shutdown":
440 Shutdown();
441 break;
442
443 case "restart":
444 m_sceneManager.RestartCurrentScene();
445 break;
446
447 case "change-region":
448 if (cmdparams.Length > 0)
449 {
450 string regionName = CombineParams(cmdparams, 0);
451
452 if (!m_sceneManager.TrySetCurrentScene(regionName))
453 {
454 m_console.Error("Couldn't set current region to: " + regionName);
455 }
456 }
457
458 if (m_sceneManager.CurrentScene == null)
459 {
460 m_console.Error("CONSOLE", "Currently at Root level. To change region please use 'change-region <regioname>'");
461 }
462 else
463 {
464 m_console.Error("CONSOLE", "Current Region: " + m_sceneManager.CurrentScene.RegionInfo.RegionName +
465 ". To change region please use 'change-region <regioname>'");
466 }
467
468 break;
469
470 case "export-map":
471 if (cmdparams.Length > 0)
472 {
473 m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
474 }
475 else
476 {
477 m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
478 }
479 break;
480
481 case "config":
482 string n = command.ToUpper();
483 if (cmdparams.Length > 0)
484 {
485 switch (cmdparams[0].ToLower())
486 {
487 case "set":
488 if (cmdparams.Length < 4)
489 {
490 m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
491 m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
492 }
493 else
494 {
495 IConfig c = DefaultConfig().Configs[cmdparams[1]];
496 if (c == null)
497 c = DefaultConfig().AddConfig(cmdparams[1]);
498 string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
499 c.Set(cmdparams[2], _value);
500 m_config.Merge(c.ConfigSource);
501
502 m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
503 _value);
504 }
505 break;
506 case "get":
507 if (cmdparams.Length < 3)
508 {
509 m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
510 m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
511 }
512 else
513 {
514 IConfig c = DefaultConfig().Configs[cmdparams[1]];
515 if (c == null)
516 {
517 m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
518 break;
519 }
520 else
521 {
522 m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
523 c.GetString(cmdparams[2]));
524 }
525 }
526
527 break;
528 case "save":
529 m_console.Notice("Saving configuration file: " + Application.iniFilePath);
530 m_config.Save(Application.iniFilePath);
531 break;
532 }
533 }
534 break;
535 case "modules":
536 if (cmdparams.Length > 0)
537 {
538 switch (cmdparams[0].ToLower())
539 {
540 case "list":
541 foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
542 {
543 m_console.Notice("Shared region module: " + irm.Name);
544 }
545 break;
546 case "unload":
547 if (cmdparams.Length > 1)
548 {
549 foreach (IRegionModule rm in new System.Collections.ArrayList(m_moduleLoader.GetLoadedSharedModules))
550 {
551 if (rm.Name.ToLower() == cmdparams[1].ToLower())
552 {
553 m_console.Notice("Unloading module: " + rm.Name);
554 m_moduleLoader.UnloadModule(rm);
555 }
556 }
557 }
558 break;
559 case "load":
560 if (cmdparams.Length > 1)
561 {
562 foreach (Scene s in new System.Collections.ArrayList(m_sceneManager.Scenes))
563 {
564
565 m_console.Notice("Loading module: " + cmdparams[1]);
566 m_moduleLoader.LoadRegionModules(cmdparams[1], s);
567 }
568 }
569 break;
570 }
571 }
572
573 break;
574
575 default:
576 string[] tmpPluginArgs = new string[cmdparams.Length + 1];
577 cmdparams.CopyTo(tmpPluginArgs, 1);
578 tmpPluginArgs[0] = command;
579
580 m_sceneManager.SendCommandToPluginModules(tmpPluginArgs);
581 break;
582 }
583 }
584
585 public void Debug(string[] args)
586 {
587 switch (args[0])
588 {
589 case "packet":
590 if (args.Length > 1)
591 {
592 int newDebug;
593 if (int.TryParse(args[1], out newDebug))
594 {
595 m_sceneManager.SetDebugPacketOnCurrentScene(newDebug);
596 }
597 else
598 {
599 m_console.Error("packet debug should be 0..2");
600 }
601 m_console.Notice("New packet debug: " + newDebug.ToString());
602 }
603
604 break;
605 default:
606 m_console.Error("Unknown debug");
607 break;
608 }
609 }
610
611 // see BaseOpenSimServer
612 public override void Show(string ShowWhat)
613 {
614 base.Show(ShowWhat);
615
616 switch (ShowWhat)
617 {
618 case "assets":
619 m_assetCache.ShowState();
620 break;
621
622 case "users":
623 IList agents = m_sceneManager.GetCurrentSceneAvatars();
624
625 m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
626
627 m_console.Notice(
628 String.Format("{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}{6,-15}", "Firstname", "Lastname",
629 "Agent ID", "Circuit", "IP", "Region", "Status"));
630
631 foreach (ScenePresence presence in agents)
632 {
633 RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
634 string regionName;
635 System.Net.EndPoint ep = null;
636
637 if (regionInfo == null)
638 {
639 regionName = "Unresolvable";
640 }
641 else
642 {
643 regionName = regionInfo.RegionName;
644 }
645
646 for (int i = 0; i < m_udpServers.Count; i++)
647 {
648 if (m_udpServers[i].RegionHandle == presence.RegionHandle)
649 {
650
651 m_udpServers[i].clientCircuits_reverse.TryGetValue(presence.ControllingClient.CircuitCode, out ep);
652 }
653 }
654
655 m_console.Notice(
656 String.Format(
657 "{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}{6,-15}",
658 presence.Firstname,
659 presence.Lastname,
660 presence.UUID,
661 presence.ControllingClient.CircuitCode,
662 ep,
663 regionName,
664 ((((ClientView)presence.ControllingClient).PacketProcessingEnabled)
665 ?"Active client":"Standby client")));
666 }
667
668 m_console.Notice("");
669
670 break;
671 case "modules":
672 m_console.Notice("The currently loaded shared modules are:");
673 foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
674 {
675 m_console.Notice("Shared Module: " + module.Name);
676 }
677 break;
678
679 case "regions":
680 m_sceneManager.ForEachScene(
681 delegate(Scene scene)
682 {
683 m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
684 scene.RegionInfo.RegionLocX + " , Region YLoc: " +
685 scene.RegionInfo.RegionLocY);
686 });
687 break;
688
689 case "stats":
690 if (StatsManager.SimExtraStats != null)
691 {
692 m_console.Notice(
693 "STATS", Environment.NewLine + StatsManager.SimExtraStats.Report());
694 }
695 else
696 {
697 m_console.Notice("Extra sim statistics collection has not been enabled");
698 }
699 break;
700 }
701 }
702
703 private string CombineParams(string[] commandParams, int pos)
704 {
705 string result = String.Empty;
706 for (int i = pos; i < commandParams.Length; i++)
707 {
708 result += commandParams[i] + " ";
709 }
710 result = result.TrimEnd(' ');
711 return result;
712 }
713
714 #endregion
715 }
716}