static void BlockDBHandler( Player player, Command cmd ) {
if( !BlockDB.IsEnabledGlobally ) {
player.Message( "&WBlockDB is disabled on this server." );
return;
}
string worldName = cmd.Next();
if( worldName == null ) {
int total = 0;
World[] autoEnabledWorlds = WorldManager.Worlds.Where( w => (w.BlockDB.EnabledState == YesNoAuto.Auto) && w.BlockDB.IsEnabled ).ToArray();
if( autoEnabledWorlds.Length > 0 ) {
total += autoEnabledWorlds.Length;
player.Message( "BlockDB is auto-enabled on: {0}",
autoEnabledWorlds.JoinToClassyString() );
}
World[] manuallyEnabledWorlds = WorldManager.Worlds.Where( w => w.BlockDB.EnabledState == YesNoAuto.Yes ).ToArray();
if( manuallyEnabledWorlds.Length > 0 ) {
total += manuallyEnabledWorlds.Length;
player.Message( "BlockDB is manually enabled on: {0}",
manuallyEnabledWorlds.JoinToClassyString() );
}
World[] manuallyDisabledWorlds = WorldManager.Worlds.Where( w => w.BlockDB.EnabledState == YesNoAuto.No ).ToArray();
if( manuallyDisabledWorlds.Length > 0 ) {
player.Message( "BlockDB is manually disabled on: {0}",
manuallyDisabledWorlds.JoinToClassyString() );
}
if( total == 0 ) {
player.Message( "BlockDB is not enabled on any world." );
}
return;
}
World world = WorldManager.FindWorldOrPrintMatches( player, worldName );
if( world == null ) return;
BlockDB db = world.BlockDB;
lock( db.SyncRoot ) {
string op = cmd.Next();
if( op == null ) {
if( !db.IsEnabled ) {
if( db.EnabledState == YesNoAuto.Auto ) {
player.Message( "BlockDB is disabled (auto) on world {0}", world.ClassyName );
} else {
player.Message( "BlockDB is disabled on world {0}", world.ClassyName );
}
} else {
if( db.IsPreloaded ) {
if( db.EnabledState == YesNoAuto.Auto ) {
player.Message( "BlockDB is enabled (auto) and preloaded on world {0}", world.ClassyName );
} else {
player.Message( "BlockDB is enabled and preloaded on world {0}", world.ClassyName );
}
} else {
if( db.EnabledState == YesNoAuto.Auto ) {
player.Message( "BlockDB is enabled (auto) on world {0}", world.ClassyName );
} else {
player.Message( "BlockDB is enabled on world {0}", world.ClassyName );
}
}
player.Message( " Change limit: {0} Time limit: {1}",
db.Limit == 0 ? "none" : db.Limit.ToString(),
db.TimeLimit == TimeSpan.Zero ? "none" : db.TimeLimit.ToMiniString() );
}
return;
}
switch( op.ToLower() ) {
case "on":
// enables BlockDB
if( db.EnabledState == YesNoAuto.Yes ) {
player.Message( "BlockDB is already manually enabled on world {0}", world.ClassyName );
} else if( db.EnabledState == YesNoAuto.Auto && db.IsEnabled ) {
db.EnabledState = YesNoAuto.Yes;
WorldManager.SaveWorldList();
player.Message( "BlockDB was auto-enabled, and is now manually enabled on world {0}", world.ClassyName );
} else {
db.EnabledState = YesNoAuto.Yes;
WorldManager.SaveWorldList();
player.Message( "BlockDB is now manually enabled on world {0}", world.ClassyName );
}
break;
case "off":
// disables BlockDB
if( db.EnabledState == YesNoAuto.No ) {
player.Message( "BlockDB is already manually disabled on world {0}", world.ClassyName );
} else if( db.IsEnabled ) {
if( cmd.IsConfirmed ) {
db.EnabledState = YesNoAuto.No;
WorldManager.SaveWorldList();
player.Message( "BlockDB is now manually disabled on world {0}&S. Use &H/BlockDB {1} clear&S to delete all the data.",
world.ClassyName, world.Name );
} else {
player.Confirm( cmd,
"Disable BlockDB on world {0}&S? Block changes will stop being recorded.",
world.ClassyName );
}
} else {
db.EnabledState = YesNoAuto.No;
WorldManager.SaveWorldList();
player.Message( "BlockDB is was auto-disabled, and is now manually disabled on world {0}&S.",
world.ClassyName );
}
break;
case "auto":
if( db.EnabledState == YesNoAuto.Auto ) {
player.Message( "BlockDB is already set to automatically enable/disable itself on world {0}", world.ClassyName );
} else {
db.EnabledState = YesNoAuto.Auto;
WorldManager.SaveWorldList();
if( db.IsEnabled ) {
player.Message( "BlockDB is now auto-enabled on world {0}",
world.ClassyName );
} else {
player.Message( "BlockDB is now auto-disabled on world {0}",
world.ClassyName );
}
}
break;
case "limit":
// sets or resets limit on the number of changes to store
if( db.IsEnabled ) {
string limitString = cmd.Next();
int limitNumber;
if( limitString == null ) {
player.Message( "BlockDB: Limit for world {0}&S is {1}",
world.ClassyName,
(db.Limit == 0 ? "none" : db.Limit.ToString()) );
return;
}
if( limitString.Equals( "none", StringComparison.OrdinalIgnoreCase ) ) {
limitNumber = 0;
} else if( !Int32.TryParse( limitString, out limitNumber ) ) {
CdBlockDB.PrintUsage( player );
return;
} else if( limitNumber < 0 ) {
player.Message( "BlockDB: Limit must be non-negative." );
return;
}
if( !cmd.IsConfirmed && limitNumber != 0 ) {
player.Confirm( cmd, "BlockDB: Change limit? Some old data for world {0}&S may be discarded.", world.ClassyName );
} else {
string limitDisplayString = (limitNumber == 0 ? "none" : limitNumber.ToString());
if( db.Limit == limitNumber ) {
player.Message( "BlockDB: Limit for world {0}&S is already set to {1}",
world.ClassyName, limitDisplayString );
} else {
db.Limit = limitNumber;
WorldManager.SaveWorldList();
player.Message( "BlockDB: Limit for world {0}&S set to {1}",
world.ClassyName, limitDisplayString );
}
}
} else {
player.Message( "Block tracking is disabled on world {0}", world.ClassyName );
}
break;
case "timelimit":
// sets or resets limit on the age of changes to store
if( db.IsEnabled ) {
string limitString = cmd.Next();
if( limitString == null ) {
if( db.TimeLimit == TimeSpan.Zero ) {
player.Message( "BlockDB: There is no time limit for world {0}",
world.ClassyName );
} else {
player.Message( "BlockDB: Time limit for world {0}&S is {1}",
world.ClassyName, db.TimeLimit.ToMiniString() );
}
return;
}
TimeSpan limit;
if( limitString.Equals( "none", StringComparison.OrdinalIgnoreCase ) ) {
limit = TimeSpan.Zero;
} else if( !limitString.TryParseMiniTimespan( out limit ) ) {
CdBlockDB.PrintUsage( player );
return;
}
if( limit > DateTimeUtil.MaxTimeSpan ) {
player.MessageMaxTimeSpan();
return;
}
if( !cmd.IsConfirmed && limit != TimeSpan.Zero ) {
player.Confirm( cmd, "BlockDB: Change time limit? Some old data for world {0}&S may be discarded.", world.ClassyName );
} else {
if( db.TimeLimit == limit ) {
if( db.TimeLimit == TimeSpan.Zero ) {
player.Message( "BlockDB: There is already no time limit for world {0}",
world.ClassyName );
} else {
player.Message( "BlockDB: Time limit for world {0}&S is already set to {1}",
world.ClassyName, db.TimeLimit.ToMiniString() );
}
} else {
db.TimeLimit = limit;
WorldManager.SaveWorldList();
if( db.TimeLimit == TimeSpan.Zero ) {
player.Message( "BlockDB: Time limit removed for world {0}",
world.ClassyName );
} else {
player.Message( "BlockDB: Time limit for world {0}&S set to {1}",
world.ClassyName, db.TimeLimit.ToMiniString() );
}
}
}
} else {
player.Message( "Block tracking is disabled on world {0}", world.ClassyName );
}
break;
case "clear":
// wipes BlockDB data
bool hasData = (db.IsEnabled || File.Exists( db.FileName ));
if( hasData ) {
if( cmd.IsConfirmed ) {
db.Clear();
player.Message( "BlockDB: Cleared all data for {0}", world.ClassyName );
} else {
player.Confirm( cmd, "Clear BlockDB data for world {0}&S? This cannot be undone.",
world.ClassyName );
}
} else {
player.Message( "BlockDB: No data to clear for world {0}", world.ClassyName );
}
break;
case "preload":
// enables/disables BlockDB preloading
if( db.IsEnabled ) {
string param = cmd.Next();
if( param == null ) {
// shows current preload setting
player.Message( "BlockDB preloading is {0} for world {1}",
(db.IsPreloaded ? "ON" : "OFF"),
world.ClassyName );
} else if( param.Equals( "on", StringComparison.OrdinalIgnoreCase ) ) {
// turns preload on
if( db.IsPreloaded ) {
player.Message( "BlockDB preloading is already enabled on world {0}", world.ClassyName );
} else {
db.IsPreloaded = true;
WorldManager.SaveWorldList();
player.Message( "BlockDB preloading is now enabled on world {0}", world.ClassyName );
}
} else if( param.Equals( "off", StringComparison.OrdinalIgnoreCase ) ) {
// turns preload off
if( !db.IsPreloaded ) {
player.Message( "BlockDB preloading is already disabled on world {0}", world.ClassyName );
} else {
db.IsPreloaded = false;
WorldManager.SaveWorldList();
player.Message( "BlockDB preloading is now disabled on world {0}", world.ClassyName );
}
} else {
CdBlockDB.PrintUsage( player );
}
} else {
player.Message( "Block tracking is disabled on world {0}", world.ClassyName );
}
break;
default:
// unknown operand
CdBlockDB.PrintUsage( player );
return;
}
}
}