/// <summary> Adds a new rank to the list. Checks for duplicates. </summary> public static void AddRank(Rank rank) { if (rank == null) { throw new ArgumentNullException("rank"); } if (PlayerDB.IsLoaded) { throw new InvalidOperationException("You may not add ranks after PlayerDB has already been loaded."); } // check for duplicate rank names if (RanksByName.ContainsKey(rank.Name.ToLower())) { throw new RankDefinitionException("Duplicate definition for rank \"{0}\" (by Name) was ignored.", rank.Name); } if (RanksByID.ContainsKey(rank.ID)) { throw new RankDefinitionException("Duplicate definition for rank \"{0}\" (by ID) was ignored.", rank.Name); } Ranks.Add(rank); RanksByName[rank.Name.ToLower()] = rank; RanksByFullName[rank.GetFullName()] = rank; RanksByID[rank.ID] = rank; RebuildIndex(); }
public static bool DeleteRank(Rank deletedRank, Rank replacementRank) { if (deletedRank == null) { throw new ArgumentNullException("deletedRank"); } if (replacementRank == null) { throw new ArgumentNullException("replacementRank"); } if (PlayerDB.IsLoaded) { throw new InvalidOperationException("You may not add ranks after PlayerDB has already been loaded."); } bool rankLimitsChanged = false; Ranks.Remove(deletedRank); RanksByName.Remove(deletedRank.Name.ToLower()); RanksByID.Remove(deletedRank.ID); RanksByFullName.Remove(deletedRank.GetFullName()); LegacyRankMapping.Add(deletedRank.ID, replacementRank.ID); foreach (Rank rank in Ranks) { for (int i = 0; i < rank.PermissionLimits.Length; i++) { if (rank.GetLimit((Permission)i) == deletedRank) { rank.ResetLimit((Permission)i); rankLimitsChanged = true; } } } RebuildIndex(); return(rankLimitsChanged); }
public override string Process(string value) { if (value.Length == 0) { Rank defaultRank = GetBlankValueSubstitute(); if (defaultRank == null) { return(""); } else { return(defaultRank.GetFullName()); } } else { return(value); } }
internal string Serialize() { StringBuilder sb = new StringBuilder(); sb.Append(Name).Append(','); // 0 if (!LastIP.Equals(IPAddress.None)) { sb.Append(LastIP.ToString()); // 1 } sb.Append(','); sb.Append(Rank.GetFullName()).Append(','); // 2 RankChangeDate.ToTickString(sb).Append(','); // 3 Escape(RankChangedBy, sb).Append(','); // 4 if (Banned) { sb.Append('b'); // 5 } sb.Append(','); BanDate.ToTickString(sb).Append(','); // 6 Escape(BannedBy, sb).Append(','); // 7 UnbanDate.ToTickString(sb).Append(','); // 8 Escape(UnbannedBy, sb).Append(','); // 9 Escape(BanReason, sb).Append(','); // 10 Escape(UnbanReason, sb).Append(','); // 11 LastFailedLoginDate.ToTickString(sb).Append(','); // 12 if (!LastFailedLoginIP.Equals(IPAddress.None)) { sb.Append(LastFailedLoginIP.ToString()); // 13 } sb.Append(','); if (FailedLoginCount > 0) { sb.Append(FailedLoginCount); // 14 } sb.Append(','); FirstLoginDate.ToTickString(sb).Append(','); // 15 LastLoginDate.ToTickString(sb).Append(','); // 16 TotalTime.ToTickString(sb).Append(','); // 17 if (BlocksBuilt > 0) { sb.Append(BlocksBuilt); // 18 } sb.Append(','); if (BlocksDeleted > 0) { sb.Append(BlocksDeleted); // 19 } sb.Append(','); sb.Append(TimesVisited).Append(','); // 20 if (LinesWritten > 0) { sb.Append(LinesWritten); // 21 } sb.Append(',', 3); // 22-23 no longer in use if (PreviousRank != null) { sb.Append(PreviousRank.GetFullName()); // 24 } sb.Append(','); Escape(RankChangeReason, sb).Append(','); // 25 if (TimesKicked > 0) { sb.Append(TimesKicked); // 26 } sb.Append(','); if (TimesKickedOthers > 0) { sb.Append(TimesKickedOthers); // 27 } sb.Append(','); if (TimesBannedOthers > 0) { sb.Append(TimesBannedOthers); // 28 } sb.Append(','); sb.Append(ID).Append(','); // 29 sb.Append((int)RankChangeType).Append(','); // 30 LastKickDate.ToTickString(sb).Append(','); // 31 if (Online) { DateTime.UtcNow.ToTickString(sb); // 32 } else { LastSeen.ToTickString(sb); } sb.Append(','); if (BlocksDrawn > 0) { sb.Append(BlocksDrawn); // 33 } sb.Append(','); Escape(LastKickBy, sb).Append(','); // 34 Escape(LastKickReason, sb).Append(','); // 35 BannedUntil.ToTickString(sb); // 36 if (IsFrozen) { sb.Append(',').Append('f').Append(','); // 37 Escape(FrozenBy, sb).Append(','); // 38 FrozenOn.ToTickString(sb).Append(','); // 39 } else { sb.Append(',', 4); // 37-39 } if (MutedUntil > DateTime.UtcNow) { MutedUntil.ToTickString(sb).Append(','); // 40 Escape(MutedBy, sb).Append(','); // 41 } else { sb.Append(',', 2); // 40-41 } Escape(Password, sb).Append(','); // 42 if (Online) { sb.Append('o'); // 43 } sb.Append(','); if (BandwidthUseMode != BandwidthUseMode.Default) { sb.Append((int)BandwidthUseMode); // 44 } return(sb.ToString()); }