static void LoadZones(Map mapFile, OpticraftDataStore dataStore) { if (dataStore.Zones.Length == 0) { return; } // TODO: investigate side effects PlayerInfo conversionPlayer = new PlayerInfo("OpticraftConversion", RankManager.HighestRank, true, RankChangeType.AutoPromoted); foreach (OpticraftZone optiZone in dataStore.Zones) { //Make zone Zone fZone = new Zone { Name = optiZone.Name, }; BoundingBox bBox = new BoundingBox(optiZone.X1, optiZone.Y1, optiZone.Z1, optiZone.X2, optiZone.X2, optiZone.Z2); fZone.Create(bBox, conversionPlayer); //Min rank Rank minRank = RankManager.FindRank(optiZone.MinimumRank); if (minRank != null) { fZone.Controller.MinRank = minRank; } foreach (string playerName in optiZone.Builders) { //These are all lower case names if (!Player.IsValidName(playerName)) { continue; } PlayerInfo pInfo = PlayerDB.FindPlayerInfoExact(playerName); if (pInfo != null) { fZone.Controller.Include(pInfo); } } //Excluded names are not as of yet implemented in opticraft, but will be soon // So add compatibility for them when they arrive. if (optiZone.Excluded != null) { foreach (string playerName in optiZone.Excluded) { //These are all lower case names if (!Player.IsValidName(playerName)) { continue; } PlayerInfo pInfo = PlayerDB.FindPlayerInfoExact(playerName); if (pInfo != null) { fZone.Controller.Exclude(pInfo); } } } mapFile.AddZone(fZone); } }
void OnPermissionLimitChanged(object sender, EventArgs args) { if (Rank == null) return; Rank rankLimit = RankManager.FindRank(comboBox.SelectedIndex - 1); if (rankLimit == null) { Rank.ResetLimit(Permission); } else { Rank.SetLimit(Permission, rankLimit); } }
public static bool ShouldKeepHistory(World world) { Rank coolrank = RankManager.FindRank("cool"); if ( (world.BuildSecurity.MinRank == RankManager.LowestRank) || (coolrank != null && world.BuildSecurity.MinRank <= coolrank) || world.Name.ToLower().StartsWith("spritebuilder") ) { return(true); } return(false); }
public static void DoAutoPromo(SchedulerTask task) { string warpfile = "warp.txt"; try { if (!File.Exists(warpfile)) { return; } using (StreamReader reader = File.OpenText(warpfile)) { while (!reader.EndOfStream) { string[] fields = reader.ReadLine().Split(' '); if (fields.Length != 3) { continue; } try { PlayerInfo info = PlayerDB.FindPlayerInfoExact(fields[0]); if (info == null) { continue; } Rank newRank = RankManager.FindRank(fields[1]); if (newRank == null) { continue; } if (info.Rank == newRank) { continue; } info.ChangeRank(Player.Console, newRank, "PROMOTION FROM FORUM (" + fields[2] + ")", true, true, false); } catch (Exception) { } } } } catch (Exception) { } try { File.Delete(warpfile); } catch (Exception) { } }
static void ZoneEditHandler(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.WorldMap.Zones.Find(zoneName); if (zone == null) { player.MessageNoZone(zoneName); return; } string name; while ((name = cmd.Next()) != null) { if (name.StartsWith("+")) { if (name.Length == 1) { CdZoneEdit.PrintUsage(player); break; } PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1)); if (info == null) { 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.ClassyName); continue; } } switch (zone.Controller.Include(info)) { case PermissionOverride.Deny: player.Message("{0}&S is no longer excluded from zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now included in zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already included in zone {1}", info.ClassyName, zone.ClassyName); break; } } else if (name.StartsWith("-")) { if (name.Length == 1) { CdZoneEdit.PrintUsage(player); break; } PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1)); if (info == null) { return; } switch (zone.Controller.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already excluded from zone {1}", info.ClassyName, zone.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now excluded from zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is no longer included in zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; } } else if (name.ToLower().StartsWith("msg=")) { zone.Message = name.Substring(4) + " " + (cmd.NextAll() ?? ""); changesWereMade = true; player.Message("Zedit: Custom denied messaged changed to '" + zone.Message + "'"); break; } else { Rank minRank = RankManager.FindRank(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.ClassyName); changesWereMade = true; } } else { player.MessageNoRank(name); } } } if (changesWereMade) { zone.Edit(player.Info); } else { player.Message("No changes were made to the zone."); } }
static void ZoneAddHandler(Player player, Command cmd) { World playerWorld = player.World; if (playerWorld == null) { PlayerOpException.ThrowNoWorld(player); } string givenZoneName = cmd.Next(); if (givenZoneName == null) { CdZoneAdd.PrintUsage(player); return; } if (!player.Info.Rank.AllowSecurityCircumvention) { SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed(player.Info); switch (buildCheck) { case SecurityCheckResult.BlackListed: player.Message("Cannot add zones to world {0}&S: You are barred from building here.", playerWorld.ClassyName); return; case SecurityCheckResult.RankTooLow: player.Message("Cannot add zones to world {0}&S: You are not allowed to build here.", playerWorld.ClassyName); return; //case SecurityCheckResult.RankTooHigh: } } Zone newZone = new Zone(); ZoneCollection zoneCollection = player.WorldMap.Zones; if (givenZoneName.StartsWith("+")) { // personal zone (/ZAdd +Name) givenZoneName = givenZoneName.Substring(1); // Find the target player PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, givenZoneName); if (info == null) { return; } // Make sure that the name is not taken already. // If a zone named after the player already exists, try adding a number after the name (e.g. "Notch2") newZone.Name = info.Name; for (int i = 2; zoneCollection.Contains(newZone.Name); i++) { newZone.Name = givenZoneName + i; } newZone.Controller.MinRank = info.Rank.NextRankUp ?? info.Rank; newZone.Controller.Include(info); player.Message("Zone: Creating a {0}+&S zone for player {1}&S.", newZone.Controller.MinRank.ClassyName, info.ClassyName); } else { // Adding an ordinary, rank-restricted zone. if (!World.IsValidName(givenZoneName)) { player.Message("\"{0}\" is not a valid zone name", givenZoneName); return; } if (zoneCollection.Contains(givenZoneName)) { player.Message("A zone with this name already exists. Use &H/ZEdit&S to edit."); return; } newZone.Name = givenZoneName; string rankName = cmd.Next(); if (rankName == null) { player.Message("No rank was specified. See &H/Help zone"); return; } Rank minRank = RankManager.FindRank(rankName); if (minRank != null) { string name; while ((name = cmd.Next()) != null) { if (name.Length == 0) { continue; } if (name.ToLower().StartsWith("msg=")) { newZone.Message = name.Substring(4) + " " + (cmd.NextAll() ?? ""); player.Message("Zone: Custom denied messaged changed to '" + newZone.Message + "'"); break; } PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1)); if (info == null) { return; } if (name.StartsWith("+")) { newZone.Controller.Include(info); } else if (name.StartsWith("-")) { newZone.Controller.Exclude(info); } } newZone.Controller.MinRank = minRank; } else { player.MessageNoRank(rankName); return; } } player.Message("Zone " + newZone.ClassyName + "&S: Place a block or type &H/Mark&S to use your location."); player.SelectionStart(2, ZoneAddCallback, newZone, CdZoneAdd.Permissions); }
internal static void RealmBuild(Player player, Command cmd, string worldName, string name, string nameIfRankIsName) { // Print information about the current realm if (worldName == null) { player.Message(player.World == null ? "When calling /wbuild from console, you must specify a realm name." : 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("+")) { if (!PlayerDB.FindPlayerInfo(name.Substring(1), out var 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); 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); 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); 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("-")) { if (!PlayerDB.FindPlayerInfo(name.Substring(1), out var info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } 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); 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); 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); 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) { player.Message(player.World == null ? "Error." : 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("+")) { if (!PlayerDB.FindPlayerInfo(name.Substring(1), out var info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } 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); 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); 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); 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("-")) { if (!PlayerDB.FindPlayerInfo(name.Substring(1), out var info)) { player.Message("More than one player found matching \"{0}\"", name.Substring(1)); continue; } 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); 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); 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); 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) { return; } 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(); }
public static void RealmLoad(Player player, Command cmd, string fileName, string worldName) { if (worldName == null && player.World == null) { player.Message("When using /realm from console, you must specify the realm name."); return; } if (fileName == null) { // No params given at all return; } string fullFileName = WorldManager.FindMapFile(player, fileName); if (fullFileName == null) { return; } // Loading map into current realm if (worldName == null) { if (!cmd.IsConfirmed) { player.Confirm(cmd, "About to replace THIS REALM with \"{0}\".", fileName); return; } Map map; try { map = MapUtility.Load(fullFileName); } catch (Exception ex) { player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message); return; } World realm = player.World; // Loading to current realm realm.MapChangedBy = player.Name; realm.ChangeMap(map); realm.Players.Message(player, "{0}&S loaded a new map for this realm.", 0, player.ClassyName); player.MessageNow("New map loaded for the realm {0}", realm.ClassyName); Logger.Log(LogType.UserActivity, "{0} loaded new map for realm \"{1}\" from {2}", player.Name, realm.Name, fileName); realm.IsHidden = false; realm.IsRealm = true; WorldManager.SaveWorldList(); } else { // Loading to some other (or new) realm if (!World.IsValidName(worldName)) { player.MessageInvalidWorldName(worldName); return; } string buildRankName = cmd.Next(); string accessRankName = cmd.Next(); Rank buildRank = RankManager.DefaultBuildRank; Rank accessRank = null; if (buildRankName != null) { buildRank = RankManager.FindRank(buildRankName); if (buildRank == null) { player.MessageNoRank(buildRankName); return; } if (accessRankName != null) { accessRank = RankManager.FindRank(accessRankName); if (accessRank == null) { player.MessageNoRank(accessRankName); return; } } } // Retype realm name, if needed if (worldName == "-") { if (player.LastUsedWorldName != null) { worldName = player.LastUsedWorldName; } else { player.Message("Cannot repeat realm name: you haven't used any names yet."); return; } } lock (WorldManager.SyncRoot) { World realm = WorldManager.FindWorldExact(worldName); if (realm != null) { player.LastUsedWorldName = realm.Name; // Replacing existing realm's map if (!cmd.IsConfirmed) { player.Confirm(cmd, "About to replace realm map for {0}&S with \"{1}\".", realm.ClassyName, fileName); return; } Map map; try { map = MapUtility.Load(fullFileName); realm.IsHidden = false; realm.IsRealm = true; WorldManager.SaveWorldList(); } catch (Exception ex) { player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message); return; } try { realm.MapChangedBy = player.Name; realm.ChangeMap(map); realm.IsHidden = false; realm.IsRealm = true; WorldManager.SaveWorldList(); } catch (WorldOpException ex) { Logger.Log(LogType.Error, "Could not complete RealmLoad operation: {0}", ex.Message); player.Message("&WRealmLoad: {0}", ex.Message); return; } realm.Players.Message(player, "{0}&S loaded a new map for the realm {1}", 0, player.ClassyName, realm.ClassyName); player.MessageNow("New map for the realm {0}&S has been loaded.", realm.ClassyName); Logger.Log(LogType.UserActivity, "{0} loaded new map for realm \"{1}\" from {2}", player.Name, realm.Name, fullFileName); } else { // Adding a new realm string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm"); if (!cmd.IsConfirmed && File.Exists(targetFullFileName) && // target file already exists !Paths.Compare(targetFullFileName, fullFileName)) { // and is different from sourceFile player.Confirm(cmd, "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".", Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName)); return; } Map map; try { map = MapUtility.Load(fullFileName); //realm.IsHidden = false; //realm.IsRealm = true; //WorldManager.SaveWorldList(); } catch (Exception ex) { player.MessageNow("Could not load \"{0}\": {1}: {2}", fileName, ex.GetType().Name, ex.Message); return; } World newWorld; try { newWorld = WorldManager.AddWorld(player, worldName, map, false); } catch (WorldOpException ex) { player.Message("RealmLoad: {0}", ex.Message); return; } player.LastUsedWorldName = worldName; newWorld.BuildSecurity.MinRank = buildRank; if (accessRank == null) { newWorld.AccessSecurity.ResetMinRank(); } else { newWorld.AccessSecurity.MinRank = accessRank; } newWorld.BlockDB.AutoToggleIfNeeded(); if (BlockDB.IsEnabledGlobally && newWorld.BlockDB.IsEnabled) { player.Message("BlockDB is now auto-enabled on realm {0}", newWorld.ClassyName); } newWorld.LoadedBy = player.Name; newWorld.LoadedOn = DateTime.UtcNow; Server.Message("{0}&S created a new realm named {1}", player.ClassyName, newWorld.ClassyName); Logger.Log(LogType.UserActivity, "{0} created a new realm named \"{1}\" (loaded from \"{2}\")", player.Name, worldName, fileName); newWorld.IsHidden = false; newWorld.IsRealm = true; WorldManager.SaveWorldList(); player.MessageNow("Access permission is {0}+&S, and build permission is {1}+", newWorld.AccessSecurity.MinRank.ClassyName, newWorld.BuildSecurity.MinRank.ClassyName); } } } Server.RequestGC(); }
void SaveConfig() { // General Config.TrySetValue(ConfigKey.ServerName, tServerName.Text); Config.TrySetValue(ConfigKey.MOTD, tMOTD.Text); Config.TrySetValue(ConfigKey.MaxPlayers, nMaxPlayers.Value); Config.TrySetValue(ConfigKey.MaxPlayersPerWorld, nMaxPlayersPerWorld.Value); if (cDefaultRank.SelectedIndex == 0) { Config.TrySetValue(ConfigKey.DefaultRank, ""); } else { Config.TrySetValue(ConfigKey.DefaultRank, RankManager.FindRank(cDefaultRank.SelectedIndex - 1).GetFullName()); } Config.TrySetValue(ConfigKey.IsPublic, cPublic.SelectedIndex == 0); Config.TrySetValue(ConfigKey.Port, nPort.Value); if (xIP.Checked) { ConfigKey.IP.TrySetValue(tIP.Text); } else { ConfigKey.IP.ResetValue(); } Config.TrySetValue(ConfigKey.UploadBandwidth, nUploadBandwidth.Value); if (xAnnouncements.Checked) { Config.TrySetValue(ConfigKey.AnnouncementInterval, nAnnouncements.Value); } else { Config.TrySetValue(ConfigKey.AnnouncementInterval, 0); } // UpdaterSettingsWindow ConfigKey.UpdaterMode.TrySetValue(updaterWindow.UpdaterMode); ConfigKey.BackupBeforeUpdate.TrySetValue(updaterWindow.BackupBeforeUpdate); ConfigKey.RunBeforeUpdate.TrySetValue(updaterWindow.RunBeforeUpdate); ConfigKey.RunAfterUpdate.TrySetValue(updaterWindow.RunAfterUpdate); // Chat Config.TrySetValue(ConfigKey.SystemMessageColor, Color.GetName(colorSys)); Config.TrySetValue(ConfigKey.HelpColor, Color.GetName(colorHelp)); Config.TrySetValue(ConfigKey.SayColor, Color.GetName(colorSay)); Config.TrySetValue(ConfigKey.AnnouncementColor, Color.GetName(colorAnnouncement)); Config.TrySetValue(ConfigKey.PrivateMessageColor, Color.GetName(colorPM)); Config.TrySetValue(ConfigKey.WarningColor, Color.GetName(colorWarning)); Config.TrySetValue(ConfigKey.MeColor, Color.GetName(colorMe)); Config.TrySetValue(ConfigKey.ShowJoinedWorldMessages, xShowJoinedWorldMessages.Checked); Config.TrySetValue(ConfigKey.RankColorsInWorldNames, xRankColorsInWorldNames.Checked); Config.TrySetValue(ConfigKey.RankColorsInChat, xRankColorsInChat.Checked); Config.TrySetValue(ConfigKey.RankPrefixesInChat, xRankPrefixesInChat.Checked); Config.TrySetValue(ConfigKey.RankPrefixesInList, xRankPrefixesInList.Checked); // Worlds if (cDefaultBuildRank.SelectedIndex == 0) { Config.TrySetValue(ConfigKey.DefaultBuildRank, ""); } else { Config.TrySetValue(ConfigKey.DefaultBuildRank, RankManager.FindRank(cDefaultBuildRank.SelectedIndex - 1).GetFullName()); } if (xMapPath.Checked) { Config.TrySetValue(ConfigKey.MapPath, tMapPath.Text); } else { Config.TrySetValue(ConfigKey.MapPath, ConfigKey.MapPath.GetDefault()); } // Security WriteEnum <NameVerificationMode>(cVerifyNames, ConfigKey.VerifyNames); if (xMaxConnectionsPerIP.Checked) { Config.TrySetValue(ConfigKey.MaxConnectionsPerIP, nMaxConnectionsPerIP.Value); } else { Config.TrySetValue(ConfigKey.MaxConnectionsPerIP, 0); } Config.TrySetValue(ConfigKey.AllowUnverifiedLAN, xAllowUnverifiedLAN.Checked); Config.TrySetValue(ConfigKey.AntispamMessageCount, nAntispamMessageCount.Value); Config.TrySetValue(ConfigKey.AntispamInterval, nAntispamInterval.Value); Config.TrySetValue(ConfigKey.AntispamMuteDuration, nSpamMute.Value); if (xAntispamKicks.Checked) { Config.TrySetValue(ConfigKey.AntispamMaxWarnings, nAntispamMaxWarnings.Value); } else { Config.TrySetValue(ConfigKey.AntispamMaxWarnings, 0); } Config.TrySetValue(ConfigKey.RequireKickReason, xRequireKickReason.Checked); Config.TrySetValue(ConfigKey.RequireBanReason, xRequireBanReason.Checked); Config.TrySetValue(ConfigKey.RequireRankChangeReason, xRequireRankChangeReason.Checked); Config.TrySetValue(ConfigKey.AnnounceKickAndBanReasons, xAnnounceKickAndBanReasons.Checked); Config.TrySetValue(ConfigKey.AnnounceRankChanges, xAnnounceRankChanges.Checked); Config.TrySetValue(ConfigKey.AnnounceRankChangeReasons, xAnnounceRankChangeReasons.Checked); if (cPatrolledRank.SelectedIndex == 0) { Config.TrySetValue(ConfigKey.PatrolledRank, ""); } else { Config.TrySetValue(ConfigKey.PatrolledRank, RankManager.FindRank(cPatrolledRank.SelectedIndex - 1).GetFullName()); } Config.TrySetValue(ConfigKey.PaidPlayersOnly, xPaidPlayersOnly.Checked); // Saving & Backups if (xSaveInterval.Checked) { Config.TrySetValue(ConfigKey.SaveInterval, nSaveInterval.Value); } else { Config.TrySetValue(ConfigKey.SaveInterval, 0); } Config.TrySetValue(ConfigKey.BackupOnStartup, xBackupOnStartup.Checked); Config.TrySetValue(ConfigKey.BackupOnJoin, xBackupOnJoin.Checked); Config.TrySetValue(ConfigKey.BackupOnlyWhenChanged, xBackupOnlyWhenChanged.Checked); if (xBackupInterval.Checked) { Config.TrySetValue(ConfigKey.BackupInterval, nBackupInterval.Value); } else { Config.TrySetValue(ConfigKey.BackupInterval, 0); } if (xMaxBackups.Checked) { Config.TrySetValue(ConfigKey.MaxBackups, nMaxBackups.Value); } else { Config.TrySetValue(ConfigKey.MaxBackups, 0); } if (xMaxBackupSize.Checked) { Config.TrySetValue(ConfigKey.MaxBackupSize, nMaxBackupSize.Value); } else { Config.TrySetValue(ConfigKey.MaxBackupSize, 0); } // Logging WriteEnum <LogSplittingType>(cLogMode, ConfigKey.LogMode); if (xLogLimit.Checked) { Config.TrySetValue(ConfigKey.MaxLogs, nLogLimit.Value); } else { Config.TrySetValue(ConfigKey.MaxLogs, "0"); } foreach (ListViewItem item in vConsoleOptions.Items) { Logger.ConsoleOptions[item.Index] = item.Checked; } foreach (ListViewItem item in vLogFileOptions.Items) { Logger.LogFileOptions[item.Index] = item.Checked; } // IRC Config.TrySetValue(ConfigKey.IRCBotEnabled, xIRCBotEnabled.Checked); Config.TrySetValue(ConfigKey.IRCBotNetwork, tIRCBotNetwork.Text); Config.TrySetValue(ConfigKey.IRCBotPort, nIRCBotPort.Value); Config.TrySetValue(ConfigKey.IRCDelay, nIRCDelay.Value); Config.TrySetValue(ConfigKey.IRCBotChannels, tIRCBotChannels.Text); Config.TrySetValue(ConfigKey.IRCBotNick, tIRCBotNick.Text); Config.TrySetValue(ConfigKey.IRCRegisteredNick, xIRCRegisteredNick.Checked); Config.TrySetValue(ConfigKey.IRCNickServ, tIRCNickServ.Text); Config.TrySetValue(ConfigKey.IRCNickServMessage, tIRCNickServMessage.Text); Config.TrySetValue(ConfigKey.IRCBotAnnounceIRCJoins, xIRCBotAnnounceIRCJoins.Checked); Config.TrySetValue(ConfigKey.IRCBotAnnounceServerJoins, xIRCBotAnnounceServerJoins.Checked); Config.TrySetValue(ConfigKey.IRCBotAnnounceServerEvents, xIRCBotAnnounceServerEvents.Checked); Config.TrySetValue(ConfigKey.IRCBotForwardFromIRC, xIRCBotForwardFromIRC.Checked); Config.TrySetValue(ConfigKey.IRCBotForwardFromServer, xIRCBotForwardFromServer.Checked); Config.TrySetValue(ConfigKey.IRCMessageColor, Color.GetName(colorIRC)); Config.TrySetValue(ConfigKey.IRCUseColor, xIRCUseColor.Checked); // advanced Config.TrySetValue(ConfigKey.SubmitCrashReports, xSubmitCrashReports.Checked); Config.TrySetValue(ConfigKey.RelayAllBlockUpdates, xRelayAllBlockUpdates.Checked); Config.TrySetValue(ConfigKey.NoPartialPositionUpdates, xNoPartialPositionUpdates.Checked); Config.TrySetValue(ConfigKey.TickInterval, Convert.ToInt32(nTickInterval.Value)); switch (cProcessPriority.SelectedIndex) { case 0: ConfigKey.ProcessPriority.ResetValue(); break; case 1: ConfigKey.ProcessPriority.TrySetValue(ProcessPriorityClass.High); break; case 2: ConfigKey.ProcessPriority.TrySetValue(ProcessPriorityClass.AboveNormal); break; case 3: ConfigKey.ProcessPriority.TrySetValue(ProcessPriorityClass.Normal); break; case 4: ConfigKey.ProcessPriority.TrySetValue(ProcessPriorityClass.BelowNormal); break; case 5: ConfigKey.ProcessPriority.TrySetValue(ProcessPriorityClass.Idle); break; } Config.TrySetValue(ConfigKey.BlockUpdateThrottling, Convert.ToInt32(nThrottling.Value)); Config.TrySetValue(ConfigKey.LowLatencyMode, xLowLatencyMode.Checked); if (xMaxUndo.Checked) { Config.TrySetValue(ConfigKey.MaxUndo, Convert.ToInt32(nMaxUndo.Value)); } else { Config.TrySetValue(ConfigKey.MaxUndo, 0); } Config.TrySetValue(ConfigKey.ConsoleName, tConsoleName.Text); SaveWorldList(); }
static MenuState ShowRanks() { Refresh("Rank list"); TextMenu menu = new TextMenu(); for (int i = 0; i < RankManager.Ranks.Count; i++) { Rank rank = RankManager.Ranks[i]; TextOption derp = menu.AddOption(i + 1, rank.Name, rank); derp.ForeColor = Color.ToConsoleColor(rank.Color); if (derp.ForeColor == ConsoleColor.Black) { derp.BackColor = ConsoleColor.Gray; } } TextOption optionErase = null, optionRaise = null, optionLower = null; menu.Column = Column.Right; TextOption optionBack = menu.AddOption("B", "Back to sections"); menu.AddSpacer(); TextOption optionAdd = menu.AddOption("A", "Add rank (blank)"); TextOption optionCopy = menu.AddOption("C", "Copy existing rank"); if (RankManager.Ranks.Count > 1) { optionErase = menu.AddOption("E", "Erase rank"); } if (RankManager.Ranks.Count > 1) { menu.AddSpacer(); optionRaise = menu.AddOption("R", "Raise rank in hierarchy"); optionLower = menu.AddOption("L", "Lower rank in hierarchy"); } menu.AddSpacer(); TextOption optionDefaults = menu.AddOption("D", "Use defaults"); TextOption choice = menu.Show(); if (choice == optionBack) { return(MenuState.SectionList); } else if (choice == optionAdd) { Console.Write("Enter new rank name: "); while (true) { string rankName = Console.ReadLine(); if (Rank.IsValidRankName(rankName)) { if (RankManager.FindRank(rankName) != null) { WriteWarning("A rank with this name already exists."); } else { Rank newRank = new Rank(rankName, RankManager.GenerateID()); AddRank(newRank); break; } } else { WriteWarning("Rank names must be between 1 and 16 characters long, " + "and must contain only letters, digits, and underscores."); } } } else if (choice == optionCopy) { int rankToCopyIndex = TextMenu.ShowNumber("Which rank to copy?", 1, RankManager.Ranks.Count); if (rankToCopyIndex != -1) { Console.WriteLine(); Rank rankToCopy = RankManager.Ranks[rankToCopyIndex - 1]; Console.Write("Enter new rank name: "); while (true) { string rankName = Console.ReadLine(); if (Rank.IsValidRankName(rankName)) { if (RankManager.FindRank(rankName) != null) { WriteWarning("A rank with this name already exists."); } else { Rank newRank = new Rank(rankName, RankManager.GenerateID(), rankToCopy); AddRank(newRank); break; } } else { WriteWarning("Rank names must be between 1 and 16 characters long, " + "and must contain only letters, digits, and underscores."); } } } } else if (choice == optionErase) { EraseRank(); } else if (choice == optionRaise) { int rankToRaise = TextMenu.ShowNumber("Which rank to raise?", 2, RankManager.Ranks.Count); if (rankToRaise != -1) { RankManager.RaiseRank(RankManager.Ranks[rankToRaise - 1]); } } else if (choice == optionLower) { int rankToLower = TextMenu.ShowNumber("Which rank to lower?", 1, RankManager.Ranks.Count - 1); if (rankToLower != -1) { RankManager.LowerRank(RankManager.Ranks[rankToLower - 1]); } } else if (choice == optionDefaults) { if (TextMenu.ShowYesNo("Reset all ranks to defaults?")) { RankManager.ResetToDefaults(); } } else { currentRank = (Rank)choice.Tag; return(MenuState.RankDetails); } return(MenuState.Ranks); }