using System; using System.Data; using System.Text; using System.Collections; using System.Threading; using Ion.Storage; namespace Holo.Managers { /// /// Provides information about the various user ranks/levels, aswell as ranks for games such as 'BattleBall' and 'SnowStorm'. /// public static class rankManager { private static Hashtable userRanks; private static gameRank[] gameRanksBB; private static gameRank[] gameRanksSS; private static gameRank[] gameRanksWS; /// /// Initializes the various user ranks, aswell as the ranks for games such as 'BattleBall' and 'SnowStorm'. /// public static void Init(bool Update) { Out.WriteLine("Intializing user rank fuserights..."); userRanks = new Hashtable(); for (byte b = 1; b <= 8; b++) userRanks.Add(b, new userRank(b)); Out.WriteLine("Fuserights for 7 ranks loaded."); Out.WriteBlank(); Out.WriteLine("Initializing game ranks..."); DataTable dTable; using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { dTable = dbClient.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC"); } gameRanksBB = new gameRank[dTable.Rows.Count]; int i = 0; foreach (DataRow dRow in dTable.Rows) { gameRanksBB[i] = new gameRank(Convert.ToString(dRow["title"]), Convert.ToInt32(dRow["minpoints"]), Convert.ToInt32(dRow["maxpoints"])); i++; } Out.WriteLine("Loaded " + gameRanksBB.Length + " ranks for game 'BattleBall'."); using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { dTable = dbClient.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC"); } gameRanksSS = new gameRank[dTable.Rows.Count]; i = 0; foreach (DataRow dRow in dTable.Rows) { gameRanksSS[i] = new gameRank(Convert.ToString(dRow["title"]), Convert.ToInt32(dRow["minpoints"]), Convert.ToInt32(dRow["maxpoints"])); i++; } Out.WriteLine("Loaded " + gameRanksSS.Length + " ranks for game 'SnowStorm'."); using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { dTable = dbClient.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'ws' ORDER BY id ASC"); } gameRanksWS = new gameRank[dTable.Rows.Count]; i = 0; foreach (DataRow dRow in dTable.Rows) { gameRanksWS[i] = new gameRank(Convert.ToString(dRow["title"]), Convert.ToInt32(dRow["minpoints"]), Convert.ToInt32(dRow["maxpoints"])); i++; } //fOut.WriteLine("Loaded " + gameRanksWS.Length + " ranks for game 'Wobble Squabble'."); if (Update) Thread.CurrentThread.Abort(); } /// /// Returns the fuserights string for a certain user rank. /// /// The ID of the user rank. /// The ID of the user. public static string fuseRights(byte rankID, int userID) { string[] fuseRights = ((userRank)userRanks[rankID]).fuseRights; StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < fuseRights.Length; i++) strBuilder.Append(fuseRights[i] + Convert.ToChar(2)); foreach (string fuseright in userManager.getUser(userID)._fuserights) strBuilder.Append(fuseright + Convert.ToChar(2)); return strBuilder.ToString(); } /// /// Returns a bool that indicates if a certain user has a certain fuseright. /// /// The ID of the user rank. /// The fuseright to look for. /// The ID of the user. public static bool containsRight(byte rankID, string fuseRight, int userID) { userRank objRank = ((userRank)userRanks[rankID]); for (int i = 0; i < objRank.fuseRights.Length; i++) if (objRank.fuseRights[i] == fuseRight) return true; return userManager.getUser(userID)._fuserights.Contains(fuseRight); } /// /// Returns a bool that indicates if a certain user has a certain fuseright. /// /// The ID of the user rank. /// The fuseright to look for. /// public static bool containsRankRight(byte rankID, string fuseRight) { userRank objRank = ((userRank)userRanks[rankID]); for (int i = 0; i < objRank.fuseRights.Length; i++) if (objRank.fuseRights[i] == fuseRight) return true; return false; } public static gameRank getGameRank(bool isBattleBall, string Title) { gameRank[] Ranks = null; if (isBattleBall) Ranks = gameRanksBB; else Ranks = gameRanksSS; foreach (gameRank Rank in Ranks) if (Rank.Title == Title) return Rank; return new gameRank("holo.cast.gamerank.null", 0, 0); } /// /// Returns the game rank title as a string for a certain game type ('BattleBall' or 'SnowStorm') and score. /// /// Specifies if to lookup a 'BattleBall' game. If false, then the rank for a 'SnowStorm' game will be returned. /// The score to get the rank for. public static string getGameRankTitle(bool isBattleBall, int Score) { gameRank[] Ranks = null; if (isBattleBall) Ranks = gameRanksBB; else Ranks = gameRanksSS; foreach (gameRank Rank in Ranks) if (Score >= Rank.minPoints && (Rank.maxPoints == 0 || Score <= Rank.maxPoints)) return Rank.Title; return "holo.cast.gamerank.null"; } /// /// Represents a user rank. /// private struct userRank { internal string[] fuseRights; /// /// Initializes a user rank. /// /// The ID of the rank to initialize. internal userRank(byte rankID) { DataColumn dCol; using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { dCol = dbClient.getColumn("SELECT fuseright FROM system_fuserights WHERE minrank <= " + rankID); } fuseRights = dataHandling.dColToArray(dCol); } } /// /// Represents a game rank, containing the min and max score and the rank name. /// public struct gameRank { /// /// The minimum amount of points of this rank. /// internal int minPoints; /// /// The maximum amount of points of this rank. /// internal int maxPoints; /// /// The title of this rank. /// internal string Title; /// /// Initializes the gamerank with given values. /// /// The title of this rank. /// The minimum amount of points of this rank. /// The maximum amount of points of this rank. internal gameRank(string Title, int minPoints, int maxPoints) { this.Title = Title; this.minPoints = minPoints; this.maxPoints = maxPoints; } } } }