public FindPlayerInfo ( Player player ) : |
||
player | Player | |
Résultat |
internal static void Unignore(Player player, Command cmd) { string name = cmd.Next(); if (name != null) { PlayerInfo targetInfo; if (!PlayerDB.FindPlayerInfo(name, out targetInfo)) { PlayerInfo[] infos = PlayerDB.FindPlayers(name); if (infos.Length == 1) { targetInfo = infos[0]; } else if (infos.Length > 1) { player.ManyMatchesMessage("player", infos); return; } else { player.NoPlayerMessage(name); return; } } else if (targetInfo == null) { player.NoPlayerMessage(name); return; } if (player.Unignore(targetInfo)) { player.MessageNow("You are no longer ignoring {0}", targetInfo.GetClassyName()); } else { player.MessageNow("You are not currently ignoring {0}", targetInfo.GetClassyName()); } } else { PlayerInfo[] ignoreList = player.GetIgnoreList(); if (ignoreList.Length > 0) { player.MessageNow("Ignored players: {0}", ignoreList.JoinToClassyString()); } else { player.MessageNow("You are not currently ignoring anyone."); } return; } }
internal static void RealmBuild(Player player, Command cmd, string worldName, string name, string NameIfRankIsName) { // Print information about the current realm if (worldName == null) { if (player.World == null) { player.Message("When calling /wbuild from console, you must specify a realm name."); } else { player.Message(player.World.BuildSecurity.GetDescription(player.World, "realm", "modified")); } return; } // Find a realm by name World realm = WorldManager.FindWorldOrPrintMatches(player, worldName); if (realm == null) { return; } if (name == null) { player.Message(realm.BuildSecurity.GetDescription(realm, "realm", "modified")); return; } bool changesWereMade = false; do { if (name.Length < 2) { continue; } // Whitelisting individuals if (name.StartsWith("+")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } else if (info == null) { player.MessageNoPlayer(name.Substring(1)); continue; } if (realm.BuildSecurity.CheckDetailed(info) == SecurityCheckResult.Allowed) { player.Message("{0}&S is already allowed to build in {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) { target = null; // to avoid duplicate messages } switch (realm.BuildSecurity.Include(info)) { case PermissionOverride.Deny: if (realm.BuildSecurity.Check(info)) { player.Message("{0}&S is no longer barred from building in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You can now build in realm {0}&S (removed from blacklist by {1}&S).", realm.ClassyName, player.ClassyName); } } else { player.Message("{0}&S was removed from the build blacklist of {1}&S. " + "Player is still NOT allowed to build (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were removed from the build blacklist of realm {0}&S by {1}&S. " + "You are still NOT allowed to build (by rank).", player.ClassyName, realm.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the build blacklist of {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now allowed to build in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You can now build in realm {0}&S (whitelisted by {1}&S).", realm.ClassyName, player.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the build whitelist on realm {2}", player.Name, info.Name, realm.Name); break; case PermissionOverride.Allow: player.Message("{0}&S is already on the build whitelist of {1}", info.ClassyName, realm.ClassyName); break; } // Blacklisting individuals } else if (name.StartsWith("-")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } else if (info == null) { player.MessageNoPlayer(name.Substring(1)); continue; } if (realm.BuildSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooHigh || realm.BuildSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooLow) { player.Message("{0}&S is already barred from building in {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) { target = null; // to avoid duplicate messages } switch (realm.BuildSecurity.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already on build blacklist of {1}", info.ClassyName, realm.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now barred from building in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou were barred by {0}&W from building in realm {1}", player.ClassyName, realm.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the build blacklist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.Allow: if (realm.BuildSecurity.Check(info)) { player.Message("{0}&S is no longer on the build whitelist of {1}&S. " + "Player is still allowed to build (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were removed from the build whitelist of realm {0}&S by {1}&S. " + "You are still allowed to build (by rank).", player.ClassyName, realm.ClassyName); } } else { player.Message("{0}&S is no longer allowed to build in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou can no longer build in realm {0}&W (removed from whitelist by {1}&W).", realm.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the build whitelist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; } // Setting minimum rank } else { Rank rank = RankManager.FindRank(name); if (rank == null) { player.MessageNoRank(name); } else if (!player.Info.Rank.AllowSecurityCircumvention && realm.BuildSecurity.MinRank > rank && realm.BuildSecurity.MinRank > player.Info.Rank) { player.Message("&WYou must be ranked {0}&W+ to lower build restrictions for realm {1}", realm.BuildSecurity.MinRank.ClassyName, realm.ClassyName); } else { // list players who are redundantly blacklisted var exceptionList = realm.BuildSecurity.ExceptionList; PlayerInfo[] noLongerExcluded = exceptionList.Excluded.Where(excludedPlayer => excludedPlayer.Rank < rank).ToArray(); if (noLongerExcluded.Length > 0) { player.Message("Following players no longer need to be blacklisted on realm {0}&S: {1}", realm.ClassyName, noLongerExcluded.JoinToClassyString()); } // list players who are redundantly whitelisted PlayerInfo[] noLongerIncluded = exceptionList.Included.Where(includedPlayer => includedPlayer.Rank >= rank).ToArray(); if (noLongerIncluded.Length > 0) { player.Message("Following players no longer need to be whitelisted on realm {0}&S: {1}", realm.ClassyName, noLongerIncluded.JoinToClassyString()); } // apply changes realm.BuildSecurity.MinRank = rank; changesWereMade = true; if (realm.BuildSecurity.MinRank == RankManager.LowestRank) { Server.Message("{0}&S allowed anyone to build on realm {1}", player.ClassyName, realm.ClassyName); } else { Server.Message("{0}&S allowed only {1}+&S to build in realm {2}", player.ClassyName, realm.BuildSecurity.MinRank.ClassyName, realm.ClassyName); } Logger.Log(LogType.UserActivity, "{0} set build rank for realm {1} to {2}+", player.Name, realm.Name, realm.BuildSecurity.MinRank.Name); } } } while ((name = cmd.Next()) != null); if (changesWereMade) { WorldManager.SaveWorldList(); } }
internal static void RealmAccess(Player player, Command cmd, string worldName, string name) { // Print information about the current realm if (worldName == null) { if (player.World == null) { player.Message("Error."); } else { player.Message(player.World.AccessSecurity.GetDescription(player.World, "realm", "accessed")); } return; } // Find a realm by name World realm = WorldManager.FindWorldOrPrintMatches(player, worldName); if (realm == null) { return; } if (name == null) { player.Message(realm.AccessSecurity.GetDescription(realm, "realm", "accessed")); return; } if (realm == WorldManager.MainWorld) { player.Message("The main realm cannot have access restrictions."); return; } bool changesWereMade = false; do { if (name.Length < 2) { continue; } // Whitelisting individuals if (name.StartsWith("+")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } else if (info == null) { player.MessageNoPlayer(name.Substring(1)); continue; } // prevent players from whitelisting themselves to bypass protection if (realm.AccessSecurity.CheckDetailed(info) == SecurityCheckResult.Allowed) { player.Message("{0}&S is already allowed to access {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) { target = null; // to avoid duplicate messages } switch (realm.AccessSecurity.Include(info)) { case PermissionOverride.Deny: if (realm.AccessSecurity.Check(info)) { player.Message("{0}&S is unbanned from Realm {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You are now unbanned from Realm {0}&S (removed from blacklist by {1}&S).", realm.ClassyName, player.ClassyName); } } else { player.Message("{0}&S was unbanned from Realm {1}&S. " + "Player is still NOT allowed to join (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were Unbanned from Realm {0}&S by {1}&S. " + "You are still NOT allowed to join (by rank).", player.ClassyName, realm.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the access blacklist of {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now allowed to access {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You can now access realm {0}&S (whitelisted by {1}&S).", realm.ClassyName, player.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the access whitelist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already on the access whitelist of {1}", info.ClassyName, realm.ClassyName); break; } // Blacklisting individuals } else if (name.StartsWith("-")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } else if (info == null) { player.MessageNoPlayer(name.Substring(1)); continue; } if (realm.AccessSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooHigh || realm.AccessSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooLow) { player.Message("{0}&S is already barred from accessing {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) { target = null; // to avoid duplicate messages } switch (realm.AccessSecurity.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already banned from Realm {1}", info.ClassyName, realm.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now banned from accessing {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou were banned by {0}&W from accessing realm {1}", player.ClassyName, realm.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the access blacklist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.Allow: if (realm.AccessSecurity.Check(info)) { player.Message("{0}&S is no longer on the access whitelist of {1}&S. " + "Player is still allowed to join (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were banned from Realm {0}&S by {1}&S. " + "You are still allowed to join (by rank).", player.ClassyName, realm.ClassyName); } } else { player.Message("{0}&S is no longer allowed to access {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou were banned from Realm {0}&W (Banned by {1}&W).", realm.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the access whitelist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; } // Setting minimum rank } else { Rank rank = RankManager.FindRank(name); if (rank == null) { player.MessageNoRank(name); } else { // list players who are redundantly blacklisted var exceptionList = realm.AccessSecurity.ExceptionList; PlayerInfo[] noLongerExcluded = exceptionList.Excluded.Where(excludedPlayer => excludedPlayer.Rank < rank).ToArray(); if (noLongerExcluded.Length > 0) { player.Message("Following players no longer need to be blacklisted to be barred from {0}&S: {1}", realm.ClassyName, noLongerExcluded.JoinToClassyString()); } // list players who are redundantly whitelisted PlayerInfo[] noLongerIncluded = exceptionList.Included.Where(includedPlayer => includedPlayer.Rank >= rank).ToArray(); if (noLongerIncluded.Length > 0) { player.Message("Following players no longer need to be whitelisted to access {0}&S: {1}", realm.ClassyName, noLongerIncluded.JoinToClassyString()); } // apply changes realm.AccessSecurity.MinRank = rank; changesWereMade = true; if (realm.AccessSecurity.MinRank == RankManager.LowestRank) { Server.Message("{0}&S made the realm {1}&S accessible to everyone.", player.ClassyName, realm.ClassyName); } else { Server.Message("{0}&S made the realm {1}&S accessible only by {2}+", player.ClassyName, realm.ClassyName, realm.AccessSecurity.MinRank.ClassyName); } Logger.Log(LogType.UserActivity, "{0} set access rank for realm {1} to {2}+", player.Name, realm.Name, realm.AccessSecurity.MinRank.Name); } } } while ((name = cmd.Next()) != null); if (changesWereMade) { var playersWhoCantStay = realm.Players.Where(p => !p.CanJoin(realm)); foreach (Player p in playersWhoCantStay) { p.Message("&WYou are no longer allowed to join realm {0}", realm.ClassyName); p.JoinWorld(WorldManager.MainWorld, WorldChangeReason.PermissionChanged); } WorldManager.SaveWorldList(); } }
internal static void ZoneEdit(Player player, Command cmd) { bool changesWereMade = false; string zoneName = cmd.Next(); if (zoneName == null) { player.Message("No zone name specified. See &H/help zedit"); return; } Zone zone = player.World.Map.FindZone(zoneName); if (zone == null) { player.Message("No zone found with the name \"{0}\". See &H/zones", zoneName); return; } string name; while ((name = cmd.Next()) != null) { if (name.Length < 2) { continue; } if (name.StartsWith("+")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); return; } if (info == null) { player.NoPlayerMessage(name.Substring(1)); return; } // prevent players from whitelisting themselves to bypass protection if (!player.Info.Rank.AllowSecurityCircumvention && player.Info == info) { if (!zone.Controller.Check(info)) { player.Message("You must be {0}+&S to add yourself to this zone's whitelist.", zone.Controller.MinRank.GetClassyName()); continue; } } switch (zone.Controller.Include(info)) { case PermissionOverride.Deny: player.Message("{0}&S is no longer excluded from zone {1}", info.GetClassyName(), zone.GetClassyName()); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now included in zone {1}", info.GetClassyName(), zone.GetClassyName()); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already included in zone {1}", info.GetClassyName(), zone.GetClassyName()); break; } } else if (name.StartsWith("-")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); return; } if (info == null) { player.NoPlayerMessage(name.Substring(1)); return; } switch (zone.Controller.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already excluded from zone {1}", info.GetClassyName(), zone.GetClassyName()); break; case PermissionOverride.None: player.Message("{0}&S is now excluded from zone {1}", info.GetClassyName(), zone.GetClassyName()); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is no longer included in zone {1}", info.GetClassyName(), zone.GetClassyName()); changesWereMade = true; break; } } else { Rank minRank = RankManager.ParseRank(name); if (minRank != null) { // prevent players from lowering rank so bypass protection if (!player.Info.Rank.AllowSecurityCircumvention && zone.Controller.MinRank > player.Info.Rank && minRank <= player.Info.Rank) { player.Message("You are not allowed to lower the zone's rank."); continue; } if (zone.Controller.MinRank != minRank) { zone.Controller.MinRank = minRank; player.Message("Permission for zone \"{0}\" changed to {1}+", zone.Name, minRank.GetClassyName()); changesWereMade = true; } } else { player.NoRankMessage(name); } } if (changesWereMade) { zone.Edit(player.Info); player.World.Map.ChangedSinceSave = true; } else { player.Message("No changes were made to the zone."); } } }
internal static void ZoneAdd(Player player, Command cmd) { string zoneName = cmd.Next(); if (zoneName == null) { cdZoneAdd.PrintUsage(player); return; } Zone zone = new Zone(); if (zoneName.StartsWith("+")) { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(zoneName.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", zoneName.Substring(1)); return; } if (info == null) { player.NoPlayerMessage(zoneName.Substring(1)); return; } zone.Name = info.Name; zone.Controller.MinRank = info.Rank.NextRankUp ?? info.Rank; zone.Controller.Include(info); player.Message("Zone: Creating a {0}+&S zone for player {1}&S. Place a block or type /mark to use your location.", zone.Controller.MinRank.GetClassyName(), info.GetClassyName()); player.SetCallback(2, ZoneAddCallback, zone, cdZoneAdd.Permissions); } else { if (!World.IsValidName(zoneName)) { player.Message("\"{0}\" is not a valid zone name", zoneName); return; } if (player.World.Map.FindZone(zoneName) != null) { player.Message("A zone with this name already exists. Use &H/zedit&S to edit."); return; } zone.Name = zoneName; string rankName = cmd.Next(); if (rankName == null) { player.Message("No rank was specified. See &H/help zone"); return; } Rank minRank = RankManager.ParseRank(rankName); if (minRank != null) { string name; while ((name = cmd.Next()) != null) { if (name.Length == 0) { continue; } PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); return; } if (info == null) { player.NoPlayerMessage(name.Substring(1)); return; } if (name.StartsWith("+")) { zone.Controller.Include(info); } else if (name.StartsWith("-")) { zone.Controller.Exclude(info); } } zone.Controller.MinRank = minRank; player.SetCallback(2, ZoneAddCallback, zone, cdZoneAdd.Permissions); player.Message("Zone: Place a block or type /mark to use your location."); } else { player.NoRankMessage(rankName); } } }
internal static void Info(Player player, Command cmd) { string name = cmd.Next(); if (name == null) { name = player.Name; } else if (!player.Can(Permission.ViewOthersInfo)) { player.NoAccessMessage(Permission.ViewOthersInfo); return; } IPAddress ip; PlayerInfo[] infos; if (Server.IsIP(name) && IPAddress.TryParse(name, out ip)) { // find players by IP infos = PlayerDB.FindPlayers(ip, PlayerDB.NumberOfMatchesToPrint); } else if (name.Contains("*") || name.Contains(".")) { // find players by regex/wildcard string regexString = "^" + RegexNonNameChars.Replace(name, "").Replace("*", ".*") + "$"; Regex regex = new Regex(regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled); infos = PlayerDB.FindPlayers(regex, PlayerDB.NumberOfMatchesToPrint); } else { // find players by partial matching PlayerInfo tempInfo; if (!PlayerDB.FindPlayerInfo(name, out tempInfo)) { infos = PlayerDB.FindPlayers(name, PlayerDB.NumberOfMatchesToPrint); } else if (tempInfo == null) { player.NoPlayerMessage(name); return; } else { infos = new[] { tempInfo }; } } if (infos.Length == 1) { PrintPlayerInfo(player, infos[0]); } else if (infos.Length > 1) { player.ManyMatchesMessage("player", infos); if (infos.Length == PlayerDB.NumberOfMatchesToPrint) { player.Message("NOTE: Only first {0} matches are shown.", PlayerDB.NumberOfMatchesToPrint); } } else { player.NoPlayerMessage(name); } }
internal static void BanInfo(Player player, Command cmd) { string name = cmd.Next(); IPAddress address; if (name == null) { name = player.Name; } else if (!player.Can(Permission.ViewOthersInfo)) { player.NoAccessMessage(Permission.ViewOthersInfo); return; } if (Server.IsIP(name) && IPAddress.TryParse(name, out address)) { IPBanInfo info = IPBanList.Get(address); if (info != null) { player.Message("{0} was banned by {1} on {2:dd MMM yyyy}.", info.Address, info.BannedBy, info.BanDate); if (!String.IsNullOrEmpty(info.PlayerName)) { player.Message(" IP ban was banned by association with {0}", info.PlayerName); } if (info.Attempts > 0) { player.Message(" There have been {0} attempts to log in, most recently", info.Attempts); player.Message(" on {0:dd MMM yyyy} by {1}.", info.LastAttemptDate, info.LastAttemptName); } if (info.BanReason.Length > 0) { player.Message(" Ban reason: {0}", info.BanReason); } } else { player.Message("{0} is currently NOT banned.", address); } } else { PlayerInfo info; if (!PlayerDB.FindPlayerInfo(name, out info)) { player.Message("More than one player found matching \"{0}\"", name); } else if (info != null) { if (info.Banned) { player.Message("Player {0}&S is &WBANNED", info.GetClassyName()); } else { player.Message("Player {0}&S is NOT banned.", info.GetClassyName()); } if (!String.IsNullOrEmpty(info.BannedBy)) { player.Message(" Last ban by {0} on {1:dd MMM yyyy} ({2} ago).", info.BannedBy, info.BanDate, info.TimeSinceBan.ToMiniString()); if (info.BanReason.Length > 0) { player.Message(" Last ban reason: {0}", info.BanReason); } } if (!String.IsNullOrEmpty(info.UnbannedBy)) { player.Message(" Unbanned by {0} on {1:dd MMM yyyy} ({2} ago).", info.UnbannedBy, info.UnbanDate, info.TimeSinceUnban.ToMiniString()); if (info.UnbanReason.Length > 0) { player.Message(" Last unban reason: {0}", info.UnbanReason); } } if (info.BanDate != DateTime.MinValue) { TimeSpan banDuration; if (info.Banned) { banDuration = info.TimeSinceBan; } else { banDuration = info.UnbanDate.Subtract(info.BanDate); } player.Message(" Last ban duration: {0} days and {1:F1} hours.", (int)banDuration.TotalDays, banDuration.TotalHours); } } else { player.NoPlayerMessage(name); } } }