static void ImportHandler(Player player, CommandReader cmd) { string action = cmd.Next(); if (action == null) { CdImport.PrintUsage(player); return; } switch (action.ToLower()) { case "bans": if (!player.Can(Permission.Ban)) { player.MessageNoAccess(Permission.Ban); return; } ImportBans(player, cmd); break; case "ranks": if (!player.Can(Permission.Promote)) { player.MessageNoAccess(Permission.Promote); return; } ImportRanks(player, cmd); break; default: CdImport.PrintUsage(player); break; } }
static void SayHandler([NotNull] Player player, [NotNull] CommandReader cmd) { if (player.Info.IsMuted) { player.MessageMuted(); return; } if (player.DetectChatSpam()) { return; } if (player.Can(Permission.Say)) { string msg = cmd.NextAll().Trim(' '); if (msg.Length > 0) { Chat.SendSay(player, msg); } else { CdSay.PrintUsage(player); } } else { player.MessageNoAccess(Permission.Say); } }
static void SayHandler(Player player, Command cmd) { if (player.Info.IsMuted) { player.MessageMuted(); return; } if (player.DetectChatSpam()) { return; } if (player.Can(Permission.Say)) { string msg = cmd.NextAll().Trim(); if (player.Can(Permission.UseColorCodes) && msg.Contains("%")) { msg = Color.ReplacePercentCodes(msg); } if (msg.Length > 0) { Chat.SendSay(player, msg); } else { CdSay.PrintUsage(player); } } else { player.MessageNoAccess(Permission.Say); } }
/// <summary> Parses and calls a specified command. </summary> /// <param name="player"> Player who issued the command. </param> /// <param name="cmd"> Command to be parsed and executed. </param> /// <param name="fromConsole"> Whether this command is being called from a non-player (e.g. Console). </param> /// <returns> True if the command was called, false if something prevented it from being called. </returns> public static bool ParseCommand([NotNull] Player player, [NotNull] Command cmd, bool fromConsole) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } CommandDescriptor descriptor = cmd.Descriptor; if (descriptor == null) { player.Message("Unknown command \"{0}\". See &H/Commands", cmd.Name); Logger.Log(LogType.UserCommand, "{0}: /{1}", player.Name, cmd.Name); return(false); } if (!descriptor.IsConsoleSafe && fromConsole) { player.Message("You cannot use this command from console."); } else { if (descriptor.Permissions != null) { if (!descriptor.CanBeCalledBy(player.Info.Rank)) { player.MessageNoAccess(descriptor); } else if (!descriptor.Call(player, cmd, true)) { player.Message("Command was cancelled."); } else { return(true); } } else { if (descriptor.Call(player, cmd, true)) { return(true); } else { player.Message("Command was cancelled."); } } } return(false); }
/// <summary> Parses and calls a specified command. </summary> /// <param name="player"> Player who issued the command. </param> /// <param name="cmd"> Command to be parsed and executed. </param> /// <param name="fromConsole"> Whether this command is being called from a non-player (e.g. Console). </param> /// <returns> True if the command was called, false if something prevented it from being called. </returns> /// <exception cref="ArgumentNullException"> player or cmd is null. </exception> public static bool ParseCommand([NotNull] Player player, [NotNull] CommandReader cmd, bool fromConsole) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } CommandDescriptor descriptor = cmd.Descriptor; if (descriptor == null) { if (CommandManager.ParseUnknownCommand(player, cmd)) { return(true); } player.Message("Unknown command \"{0}\". See &H/Commands", cmd.Name); return(false); } if (!descriptor.IsConsoleSafe && fromConsole) { player.Message("You cannot use this command from console."); return(false); } if (descriptor.Permissions != null) { if (!descriptor.CanBeCalledBy(player.Info.Rank)) { player.MessageNoAccess(descriptor); return(false); } if (descriptor.MinRank != RankManager.LowestRank && !player.Info.ClassicubeVerified) { player.Message("As you had an older minecraft.net account, you must have an admin verify your " + "new classicube.net account actually is you with /verify before you can use non-guest commands."); return(false); } } if (descriptor.Call(player, cmd, true)) { return(true); } else { player.Message("Command was cancelled."); return(false); } }
static void SayHandler( Player player, Command cmd ) { if( player.Info.IsMuted ) { player.MessageMuted(); return; } if( player.DetectChatSpam() ) return; if( player.Can( Permission.Say ) ) { string msg = cmd.NextAll().Trim(); if( msg.Length > 0 ) { Chat.SendSay( player, msg ); } else { CdSay.PrintUsage( player ); } } else { player.MessageNoAccess( Permission.Say ); } }
static void WhereHandler( Player player, CommandReader cmd ) { string name = cmd.Next(); if( cmd.HasNext ) { CdWhere.PrintUsage( player ); return; } Player target = player; if( name != null ) { if( !player.Can( Permission.ViewOthersInfo ) ) { player.MessageNoAccess( Permission.ViewOthersInfo ); return; } target = Server.FindPlayerOrPrintMatches( player, name, false, true ); if( target == null ) return; } else if( target.World == null ) { player.Message( "When called from console, &H/Where&S requires a player name." ); return; } if( target.World == null ) { // Chances of this happening are miniscule player.Message( "Player {0}&S is not in any world.", target.Name ); return; } else { player.Message( "Player {0}&S is on world {1}&S:", target.ClassyName, target.World.ClassyName ); } Vector3I targetBlockCoords = target.Position.ToBlockCoords(); player.Message( "{0}{1} - {2}", Color.Silver, targetBlockCoords, GetCompassString( target.Position.R ) ); }
internal static void HelpHandler( Player player, Command cmd ) { string commandName = cmd.Next(); if( commandName == "commands" ) { CdCommands.Call( player, cmd, false ); } else if( commandName != null ) { CommandDescriptor descriptor = CommandManager.GetDescriptor( commandName, true ); if( descriptor == null ) { player.Message( "Unknown command: \"{0}\"", commandName ); return; } string sectionName = cmd.Next(); if( sectionName != null ) { string sectionHelp; if( descriptor.HelpSections != null && descriptor.HelpSections.TryGetValue( sectionName.ToLower(), out sectionHelp ) ) { player.MessagePrefixed( HelpPrefix, sectionHelp ); } else { player.Message( "No help found for \"{0}\"", sectionName ); } } else { StringBuilder sb = new StringBuilder( Color.Help ); sb.Append( descriptor.Usage ).Append( '\n' ); if( descriptor.Aliases != null ) { sb.Append( "Aliases: &H" ); sb.Append( descriptor.Aliases.JoinToString() ); sb.Append( "\n&S" ); } if( String.IsNullOrEmpty( descriptor.Help ) ) { sb.Append( "No help is available for this command." ); } else { sb.Append( descriptor.Help ); } player.MessagePrefixed( HelpPrefix, sb.ToString() ); if( descriptor.Permissions != null && descriptor.Permissions.Length > 0 ) { player.MessageNoAccess( descriptor ); } } } else { player.Message( " To see a list of all commands, write &H/Commands" ); player.Message( " To see detailed help for a command, write &H/Help Command" ); if( player != Player.Console ) { player.Message( " To see your stats, write &H/Info" ); } player.Message( " To list available worlds, write &H/Worlds" ); player.Message( " To join a world, write &H/Join WorldName" ); player.Message( " To send private messages, write &H@PlayerName Message" ); } }
static void SetSpawnHandler( Player player, CommandReader cmd ) { World playerWorld = player.World; if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player ); string playerName = cmd.Next(); if( playerName == null ) { Map map = player.WorldMap; map.Spawn = player.Position; player.TeleportTo( map.Spawn ); player.Send( Packet.MakeAddEntity( Packet.SelfID, player.ListName, player.Position ) ); player.Message( "New spawn point saved." ); Logger.Log( LogType.UserActivity, "{0} changed the spawned point.", player.Name ); } else if( player.Can( Permission.Bring ) ) { Player[] infos = playerWorld.FindPlayers( player, playerName ); if( infos.Length == 1 ) { Player target = infos[0]; player.LastUsedPlayerName = target.Name; if( player.Can( Permission.Bring, target.Info.Rank ) ) { target.Send( Packet.MakeAddEntity( Packet.SelfID, target.ListName, player.Position ) ); } else { player.Message( "You may only set spawn of players ranked {0}&S or lower.", player.Info.Rank.GetLimit( Permission.Bring ).ClassyName ); player.Message( "{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName ); } } else if( infos.Length > 0 ) { player.MessageManyMatches( "player", infos ); } else { infos = Server.FindPlayers( player, playerName, true, false, true ); if( infos.Length > 0 ) { player.Message( "You may only set spawn of players on the same world as you." ); } else { player.MessageNoPlayer( playerName ); } } } else { player.MessageNoAccess( CdSetSpawn ); } }
static BlockDBUndoArgs ParseBlockDBUndoParams( Player player, CommandReader cmd, string cmdName, bool not ) { // check if command's being called by a worldless player (e.g. console) World playerWorld = player.World; if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player ); // ensure that BlockDB is enabled if( !BlockDB.IsEnabledGlobally ) { player.Message( "&W{0}: BlockDB is disabled on this server.", cmdName ); return null; } if( !playerWorld.BlockDB.IsEnabled ) { player.Message( "&W{0}: BlockDB is disabled in this world.", cmdName ); return null; } // parse the first parameter - either numeric or time limit string range = cmd.Next(); if( range == null ) { CdUndoPlayer.PrintUsage( player ); return null; } int countLimit; TimeSpan ageLimit = TimeSpan.Zero; if( !Int32.TryParse( range, out countLimit ) && !range.TryParseMiniTimeSpan( out ageLimit ) ) { player.Message( "{0}: First parameter should be a number or a timespan.", cmdName ); return null; } if( ageLimit > DateTimeUtil.MaxTimeSpan ) { player.MessageMaxTimeSpan(); return null; } // parse second and consequent parameters (player names) HashSet<PlayerInfo> targets = new HashSet<PlayerInfo>(); bool allPlayers = false; while( true ) { string name = cmd.Next(); if( name == null ) { break; } else if( name == "*" ) { // all players if( not ) { player.Message( "{0}: \"*\" not allowed (cannot undo \"everyone except everyone\")", cmdName ); return null; } if( allPlayers ) { player.Message( "{0}: \"*\" was listed twice.", cmdName ); return null; } allPlayers = true; } else { // individual player PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches( player, name, SearchOptions.IncludeSelf ); if( target == null ) { return null; } if( targets.Contains( target ) ) { player.Message( "{0}: Player {1}&S was listed twice.", target.ClassyName, cmdName ); return null; } // make sure player has the permission if( !not && player.Info != target && !player.Can( Permission.UndoAll ) && !player.Can( Permission.UndoOthersActions, target.Rank ) ) { player.Message( "&W{0}: You may only undo actions of players ranked {1}&S or lower.", cmdName, player.Info.Rank.GetLimit( Permission.UndoOthersActions ).ClassyName ); player.Message( "Player {0}&S is ranked {1}", target.ClassyName, target.Rank.ClassyName ); return null; } targets.Add( target ); } } if( targets.Count == 0 && !allPlayers ) { player.Message( "{0}: Specify at least one player name, or \"*\" to undo everyone.", cmdName ); return null; } if( targets.Count > 0 && allPlayers ) { player.Message( "{0}: Cannot mix player names and \"*\".", cmdName ); return null; } // undoing everyone ('*' in place of player name) requires UndoAll permission if( ( not || allPlayers ) && !player.Can( Permission.UndoAll ) ) { player.MessageNoAccess( Permission.UndoAll ); return null; } // Queue UndoPlayerCallback to run return new BlockDBUndoArgs { Player = player, AgeLimit = ageLimit, CountLimit = countLimit, Area = player.WorldMap.Bounds, World = playerWorld, Targets = targets.ToArray(), Not = not }; }
static void PlayerDbHandler(Player player, CommandReader cmd) { string command = cmd.Next(); if (command == null) { CdPlayerDb.PrintUsage(player); return; } switch (command.ToUpperInvariant()) { case "MERGE": player.Message("TODO: PlayerDB MERGE"); // TODO break; case "SPLIT": player.Message("TODO: PlayerDB SPLIT"); // TODO break; case "SWAP": InfoSwapHandler(player, cmd); break; case "IMPORTBANS": if (player.Can(Permission.Import, Permission.Ban)) { ImportBans(player, cmd); } else { player.MessageNoAccess(Permission.Import, Permission.Ban); } break; case "IMPORTRANKS": if (player.Can(Permission.Import, Permission.Promote, Permission.Demote)) { ImportRanks(player, cmd); } else { player.MessageNoAccess(Permission.Import, Permission.Promote, Permission.Demote); } break; case "PRUNE": PruneDBHandler(player, cmd); break; default: player.Message("Unknown PlayerDB function: " + command); CdPlayerDb.PrintUsage(player); break; } }
private static void PortalH(Player player, CommandReader cmd) { try { string option = cmd.Next(); if (string.IsNullOrEmpty(option)) { CdPortal.PrintUsage(player); return; } switch (option.ToLower()) { case "create": case "add": if (player.Can(Permission.CreatePortals)) { string addWorld = cmd.Next(); if (!string.IsNullOrEmpty(addWorld) && WorldManager.FindWorldExact(addWorld) != null) { DrawOperation operation = new CuboidDrawOperation(player); NormalBrush brush = new NormalBrush(Block.Water, Block.Water); string blockTypeOrName = cmd.Next(); Block pblock; if (blockTypeOrName != null && Map.GetBlockByName(blockTypeOrName, false, out pblock)) { if ((!validPBlocks.Contains(pblock) && pblock <= Block.StoneBrick) || (pblock == Block.Air && player.Info.Rank != RankManager.HighestRank)) { player.Message("Invalid block, choose a non-solid block"); return; } else { brush = new NormalBrush(pblock, pblock); } } string addPortalName = cmd.Next(); if (string.IsNullOrEmpty(addPortalName)) { player.PortalName = null; } else { if (!Portal.DoesNameExist(player.World, addPortalName)) { player.PortalName = addPortalName; } else { player.Message("A portal with name {0} already exists in this world.", addPortalName); return; } } World tpWorld = WorldManager.FindWorldExact(addWorld); if (cmd.HasNext) { int x, y, z, rot = player.Position.R, lot = player.Position.L; if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) { if (cmd.HasNext && cmd.HasNext) { if (cmd.NextInt(out rot) && cmd.NextInt(out lot)) { if (rot > 255 || rot < 0) { player.Message("R must be inbetween 0 and 255. Set to player R"); rot = player.Position.R; } if (lot > 255 || lot < 0) { player.Message("L must be inbetween 0 and 255. Set to player L"); lot = player.Position.L; } } } if (x < 1 || x >= 1024 || y < 1 || y >= 1024 || z < 1 || z >= 1024) { player.Message("Coordinates are outside the valid range!"); return; } else { player.PortalTPPos = new Position((short)(x * 32), (short)(y * 32), (short)(z * 32), (byte)rot, (byte)lot); } } else { player.PortalTPPos = tpWorld.map == null ? new Position(0, 0, 0) : tpWorld.map.Spawn; } } else { player.PortalTPPos = tpWorld.map == null ? new Position(0, 0, 0) : tpWorld.map.Spawn; } operation.Brush = brush; player.PortalWorld = addWorld; player.SelectionStart(operation.ExpectedMarks, PortalCreateCallback, operation, Permission.CreatePortals); player.Message("Click {0} blocks or use &H/Mark&S to mark the area of the portal.", operation.ExpectedMarks); } else { if (string.IsNullOrEmpty(addWorld)) { player.Message("No world specified."); } else { player.MessageNoWorld(addWorld); } } } else { player.MessageNoAccess(Permission.CreatePortals); } break; case "remove": case "delete": if (player.Can(Permission.CreatePortals)) { string remPortalName = cmd.Next(); string remWString = cmd.Next(); World remWorld = player.World; if (!string.IsNullOrEmpty(remWString)) { remWorld = WorldManager.FindWorldOrPrintMatches(player, remWString); } if (remWorld == null) { return; } if (string.IsNullOrEmpty(remPortalName)) { player.Message("No portal name specified."); } else { if (remWorld.Portals != null && remWorld.Portals.Count > 0) { bool found = false; Portal portalFound = null; lock (remWorld.Portals.SyncRoot) { foreach (Portal portal in remWorld.Portals) { if (portal.Name.ToLower().Equals(remPortalName.ToLower())) { portalFound = portal; found = true; break; } } if (!found) { player.Message("Could not find portal by name {0}.", remPortalName); } else { portalFound.Remove(player, remWorld); player.Message("Portal was removed."); } } } else { player.Message("Could not find portal as this world doesn't contain a portal."); } } } else { player.MessageNoAccess(Permission.CreatePortals); } break; case "info": case "i": string iPortalName = cmd.Next(); string iWString = cmd.Next(); World iWorld = player.World; if (!string.IsNullOrEmpty(iWString)) { iWorld = WorldManager.FindWorldOrPrintMatches(player, iWString); } if (iWorld == null) { return; } if (string.IsNullOrEmpty(iPortalName)) { player.Message("No portal name specified."); } else { if (iWorld.Portals != null && iWorld.Portals.Count > 0) { bool found = false; lock (iWorld.Portals.SyncRoot) { foreach (Portal portal in iWorld.Portals) { if (portal.Name.ToLower().Equals(iPortalName.ToLower())) { World portalWorld = WorldManager.FindWorldExact(portal.World); player.Message("Portal {0}&S was created by {1}&S at {2} and teleports to world {3} at {4}&S.", portal.Name, PlayerDB.FindPlayerInfoExact(portal.Creator).ClassyName, portal.Created, portalWorld.ClassyName, portal.position().ToString()); found = true; } } } if (!found) { player.Message("Could not find portal by name {0}.", iPortalName); } } else { player.Message("Could not find portal as this world doesn't contain a portal."); } } break; case "list": case "l": string lWString = cmd.Next(); World lWorld = player.World; if (!string.IsNullOrEmpty(lWString)) { lWorld = WorldManager.FindWorldOrPrintMatches(player, lWString); } if (lWorld == null) { return; } if (lWorld.Portals == null || lWorld.Portals.Count == 0) { player.Message("There are no portals in {0}&S.", lWorld.ClassyName); } else { string[] portalNames = new string[lWorld.Portals.Count]; StringBuilder output = new StringBuilder("There are " + lWorld.Portals.Count + " portals in " + lWorld.ClassyName + "&S: "); for (int i = 0; i < lWorld.Portals.Count; i++) { portalNames[i] = ((Portal)lWorld.Portals[i]).Name; } output.Append(portalNames.JoinToString(", ")); player.Message(output.ToString()); } break; case "enable": case "on": player.PortalsEnabled = true; player.Message("You enabled the use of portals."); break; case "disable": case "off": player.PortalsEnabled = false; player.Message("You disabled the use of portals, type /portal enable to re-enable portals."); break; default: CdPortal.PrintUsage(player); break; } } catch (PortalException ex) { player.Message(ex.Message); Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex); } catch (Exception ex) { player.Message("Unexpected error: " + ex); Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex); } }
static void SetSpawnHandler(Player player, Command cmd) { string playerName = cmd.Next(); if (playerName == null) { player.World.Map.Spawn = player.Position; player.TeleportTo(player.World.Map.Spawn); player.Send(PacketWriter.MakeAddEntity(255, player.ListName, player.Position)); player.Message("New spawn point saved."); Logger.Log(LogType.UserActivity, "{0} changed the spawned point.", player.Name); } else if (player.Can(Permission.Bring)) { Player[] infos = player.World.FindPlayers(player, playerName); if (infos.Length == 1) { Player target = infos[0]; if (player.Can(Permission.Bring, target.Info.Rank)) { target.Send(PacketWriter.MakeAddEntity(255, target.ListName, player.Position)); } else { player.Message("You can only set spawn of players ranked {0}&S or lower.", player.Info.Rank.GetLimit(Permission.Bring).ClassyName); player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName); } } else if (infos.Length > 0) { player.MessageManyMatches("player", infos); } else { infos = Server.FindPlayers(player, playerName, true); if (infos.Length > 0) { player.Message("You can only set spawn of players on the same world as you."); } else { player.MessageNoPlayer(playerName); } } } else { player.MessageNoAccess(CdRealm); } }
static void BanInfoHandler( Player player, CommandReader cmd ) { string name = cmd.Next(); if( cmd.HasNext ) { CdBanInfo.PrintUsage( player ); return; } IPAddress address; PlayerInfo info = null; if( name == null ) { name = player.Name; } else if( !player.Can( Permission.ViewOthersInfo ) ) { player.MessageNoAccess( Permission.ViewOthersInfo ); return; } if( IPAddressUtil.IsIP( name ) && IPAddress.TryParse( name, out address ) ) { IPBanInfo banInfo = IPBanList.Get( address ); if( banInfo != null ) { player.Message( "{0} was banned by {1}&S on {2:dd MMM yyyy} ({3} ago)", banInfo.Address, banInfo.BannedByClassy, banInfo.BanDate, banInfo.TimeSinceLastAttempt ); if( !String.IsNullOrEmpty( banInfo.PlayerName ) ) { player.Message( " Banned by association with {0}", banInfo.PlayerNameClassy ); } if( banInfo.Attempts > 0 ) { player.Message( " There have been {0} attempts to log in, most recently {1} ago by {2}", banInfo.Attempts, banInfo.TimeSinceLastAttempt.ToMiniString(), banInfo.LastAttemptNameClassy ); } if( banInfo.BanReason != null ) { player.Message( " Ban reason: {0}", banInfo.BanReason ); } } else { player.Message( "{0} is currently NOT banned.", address ); } } else { info = PlayerDB.FindPlayerInfoOrPrintMatches( player, name ); if( info == null ) return; address = info.LastIP; IPBanInfo ipBan = IPBanList.Get( info.LastIP ); switch( info.BanStatus ) { case BanStatus.Banned: if( ipBan != null ) { player.Message( "Player {0}&S and their IP are &CBANNED", info.ClassyName ); } else { player.Message( "Player {0}&S is &CBANNED&S (but their IP is not).", info.ClassyName ); } break; case BanStatus.IPBanExempt: if( ipBan != null ) { player.Message( "Player {0}&S is exempt from an existing IP ban.", info.ClassyName ); } else { player.Message( "Player {0}&S is exempt from IP bans.", info.ClassyName ); } break; case BanStatus.NotBanned: if( ipBan != null ) { player.Message( "Player {0}&s is not banned, but their IP is.", info.ClassyName ); } else { player.Message( "Player {0}&s is not banned.", info.ClassyName ); } break; } if( info.BanDate != DateTime.MinValue ) { player.Message( " Last ban by {0}&S on {1:dd MMM yyyy} ({2} ago).", info.BannedByClassy, info.BanDate, info.TimeSinceBan.ToMiniString() ); if( info.BanReason != null ) { player.Message( " Last ban reason: {0}", info.BanReason ); } } else { player.Message( "No past bans on record." ); } if( info.UnbanDate != DateTime.MinValue && !info.IsBanned ) { player.Message( " Unbanned by {0}&S on {1:dd MMM yyyy} ({2} ago).", info.UnbannedByClassy, info.UnbanDate, info.TimeSinceUnban.ToMiniString() ); if( info.UnbanReason != null ) { player.Message( " Last unban reason: {0}", info.UnbanReason ); } } if( info.BanDate != DateTime.MinValue ) { TimeSpan banDuration; if( info.IsBanned ) { banDuration = info.TimeSinceBan; player.Message( " Ban duration: {0} so far", banDuration.ToMiniString() ); } else { banDuration = info.UnbanDate.Subtract( info.BanDate ); player.Message( " Previous ban's duration: {0}", banDuration.ToMiniString() ); } } } // Show alts if( !address.Equals( IPAddress.None ) ) { List<PlayerInfo> altNames = new List<PlayerInfo>(); int bannedAltCount = 0; foreach( PlayerInfo playerFromSameIP in PlayerDB.FindPlayers( address ) ) { if( playerFromSameIP == info ) continue; altNames.Add( playerFromSameIP ); if( playerFromSameIP.IsBanned ) { bannedAltCount++; } } if( altNames.Count > 0 ) { altNames.Sort( new PlayerInfoComparer( player ) ); if( altNames.Count > MaxAltsToPrint ) { if( bannedAltCount > 0 ) { player.MessagePrefixed( "&S ", "&S Over {0} accounts ({1} banned) on IP: {2} &Setc", MaxAltsToPrint, bannedAltCount, altNames.Take( 15 ).ToArray().JoinToClassyString() ); } else { player.MessagePrefixed( "&S ", "&S Over {0} accounts on IP: {1} &Setc", MaxAltsToPrint, altNames.Take( 15 ).ToArray().JoinToClassyString() ); } } else { if( bannedAltCount > 0 ) { player.MessagePrefixed( "&S ", "&S {0} accounts ({1} banned) on IP: {2}", altNames.Count, bannedAltCount, altNames.ToArray().JoinToClassyString() ); } else { player.MessagePrefixed( "&S ", "&S {0} accounts on IP: {1}", altNames.Count, altNames.ToArray().JoinToClassyString() ); } } } } }
static void ReportHandler(Player player, Command cmd) { string option = cmd.Next(); string name = cmd.Next(); string PrintUsage = "&SAvailable options are: &HList, Add, Remove"; if (option == null) { player.Message("Please choose an option"); player.Message(PrintUsage); return; } if (option.ToLower() == "add") { if (!player.Can(Permission.MakeReport)) { player.MessageNoAccess(Permission.MakeReport); return; } if (name == null) { player.Message("Please enter a name to report."); return; } PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, name); if (target == null) return; if (target.Name == player.Name) { player.Message("You cannot report yourself."); return; } if (!Reports.Contains(target.Name)) { Reports.Add(target.Name); player.Message("Successfully reported {0}", target.ClassyName); Server.Players.Except(player).Message("{0}&S has been reported by {1}", target.ClassyName, player.ClassyName); return; } else { player.Message("This player has already been reported."); return; } } else if (option.ToLower() == "remove") { if (!player.Can(Permission.RemoveReport)) { player.MessageNoAccess(Permission.RemoveReport); return; } if (name == null) { player.Message("Please enter a name to remove."); return; } PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, name); if (target == null) return; if (target.Name == player.Name) { player.Message("You cannot report yourself."); return; } if (Reports.Contains(target.Name)) { Reports.Remove(target.Name); player.Message("Successfully removed {0}", target.ClassyName); Server.Players.Except(player).Message("{0}&S has been removed from the report list by {1}", target.ClassyName, player.ClassyName); return; } else { player.Message("This player has not been reported."); return; } } else if (option.ToLower() == "list") { if (!player.Can(Permission.ViewReports)) { player.MessageNoAccess(Permission.ViewReports); return; } if (Reports.Count != 0) { player.Message("&S--------&cReports&S--------"); foreach (string ReportedPlayers in Reports) { player.Message("&c-&S {0}", ReportedPlayers); } player.Message("&S-----&cEnd of Reports&S-----"); } else { player.Message("There are no reports."); return; } } else { player.Message(PrintUsage); return; } }
static void InfoHandler( Player player, CommandReader cmd ) { string name = cmd.Next(); if( name == null ) { // no name given, print own info PrintPlayerInfo( player, player.Info ); return; } else if( name.Equals( player.Name, StringComparison.OrdinalIgnoreCase ) ) { // own name given player.LastUsedPlayerName = player.Name; PrintPlayerInfo( player, player.Info ); return; } else if( !player.Can( Permission.ViewOthersInfo ) ) { // someone else's name or IP given, permission required. player.MessageNoAccess( Permission.ViewOthersInfo ); return; } // repeat last-typed name if( name == "-" ) { if( player.LastUsedPlayerName != null ) { name = player.LastUsedPlayerName; } else { player.Message( "Cannot repeat player name: you haven't used any names yet." ); return; } } PlayerInfo[] infos; IPAddress ip; if( name.Contains( "/" ) ) { // IP range matching (CIDR notation) string ipString = name.Substring( 0, name.IndexOf( '/' ) ); string rangeString = name.Substring( name.IndexOf( '/' ) + 1 ); byte range; if( IPAddressUtil.IsIP( ipString ) && IPAddress.TryParse( ipString, out ip ) && Byte.TryParse( rangeString, out range ) && range <= 32 ) { player.Message( "Searching {0}-{1}", ip.RangeMin( range ), ip.RangeMax( range ) ); infos = PlayerDB.FindPlayersCidr( ip, range ); } else { player.Message( "Info: Invalid IP range format. Use CIDR notation." ); return; } } else if( IPAddressUtil.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) { // find players by IP infos = PlayerDB.FindPlayers( ip ); } else if( name.Equals( "*" ) ) { infos = (PlayerInfo[])PlayerDB.PlayerInfoList.Clone(); } else if( name.Contains( "*" ) || name.Contains( "?" ) ) { // find players by regex/wildcard string regexString = "^" + RegexNonNameChars.Replace( name, "" ).Replace( "*", ".*" ).Replace( "?", "." ) + "$"; Regex regex = new Regex( regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled ); infos = PlayerDB.FindPlayers( regex ); } else if( name.StartsWith( "@" ) ) { string rankName = name.Substring( 1 ); Rank rank = RankManager.FindRank( rankName ); if( rank == null ) { player.MessageNoRank( rankName ); return; } else { infos = PlayerDB.PlayerInfoList .Where( info => info.Rank == rank ) .ToArray(); } } else if( name.StartsWith( "!" ) ) { // find online players by partial matches name = name.Substring( 1 ); infos = Server.FindPlayers( name, true ) .Select( p => p.Info ) .ToArray(); } else { // find players by partial matching PlayerInfo tempInfo; if( !PlayerDB.FindPlayerInfo( name, out tempInfo ) ) { infos = PlayerDB.FindPlayers( name ); } else if( tempInfo == null ) { player.MessageNoPlayer( name ); return; } else { infos = new[] { tempInfo }; } } Array.Sort( infos, new PlayerInfoComparer( player ) ); if( infos.Length == 1 ) { // only one match found; print it right away player.LastUsedPlayerName = infos[0].Name; PrintPlayerInfo( player, infos[0] ); } else if( infos.Length > 1 ) { // multiple matches found if( infos.Length <= PlayersPerPage ) { // all fit to one page player.MessageManyMatches( "player", infos ); } else { // pagination int offset; if( !cmd.NextInt( out offset ) ) offset = 0; if( offset >= infos.Length ) { offset = Math.Max( 0, infos.Length - PlayersPerPage ); } PlayerInfo[] infosPart = infos.Skip( offset ).Take( PlayersPerPage ).ToArray(); player.MessageManyMatches( "player", infosPart ); if( offset + infosPart.Length < infos.Length ) { // normal page player.Message( "Showing {0}-{1} (out of {2}). Next: &H/Info {3} {4}", offset + 1, offset + infosPart.Length, infos.Length, name, offset + infosPart.Length ); } else { // last page player.Message( "Showing matches {0}-{1} (out of {2}).", offset + 1, offset + infosPart.Length, infos.Length ); } } } else { // no matches found player.MessageNoPlayer( name ); } }
private static void PortalH(Player player, Command command) { try { String option = command.Next(); if (option == null) { CdPortal.PrintUsage(player); } else if (option.ToLower().Equals("create")) { if (player.Can(Permission.ManagePortal)) { string world = command.Next(); if (world != null && WorldManager.FindWorldExact(world) != null) { DrawOperation operation = new CuboidDrawOperation(player); NormalBrush brush = new NormalBrush(Block.Water, Block.Water); string blockTypeOrName = command.Next(); if (blockTypeOrName != null && blockTypeOrName.ToLower().Equals("lava")) { brush = new NormalBrush(Block.Lava, Block.Lava); } else if (blockTypeOrName != null && !blockTypeOrName.ToLower().Equals("water")) { player.Message("Invalid block, choose between water or lava."); return; } string portalName = command.Next(); if (portalName == null) { player.PortalName = null; } else { if (!Portal.DoesNameExist(player.World, portalName)) { player.PortalName = portalName; } else { player.Message("A portal with name {0} already exists in this world.", portalName); return; } } operation.Brush = brush; player.PortalWorld = world; player.SelectionStart(operation.ExpectedMarks, PortalCreateCallback, operation, Permission.Draw); player.Message("Click {0} blocks or use &H/Mark&S to mark the area of the portal.", operation.ExpectedMarks); } else { if (world == null) { player.Message("No world specified."); } else { player.MessageNoWorld(world); } } } else { player.MessageNoAccess(Permission.ManagePortal); } } else if (option.ToLower().Equals("remove")) { if (player.Can(Permission.ManagePortal)) { string portalName = command.Next(); if (portalName == null) { player.Message("No portal name specified."); } else { if (player.World.Portals != null && player.World.Portals.Count > 0) { bool found = false; Portal portalFound = null; lock (player.World.Portals.SyncRoot) { foreach (Portal portal in player.World.Portals) { if (portal.Name.Equals(portalName)) { portalFound = portal; found = true; break; } } if (!found) { player.Message("Could not find portal by name {0}.", portalName); } else { portalFound.Remove(player); player.Message("Portal was removed."); } } } else { player.Message("Could not find portal as this world doesn't contain a portal."); } } } else { player.MessageNoAccess(Permission.ManagePortal); } } else if (option.ToLower().Equals("info")) { string portalName = command.Next(); if (portalName == null) { player.Message("No portal name specified."); } else { if (player.World.Portals != null && player.World.Portals.Count > 0) { bool found = false; lock (player.World.Portals.SyncRoot) { foreach (Portal portal in player.World.Portals) { if (portal.Name.Equals(portalName)) { World portalWorld = WorldManager.FindWorldExact(portal.World); player.Message("Portal {0}&S was created by {1}&S at {2} and teleports to world {3}&S.", portal.Name, PlayerDB.FindPlayerInfoExact(portal.Creator).ClassyName, portal.Created, portalWorld.ClassyName); found = true; } } } if (!found) { player.Message("Could not find portal by name {0}.", portalName); } } else { player.Message("Could not find portal as this world doesn't contain a portal."); } } } else if (option.ToLower().Equals("list")) { if (player.World.Portals == null || player.World.Portals.Count == 0) { player.Message("There are no portals in {0}&S.", player.World.ClassyName); } else { String[] portalNames = new String[player.World.Portals.Count]; StringBuilder output = new StringBuilder("There are " + player.World.Portals.Count + " portals in " + player.World.ClassyName + "&S: "); for (int i = 0; i < player.World.Portals.Count; i++) { portalNames[i] = ((Portal)player.World.Portals[i]).Name; } output.Append(portalNames.JoinToString(", ")); player.Message(output.ToString()); } } else if (option.ToLower().Equals("enable")) { player.PortalsEnabled = true; player.Message("You enabled the use of portals."); } else if (option.ToLower().Equals("disable")) { player.PortalsEnabled = false; player.Message("You disabled the use of portals, type /portal enable to re-enable portals."); } else { CdPortal.PrintUsage(player); } } catch (PortalException ex) { player.Message(ex.Message); Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex); } catch (Exception ex) { player.Message("Unexpected error: " + ex); Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex); } }
static void ImportHandler( Player player, Command cmd ) { string action = cmd.Next(); if( action == null ) { CdImport.PrintUsage( player ); return; } switch( action.ToLower() ) { case "bans": if( !player.Can( Permission.Ban ) ) { player.MessageNoAccess( Permission.Ban ); return; } ImportBans( player, cmd ); break; case "ranks": if( !player.Can( Permission.Promote ) ) { player.MessageNoAccess( Permission.Promote ); return; } ImportRanks( player, cmd ); break; default: CdImport.PrintUsage( player ); break; } }
static void InfoHandler( Player player, CommandReader cmd ) { string name = cmd.Next(); if( name == null ) { // no name given, print own info PrintPlayerInfo( player, player.Info ); return; } else if( name.Equals( player.Name, StringComparison.OrdinalIgnoreCase ) ) { // own name given player.LastUsedPlayerName = player.Name; PrintPlayerInfo( player, player.Info ); return; } else if( !player.Can( Permission.ViewOthersInfo ) ) { // someone else's name or IP given, permission required. player.MessageNoAccess( Permission.ViewOthersInfo ); return; } // repeat last-typed name if( name == "-" ) { if( player.LastUsedPlayerName != null ) { name = player.LastUsedPlayerName; } else { player.Message( "Cannot repeat player name: you haven't used any names yet." ); return; } } PlayerInfo[] infos; IPAddress ip; if( IPAddressUtil.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) { // find players by IP infos = PlayerDB.FindByIP( ip ).ToArray(); } else if( name.Contains( "*" ) || name.Contains( "?" ) ) { // find players by regex/wildcard infos = PlayerDB.FindByPattern( name ).ToArray(); } else if( name.StartsWith( "@" ) ) { string rankName = name.Substring( 1 ); Rank rank = RankManager.FindRank( rankName ); if( rank == null ) { player.Message( "Unknown rank: {0}", rankName ); return; } else { using( PlayerDB.GetReadLock() ) { infos = PlayerDB.List .Where( info => info.Rank == rank ) .ToArray(); } } } else { // find players by partial matching PlayerInfo tempInfo; if( !PlayerDB.FindOneByPartialName( name, out tempInfo ) ) { infos = PlayerDB.FindByPartialName( name ).ToArray(); } else if( tempInfo == null ) { player.MessageNoPlayer( name ); return; } else { infos = new[] { tempInfo }; } } Array.Sort( infos, new PlayerInfoComparer( player ) ); if( infos.Length == 1 ) { // only one match found; print it right away player.LastUsedPlayerName = infos[0].Name; PrintPlayerInfo( player, infos[0] ); } else if( infos.Length > 1 ) { // multiple matches found if( infos.Length <= PlayersPerPage ) { // all fit to one page player.MessageManyMatches( "player", infos ); } else { // pagination int offset; if( !cmd.NextInt( out offset ) ) offset = 0; if( offset >= infos.Length ) { offset = Math.Max( 0, infos.Length - PlayersPerPage ); } PlayerInfo[] infosPart = infos.Skip( offset ).Take( PlayersPerPage ).ToArray(); player.MessageManyMatches( "player", infosPart ); if( offset + infosPart.Length < infos.Length ) { // normal page player.Message( "Showing {0}-{1} (out of {2}). Next: &H/Info {3} {4}", offset + 1, offset + infosPart.Length, infos.Length, name, offset + infosPart.Length ); } else { // last page player.Message( "Showing matches {0}-{1} (out of {2}).", offset + 1, offset + infosPart.Length, infos.Length ); } } } else { // no matches found player.MessageNoPlayer( name ); } }