本文整理汇总了C#中fCraft.Command.Rewind方法的典型用法代码示例。如果您正苦于以下问题:C# Command.Rewind方法的具体用法?C# Command.Rewind怎么用?C# Command.Rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fCraft.Command
的用法示例。
在下文中一共展示了Command.Rewind方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RealmCreate
public static void RealmCreate(Player player, Command cmd, string themeName, string templateName)
{
MapGenTemplate template;
MapGenTheme theme;
int wx, wy, height = 128;
if (!(cmd.NextInt(out wx) && cmd.NextInt(out wy) && cmd.NextInt(out height)))
{
if (player.World != null)
{
wx = 128;
wy = 128;
height = 128;
}
else
{
player.Message("When used from console, /gen requires map dimensions.");
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 = player.Name;
string fullFileName = null;
if (fileName == null)
{
if (player.World == null)
{
player.Message("When used from console, /gen requires FileName.");
return;
}
if (!cmd.IsConfirmed)
{
player.Confirm(cmd, "Replace this realm'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.MessageUnsafePath();
return;
}
string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar));
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
if (!cmd.IsConfirmed && File.Exists(fullFileName))
{
player.Confirm(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);
//.........这里部分代码省略.........
示例2: TPHandler
static void TPHandler( Player player, Command cmd )
{
string name = cmd.Next();
if( name == null ) {
CdTP.PrintUsage( player );
return;
}
if( cmd.Next() != null ) {
cmd.Rewind();
int x, y, z;
if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out z ) ) {
if( x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024 ) {
player.Message( "Coordinates are outside the valid range!" );
} else {
player.previousLocation = player.Position;
player.previousWorld = null;
player.TeleportTo( new Position {
X = (short)(x * 32 + 16),
Y = (short)(y * 32 + 16),
Z = (short)(z * 32 + 16),
R = player.Position.R,
L = player.Position.L
} );
}
} else {
CdTP.PrintUsage( player );
}
} else {
if( name == "-" ) {
if( player.LastUsedPlayerName != null ) {
name = player.LastUsedPlayerName;
} else {
player.Message( "Cannot repeat player name: you haven't used any names yet." );
return;
}
}
Player[] matches = Server.FindPlayers( player, name, true );
if( matches.Length == 1 ) {
Player target = matches[0];
World targetWorld = target.World;
if( targetWorld == null ) PlayerOpException.ThrowNoWorld( target );
if( targetWorld == player.World ) {
player.previousLocation = player.Position;
player.previousWorld = null;
player.TeleportTo( target.Position );
} else {
switch( targetWorld.AccessSecurity.CheckDetailed( player.Info ) ) {
case SecurityCheckResult.Allowed:
case SecurityCheckResult.WhiteListed:
if( targetWorld.IsFull ) {
player.Message( "Cannot teleport to {0}&S because world {1}&S is full.",
target.ClassyName,
targetWorld.ClassyName );
return;
}
player.StopSpectating();
player.previousLocation = player.Position;
player.previousWorld = player.World;
player.JoinWorld( targetWorld, WorldChangeReason.Tp, target.Position );
break;
case SecurityCheckResult.BlackListed:
player.Message( "Cannot teleport to {0}&S because you are blacklisted on world {1}",
target.ClassyName,
targetWorld.ClassyName );
break;
case SecurityCheckResult.RankTooLow:
player.Message( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
target.ClassyName,
targetWorld.ClassyName,
targetWorld.AccessSecurity.MinRank.ClassyName );
break;
// TODO: case PermissionType.RankTooHigh:
}
}
} else if( matches.Length > 1 ) {
player.MessageManyMatches( "player", matches );
} else {
// Try to guess if player typed "/TP" instead of "/Join"
World[] worlds = WorldManager.FindWorlds( player, name );
if( worlds.Length == 1 ) {
player.LastUsedWorldName = worlds[0].Name;
player.StopSpectating();
player.ParseMessage( "/Join " + worlds[0].Name, false, true );
} else {
player.MessageNoPlayer( name );
}
}
}
}
示例3: ParseMessage
// Parses message incoming from the player
public void ParseMessage( string rawMessage, bool fromConsole ) {
if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
if( partialMessage != null ) {
rawMessage = partialMessage + rawMessage;
partialMessage = null;
}
switch( CommandManager.GetMessageType( rawMessage ) ) {
case MessageType.Chat: {
if( !Can( Permission.Chat ) ) return;
if( Info.IsMuted ) {
MutedMessage();
return;
}
if( DetectChatSpam() ) return;
if( World != null && !World.FireSentMessageEvent( this, ref rawMessage ) ||
!Server.FireSentMessageEvent( this, ref rawMessage ) ) return;
Info.LinesWritten++;
Logger.Log( "{0}: {1}", LogType.GlobalChat, Name, rawMessage );
// Escaped slash removed AFTER logging, to avoid confusion with real commands
if( rawMessage.StartsWith( "//" ) ) {
rawMessage = rawMessage.Substring( 1 );
}
if( rawMessage.EndsWith( "//" ) ) {
rawMessage = rawMessage.Substring( 0, rawMessage.Length - 1 );
}
if( Can( Permission.UseColorCodes ) && rawMessage.Contains( "%" ) ) {
rawMessage = Color.ReplacePercentCodes( rawMessage );
}
Server.SendToAllExceptIgnored( this, "{0}{1}: {2}", Console,
GetClassyName(), Color.White, rawMessage );
} break;
case MessageType.Command: {
if( rawMessage.EndsWith( "//" ) ) {
rawMessage = rawMessage.Substring( 0, rawMessage.Length - 1 );
}
Logger.Log( "{0}: {1}", LogType.UserCommand,
Name, rawMessage );
Command cmd = new Command( rawMessage );
LastCommand = cmd;
CommandManager.ParseCommand( this, cmd, fromConsole );
} break;
case MessageType.RepeatCommand: {
if( LastCommand == null ) {
Message( "No command to repeat." );
} else {
LastCommand.Rewind();
Logger.Log( "{0}: repeat {1}", LogType.UserCommand,
Name, LastCommand.Message );
Message( "Repeat: {0}", LastCommand.Message );
CommandManager.ParseCommand( this, LastCommand, fromConsole );
}
} break;
case MessageType.PrivateChat: {
if( !Can( Permission.Chat ) ) return;
if( Info.IsMuted ) {
MutedMessage();
return;
}
if( DetectChatSpam() ) return;
if( rawMessage.EndsWith( "//" ) ) {
rawMessage = rawMessage.Substring( 0, rawMessage.Length - 1 );
}
string otherPlayerName, messageText;
if( rawMessage[1] == ' ' ) {
otherPlayerName = rawMessage.Substring( 2, rawMessage.IndexOf( ' ', 2 ) - 2 );
messageText = rawMessage.Substring( rawMessage.IndexOf( ' ', 2 ) + 1 );
} else {
otherPlayerName = rawMessage.Substring( 1, rawMessage.IndexOf( ' ' ) - 1 );
messageText = rawMessage.Substring( rawMessage.IndexOf( ' ' ) + 1 );
}
if( messageText.Contains( "%" ) && Can( Permission.UseColorCodes ) ) {
messageText = Color.ReplacePercentCodes( messageText );
}
// first, find ALL players (visible and hidden)
Player[] allPlayers = Server.FindPlayers( otherPlayerName );
//.........这里部分代码省略.........
示例4: AskForConfirmation
public void AskForConfirmation( Command cmd, string message, params object[] args ) {
if( cmd == null ) throw new ArgumentNullException( "cmd" );
if( message == null ) throw new ArgumentNullException( "message" );
CommandToConfirm = cmd;
CommandToConfirmDate = DateTime.UtcNow;
Message( "{0} Type &H/ok&S to continue.", String.Format( message, args ) );
CommandToConfirm.Rewind();
}
示例5: TP
internal static void TP( Player player, Command cmd )
{
if( player.Can( Permissions.Teleport ) ) {
string name = cmd.Next();
if( name == null ) {
player.Send( PacketWriter.MakeTeleport( 255, player.world.map.spawn ) );
} else {
Player target = player.world.FindPlayer( name );
if( target != null ) {
Position pos = target.pos;
pos.x += 1;
pos.y += 1;
pos.h += 1;
player.Send( PacketWriter.MakeTeleport( 255, pos ) );
} else if( cmd.Next() == null ) {
player.NoPlayerMessage( name );
} else {
cmd.Rewind();
int x, y, h;
if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out h ) ) {
if( x < 0 || x > player.world.map.widthX ||
y < 0 || y > player.world.map.widthY ||
y < 0 || y > player.world.map.height ) {
player.Message( "Specified coordinates are outside the map!" );
} else {
player.pos.Set( x * 32 + 16, y * 32 + 16, h * 32 + 16, player.pos.r, player.pos.l );
player.Send( PacketWriter.MakeTeleport( 255, player.pos ) );
}
} else {
player.Message( "See " + Color.Help + "/help tp" + Color.Sys + " for information on using /tp" );
}
}
}
} else {
player.NoAccessMessage( Permissions.Teleport );
}
}
示例6: Generate
internal static void Generate( Player player, Command cmd )
{
if( !player.Can( Permissions.ManageWorlds ) ) {
player.NoAccessMessage( Permissions.ManageWorlds );
return;
}
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( "Usage: " + Color.Help + "/gen widthX widthY height type filename" );
return;
}
cmd.Rewind();
}
string mode = cmd.Next();
string filename = cmd.Next();
if( mode == null || filename == null ) {
player.Message( "Usage: " + Color.Help + "/gen widthX widthY height type filename" );
return;
}
filename += ".fcm";
int seed;
if( !cmd.NextInt( out seed ) ) {
seed = new Random().Next();
}
Random rand = new Random( seed );
//player.Message( "Seed: " + Convert.ToBase64String( BitConverter.GetBytes( seed ) ) );
Map map = new Map( player.world, wx, wy, height );
map.spawn.Set( map.widthX / 2 * 32 + 16, map.widthY / 2 * 32 + 16, map.height * 32, 0, 0 );
DoGenerate( map, player, mode, filename, rand, false );
}
示例7: GenHandler
static void GenHandler( Player player, Command cmd ) {
World playerWorld = player.World;
Map oldMap = player.WorldMap;
string themeName = cmd.Next();
string templateName;
bool genOcean = false;
bool genEmpty = false;
bool noTrees = false;
if( themeName == null ) {
CdGenerate.PrintUsage( player );
return;
}
MapGenTheme theme = MapGenTheme.Forest;
MapGenTemplate template = MapGenTemplate.Flat;
// parse special template names (which do not need a theme)
if( themeName.Equals( "ocean" ) ) {
genOcean = true;
} else if( themeName.Equals( "empty" ) ) {
genEmpty = true;
} else {
templateName = cmd.Next();
if( templateName == null ) {
CdGenerate.PrintUsage( player );
return;
}
// parse theme
bool swapThemeAndTemplate = false;
if( themeName.Equals( "grass", StringComparison.OrdinalIgnoreCase ) ) {
theme = MapGenTheme.Forest;
noTrees = true;
} else if( templateName.Equals( "grass", StringComparison.OrdinalIgnoreCase ) ) {
theme = MapGenTheme.Forest;
noTrees = true;
swapThemeAndTemplate = true;
} else if( EnumUtil.TryParse( themeName, out theme, true ) ) {
noTrees = (theme != MapGenTheme.Forest);
} else if( EnumUtil.TryParse( templateName, out theme, true ) ) {
noTrees = (theme != MapGenTheme.Forest);
swapThemeAndTemplate = true;
} else {
player.Message( "Gen: Unrecognized theme \"{0}\". Available themes are: {1}",
themeName,
Enum.GetNames( typeof( MapGenTheme ) ).JoinToString() );
return;
}
// parse template
if( swapThemeAndTemplate ) {
if( !EnumUtil.TryParse( themeName, out template, true ) ) {
player.Message( "Unrecognized template \"{0}\". Available templates are: {1}",
themeName,
Enum.GetNames( typeof( MapGenTemplate ) ).JoinToString() );
return;
}
} else {
if( !EnumUtil.TryParse( templateName, out template, true ) ) {
player.Message( "Unrecognized template \"{0}\". Available templates are: {1}",
templateName,
Enum.GetNames( typeof( MapGenTemplate ) ).JoinToString() );
return;
}
}
}
// parse map dimensions
int mapWidth, mapLength, mapHeight;
if( !(cmd.NextInt( out mapWidth ) && cmd.NextInt( out mapLength ) && cmd.NextInt( out mapHeight )) ) {
if( playerWorld != null ) {
// If map dimensions were not given, use current map's dimensions
mapWidth = oldMap.Width;
mapLength = oldMap.Length;
mapHeight = oldMap.Height;
} else {
player.Message( "When used from console, /Gen requires map dimensions." );
CdGenerate.PrintUsage( player );
return;
}
cmd.Rewind();
cmd.Next();
cmd.Next();
}
// Check map dimensions
const string dimensionRecommendation = "Dimensions must be between 1 and 2047. " +
"Recommended values: 16, 32, 64, 128, 256, 512, and 1024.";
if( !Map.IsValidDimension( mapWidth ) ) {
player.Message( "Cannot make map with width {0}. {1}", mapWidth, dimensionRecommendation );
return;
} else if( !Map.IsValidDimension( mapLength ) ) {
player.Message( "Cannot make map with length {0}. {1}", mapLength, dimensionRecommendation );
return;
//.........这里部分代码省略.........
示例8: Restart
static void Restart( Player player, Command cmd ) {
int delay;
if( !cmd.NextInt( out delay ) ) {
delay = 5;
cmd.Rewind();
}
string reason = cmd.Next();
Server.SendToAll( "&WServer restarting in {0} seconds.", delay );
if( reason == null ) {
Logger.Log( "{0} restarted the server ({1} second delay).", LogType.UserActivity,
player.Name, delay );
ShutdownParams sp = new ShutdownParams( ShutdownReason.Restarting, delay, true, true );
Server.Shutdown( sp, false );
} else {
Logger.Log( "{0} restarted the server ({1} second delay). Reason: {2}", LogType.UserActivity,
player.Name, delay, reason );
ShutdownParams sp = new ShutdownParams( ShutdownReason.Restarting, delay, true, true, reason, player );
Server.Shutdown( sp, false );
}
}
示例9: Shutdown
static void Shutdown( Player player, Command cmd ) {
int delay;
if( !cmd.NextInt( out delay ) ) {
delay = 5;
cmd.Rewind();
}
string reason = cmd.NextAll();
if( reason.Equals( "abort", StringComparison.OrdinalIgnoreCase ) ) {
if( Server.CancelShutdown() ) {
Logger.Log( "Shutdown aborted by {0}.", LogType.UserActivity, player.Name );
Server.SendToAll( "&WShutdown aborted by {0}", player.GetClassyName() );
} else {
player.MessageNow( "Cannot abort shutdown - too late." );
}
return;
}
Server.SendToAll( "&WServer shutting down in {0} seconds.", delay );
if( String.IsNullOrEmpty( reason ) ) {
Logger.Log( "{0} shut down the server ({1} second delay).", LogType.UserActivity,
player.Name, delay );
ShutdownParams sp = new ShutdownParams( ShutdownReason.ShuttingDown, delay, true, false );
Server.Shutdown( sp, false );
} else {
Server.SendToAll( "&WShutdown reason: {0}", reason );
Logger.Log( "{0} shut down the server ({1} second delay). Reason: {2}", LogType.UserActivity,
player.Name, delay, reason );
ShutdownParams sp = new ShutdownParams( ShutdownReason.ShuttingDown, delay, true, false, reason, player );
Server.Shutdown( sp, false );
}
}