本文整理汇总了C#中fCraft.Player.AskForConfirmation方法的典型用法代码示例。如果您正苦于以下问题:C# Player.AskForConfirmation方法的具体用法?C# Player.AskForConfirmation怎么用?C# Player.AskForConfirmation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fCraft.Player
的用法示例。
在下文中一共展示了Player.AskForConfirmation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZoneRemove
internal static void ZoneRemove( Player player, Command cmd ) {
string zoneName = cmd.Next();
if( zoneName == null ) {
cdZoneRemove.PrintUsage( player );
return;
}
Zone zone = player.World.Map.FindZone( zoneName );
if( zone != null ) {
if( !zone.Controller.Check( player.Info ) && !player.Info.Rank.AllowSecurityCircumvention ) {
player.Message( "You are not allowed to remove zone {0}", zone.GetClassyName() );
return;
}
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "You are about to remove zone {0}&S.", zone.GetClassyName() );
return;
}
if( player.World.Map.RemoveZone( zoneName ) ) {
player.Message( "Zone \"{0}\" removed.", zoneName );
}
} else {
player.Message( "No zone with the name \"{0}\" was found.", zoneName );
}
}
示例2: WorldSave
internal static void WorldSave( Player player, Command cmd ) {
string p1 = cmd.Next(), p2 = cmd.Next();
if( p1 == null ) {
cdWorldSave.PrintUsage( player );
return;
}
World world = player.World;
string fileName;
if( p2 == null ) {
fileName = p1;
if( world == null ) {
player.Message( "When called from console, /save requires WorldName. See \"/help save\" for details." );
return;
}
} else {
world = WorldManager.FindWorldOrPrintMatches( player, p1 );
if( world == null ) return;
fileName = p2;
}
// normalize the path
fileName = fileName.Replace( Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar );
if( fileName.EndsWith( "/" ) && fileName.EndsWith( @"\" ) ) {
fileName += world.Name + ".fcm";
} else if( !fileName.ToLower().EndsWith( ".fcm", StringComparison.OrdinalIgnoreCase ) ) {
fileName += ".fcm";
}
string fullFileName = Path.Combine( Paths.MapPath, fileName );
if( !Paths.IsValidPath( fullFileName ) ) {
player.Message( "Invalid filename." );
return;
}
if( !Paths.Contains( Paths.MapPath, fullFileName ) ) {
player.UnsafePathMessage();
return;
}
// Ask for confirmation if overwriting
if( File.Exists( fullFileName ) ) {
FileInfo targetFile = new FileInfo( fullFileName );
FileInfo sourceFile = new FileInfo( world.GetMapName() );
if( !targetFile.FullName.Equals( sourceFile.FullName, StringComparison.OrdinalIgnoreCase ) ) {
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "Target file \"{0}\" already exists, and will be overwritten.", targetFile.Name );
return;
}
}
}
// Create the target directory if it does not exist
string dirName = fullFileName.Substring( 0, fullFileName.LastIndexOf( Path.DirectorySeparatorChar ) );
if( !Directory.Exists( dirName ) ) {
Directory.CreateDirectory( dirName );
}
player.MessageNow( "Saving map to {0}", fileName );
const string mapSavingErrorMessage = "Map saving failed. See server logs for details.";
Map map = world.Map;
if( map == null ) {
if( File.Exists( world.GetMapName() ) ) {
try {
File.Copy( world.GetMapName(), fullFileName, true );
} catch( Exception ex ) {
Logger.Log( "StandardCommands.Save: Error occured while trying to copy an unloaded map: {0}", LogType.Error, ex );
player.Message( mapSavingErrorMessage );
}
} else {
Logger.Log( "StandardCommands.Save: Map for world \"{0}\" is unloaded, and file does not exist.", LogType.Error, world.Name );
player.Message( mapSavingErrorMessage );
}
} else if( map.Save( fullFileName ) ) {
player.Message( "Map saved succesfully." );
} else {
Logger.Log( "StandardCommands.Save: Saving world \"{0}\" failed.", LogType.Error, world.Name );
player.Message( mapSavingErrorMessage );
}
}
示例3: WorldLoad
internal static void WorldLoad( Player player, Command cmd ) {
string fileName = cmd.Next();
string worldName = cmd.Next();
if( worldName == null && player.World == null ) {
player.Message( "When using /wload from console, you must specify the world name." );
return;
}
if( fileName == null ) {
// No params given at all
cdWorldLoad.PrintUsage( player );
return;
}
// Check if path contains missing drives or invalid characters
if( !Paths.IsValidPath( fileName ) ) {
player.Message( "Invalid filename or path." );
return;
}
player.MessageNow( "Looking for \"{0}\"...", fileName );
// Look for the file
string sourceFullFileName = Path.Combine( Paths.MapPath, fileName );
if( !File.Exists( sourceFullFileName ) && !Directory.Exists( sourceFullFileName ) ) {
if( File.Exists( sourceFullFileName + ".fcm" ) ) {
// Try with extension added
fileName += ".fcm";
sourceFullFileName += ".fcm";
} else if( MonoCompat.IsCaseSensitive ) {
try {
// If we're on a case-sensitive OS, try case-insensitive search
FileInfo[] candidates = Paths.FindFiles( sourceFullFileName + ".fcm" );
if( candidates.Length == 0 ) {
candidates = Paths.FindFiles( sourceFullFileName );
}
if( candidates.Length == 0 ) {
player.Message( "File/directory not found: {0}", fileName );
} else if( candidates.Length == 1 ) {
player.Message( "Filenames are case-sensitive! Did you mean to load \"{0}\"?", candidates[0].Name );
} else {
player.Message( "Filenames are case-sensitive! Did you mean to load one of these: {0}",
String.Join( ", ", candidates.Select( c => c.Name ).ToArray() ) );
}
} catch( DirectoryNotFoundException ex ) {
player.Message( ex.Message );
}
return;
} else {
// Nothing found!
player.Message( "File/directory not found: {0}", fileName );
return;
}
}
// Make sure that the given file is within the map directory
if( !Paths.Contains( Paths.MapPath, sourceFullFileName ) ) {
player.UnsafePathMessage();
return;
}
// Loading map into current world
if( worldName == null ) {
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "About to replace THIS MAP with \"{0}\".", fileName );
return;
}
Map map;
try {
map = MapUtility.Load( sourceFullFileName );
} catch( Exception ex ) {
player.MessageNow( "Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message );
return;
}
// Loading to current world
player.World.ChangeMap( map );
player.World.SendToAllExcept( "{0}&S loaded a new map for this world.", player,
player.GetClassyName() );
player.MessageNow( "New map loaded for the world {0}", player.World.GetClassyName() );
Logger.Log( "{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
player.Name, player.World.Name, fileName );
} else {
// Loading to some other (or new) world
if( !World.IsValidName( worldName ) ) {
player.MessageNow( "Invalid world name: \"{0}\".", worldName );
return;
}
lock( WorldManager.WorldListLock ) {
//.........这里部分代码省略.........
示例4: WorldRename
internal static void WorldRename( Player player, Command cmd ) {
string oldName = cmd.Next();
string newName = cmd.Next();
if( oldName == null || newName == null ) {
cdWorldRename.PrintUsage( player );
return;
}
World oldWorld = WorldManager.FindWorldOrPrintMatches( player, oldName );
if( oldWorld == null ) return;
oldName = oldWorld.Name;
if( !cmd.IsConfirmed && File.Exists( Path.Combine( Paths.MapPath, newName + ".fcm" ) ) ) {
player.AskForConfirmation( cmd, "Renaming this world will overwrite an existing map file \"{0}.fcm\".", newName );
return;
}
try {
WorldManager.RenameWorld( oldWorld, newName, true );
} catch( WorldOpException ex ) {
switch( ex.ErrorCode ) {
case WorldOpExceptionCode.NoChangeNeeded:
player.MessageNow( "Rename: World is already named \"{0}\"", oldName );
return;
case WorldOpExceptionCode.DuplicateWorldName:
player.MessageNow( "Rename: Another world named \"{0}\" already exists.", newName );
return;
case WorldOpExceptionCode.InvalidWorldName:
player.MessageNow( "Rename: Invalid world name: \"{0}\"", newName );
return;
case WorldOpExceptionCode.MapMoveError:
player.MessageNow( "Rename: World \"{0}\" was renamed to \"{1}\", but the map file could not be moved due to an error: {2}",
oldName, newName, ex.InnerException );
return;
default:
player.MessageNow( "Unexpected error occured while renaming world \"{0}\"", oldName );
Logger.Log( "WorldCommands.Rename: Unexpected error while renaming world {0} to {1}: {2}",
LogType.Error, oldWorld.Name, newName, ex );
return;
}
}
WorldManager.SaveWorldList();
Logger.Log( "{0} renamed the world \"{1}\" to \"{2}\".", LogType.UserActivity,
player.Name, oldName, newName );
Server.SendToAll( "{0}&S renamed the world \"{1}\" to \"{2}\"",
player.GetClassyName(), oldName, newName );
}
示例5: Generate
internal static void Generate( Player player, Command cmd ) {
string themeName = cmd.Next();
string templateName = cmd.Next();
if( templateName == null ) {
cdGenerate.PrintUsage( player );
return;
}
MapGenTemplate template;
MapGenTheme theme;
int wx, wy, height;
if( !(cmd.NextInt( out wx ) && cmd.NextInt( out wy ) && cmd.NextInt( out height )) ) {
if( player.World != null ) {
wx = player.World.Map.WidthX;
wy = player.World.Map.WidthY;
height = player.World.Map.Height;
} else {
player.Message( "When used from console, /gen requires map dimensions." );
cdGenerate.PrintUsage( player );
return;
}
cmd.Rewind();
cmd.Next();
cmd.Next();
}
if( !Map.IsValidDimension( wx ) ) {
player.Message( "Cannot make map with width {0}: dimensions must be multiples of 16.", wx );
return;
} else if( !Map.IsValidDimension( wy ) ) {
player.Message( "Cannot make map with length {0}: dimensions must be multiples of 16.", wy );
return;
} else if( !Map.IsValidDimension( height ) ) {
player.Message( "Cannot make map with height {0}: dimensions must be multiples of 16.", height );
return;
}
string fileName = cmd.Next();
string fullFileName = null;
if( fileName == null ) {
if( player.World == null ) {
player.Message( "When used from console, /gen requires FileName." );
cdGenerate.PrintUsage( player );
return;
}
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "Replace this world's map with a generated one?" );
return;
}
} else {
fileName = fileName.Replace( Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar );
if( !fileName.EndsWith( ".fcm", StringComparison.OrdinalIgnoreCase ) ) {
fileName += ".fcm";
}
fullFileName = Path.Combine( Paths.MapPath, fileName );
if( !Paths.IsValidPath( fullFileName ) ) {
player.Message( "Invalid filename." );
return;
}
if( !Paths.Contains( Paths.MapPath, fullFileName ) ) {
player.UnsafePathMessage();
return;
}
string dirName = fullFileName.Substring( 0, fullFileName.LastIndexOf( Path.DirectorySeparatorChar ) );
if( !Directory.Exists( dirName ) ) {
Directory.CreateDirectory( dirName );
}
if( !cmd.IsConfirmed && File.Exists( fullFileName ) ) {
player.AskForConfirmation( cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName );
return;
}
}
bool noTrees;
if( themeName.Equals( "grass", StringComparison.OrdinalIgnoreCase ) ) {
theme = MapGenTheme.Forest;
noTrees = true;
} else {
try {
theme = (MapGenTheme)Enum.Parse( typeof( MapGenTheme ), themeName, true );
noTrees = (theme != MapGenTheme.Forest);
} catch( Exception ) {
player.MessageNow( "Unrecognized theme \"{0}\". Available themes are: Grass, {1}",
themeName,
String.Join( ", ", Enum.GetNames( typeof( MapGenTheme ) ) ) );
return;
}
}
try {
template = (MapGenTemplate)Enum.Parse( typeof( MapGenTemplate ), templateName, true );
} catch( Exception ) {
player.Message( "Unrecognized template \"{0}\". Available templates are: {1}",
templateName,
String.Join( ", ", Enum.GetNames( typeof( MapGenTemplate ) ) ) );
return;
//.........这里部分代码省略.........
示例6: ImportRanks
static void ImportRanks( Player player, Command cmd ) {
string serverName = cmd.Next();
string fileName = cmd.Next();
string rankName = cmd.Next();
bool silent = (cmd.Next() != null);
// Make sure all parameters are specified
if( rankName == null ) {
cdImportRanks.PrintUsage( player );
return;
}
// Check if file exists
if( !File.Exists( fileName ) ) {
player.Message( "File not found: {0}", fileName );
return;
}
Rank targetRank = RankManager.ParseRank( rankName );
if( targetRank == null ) {
player.NoRankMessage( rankName );
return;
}
string[] names;
switch( serverName.ToLower() ) {
case "mcsharp":
case "mczall":
case "mclawl":
try {
names = File.ReadAllLines( fileName );
} catch( Exception ex ) {
Logger.Log( "Could not open \"{0}\" to import ranks: {1}", LogType.Error,
fileName,
ex );
return;
}
break;
default:
player.Message( "fCraft does not support importing from {0}", serverName );
return;
}
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "You are about to import {0} player ranks.", names.Length );
return;
}
string reason = "(import from " + serverName + ")";
foreach( string name in names ) {
PlayerInfo info = PlayerDB.FindPlayerInfoExact( name ) ??
PlayerDB.AddFakeEntry( name, RankChangeType.Promoted );
ModerationCommands.DoChangeRank( player, info, targetRank, reason, silent, false );
}
PlayerDB.Save();
}
示例7: ImportBans
static void ImportBans( Player player, Command cmd ) {
string serverName = cmd.Next();
string file = cmd.Next();
// Make sure all parameters are specified
if( file == null ) {
cdImportBans.PrintUsage( player );
return;
}
// Check if file exists
if( !File.Exists( file ) ) {
player.Message( "File not found: {0}", file );
return;
}
string[] names;
switch( serverName.ToLower() ) {
case "mcsharp":
case "mczall":
case "mclawl":
try {
names = File.ReadAllLines( file );
} catch( Exception ex ) {
Logger.Log( "Could not open \"{0}\" to import bans: {1}", LogType.Error,
file,
ex );
return;
}
break;
default:
player.Message( "fCraft does not support importing from {0}", serverName );
return;
}
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "You are about to import {0} bans.", names.Length );
return;
}
string reason = "(import from " + serverName + ")";
foreach( string name in names ) {
if( Player.IsValidName( name ) ) {
ModerationCommands.DoBan( player, name, reason, false, false, false );
} else {
IPAddress ip;
if( Server.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) {
ModerationCommands.DoIPBan( player, ip, reason, "", false, false );
} else {
player.Message( "Could not parse \"{0}\" as either name or IP. Skipping.", name );
}
}
}
PlayerDB.Save();
IPBanList.Save();
}
示例8: PruneDB
internal static void PruneDB( Player player, Command cmd ) {
if( !cmd.IsConfirmed ) {
player.MessageNow( "PruneDB: Finding inactive players..." );
player.AskForConfirmation( cmd, "Remove {0} inactive players from the database?",
PlayerDB.CountInactivePlayers() );
return;
}
player.MessageNow( "PruneDB: Removing inactive players... (this may take a while)" );
Scheduler.NewBackgroundTask( delegate {
player.MessageNow( "PruneDB: Removed {0} inactive players!", PlayerDB.RemoveInactivePlayers() );
} ).RunOnce();
}
示例9: DumpStats
internal static void DumpStats( Player player, Command cmd ) {
string fileName = cmd.Next();
if( fileName == null ) {
cdDumpStats.PrintUsage( player );
return;
}
if( !Paths.Contains( Paths.WorkingPath, fileName ) ) {
player.UnsafePathMessage();
return;
}
if( Paths.IsProtectedFileName( Path.GetFileName( fileName ) ) ) {
player.Message( "You may not use this file." );
return;
}
if( Path.HasExtension( fileName ) &&
!Path.GetExtension( fileName ).Equals( ".txt", StringComparison.OrdinalIgnoreCase ) ) {
player.Message( "Stats filename must end with .txt" );
return;
}
if( File.Exists( fileName ) && !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "File \"{0}\" already exists. Overwrite?", Path.GetFileName( fileName ) );
return;
}
if( !Paths.TestFile( "dumpstats file", fileName, false, true, false ) ) {
player.Message( "Cannot create specified file. See log for details." );
return;
}
PlayerInfo[] infos;
using( FileStream fs = File.Create( fileName ) ) {
using( StreamWriter writer = new StreamWriter( fs ) ) {
infos = PlayerDB.GetPlayerListCopy();
if( infos.Length == 0 ) {
writer.WriteLine( "{0} (0 players)", "(TOTAL)" );
writer.WriteLine();
} else {
DumpPlayerGroupStats( writer, infos, "(TOTAL)" );
}
foreach( Rank rank in RankManager.Ranks ) {
infos = PlayerDB.GetPlayerListCopy( rank );
if( infos.Length == 0 ) {
writer.WriteLine( "{0} (0 players)", rank.Name );
writer.WriteLine();
} else {
DumpPlayerGroupStats( writer, infos, rank.Name );
}
}
}
}
player.Message( "Stats saved to \"{0}\"", Path.GetFileName( fileName ) );
}
示例10: MassRank
internal static void MassRank( Player player, Command cmd ) {
string fromRankName = cmd.Next();
string toRankName = cmd.Next();
bool silent = (cmd.Next() != null);
if( toRankName == null ) {
cdMassRank.PrintUsage( player );
return;
}
Rank fromRank = RankManager.ParseRank( fromRankName );
if( fromRank == null ) {
player.NoRankMessage( fromRankName );
return;
}
Rank toRank = RankManager.ParseRank( toRankName );
if( toRank == null ) {
player.NoRankMessage( toRankName );
return;
}
if( fromRank == toRank ) {
player.Message( "Ranks must be different" );
return;
}
int playerCount = PlayerDB.CountPlayersByRank( fromRank );
string verb = (fromRank > toRank ? "demot" : "promot");
if( !cmd.IsConfirmed ) {
player.AskForConfirmation( cmd, "About to {0}e {1} players.", verb, playerCount );
return;
}
player.Message( "MassRank: {0}ing {1} players...",
verb, playerCount );
int affected = PlayerDB.MassRankChange( player, fromRank, toRank, silent );
player.Message( "MassRank: done.", affected );
}