private void HandleUsers(RMSQLiteConnection DB) { AddToLog("Importing users"); SQL = "SELECT * FROM UserTbl U INNER JOIN GroupTbl G ON U.GroupID = G.GroupID"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { // UserID, GroupID, RLoginHostID, UserName, Password, RealName, Email, EmailVerification, EmailVerified, RegistrationDate string AccessLevel = DB.Reader["AccessLevel"].ToString(); string Alias = DB.Reader["UserName"].ToString(); string PasswordSalt = StringUtils.RandomString(100); string PasswordHash = UserInfo.GetPasswordHash(DB.Reader["Password"].ToString(), PasswordSalt, _PasswordPepper); string UserId = DB.Reader["UserID"].ToString(); using (IniFile Ini = new IniFile(StringUtils.PathCombine(ProcessUtils.StartupPath, "users", UserInfo.SafeAlias(Alias.ToLower()) + ".ini"))) { Ini.WriteString("USER", "AccessLevel", AccessLevel); Ini.WriteString("USER", "Alias", Alias); Ini.WriteString("USER", "PasswordSalt", PasswordSalt); Ini.WriteString("USER", "PasswordHash", PasswordHash); Ini.WriteString("USER", "UserId", UserId); AddToLog(" - Added Alias = " + Alias); AddToLog(" AccessLevel = " + AccessLevel); AddToLog(" PasswordSalt = " + PasswordSalt); AddToLog(" PasswordHash = " + PasswordHash); AddToLog(" UserId = " + UserId); AddToLog(""); } } DB.Reader.Close(); }
private void HandleMenus(RMSQLiteConnection DB) { AddToLog("Importing menus"); // Get menu names List<string> MenuNames = new List<string>(); SQL = "SELECT DISTINCT MenuName FROM MenuTbl WHERE MenuName <> 'GLOBAL' ORDER BY MenuName"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { MenuNames.Add(DB.Reader["MenuName"].ToString()); } DB.Reader.Close(); // Erase old menus foreach (string MenuName in MenuNames) { string FileName = StringUtils.PathCombine(ProcessUtils.StartupPath, "menus", MenuName.ToLower().Replace(" ", "_") + ".ini"); if (File.Exists(FileName)) FileUtils.FileDelete(FileName); } // Add hotkeys to menus SQL = "SELECT * FROM MenuTbl ORDER BY MenuName, HotKey"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { string HotKey = DB.Reader["HotKey"].ToString(); string Name = DB.Reader["Description"].ToString(); string Action = CommandToAction(DB.Reader["Command"].ToString()); string Parameters = DB.Reader["Parameters"].ToString(); string RequiredAccess = DB.Reader["RequiredAccess"].ToString(); // Modify parameters, for those that need it if (Action == "ChangeMenu") { Parameters = Parameters.Replace(" ", "_"); } else if (Action == "RunDoor") { Parameters = GetSafeDoorFileName(Name); } if (Action == DB.Reader["Command"].ToString()) { AddToLog(" - Ignoring command that no longer exists (" + Action + ")"); } else { List<string> MenuNamesToUpdate = new List<string>(); if (DB.Reader["MenuName"].ToString().ToUpper() == "GLOBAL") { foreach (string MenuName in MenuNames) { // Don't add the global CHANGE_MENU commands to the menu we're wanting to change to // i.e. Don't add a CHANGE_MENU MAIN to the MAIN menu if ((Action != "ChangeMenu") || (Parameters.ToUpper() != MenuName.ToUpper())) { MenuNamesToUpdate.Add(MenuName); } } } else { MenuNamesToUpdate.Add(DB.Reader["MenuName"].ToString()); } foreach (string MenuNameToUpdate in MenuNamesToUpdate) { using (IniFile Ini = new IniFile(StringUtils.PathCombine(ProcessUtils.StartupPath, "menus", MenuNameToUpdate.ToLower().Replace(" ", "_") + ".ini"))) { Ini.WriteString(HotKey, "Name", Name); Ini.WriteString(HotKey, "Action", Action); Ini.WriteString(HotKey, "Parameters", Parameters); Ini.WriteString(HotKey, "RequiredAccess", RequiredAccess); AddToLog(" - Added Menu = " + MenuNameToUpdate); AddToLog(" HotKey = " + HotKey); AddToLog(" Name = " + Name); AddToLog(" Action = " + Action); AddToLog(" Parameters = " + Parameters); AddToLog(" RequiredAccess = " + RequiredAccess); } } } } DB.Reader.Close(); // RecordID, MenuName, HotKey, Description, Command, Parameters, RequiredAccess AddToLog(""); }
private void HandleDoors(RMSQLiteConnection DB) { AddToLog("Importing settings for doors.ini"); SQL = "SELECT * FROM MenuTbl WHERE Command IN ('EXEC', 'EXEC_NETFOSS', 'EXEC_MSYNCFOS')"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { string Name = DB.Reader["Description"].ToString(); string[] CommandAndParameters = DB.Reader["Parameters"].ToString().Split(' '); string Command = CommandAndParameters[0]; string Parameters = string.Join(" ", CommandAndParameters, 1, CommandAndParameters.Length - 1); bool Native = DB.Reader["Command"].ToString() == "EXEC"; using (IniFile Ini = new IniFile(StringUtils.PathCombine(ProcessUtils.StartupPath, "doors", GetSafeDoorFileName(Name) + ".ini"))) { Ini.WriteString("DOOR", "Name", Name); Ini.WriteString("DOOR", "Command", Command); Ini.WriteString("DOOR", "Parameters", Parameters); Ini.WriteString("DOOR", "Native", Native.ToString()); Ini.WriteString("DOOR", "ForceQuitDelay", "5"); Ini.WriteString("DOOR", "WindowStyle", "Minimized"); } AddToLog(" - Added Name = " + Name); AddToLog(" Command = " + Command); AddToLog(" Parameters = " + Parameters); AddToLog(" Native = " + Native.ToString()); } DB.Reader.Close(); AddToLog(""); }
private void HandleLogOffOrOnProcessDotIni(RMSQLiteConnection DB, string offOrOn, string inOrOut) { AddToLog("Importing settings for log" + offOrOn + "process.ini"); using (IniFile Ini = new IniFile(StringUtils.PathCombine(ProcessUtils.StartupPath, "config", "log" + offOrOn + "process.ini"))) { // Erase old sections string[] Sections = Ini.ReadSections(); foreach (string Section in Sections) { Ini.EraseSection(Section); } SQL = "SELECT * FROM Log" + inOrOut + "ProcessTbl ORDER BY StepNumber"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { string Name = "Log" + offOrOn + "Process" + DB.Reader["StepNumber"].ToString(); string Action = CommandToAction(DB.Reader["Command"].ToString()); string Parameters = DB.Reader["Parameters"].ToString(); string RequiredAccess = DB.Reader["RequiredAccess"].ToString(); if (Action == DB.Reader["Command"].ToString()) { AddToLog(" - Ignoring command that no longer exists (" + Action + ")"); } else { // See if we need to add the logon/off process as a door if (Action == "RunDoor") { string[] CommandAndParameters = DB.Reader["Parameters"].ToString().Split(' '); string Command = CommandAndParameters[0]; string DoorParameters = string.Join(" ", CommandAndParameters, 1, CommandAndParameters.Length - 1); bool Native = DB.Reader["Command"].ToString() == "EXEC"; using (IniFile DoorIni = new IniFile(StringUtils.PathCombine(ProcessUtils.StartupPath, "doors", GetSafeDoorFileName(Name) + ".ini"))) { DoorIni.WriteString("DOOR", "Name", Name); DoorIni.WriteString("DOOR", "Command", Command); DoorIni.WriteString("DOOR", "Parameters", DoorParameters); DoorIni.WriteString("DOOR", "Native", Native.ToString()); DoorIni.WriteString("DOOR", "ForceQuitDelay", "5"); DoorIni.WriteString("DOOR", "WindowStyle", "Minimized"); } AddToLog(" - Added Door = " + Name); AddToLog(" Command = " + Command); AddToLog(" Parameters = " + DoorParameters); AddToLog(" Native = " + Native.ToString()); // Override settings to be used below Action = "RunDoor"; Parameters = Name; } Ini.WriteString(Name, "Name", Name); Ini.WriteString(Name, "Action", Action); Ini.WriteString(Name, "Parameters", Parameters); Ini.WriteString(Name, "RequiredAccess", RequiredAccess); AddToLog(" - Added Name = " + Name); AddToLog(" Action = " + Action); AddToLog(" Parameters = " + Parameters); AddToLog(" RequiredAccess = " + RequiredAccess); } } DB.Reader.Close(); } AddToLog(""); }
// Show the high scores static void HighScores() { Door.TextAttr(7); Door.ClrScr(); Door.GotoXY(25, 2); Door.Write("|0ERMastermind Top 10 Fastest Solves"); Door.DrawBox(2, 3, 79, 14, Crt.White, Crt.Blue, CrtPanel.BorderStyle.SingleV); Door.GotoXY(4, 3); Door.Write("|1F###"); Door.CursorRight(1); Door.Write("Player Name"); Door.CursorRight(29); Door.Write("Seconds"); Door.CursorRight(1); Door.Write("Date"); Door.GotoXY(1, 4); using (RMSQLiteConnection DB = new RMSQLiteConnection("HighScores.sqlite", false)) { int i = 0; DB.ExecuteReader("SELECT * FROM HighScores ORDER BY Seconds, RecordDate LIMIT 10"); while (DB.Reader.Read()) { i++; Door.CursorRight(3); Door.Write(StringUtils.PadLeft(i.ToString(), '0', 2) + ". "); Door.Write(StringUtils.PadRight(DB.Reader["PlayerName"].ToString(), ' ', 40)); Door.Write(StringUtils.PadLeft(DB.Reader["Seconds"].ToString(), ' ', 5) + " "); Door.Write(StringUtils.PadRight(DB.Reader["RecordDate"].ToString(), ' ', 22)); Door.WriteLn(); } while (i < 10) { i++; Door.CursorRight(3); Door.WriteLn(StringUtils.PadLeft(i.ToString(), '0', 2) + ". "); } } Door.GotoXY(1, 16); Door.More(); }