namespace Otaku.Managers { using Otaku; using System; using System.Collections; using System.Runtime.InteropServices; using System.Text; public static class rankManager { private static gameRank[] gameRanksBB; private static gameRank[] gameRanksSS; private static Hashtable userRanks; public static bool containsRight(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 string fuseRights(byte rankID) { 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)); } 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("Otaku.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 "Otaku.cast.gamerank.null"; } public static void Init() { 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..."); string[] strArray = DB.runReadColumn("SELECT title FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0); int[] numArray = DB.runReadColumn("SELECT minpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0, null); int[] numArray2 = DB.runReadColumn("SELECT maxpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0, null); gameRanksBB = new gameRank[strArray.Length]; for (int j = 0; j < gameRanksBB.Length; j++) { gameRanksBB[j] = new gameRank(strArray[j], numArray[j], numArray2[j]); Out.WriteLine(string.Concat(new object[] { "Loaded gamerank '", strArray[j], "' [", numArray[j], "-", numArray2[j], "] for game 'BattleBall'." })); } Out.WriteLine("Loaded " + strArray.Length + " ranks for game 'BattleBall'."); strArray = DB.runReadColumn("SELECT title FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0); numArray = DB.runReadColumn("SELECT minpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0, null); numArray2 = DB.runReadColumn("SELECT maxpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0, null); gameRanksSS = new gameRank[strArray.Length]; for (int k = 0; k < gameRanksSS.Length; k++) { gameRanksSS[k] = new gameRank(strArray[k], numArray[k], numArray2[k]); Out.WriteLine(string.Concat(new object[] { "Loaded gamerank '", strArray[k], "' [", numArray[k], "-", numArray2[k], "] for game 'SnowStorm'." })); } Out.WriteLine("Loaded " + strArray.Length + " ranks for game 'SnowStorm'."); } [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) { this.fuseRights = DB.runReadColumn("SELECT fuseright FROM system_fuserights WHERE minrank <= " + rankID, 0); } } } }