public static void SetUserRole(Guid profileId, int userRole) { CProfile profile = CProfiles.GetProfile(profileId); if (profile == null) { throw new ArgumentException("Invalid profileId"); } var option = (EUserRole)userRole; //Only allow the change of all options exept TR_USERROLE_GUEST and TR_USERROLE_NORMAL const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL); option &= ~mask; profile.UserRole = (profile.UserRole & mask) | option; CProfiles.EditProfile(profile); CProfiles.Update(); CProfiles.SaveProfiles(); }
private static void _Run(string[] args) { Application.DoEvents(); try { // Create data folder Directory.CreateDirectory(CSettings.DataFolder); // Init Log CLog.Init(); if (!CProgrammHelper.CheckRequirements()) { return; } CProgrammHelper.Init(); CLog.StartBenchmark("Init Program"); CMain.Init(); Application.DoEvents(); // Init Language CLog.StartBenchmark("Init Language"); if (!CLanguage.Init()) { throw new CLoadingException("Language"); } CLog.StopBenchmark("Init Language"); Application.DoEvents(); // load config CLog.StartBenchmark("Init Config"); CConfig.LoadCommandLineParams(args); CConfig.UseCommandLineParamsBefore(); CConfig.Init(); CConfig.UseCommandLineParamsAfter(); CLog.StopBenchmark("Init Config"); // Create folders CSettings.CreateFolders(); _SplashScreen = new CSplashScreen(); Application.DoEvents(); // Init Draw CLog.StartBenchmark("Init Draw"); if (!CDraw.Init()) { throw new CLoadingException("drawing"); } CLog.StopBenchmark("Init Draw"); Application.DoEvents(); // Init Playback CLog.StartBenchmark("Init Playback"); if (!CSound.Init()) { throw new CLoadingException("playback"); } CLog.StopBenchmark("Init Playback"); Application.DoEvents(); // Init Record CLog.StartBenchmark("Init Record"); if (!CRecord.Init()) { throw new CLoadingException("record"); } CLog.StopBenchmark("Init Record"); Application.DoEvents(); // Init VideoDecoder CLog.StartBenchmark("Init Videodecoder"); if (!CVideo.Init()) { throw new CLoadingException("video"); } CLog.StopBenchmark("Init Videodecoder"); Application.DoEvents(); // Init Database CLog.StartBenchmark("Init Database"); if (!CDataBase.Init()) { throw new CLoadingException("database"); } CLog.StopBenchmark("Init Database"); Application.DoEvents(); //Init Webcam CLog.StartBenchmark("Init Webcam"); if (!CWebcam.Init()) { throw new CLoadingException("webcam"); } CLog.StopBenchmark("Init Webcam"); Application.DoEvents(); // Init Background Music CLog.StartBenchmark("Init Background Music"); CBackgroundMusic.Init(); CLog.StopBenchmark("Init Background Music"); Application.DoEvents(); // Init Profiles CLog.StartBenchmark("Init Profiles"); CProfiles.Init(); CLog.StopBenchmark("Init Profiles"); Application.DoEvents(); // Init Fonts CLog.StartBenchmark("Init Fonts"); if (!CFonts.Init()) { throw new CLoadingException("fonts"); } CLog.StopBenchmark("Init Fonts"); Application.DoEvents(); // Theme System CLog.StartBenchmark("Init Theme"); if (!CThemes.Init()) { throw new CLoadingException("theme"); } CLog.StopBenchmark("Init Theme"); CLog.StartBenchmark("Load Theme"); CThemes.Load(); CLog.StopBenchmark("Load Theme"); Application.DoEvents(); // Load Cover CLog.StartBenchmark("Init Cover"); if (!CCover.Init()) { throw new CLoadingException("covertheme"); } CLog.StopBenchmark("Init Cover"); Application.DoEvents(); // Init Screens CLog.StartBenchmark("Init Screens"); CGraphics.Init(); CLog.StopBenchmark("Init Screens"); Application.DoEvents(); // Init Server CLog.StartBenchmark("Init Server"); CVocaluxeServer.Init(); CLog.StopBenchmark("Init Server"); Application.DoEvents(); // Init Input CLog.StartBenchmark("Init Input"); CController.Init(); CController.Connect(); CLog.StopBenchmark("Init Input"); Application.DoEvents(); // Init Game; CLog.StartBenchmark("Init Game"); CGame.Init(); CProfiles.Update(); CConfig.UsePlayers(); CLog.StopBenchmark("Init Game"); Application.DoEvents(); // Init Party Modes; CLog.StartBenchmark("Init Party Modes"); if (!CParty.Init()) { throw new CLoadingException("Party Modes"); } CLog.StopBenchmark("Init Party Modes"); Application.DoEvents(); //Only reasonable point to call GC.Collect() because initialization may cause lots of garbage //Rely on GC doing its job afterwards and call Dispose methods where appropriate GC.Collect(); CLog.StopBenchmark("Init Program"); } catch (Exception e) { MessageBox.Show("Error on start up: " + e.Message); CLog.LogError("Error on start up: " + e); if (_SplashScreen != null) { _SplashScreen.Close(); } _CloseProgram(); return; } Application.DoEvents(); // Start Main Loop if (_SplashScreen != null) { _SplashScreen.Close(); } CDraw.MainLoop(); }
private static void _Run(string[] args) { Application.DoEvents(); try { // Create data folder Directory.CreateDirectory(CSettings.DataFolder); // Init Log CLog.Init(CSettings.FolderNameLogs, CSettings.FileNameMainLog, CSettings.FileNameSongLog, CSettings.FileNameCrashMarker, CSettings.GetFullVersionText(), CReporter.ShowReporterFunc, ELogLevel.Information); if (!CProgrammHelper.CheckRequirements()) { return; } CProgrammHelper.Init(); using (CBenchmark.Time("Init Program")) { CMain.Init(); Application.DoEvents(); // Init Language using (CBenchmark.Time("Init Language")) { if (!CLanguage.Init()) { throw new CLoadingException("Language"); } } Application.DoEvents(); // load config using (CBenchmark.Time("Init Config")) { CConfig.LoadCommandLineParams(args); CConfig.UseCommandLineParamsBefore(); CConfig.Init(); CConfig.UseCommandLineParamsAfter(); } // Create folders CSettings.CreateFolders(); _SplashScreen = new CSplashScreen(); Application.DoEvents(); // Init Draw using (CBenchmark.Time("Init Draw")) { if (!CDraw.Init()) { throw new CLoadingException("drawing"); } } Application.DoEvents(); // Init Playback using (CBenchmark.Time("Init Playback")) { if (!CSound.Init()) { throw new CLoadingException("playback"); } } Application.DoEvents(); // Init Record using (CBenchmark.Time("Init Record")) { if (!CRecord.Init()) { throw new CLoadingException("record"); } } Application.DoEvents(); // Init VideoDecoder using (CBenchmark.Time("Init Videodecoder")) { if (!CVideo.Init()) { throw new CLoadingException("video"); } } Application.DoEvents(); // Init Database using (CBenchmark.Time("Init Database")) { if (!CDataBase.Init()) { throw new CLoadingException("database"); } } Application.DoEvents(); //Init Webcam using (CBenchmark.Time("Init Webcam")) { if (!CWebcam.Init()) { throw new CLoadingException("webcam"); } } Application.DoEvents(); // Init Background Music using (CBenchmark.Time("Init Background Music")) { CBackgroundMusic.Init(); } Application.DoEvents(); // Init Profiles using (CBenchmark.Time("Init Profiles")) { CProfiles.Init(); } Application.DoEvents(); // Init Fonts using (CBenchmark.Time("Init Fonts")) { if (!CFonts.Init()) { throw new CLoadingException("fonts"); } } Application.DoEvents(); // Theme System using (CBenchmark.Time("Init Theme")) { if (!CThemes.Init()) { throw new CLoadingException("theme"); } } using (CBenchmark.Time("Load Theme")) { CThemes.Load(); } Application.DoEvents(); // Load Cover using (CBenchmark.Time("Init Cover")) { if (!CCover.Init()) { throw new CLoadingException("covertheme"); } } Application.DoEvents(); // Init Screens using (CBenchmark.Time("Init Screens")) { CGraphics.Init(); } Application.DoEvents(); // Init Server using (CBenchmark.Time("Init Server")) { CVocaluxeServer.Init(); } Application.DoEvents(); // Init Input using (CBenchmark.Time("Init Input")) { CController.Init(); CController.Connect(); } Application.DoEvents(); // Init Game using (CBenchmark.Time("Init Game")) { CGame.Init(); CProfiles.Update(); CConfig.UsePlayers(); } Application.DoEvents(); // Init Party Modes using (CBenchmark.Time("Init Party Modes")) { if (!CParty.Init()) { throw new CLoadingException("Party Modes"); } } Application.DoEvents(); //Only reasonable point to call GC.Collect() because initialization may cause lots of garbage //Rely on GC doing its job afterwards and call Dispose methods where appropriate GC.Collect(); } } catch (Exception e) { CLog.Error(e, "Error on start up: {ExceptionMessage}", CLog.Params(e.Message), show: true); if (_SplashScreen != null) { _SplashScreen.Close(); } _CloseProgram(); return; } Application.DoEvents(); // Start Main Loop if (_SplashScreen != null) { _SplashScreen.Close(); } CDraw.MainLoop(); }
public static bool SendProfileData(SProfileData profile) { CProfile newProfile; CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId); if (existingProfile != null) { newProfile = new CProfile { ID = existingProfile.ID, FilePath = existingProfile.FilePath, Active = existingProfile.Active, Avatar = existingProfile.Avatar, Difficulty = existingProfile.Difficulty, UserRole = existingProfile.UserRole, PlayerName = existingProfile.PlayerName }; } else { newProfile = new CProfile { Active = EOffOn.TR_CONFIG_ON, UserRole = EUserRole.TR_USERROLE_NORMAL }; } if (profile.Avatar != null) { newProfile.Avatar = _AddAvatar(profile.Avatar); } else if (newProfile.Avatar == null || newProfile.Avatar.ID == -1) { newProfile.Avatar = CProfiles.GetAvatars().First(); /*CAvatar avatar = new CAvatar(-1); * avatar.LoadFromFile("Profiles\\Avatar_f.png"); * CProfiles.AddAvatar(avatar); * newProfile.Avatar = avatar;*/ } if (!string.IsNullOrEmpty(profile.PlayerName)) { newProfile.PlayerName = profile.PlayerName; } else if (!string.IsNullOrEmpty(newProfile.PlayerName)) { newProfile.PlayerName = "DummyName"; } if (profile.Difficulty >= 0 && profile.Difficulty <= 2) { newProfile.Difficulty = (EGameDifficulty)profile.Difficulty; } if (profile.Type >= 0 && profile.Type <= 1) { EUserRole option = profile.Type == 0 ? EUserRole.TR_USERROLE_GUEST : EUserRole.TR_USERROLE_NORMAL; //Only allow the change of TR_USERROLE_GUEST and TR_USERROLE_NORMAL const EUserRole mask = EUserRole.TR_USERROLE_NORMAL; newProfile.UserRole = (newProfile.UserRole & mask) | option; } if (!string.IsNullOrEmpty(profile.Password)) { if (profile.Password == "***__CLEAR_PASSWORD__***") { newProfile.PasswordSalt = null; newProfile.PasswordHash = null; } else { RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] buffer = new byte[32]; rng.GetNonZeroBytes(buffer); byte[] salt = buffer; byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(profile.Password), salt); newProfile.PasswordSalt = salt; newProfile.PasswordHash = hashedPassword; } } if (existingProfile != null) { CProfiles.EditProfile(newProfile); CProfiles.Update(); CProfiles.SaveProfiles(); } else { CProfiles.AddProfile(newProfile); } return(true); }