2008-04-28 14:41:46 +00:00
/ *
* Copyright ( c ) Contributors , http : //opensimulator.org/
* See CONTRIBUTORS . TXT for a full list of copyright holders .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ` ` AS IS ' ' AND ANY
* EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
* LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
using System ;
2008-05-01 14:45:56 +00:00
using System.Collections ;
2008-04-28 14:41:46 +00:00
using System.Collections.Generic ;
using System.IO ;
2008-05-01 14:45:56 +00:00
using System.Net ;
using System.Reflection ;
2008-04-28 14:41:46 +00:00
using System.Threading ;
2008-09-06 07:52:41 +00:00
using OpenMetaverse ;
2008-05-01 14:45:56 +00:00
using log4net ;
2008-04-28 14:41:46 +00:00
using Nini.Config ;
using OpenSim.Framework ;
using OpenSim.Framework.Console ;
using OpenSim.Framework.Statistics ;
using OpenSim.Region.Environment.Interfaces ;
using OpenSim.Region.Environment.Scenes ;
2008-10-19 18:26:44 +00:00
using OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver ;
2008-04-28 14:41:46 +00:00
using Timer = System . Timers . Timer ;
namespace OpenSim
{
2008-06-01 01:01:16 +00:00
/// <summary>
/// Interactive OpenSim region server
/// </summary>
public class OpenSim : OpenSimBase , conscmd_callback
2008-05-16 01:22:11 +00:00
{
2008-05-01 14:45:56 +00:00
private static readonly ILog m_log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2008-04-28 14:41:46 +00:00
protected string m_startupCommandsFile ;
protected string m_shutdownCommandsFile ;
private string m_timedScript = "disabled" ;
private Timer m_scriptTimer ;
2008-08-19 02:59:27 +00:00
2008-06-08 00:34:00 +00:00
/// <summary>
/// List of Console Plugin Commands
/// </summary>
private static List < ConsolePluginCommand > m_PluginCommandInfos = new List < ConsolePluginCommand > ( ) ;
2008-04-28 14:41:46 +00:00
2008-06-01 01:01:16 +00:00
public OpenSim ( IConfigSource configSource ) : base ( configSource )
2008-04-28 14:41:46 +00:00
{
}
2008-11-05 20:14:52 +00:00
protected override void ReadExtraConfigSettings ( )
2008-04-28 14:41:46 +00:00
{
2008-11-06 20:17:20 +00:00
base . ReadExtraConfigSettings ( ) ;
2008-06-26 17:23:05 +00:00
IConfig startupConfig = m_config . Source . Configs [ "Startup" ] ;
2008-04-28 14:41:46 +00:00
if ( startupConfig ! = null )
{
m_startupCommandsFile = startupConfig . GetString ( "startup_console_commands_file" , String . Empty ) ;
m_shutdownCommandsFile = startupConfig . GetString ( "shutdown_console_commands_file" , String . Empty ) ;
m_timedScript = startupConfig . GetString ( "timer_Script" , "disabled" ) ;
}
}
/// <summary>
/// Performs initialisation of the scene, such as loading configuration from disk.
/// </summary>
2008-10-03 15:41:27 +00:00
protected override void StartupSpecific ( )
2008-04-28 14:41:46 +00:00
{
m_log . Info ( "====================================================================" ) ;
m_log . Info ( "========================= STARTING OPENSIM =========================" ) ;
m_log . Info ( "====================================================================" ) ;
2008-11-05 17:45:56 +00:00
m_log . InfoFormat ( "[OPENSIM MAIN]: Running in {0} mode" , ( ConfigurationSettings . Standalone ? "sandbox" : "grid" ) ) ;
2008-05-16 01:22:11 +00:00
2008-08-05 17:00:35 +00:00
m_console = new ConsoleBase ( "Region" , this ) ;
2008-08-18 00:39:10 +00:00
MainConsole . Instance = m_console ;
2008-10-03 15:41:27 +00:00
base . StartupSpecific ( ) ;
2008-04-28 14:41:46 +00:00
//Run Startup Commands
2008-09-08 14:30:35 +00:00
if ( String . IsNullOrEmpty ( m_startupCommandsFile ) )
2008-04-28 14:41:46 +00:00
{
2008-09-08 14:30:35 +00:00
m_log . Info ( "[STARTUP]: No startup command script specified. Moving on..." ) ;
2008-04-28 14:41:46 +00:00
}
else
{
2008-09-08 14:30:35 +00:00
RunCommandScript ( m_startupCommandsFile ) ;
2008-04-28 14:41:46 +00:00
}
// Start timer script (run a script every xx seconds)
if ( m_timedScript ! = "disabled" )
{
m_scriptTimer = new Timer ( ) ;
m_scriptTimer . Enabled = true ;
2008-05-02 16:41:08 +00:00
m_scriptTimer . Interval = 1200 * 1000 ;
m_scriptTimer . Elapsed + = RunAutoTimerScript ;
2008-04-28 14:41:46 +00:00
}
2008-05-16 01:22:11 +00:00
2008-04-28 14:41:46 +00:00
PrintFileToConsole ( "startuplogo.txt" ) ;
2008-06-18 21:07:40 +00:00
RegisterCmd ( "echoTest" , RunEchoTest , "this echos your command args to see how they are parsed" ) ;
2008-06-22 05:08:58 +00:00
RegisterCmd ( "kickuser" , KickUserCommand , "kickuser [first] [last] - attempts to log off a user from any region we are serving" ) ;
2008-08-18 00:39:10 +00:00
2008-08-05 17:52:06 +00:00
// For now, start at the 'root' level by default
2008-08-18 00:39:10 +00:00
ChangeSelectedRegion ( new string [ ] { "root" } ) ;
2008-04-28 14:41:46 +00:00
}
private void RunAutoTimerScript ( object sender , EventArgs e )
{
if ( m_timedScript ! = "disabled" )
{
RunCommandScript ( m_timedScript ) ;
}
}
#region Console Commands
2008-06-25 14:30:28 +00:00
private void RunEchoTest ( string [ ] cmdparams )
{
for ( int i = 0 ; i < cmdparams . Length ; i + + )
{
2008-08-18 00:39:10 +00:00
m_log . Info ( "[EchoTest]: <arg" + i + ">" + cmdparams [ i ] + "</arg" + i + ">" ) ;
2008-06-25 14:30:28 +00:00
}
}
2008-06-18 21:07:40 +00:00
2008-06-22 05:08:58 +00:00
private void KickUserCommand ( string [ ] cmdparams )
{
if ( cmdparams . Length < 2 )
return ;
IList agents = m_sceneManager . GetCurrentSceneAvatars ( ) ;
foreach ( ScenePresence presence in agents )
{
RegionInfo regionInfo = m_sceneManager . GetRegionInfo ( presence . RegionHandle ) ;
2008-06-23 09:31:08 +00:00
if ( presence . Firstname . ToLower ( ) . Contains ( cmdparams [ 0 ] . ToLower ( ) ) & & presence . Lastname . ToLower ( ) . Contains ( cmdparams [ 1 ] . ToLower ( ) ) )
2008-06-22 05:08:58 +00:00
{
m_console . Notice (
String . Format (
2008-06-23 09:31:08 +00:00
"Kicking user: {0,-16}{1,-16}{2,-37} in region: {3,-16}" ,
2008-06-22 05:08:58 +00:00
presence . Firstname ,
presence . Lastname ,
presence . UUID ,
regionInfo . RegionName ) ) ;
2008-11-12 19:12:33 +00:00
presence . Scene . CloseConnection ( presence . UUID ) ;
2008-06-22 05:08:58 +00:00
}
}
m_console . Notice ( "" ) ;
}
2008-04-28 14:41:46 +00:00
/// <summary>
2008-05-16 01:22:11 +00:00
///
2008-04-28 14:41:46 +00:00
/// </summary>
/// <param name="fileName"></param>
private void RunCommandScript ( string fileName )
{
m_log . Info ( "[COMMANDFILE]: Running " + fileName ) ;
if ( File . Exists ( fileName ) )
{
StreamReader readFile = File . OpenText ( fileName ) ;
2008-05-02 16:41:08 +00:00
string currentCommand ;
2008-04-28 14:41:46 +00:00
while ( ( currentCommand = readFile . ReadLine ( ) ) ! = null )
{
if ( currentCommand ! = String . Empty )
{
m_log . Info ( "[COMMANDFILE]: Running '" + currentCommand + "'" ) ;
m_console . RunCommand ( currentCommand ) ;
}
}
}
else
{
m_log . Error ( "[COMMANDFILE]: Command script missing. Can not run commands" ) ;
}
}
2008-05-01 16:03:53 +00:00
private static void PrintFileToConsole ( string fileName )
2008-04-28 14:41:46 +00:00
{
if ( File . Exists ( fileName ) )
{
StreamReader readFile = File . OpenText ( fileName ) ;
2008-05-02 16:41:08 +00:00
string currentLine ;
2008-04-28 14:41:46 +00:00
while ( ( currentLine = readFile . ReadLine ( ) ) ! = null )
{
m_log . Info ( "[!]" + currentLine ) ;
}
}
}
/// <summary>
/// Runs commands issued by the server console from the operator
/// </summary>
/// <param name="command">The first argument of the parameter (the command)</param>
/// <param name="cmdparams">Additional arguments passed to the command</param>
public override void RunCmd ( string command , string [ ] cmdparams )
{
base . RunCmd ( command , cmdparams ) ;
2008-06-21 23:17:15 +00:00
RunPluginCommands ( command , cmdparams ) ;
2008-08-18 00:39:10 +00:00
2008-04-28 14:41:46 +00:00
switch ( command )
{
case "clear-assets" :
m_assetCache . Clear ( ) ;
break ;
case "set-time" :
m_sceneManager . SetCurrentSceneTimePhase ( Convert . ToInt32 ( cmdparams [ 0 ] ) ) ;
break ;
case "force-update" :
m_console . Notice ( "Updating all clients" ) ;
m_sceneManager . ForceCurrentSceneClientUpdate ( ) ;
break ;
case "edit-scale" :
if ( cmdparams . Length = = 4 )
{
m_sceneManager . HandleEditCommandOnCurrentScene ( cmdparams ) ;
}
break ;
case "debug" :
2008-07-12 19:47:45 +00:00
Debug ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
case "save-xml" :
2008-07-12 20:14:17 +00:00
SaveXml ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
case "load-xml" :
2008-07-12 20:14:17 +00:00
LoadXml ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
case "save-xml2" :
2008-07-12 20:14:17 +00:00
SaveXml2 ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
case "load-xml2" :
2008-07-12 20:14:17 +00:00
LoadXml2 ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
2008-05-25 23:27:38 +00:00
2008-07-01 19:23:45 +00:00
case "save-prims-xml2" :
if ( cmdparams . Length > 1 )
{
m_sceneManager . SaveNamedPrimsToXml2 ( cmdparams [ 0 ] , cmdparams [ 1 ] ) ;
}
else
{
m_sceneManager . SaveNamedPrimsToXml2 ( "Primitive" , DEFAULT_PRIM_BACKUP_FILENAME ) ;
}
break ;
2008-05-28 17:49:34 +00:00
case "load-oar" :
2008-07-12 20:14:17 +00:00
LoadOar ( cmdparams ) ;
2008-05-28 17:49:34 +00:00
break ;
2008-08-18 00:39:10 +00:00
2008-05-22 17:09:33 +00:00
case "save-oar" :
2008-07-12 20:14:17 +00:00
SaveOar ( cmdparams ) ;
2008-05-25 23:27:38 +00:00
break ;
2008-08-18 00:39:10 +00:00
2008-07-29 14:28:08 +00:00
case "save-inv" :
SaveInv ( cmdparams ) ;
break ;
2008-04-28 14:41:46 +00:00
2008-09-29 14:41:16 +00:00
case "load-inv" :
LoadInv ( cmdparams ) ;
break ;
2008-04-28 14:41:46 +00:00
case "plugin" :
m_sceneManager . SendCommandToPluginModules ( cmdparams ) ;
break ;
case "command-script" :
if ( cmdparams . Length > 0 )
{
RunCommandScript ( cmdparams [ 0 ] ) ;
}
break ;
case "backup" :
m_sceneManager . BackupCurrentScene ( ) ;
break ;
case "alert" :
m_sceneManager . HandleAlertCommandOnCurrentScene ( cmdparams ) ;
break ;
case "create" :
2008-08-18 00:39:10 +00:00
Create ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
2008-11-24 09:53:49 +00:00
case "login-enable" :
ProcessLogin ( true ) ;
break ;
case "login-disable" :
ProcessLogin ( false ) ;
break ;
case "login-status" :
if ( m_commsManager . GridService . RegionLoginsEnabled = = false )
m_log . Info ( "[ Login ] Login are disabled " ) ;
else
m_log . Info ( "[ Login ] Login are enabled" ) ;
break ;
2008-04-28 14:41:46 +00:00
case "create-region" :
2008-08-28 10:01:56 +00:00
string regionsDir = ConfigSource . Source . Configs [ "Startup" ] . GetString ( "regionload_regionsdir" , "Regions" ) . Trim ( ) ;
2008-09-30 10:50:41 +00:00
string regionFile = String . Format ( "{0}/{1}" , regionsDir , cmdparams [ 1 ] ) ;
// Allow absolute and relative specifiers
if ( cmdparams [ 1 ] . StartsWith ( "/" ) | | cmdparams [ 1 ] . StartsWith ( "\\" ) | | cmdparams [ 1 ] . StartsWith ( ".." ) )
regionFile = cmdparams [ 1 ] ;
CreateRegion ( new RegionInfo ( cmdparams [ 0 ] , regionFile , false ) , true ) ;
2008-04-28 14:41:46 +00:00
break ;
2008-08-18 00:39:10 +00:00
2008-04-28 14:41:46 +00:00
case "remove-region" :
2008-09-18 15:44:05 +00:00
string regRemoveName = CombineParams ( cmdparams , 0 ) ;
2008-04-28 14:41:46 +00:00
2008-09-18 15:44:05 +00:00
Scene removeScene ;
if ( m_sceneManager . TryGetScene ( regRemoveName , out removeScene ) )
RemoveRegion ( removeScene , false ) ;
else
m_console . Error ( "no region with that name" ) ;
break ;
2008-09-08 14:30:35 +00:00
2008-09-18 15:44:05 +00:00
case "delete-region" :
string regDeleteName = CombineParams ( cmdparams , 0 ) ;
Scene killScene ;
if ( m_sceneManager . TryGetScene ( regDeleteName , out killScene ) )
RemoveRegion ( killScene , true ) ;
else
m_console . Error ( "no region with that name" ) ;
2008-04-28 14:41:46 +00:00
break ;
case "restart" :
m_sceneManager . RestartCurrentScene ( ) ;
break ;
case "change-region" :
2008-08-05 17:03:06 +00:00
ChangeSelectedRegion ( cmdparams ) ;
2008-04-28 14:41:46 +00:00
break ;
case "export-map" :
if ( cmdparams . Length > 0 )
{
m_sceneManager . CurrentOrFirstScene . ExportWorldMap ( cmdparams [ 0 ] ) ;
}
else
{
m_sceneManager . CurrentOrFirstScene . ExportWorldMap ( "exportmap.jpg" ) ;
}
break ;
case "config" :
string n = command . ToUpper ( ) ;
if ( cmdparams . Length > 0 )
{
switch ( cmdparams [ 0 ] . ToLower ( ) )
{
case "set" :
if ( cmdparams . Length < 4 )
{
m_console . Error ( n , "SYNTAX: " + n + " SET SECTION KEY VALUE" ) ;
m_console . Error ( n , "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5" ) ;
}
else
{
2008-11-05 19:47:29 +00:00
// IConfig c = DefaultConfig().Configs[cmdparams[1]];
// if (c == null)
// c = DefaultConfig().AddConfig(cmdparams[1]);
IConfig c ;
IConfigSource source = new IniConfigSource ( ) ;
c = source . AddConfig ( cmdparams [ 1 ] ) ;
if ( c ! = null )
{
string _value = String . Join ( " " , cmdparams , 3 , cmdparams . Length - 3 ) ;
c . Set ( cmdparams [ 2 ] , _value ) ;
m_config . Source . Merge ( source ) ;
2008-04-28 14:41:46 +00:00
2008-11-05 19:47:29 +00:00
m_console . Error ( n , n + " " + n + " " + cmdparams [ 1 ] + " " + cmdparams [ 2 ] + " " +
_value ) ;
}
2008-04-28 14:41:46 +00:00
}
break ;
case "get" :
if ( cmdparams . Length < 3 )
{
m_console . Error ( n , "SYNTAX: " + n + " GET SECTION KEY" ) ;
m_console . Error ( n , "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads" ) ;
}
else
{
2008-11-05 19:47:29 +00:00
IConfig c = m_config . Source . Configs [ cmdparams [ 1 ] ] ; // DefaultConfig().Configs[cmdparams[1]];
2008-04-28 14:41:46 +00:00
if ( c = = null )
{
m_console . Notice ( n , "Section \"" + cmdparams [ 1 ] + "\" does not exist." ) ;
break ;
}
else
{
m_console . Notice ( n + " GET " + cmdparams [ 1 ] + " " + cmdparams [ 2 ] + ": " +
c . GetString ( cmdparams [ 2 ] ) ) ;
}
}
break ;
case "save" :
m_console . Notice ( "Saving configuration file: " + Application . iniFilePath ) ;
m_config . Save ( Application . iniFilePath ) ;
break ;
}
}
break ;
2008-08-18 00:39:10 +00:00
2008-04-28 14:41:46 +00:00
case "modules" :
if ( cmdparams . Length > 0 )
{
switch ( cmdparams [ 0 ] . ToLower ( ) )
{
case "list" :
foreach ( IRegionModule irm in m_moduleLoader . GetLoadedSharedModules )
{
m_console . Notice ( "Shared region module: " + irm . Name ) ;
}
break ;
case "unload" :
if ( cmdparams . Length > 1 )
{
2008-05-01 14:45:56 +00:00
foreach ( IRegionModule rm in new ArrayList ( m_moduleLoader . GetLoadedSharedModules ) )
2008-04-28 14:41:46 +00:00
{
if ( rm . Name . ToLower ( ) = = cmdparams [ 1 ] . ToLower ( ) )
{
m_console . Notice ( "Unloading module: " + rm . Name ) ;
m_moduleLoader . UnloadModule ( rm ) ;
}
}
}
break ;
case "load" :
if ( cmdparams . Length > 1 )
{
2008-05-01 14:45:56 +00:00
foreach ( Scene s in new ArrayList ( m_sceneManager . Scenes ) )
2008-04-28 14:41:46 +00:00
{
2008-05-16 01:22:11 +00:00
2008-04-28 14:41:46 +00:00
m_console . Notice ( "Loading module: " + cmdparams [ 1 ] ) ;
m_moduleLoader . LoadRegionModules ( cmdparams [ 1 ] , s ) ;
}
}
break ;
}
}
2008-05-16 01:22:11 +00:00
break ;
2008-06-28 17:52:06 +00:00
case "Add-InventoryHost" :
if ( cmdparams . Length > 0 )
{
m_commsManager . AddInventoryService ( cmdparams [ 0 ] ) ;
}
break ;
2008-09-15 17:29:11 +00:00
case "reset" :
Reset ( cmdparams ) ;
break ;
2008-08-18 00:39:10 +00:00
2008-04-28 14:41:46 +00:00
default :
string [ ] tmpPluginArgs = new string [ cmdparams . Length + 1 ] ;
cmdparams . CopyTo ( tmpPluginArgs , 1 ) ;
tmpPluginArgs [ 0 ] = command ;
m_sceneManager . SendCommandToPluginModules ( tmpPluginArgs ) ;
break ;
}
}
2008-08-18 00:39:10 +00:00
2008-08-05 17:00:35 +00:00
/// <summary>
2008-08-05 17:03:06 +00:00
/// Change the currently selected region. The selected region is that operated upon by single region commands.
2008-08-05 17:00:35 +00:00
/// </summary>
/// <param name="cmdParams"></param>
2008-08-05 17:03:06 +00:00
protected void ChangeSelectedRegion ( string [ ] cmdparams )
2008-08-05 17:00:35 +00:00
{
if ( cmdparams . Length > 0 )
{
2008-08-05 17:52:06 +00:00
string newRegionName = CombineParams ( cmdparams , 0 ) ;
2008-08-05 17:00:35 +00:00
2008-08-05 17:52:06 +00:00
if ( ! m_sceneManager . TrySetCurrentScene ( newRegionName ) )
m_console . Error ( "Couldn't select region " + newRegionName ) ;
2008-08-05 17:00:35 +00:00
}
2008-08-05 17:52:06 +00:00
else
{
m_console . Error ( "Usage: change-region <region name>" ) ;
2008-08-18 00:39:10 +00:00
}
2008-08-05 17:52:06 +00:00
2008-08-18 00:39:10 +00:00
string regionName = ( m_sceneManager . CurrentScene = = null ? "root" : m_sceneManager . CurrentScene . RegionInfo . RegionName ) ;
2008-08-05 17:52:06 +00:00
m_console . Notice ( String . Format ( "Currently selected region is {0}" , regionName ) ) ;
2008-08-18 00:39:10 +00:00
m_console . DefaultPrompt = String . Format ( "Region ({0}) " , regionName ) ;
2008-08-05 17:00:35 +00:00
}
2008-08-18 00:39:10 +00:00
2008-07-29 17:39:15 +00:00
/// <summary>
/// Execute switch for some of the create commands
/// </summary>
/// <param name="args"></param>
protected void Create ( string [ ] args )
{
if ( args . Length = = 0 )
return ;
2008-08-18 00:39:10 +00:00
2008-07-29 17:39:15 +00:00
switch ( args [ 0 ] )
{
case "user" :
2008-11-23 03:38:40 +00:00
if ( ConfigurationSettings . Standalone )
{
CreateUser ( args ) ;
}
else
{
2008-11-28 15:34:30 +00:00
m_console . Notice ( "Create user is not available in grid mode, use the user server." ) ;
2008-11-23 03:38:40 +00:00
}
2008-07-29 17:39:15 +00:00
break ;
}
}
2008-09-15 17:29:11 +00:00
/// <summary>
/// Execute switch for some of the reset commands
/// </summary>
/// <param name="args"></param>
protected void Reset ( string [ ] args )
{
if ( args . Length = = 0 )
return ;
switch ( args [ 0 ] )
{
case "user" :
switch ( args [ 1 ] )
{
case "password" :
2008-11-23 03:38:40 +00:00
if ( ConfigurationSettings . Standalone )
{
ResetUserPassword ( args ) ;
}
else
{
m_console . Notice ( "Reset user password is not available in grid mode, use the user-server." ) ;
}
2008-09-15 17:29:11 +00:00
break ;
}
break ;
}
}
2008-04-28 14:41:46 +00:00
2008-07-12 19:47:45 +00:00
/// <summary>
/// Turn on some debugging values for OpenSim.
/// </summary>
/// <param name="args"></param>
protected void Debug ( string [ ] args )
2008-04-28 14:41:46 +00:00
{
2008-07-12 19:47:45 +00:00
if ( args . Length = = 0 )
return ;
2008-08-18 00:39:10 +00:00
2008-04-28 14:41:46 +00:00
switch ( args [ 0 ] )
{
case "packet" :
if ( args . Length > 1 )
{
int newDebug ;
if ( int . TryParse ( args [ 1 ] , out newDebug ) )
{
2008-10-14 18:53:56 +00:00
m_sceneManager . SetDebugPacketLevelOnCurrentScene ( newDebug ) ;
2008-04-28 14:41:46 +00:00
}
else
{
2008-10-14 18:53:56 +00:00
m_console . Error ( "packet debug should be 0..255" ) ;
2008-04-28 14:41:46 +00:00
}
m_console . Notice ( "New packet debug: " + newDebug . ToString ( ) ) ;
}
break ;
2008-08-18 00:39:10 +00:00
2008-07-12 20:04:31 +00:00
case "scene" :
if ( args . Length = = 4 )
{
if ( m_sceneManager . CurrentScene = = null )
{
m_console . Error ( "CONSOLE" , "Please use 'change-region <regioname>' first" ) ;
}
else
{
bool scriptingOn = ! Convert . ToBoolean ( args [ 1 ] ) ;
bool collisionsOn = ! Convert . ToBoolean ( args [ 2 ] ) ;
bool physicsOn = ! Convert . ToBoolean ( args [ 3 ] ) ;
m_sceneManager . CurrentScene . SetSceneCoreDebug ( scriptingOn , collisionsOn , physicsOn ) ;
2008-08-18 00:39:10 +00:00
2008-07-12 20:04:31 +00:00
m_console . Notice (
2008-08-18 00:39:10 +00:00
"CONSOLE" ,
2008-07-12 20:04:31 +00:00
String . Format (
2008-08-18 00:39:10 +00:00
"Set debug scene scripting = {0}, collisions = {1}, physics = {2}" ,
2008-07-12 20:04:31 +00:00
! scriptingOn , ! collisionsOn , ! physicsOn ) ) ;
}
}
else
{
m_console . Error ( "debug scene <scripting> <collisions> <physics> (where inside <> is true/false)" ) ;
}
2008-08-18 00:39:10 +00:00
break ;
2008-04-28 14:41:46 +00:00
default :
m_console . Error ( "Unknown debug" ) ;
break ;
}
}
2008-08-19 02:59:27 +00:00
2008-08-25 23:21:07 +00:00
protected override void ShowHelp ( string [ ] helpArgs )
2008-08-18 21:14:38 +00:00
{
base . ShowHelp ( helpArgs ) ;
2008-08-19 02:59:27 +00:00
2008-08-18 21:14:38 +00:00
m_console . Notice ( "alert - send alert to a designated user or all users." ) ;
m_console . Notice ( " alert [First] [Last] [Message] - send an alert to a user. Case sensitive." ) ;
m_console . Notice ( " alert general [Message] - send an alert to all users." ) ;
m_console . Notice ( "backup - persist simulator objects to the database ahead of the normal schedule." ) ;
m_console . Notice ( "clear-assets - clear the asset cache" ) ;
m_console . Notice ( "create-region <name> <regionfile.xml> - create a new region" ) ;
m_console . Notice ( "change-region <name> - select the region that single region commands operate upon." ) ;
m_console . Notice ( "command-script [filename] - Execute command in a file." ) ;
m_console . Notice ( "debug - debugging commands" ) ;
m_console . Notice ( " debug packet 0..255 - print incoming/outgoing packets (0=off)" ) ;
m_console . Notice ( " debug scene [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False" ) ;
m_console . Notice ( "edit-scale [prim name] [x] [y] [z] - resize given prim" ) ;
m_console . Notice ( "export-map [filename] - save image of world map" ) ;
2008-08-19 02:59:27 +00:00
m_console . Notice ( "force-update - force an update of prims in the scene" ) ;
2008-08-18 21:14:38 +00:00
m_console . Notice ( "restart - disconnects all clients and restarts the sims in the instance." ) ;
m_console . Notice ( "remove-region [name] - remove a region" ) ;
2008-09-29 12:29:11 +00:00
m_console . Notice ( "delete-region [name] - delete a region and its associated region file" ) ;
2008-08-18 21:14:38 +00:00
m_console . Notice ( "load-xml [filename] - load prims from XML (DEPRECATED)" ) ;
m_console . Notice ( "save-xml [filename] - save prims to XML (DEPRECATED)" ) ;
m_console . Notice ( "save-xml2 [filename] - save prims to XML using version 2 format" ) ;
m_console . Notice ( "load-xml2 [filename] - load prims from XML using version 2 format" ) ;
m_console . Notice ( "load-oar [filename] - load an OpenSimulator region archive. This replaces everything in the current region." ) ;
m_console . Notice ( "save-oar [filename] - Save the current region to an OpenSimulator region archive." ) ;
m_console . Notice ( "script - manually trigger scripts? or script commands?" ) ;
m_console . Notice ( "set-time [x] - set the current scene time phase" ) ;
m_console . Notice ( "show assets - show state of asset cache." ) ;
2008-09-12 22:39:17 +00:00
m_console . Notice ( "show users - show info about connected users (only root agents)." ) ;
m_console . Notice ( "show users full - show info about connected users (root and child agents)." ) ;
2008-08-18 21:14:38 +00:00
m_console . Notice ( "show modules - shows info about loaded modules." ) ;
m_console . Notice ( "show regions - show running region information." ) ;
m_console . Notice ( "config set section field value - set a config value" ) ;
m_console . Notice ( "config get section field - get a config value" ) ;
m_console . Notice ( "config save - save OpenSim.ini" ) ;
2008-08-19 02:59:27 +00:00
m_console . Notice ( "terrain help - show help for terrain commands." ) ;
2008-11-24 09:53:49 +00:00
m_console . Notice ( "login-enable - Allows login at sim level" ) ;
m_console . Notice ( "login-disable - Disable login at sim level" ) ;
m_console . Notice ( "login-status - Show the actual login status" ) ;
2008-08-19 02:59:27 +00:00
2008-08-18 21:14:38 +00:00
ShowPluginCommandsHelp ( CombineParams ( helpArgs , 0 ) , m_console ) ;
2008-08-19 02:59:27 +00:00
2008-11-05 17:45:56 +00:00
if ( ConfigurationSettings . Standalone )
2008-08-18 21:14:38 +00:00
{
m_console . Notice ( "" ) ;
m_console . Notice ( "create user - adds a new user." ) ;
2008-09-15 17:29:11 +00:00
m_console . Notice ( "reset user password - reset a user's password." ) ;
2008-08-19 02:59:27 +00:00
}
2008-08-18 21:14:38 +00:00
}
2008-04-28 14:41:46 +00:00
// see BaseOpenSimServer
2008-09-12 22:39:17 +00:00
public override void Show ( string [ ] showParams )
2008-04-28 14:41:46 +00:00
{
2008-09-12 22:39:17 +00:00
base . Show ( showParams ) ;
2008-05-16 01:22:11 +00:00
2008-09-12 22:39:17 +00:00
switch ( showParams [ 0 ] )
2008-04-28 14:41:46 +00:00
{
case "assets" :
m_assetCache . ShowState ( ) ;
break ;
2008-11-24 09:53:49 +00:00
2008-05-22 04:55:23 +00:00
case "users" :
2008-09-12 22:39:17 +00:00
IList agents ;
if ( showParams . Length > 1 & & showParams [ 1 ] = = "full" )
{
agents = m_sceneManager . GetCurrentScenePresences ( ) ;
}
else
{
agents = m_sceneManager . GetCurrentSceneAvatars ( ) ;
}
2008-05-25 23:27:38 +00:00
2008-05-22 04:55:23 +00:00
m_console . Notice ( String . Format ( "\nAgents connected: {0}\n" , agents . Count ) ) ;
2008-05-25 23:27:38 +00:00
2008-05-22 04:55:23 +00:00
m_console . Notice (
2008-09-03 03:32:29 +00:00
String . Format ( "{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}" , "Firstname" , "Lastname" ,
"Agent ID" , "Root/Child" , "Region" ) ) ;
2008-05-22 04:55:23 +00:00
foreach ( ScenePresence presence in agents )
{
RegionInfo regionInfo = m_sceneManager . GetRegionInfo ( presence . RegionHandle ) ;
string regionName ;
if ( regionInfo = = null )
{
regionName = "Unresolvable" ;
}
else
{
regionName = regionInfo . RegionName ;
}
m_console . Notice (
String . Format (
2008-09-03 03:32:29 +00:00
"{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}" ,
presence . Firstname ,
presence . Lastname ,
presence . UUID ,
presence . IsChildAgent ? "Child" : "Root" ,
regionName ) ) ;
2008-05-22 04:55:23 +00:00
}
2008-05-25 23:27:38 +00:00
2008-05-22 04:55:23 +00:00
m_console . Notice ( "" ) ;
break ;
2008-04-28 14:41:46 +00:00
case "modules" :
m_console . Notice ( "The currently loaded shared modules are:" ) ;
foreach ( IRegionModule module in m_moduleLoader . GetLoadedSharedModules )
{
m_console . Notice ( "Shared Module: " + module . Name ) ;
}
break ;
case "regions" :
m_sceneManager . ForEachScene (
delegate ( Scene scene )
{
m_console . Notice ( "Region Name: " + scene . RegionInfo . RegionName + " , Region XLoc: " +
scene . RegionInfo . RegionLocX + " , Region YLoc: " +
2008-07-18 02:08:14 +00:00
scene . RegionInfo . RegionLocY + " , Region Port: " + scene . RegionInfo . InternalEndPoint . Port . ToString ( ) ) ;
2008-04-28 14:41:46 +00:00
} ) ;
break ;
}
}
2008-08-18 00:39:10 +00:00
2008-07-29 17:39:15 +00:00
/// <summary>
/// Create a new user
/// </summary>
2008-11-23 03:38:40 +00:00
/// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
2008-07-29 17:39:15 +00:00
protected void CreateUser ( string [ ] cmdparams )
{
string firstName ;
string lastName ;
string password ;
2008-11-23 03:38:40 +00:00
string email ;
2008-07-29 17:39:15 +00:00
uint regX = 1000 ;
uint regY = 1000 ;
if ( cmdparams . Length < 2 )
firstName = MainConsole . Instance . CmdPrompt ( "First name" , "Default" ) ;
else firstName = cmdparams [ 1 ] ;
if ( cmdparams . Length < 3 )
lastName = MainConsole . Instance . CmdPrompt ( "Last name" , "User" ) ;
else lastName = cmdparams [ 2 ] ;
2008-11-23 03:38:40 +00:00
if ( cmdparams . Length < 4 )
2008-07-29 17:39:15 +00:00
password = MainConsole . Instance . PasswdPrompt ( "Password" ) ;
else password = cmdparams [ 3 ] ;
if ( cmdparams . Length < 5 )
regX = Convert . ToUInt32 ( MainConsole . Instance . CmdPrompt ( "Start Region X" , regX . ToString ( ) ) ) ;
else regX = Convert . ToUInt32 ( cmdparams [ 4 ] ) ;
if ( cmdparams . Length < 6 )
regY = Convert . ToUInt32 ( MainConsole . Instance . CmdPrompt ( "Start Region Y" , regY . ToString ( ) ) ) ;
2008-08-18 00:39:10 +00:00
else regY = Convert . ToUInt32 ( cmdparams [ 5 ] ) ;
2008-07-29 17:39:15 +00:00
2008-11-23 03:38:40 +00:00
if ( cmdparams . Length < 7 )
email = MainConsole . Instance . CmdPrompt ( "Email" , "" ) ;
else email = cmdparams [ 6 ] ;
2008-07-29 17:39:15 +00:00
if ( null = = m_commsManager . UserService . GetUserProfile ( firstName , lastName ) )
{
2008-11-28 16:04:01 +00:00
m_commsManager . UserAdminService . AddUser ( firstName , lastName , password , email , regX , regY ) ;
2008-07-29 17:39:15 +00:00
}
else
{
m_log . ErrorFormat ( "[CONSOLE]: A user with the name {0} {1} already exists!" , firstName , lastName ) ;
2008-08-18 00:39:10 +00:00
}
2008-07-29 17:39:15 +00:00
}
2008-09-15 17:29:11 +00:00
/// <summary>
/// Reset a user password.
/// </summary>
/// <param name="cmdparams"></param>
private void ResetUserPassword ( string [ ] cmdparams )
{
string firstName ;
string lastName ;
string newPassword ;
if ( cmdparams . Length < 3 )
firstName = MainConsole . Instance . CmdPrompt ( "First name" ) ;
else firstName = cmdparams [ 2 ] ;
if ( cmdparams . Length < 4 )
lastName = MainConsole . Instance . CmdPrompt ( "Last name" ) ;
else lastName = cmdparams [ 3 ] ;
if ( cmdparams . Length < 5 )
newPassword = MainConsole . Instance . PasswdPrompt ( "New password" ) ;
else newPassword = cmdparams [ 4 ] ;
2008-11-28 16:04:01 +00:00
m_commsManager . UserAdminService . ResetUserPassword ( firstName , lastName , newPassword ) ;
2008-09-15 17:29:11 +00:00
}
2008-08-18 00:39:10 +00:00
2008-07-12 20:14:17 +00:00
protected void SaveXml ( string [ ] cmdparams )
{
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." ) ;
if ( cmdparams . Length > 0 )
{
m_sceneManager . SaveCurrentSceneToXml ( cmdparams [ 0 ] ) ;
}
else
{
m_sceneManager . SaveCurrentSceneToXml ( DEFAULT_PRIM_BACKUP_FILENAME ) ;
}
2008-08-18 00:39:10 +00:00
}
2008-07-12 20:14:17 +00:00
protected void LoadXml ( string [ ] cmdparams )
{
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." ) ;
2008-09-06 07:52:41 +00:00
Vector3 loadOffset = new Vector3 ( 0 , 0 , 0 ) ;
2008-07-12 20:14:17 +00:00
if ( cmdparams . Length > 0 )
{
bool generateNewIDS = false ;
if ( cmdparams . Length > 1 )
{
if ( cmdparams [ 1 ] = = "-newUID" )
{
generateNewIDS = true ;
}
if ( cmdparams . Length > 2 )
{
loadOffset . X = ( float ) Convert . ToDecimal ( cmdparams [ 2 ] ) ;
if ( cmdparams . Length > 3 )
{
loadOffset . Y = ( float ) Convert . ToDecimal ( cmdparams [ 3 ] ) ;
}
if ( cmdparams . Length > 4 )
{
loadOffset . Z = ( float ) Convert . ToDecimal ( cmdparams [ 4 ] ) ;
}
m_console . Error ( "loadOffsets <X,Y,Z> = <" + loadOffset . X + "," + loadOffset . Y + "," +
loadOffset . Z + ">" ) ;
}
}
m_sceneManager . LoadCurrentSceneFromXml ( cmdparams [ 0 ] , generateNewIDS , loadOffset ) ;
}
else
{
m_sceneManager . LoadCurrentSceneFromXml ( DEFAULT_PRIM_BACKUP_FILENAME , false , loadOffset ) ;
}
2008-08-18 00:39:10 +00:00
}
2008-07-12 20:14:17 +00:00
protected void SaveXml2 ( string [ ] cmdparams )
{
if ( cmdparams . Length > 0 )
{
m_sceneManager . SaveCurrentSceneToXml2 ( cmdparams [ 0 ] ) ;
}
else
{
m_sceneManager . SaveCurrentSceneToXml2 ( DEFAULT_PRIM_BACKUP_FILENAME ) ;
}
}
2008-08-18 00:39:10 +00:00
2008-07-12 20:14:17 +00:00
protected void LoadXml2 ( string [ ] cmdparams )
{
if ( cmdparams . Length > 0 )
{
m_sceneManager . LoadCurrentSceneFromXml2 ( cmdparams [ 0 ] ) ;
}
else
{
m_sceneManager . LoadCurrentSceneFromXml2 ( DEFAULT_PRIM_BACKUP_FILENAME ) ;
}
2008-08-18 00:39:10 +00:00
}
2008-07-29 14:28:08 +00:00
/// <summary>
/// Load a whole region from an opensim archive.
/// </summary>
/// <param name="cmdparams"></param>
2008-07-12 20:14:17 +00:00
protected void LoadOar ( string [ ] cmdparams )
{
if ( cmdparams . Length > 0 )
{
m_sceneManager . LoadArchiveToCurrentScene ( cmdparams [ 0 ] ) ;
}
else
{
m_sceneManager . LoadArchiveToCurrentScene ( DEFAULT_OAR_BACKUP_FILENAME ) ;
2008-08-18 00:39:10 +00:00
}
2008-07-12 20:14:17 +00:00
}
2008-08-18 00:39:10 +00:00
2008-07-29 14:28:08 +00:00
/// <summary>
/// Save a region to a file, including all the assets needed to restore it.
/// </summary>
/// <param name="cmdparams"></param>
2008-07-12 20:14:17 +00:00
protected void SaveOar ( string [ ] cmdparams )
{
if ( cmdparams . Length > 0 )
{
m_sceneManager . SaveCurrentSceneToArchive ( cmdparams [ 0 ] ) ;
}
else
{
m_sceneManager . SaveCurrentSceneToArchive ( DEFAULT_OAR_BACKUP_FILENAME ) ;
2008-08-18 00:39:10 +00:00
}
}
2008-10-19 18:26:44 +00:00
/// <summary>
/// Load inventory from an inventory file archive
/// </summary>
/// <param name="cmdparams"></param>
protected void LoadInv ( string [ ] cmdparams )
{
m_log . Error ( "[CONSOLE]: This command has not yet been implemented!" ) ;
if ( cmdparams . Length < 3 )
{
m_log . Error ( "[CONSOLE]: usage is load-inv <first name> <last name> <inventory path> [<load file path>]" ) ;
return ;
}
string firstName = cmdparams [ 0 ] ;
string lastName = cmdparams [ 1 ] ;
string invPath = cmdparams [ 2 ] ;
string loadPath = ( cmdparams . Length > 3 ? cmdparams [ 3 ] : DEFAULT_INV_BACKUP_FILENAME ) ;
new InventoryArchiveReadRequest (
m_sceneManager . CurrentOrFirstScene , m_commsManager ) . execute (
firstName , lastName , invPath , loadPath ) ;
}
2008-04-28 14:41:46 +00:00
2008-10-19 18:26:44 +00:00
/// <summary>
/// Save inventory to a file archive
/// </summary>
/// <param name="cmdparams"></param>
protected void SaveInv ( string [ ] cmdparams )
{
m_log . Error ( "[CONSOLE]: This command has not yet been implemented!" ) ;
if ( cmdparams . Length < 3 )
{
m_log . Error ( "[CONSOLE]: usage is save-inv <first name> <last name> <inventory path> [<save file path>]" ) ;
return ;
}
string firstName = cmdparams [ 0 ] ;
string lastName = cmdparams [ 1 ] ;
string invPath = cmdparams [ 2 ] ;
string savePath = ( cmdparams . Length > 3 ? cmdparams [ 3 ] : DEFAULT_INV_BACKUP_FILENAME ) ;
new InventoryArchiveWriteRequest (
m_sceneManager . CurrentOrFirstScene , m_commsManager ) . execute (
firstName , lastName , invPath , savePath ) ;
}
2008-05-01 16:03:53 +00:00
private static string CombineParams ( string [ ] commandParams , int pos )
2008-04-28 14:41:46 +00:00
{
string result = String . Empty ;
for ( int i = pos ; i < commandParams . Length ; i + + )
{
result + = commandParams [ i ] + " " ;
}
result = result . TrimEnd ( ' ' ) ;
return result ;
}
2008-06-09 08:46:33 +00:00
/// <summary>
/// Runs the best matching plugin command
2008-08-18 00:39:10 +00:00
///
2008-06-09 08:46:33 +00:00
/// returns true if a match was found, false otherwise.
/// </summary>
2008-06-21 23:17:15 +00:00
public bool RunPluginCommands ( string cmd , string [ ] withParams )
2008-06-09 08:46:33 +00:00
{
ConsolePluginCommand bestMatch = null ;
int bestLength = 0 ;
2008-06-21 23:17:15 +00:00
String cmdWithParams = cmd + " " + String . Join ( " " , withParams ) ;
2008-06-09 08:46:33 +00:00
foreach ( ConsolePluginCommand cmdinfo in m_PluginCommandInfos )
{
int matchLen = cmdinfo . matchLength ( cmdWithParams ) ;
if ( matchLen > bestLength )
{
bestMatch = cmdinfo ;
bestLength = matchLen ;
}
}
if ( bestMatch = = null ) return false ;
2008-06-21 23:17:15 +00:00
bestMatch . Run ( cmd , withParams ) ; //.Substring(bestLength));
2008-06-09 08:46:33 +00:00
return true ;
}
/// <summary>
/// Show the matching plugins command help
/// </summary>
public void ShowPluginCommandsHelp ( string cmdWithParams , ConsoleBase console )
{
foreach ( ConsolePluginCommand cmdinfo in m_PluginCommandInfos )
{
if ( cmdinfo . IsHelpfull ( cmdWithParams ) )
{
cmdinfo . ShowHelp ( console ) ;
}
}
}
/// <summary>
/// Registers a new console plugin command
/// </summary>
public static void RegisterCmd ( string cmd , ConsoleCommand deligate , string help )
{
RegisterConsolePluginCommand ( new ConsolePluginCommand ( cmd , deligate , help ) ) ;
}
/// <summary>
/// Registers a new console plugin command
/// </summary>
public static void RegisterConsolePluginCommand ( ConsolePluginCommand pluginCommand )
{
m_PluginCommandInfos . Add ( pluginCommand ) ;
}
2008-04-28 14:41:46 +00:00
# endregion
2008-06-09 08:46:33 +00:00
}
2008-04-28 14:41:46 +00:00
}