namespace Holo.Managers { using Holo; using Ion.Storage; using System; using System.Collections; using System.Data; using System.Runtime.InteropServices; using System.Text; using System.Threading; public static class rankManager { private static gameRank[] gameRanksBB; private static gameRank[] gameRanksSS; private static gameRank[] gameRanksWS; private static Hashtable userRanks; public static bool containsRankRight(byte rankID, string fuseRight) { userRank rank = (userRank) userRanks[rankID]; for (int i = 0; i < rank.fuseRights.Length; i++) { if (rank.fuseRights[i] == fuseRight) { return true; } } return false; } public static bool containsRight(byte rankID, string fuseRight, int userID) { userRank rank = (userRank) userRanks[rankID]; for (int i = 0; i < rank.fuseRights.Length; i++) { if (rank.fuseRights[i] == fuseRight) { return true; } } return userManager.getUser(userID)._fuserights.Contains(fuseRight); } public static string fuseRights(byte rankID, int userID) { string[] fuseRights = ((userRank) userRanks[rankID]).fuseRights; StringBuilder builder = new StringBuilder(); for (int i = 0; i < fuseRights.Length; i++) { builder.Append(fuseRights[i] + Convert.ToChar(2)); } foreach (string str in userManager.getUser(userID)._fuserights) { builder.Append(str + Convert.ToChar(2)); } return builder.ToString(); } public static gameRank getGameRank(bool isBattleBall, string Title) { gameRank[] gameRanksBB = null; if (isBattleBall) { gameRanksBB = rankManager.gameRanksBB; } else { gameRanksBB = gameRanksSS; } foreach (gameRank rank in gameRanksBB) { if (rank.Title == Title) { return rank; } } return new gameRank("holo.cast.gamerank.null", 0, 0); } public static string getGameRankTitle(bool isBattleBall, int Score) { gameRank[] gameRanksBB = null; if (isBattleBall) { gameRanksBB = rankManager.gameRanksBB; } else { gameRanksBB = gameRanksSS; } foreach (gameRank rank in gameRanksBB) { if ((Score >= rank.minPoints) && ((rank.maxPoints == 0) || (Score <= rank.maxPoints))) { return rank.Title; } } return "holo.cast.gamerank.null"; } public static void Init(bool Update) { DataTable table; DatabaseClient client; Out.WriteLine("Intializing user rank fuserights..."); userRanks = new Hashtable(); for (byte i = 1; i <= 7; i = (byte) (i + 1)) { userRanks.Add(i, new userRank(i)); } Out.WriteLine("Fuserights for 7 ranks loaded."); Out.WriteBlank(); Out.WriteLine("Initializing game ranks..."); using (client = Eucalypt.dbManager.GetClient()) { table = client.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC"); } gameRanksBB = new gameRank[table.Rows.Count]; int index = 0; foreach (DataRow row in table.Rows) { gameRanksBB[index] = new gameRank(Convert.ToString(row["title"]), Convert.ToInt32(row["minpoints"]), Convert.ToInt32(row["maxpoints"])); index++; } Out.WriteLine("Loaded " + gameRanksBB.Length + " ranks for game 'BattleBall'."); using (client = Eucalypt.dbManager.GetClient()) { table = client.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC"); } gameRanksSS = new gameRank[table.Rows.Count]; index = 0; foreach (DataRow row in table.Rows) { gameRanksSS[index] = new gameRank(Convert.ToString(row["title"]), Convert.ToInt32(row["minpoints"]), Convert.ToInt32(row["maxpoints"])); index++; } Out.WriteLine("Loaded " + gameRanksSS.Length + " ranks for game 'SnowStorm'."); using (client = Eucalypt.dbManager.GetClient()) { table = client.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'ws' ORDER BY id ASC"); } gameRanksWS = new gameRank[table.Rows.Count]; index = 0; foreach (DataRow row in table.Rows) { gameRanksWS[index] = new gameRank(Convert.ToString(row["title"]), Convert.ToInt32(row["minpoints"]), Convert.ToInt32(row["maxpoints"])); index++; } if (Update) { Thread.CurrentThread.Abort(); } } [StructLayout(LayoutKind.Sequential)] public struct gameRank { internal int minPoints; internal int maxPoints; internal string Title; internal gameRank(string Title, int minPoints, int maxPoints) { this.Title = Title; this.minPoints = minPoints; this.maxPoints = maxPoints; } } [StructLayout(LayoutKind.Sequential)] private struct userRank { internal string[] fuseRights; internal userRank(byte rankID) { DataColumn column; using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { column = client.getColumn("SELECT fuseright FROM system_fuserights WHERE minrank <= " + rankID); } this.fuseRights = dataHandling.dColToArray(column); } } } }