public static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnExit); // TODO: this should be yaml config in future or removed multiadminConfig = new OldConfig("scp_multiadmin.cfg"); if (!FindConfig()) { Console.ReadKey(); return; } if (args.Length == 1) { if (args[0].Equals("--convert-config")) { ConvertConfigs(); Console.ReadKey(); return; } } configChain = ""; if (StartHandleConfigs(args)) { server = new Server(GetServerDirectory(), configKey, multiadminConfig, configLocation, configChain, multiMode); } else { Console.ReadKey(); } }
public static void ConvertConfigs() { String[] dirs = Directory.GetDirectories(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "servers" + Path.DirectorySeparatorChar); foreach (string file in dirs) { var name = file + Path.DirectorySeparatorChar + "config.txt"; var backup = file + Path.DirectorySeparatorChar + "config.backup"; Write("Converting old config to yaml:" + file, ConsoleColor.Green); OldConfig config = new OldConfig(file + Path.DirectorySeparatorChar + "config.txt"); var serializer = new SerializerBuilder().Build(); var yaml = serializer.Serialize(config.values); Write(yaml, ConsoleColor.White); File.Copy(name, backup); File.WriteAllText(name, yaml); } }
public override void Unload() { base.Unload(); if (Storage != null) { using (Stream p = Storage?.GetStream("EmoteIDs.json", FileAccess.Write)) using (StreamWriter s = new StreamWriter(p)) { s.Write(JsonConvert.SerializeObject(EmoticonHandler.convertingEmotes, Formatting.Indented)); } } if (Irc?.Connected ?? false) { Irc?.Disconnect(); } Irc?.Dispose(); Irc = null; OldConfig?.Load(); OldConfig?.Dispose(); OldConfig = null; Storage = null; Store?.Dispose(); Store = null; Textures?.Dispose(); Textures = null; RecentChatters = null; WorldGen.SpawnTownNPC -= SpawnTownNpcHook; if (ModContent.GetInstance <EventWorld>() != null) { ModContent.GetInstance <EventWorld>().WorldScheduler = new Scheduler(Thread.CurrentThread, new GameTickClock(ModContent.GetInstance <EventWorld>())); ModContent.GetInstance <EventWorld>().RealtimeScheduler = new Scheduler(); ModContent.GetInstance <EventWorld>().CurrentEvent = null; } Web = null; Instance = null; EventsPool?.Clear(); EventsPool = null; GlobalSpawnOverride.HandleCleanup(); TwitchBoss.ClearPool(); TwitchBoss.Boss = string.Empty; }
public Server(String serverDir, String configKey, OldConfig multiAdminCfg, String mainConfigLocation, String configChain, bool multiMode) { this.multiMode = multiMode; MainConfigLocation = mainConfigLocation; ConfigKey = configKey; ConfigChain = configChain; ServerDir = serverDir; session_id = Utils.GetUnixTime().ToString(); Commands = new Dictionary <string, ICommand>(); Features = new List <Feature>(); tick = new List <IEventTick>(); MultiAdminCfg = multiAdminCfg; StartDateTime = Utils.GetDate(); maLogLocation = LogFolder + StartDateTime + "_MA_output_log.txt"; stopping = false; InitialRoundStarted = false; readerThread = new Thread(new ThreadStart(() => InputThread.Write(this))); printerThread = new Thread(new ThreadStart(() => OutputThread.Read(this))); // Register all features RegisterFeatures(); // Load config serverConfig = (multiMode ? new Config(ServerDir + Path.DirectorySeparatorChar + ConfigKey + Path.DirectorySeparatorChar + "config.txt") : new Config(mainConfigLocation)); // Enable / Disable MultiAdmin Optimizations runOptimized = serverConfig.GetBoolean("enable_multiadmin_optimizations", true); printSpeed = serverConfig.GetIntValue("multiadmin_print_speed", 150); // Init features InitFeatures(); // Start the server and threads if (StartServer()) { readerThread.Start(); printerThread.Start(); MainLoop(); } }
static void Main(string[] args) { try { Logger.ShortenSourceName = true; try { OldConfig.Initialize(); Logger.LogLevel = OldConfig.StrToLogLevel(OldConfig.LoggingLevel); if (Logger.LogLevel < LogLevel.Info) { Logger.ShortenSourceName = false; } } catch (FileNotFoundException ex) { Logger.Exception("Error initializing Config", ex); } Logger.Info($"Using Beat Saber directory: {OldConfig.BeatSaberPath}"); ScrapedDataProvider.Initialize(); Logger.Info($"Scrapes loaded, {ScrapedDataProvider.BeatSaverSongs.Data.Count} BeatSaverSongs and {ScrapedDataProvider.ScoreSaberSongs.Data.Count} ScoreSaber difficulties loaded"); //DoFullScrape(); //var scoreSaberSongs = ScrapedDataProvider.ScoreSaberSongs.Data.Select(ss => ss.hash).Distinct().Count(); //var activeSongs = ScrapedDataProvider.Songs.Values.Where(s => s.ScoreSaberInfo?.Values.Count > 0).Count(); //Tests(); try { if (args.Length > 0) { var bsDir = new DirectoryInfo(args[0]); if (bsDir.Exists) { if (bsDir.GetFiles("Beat Saber.exe").Length > 0) { Logger.Info("Found Beat Saber.exe"); OldConfig.BeatSaberPath = bsDir.FullName; Logger.Info($"Updated Beat Saber directory path to {OldConfig.BeatSaberPath}"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { Logger.Warning($"Provided directory does not appear to be Beat Saber's root folder, ignoring it"); } } } } catch (Exception ex) { Logger.Exception($"Error parsing command line arguments", ex); } if (!OldConfig.CriticalError) { WebUtils.Initialize(OldConfig.MaxConcurrentPageChecks); Stopwatch sw = new Stopwatch(); sw.Start(); SyncSaber ss = new SyncSaber(); ss.ScrapeNewSongs(); Console.WriteLine(); if (OldConfig.SyncFavoriteMappersFeed && OldConfig.FavoriteMappers.Count > 0) { Logger.Info($"Downloading songs from FavoriteMappers.ini..."); try { ss.DownloadSongsFromFeed(BeatSaverReader.NameKey, new BeatSaverFeedSettings(0) { Authors = OldConfig.FavoriteMappers.ToArray() }); } catch (AggregateException ae) { ae.WriteExceptions($"Exceptions downloading songs from FavoriteMappers.ini."); } catch (Exception ex) { Logger.Exception("Exception downloading songs from FavoriteMappers.ini.", ex); } } else { if (OldConfig.SyncFavoriteMappersFeed) { Logger.Warning($"Skipping FavoriteMappers.ini feed, no authors found in {Path.Combine(OldConfig.BeatSaberPath, "UserData", "FavoriteMappers.ini")}"); } } if (OldConfig.SyncFollowingsFeed) { // Followings Console.WriteLine(); Logger.Info($"Downloading songs from {BeastSaberReader.Feeds[BeastSaberFeeds.FOLLOWING].Name} feed..."); try { //ss.DownloadBeastSaberFeed(0, Web.BeastSaberReader.GetMaxBeastSaberPages(0)); ss.DownloadSongsFromFeed(BeastSaberReader.NameKey, new BeastSaberFeedSettings(0) { MaxPages = OldConfig.MaxFollowingsPages }); } catch (AggregateException ae) { ae.WriteExceptions($"Exceptions downloading songs from BeastSaberFeed: Following."); } catch (Exception ex) { Logger.Exception($"Exception downloading BeastSaberFeed: Following", ex); } } // Bookmarks if (OldConfig.SyncBookmarksFeed) { Console.WriteLine(); Logger.Info($"Downloading songs from {BeastSaberReader.Feeds[BeastSaberFeeds.BOOKMARKS].Name} feed..."); try { //ss.DownloadBeastSaberFeed(1, Web.BeastSaberReader.GetMaxBeastSaberPages(1)); ss.DownloadSongsFromFeed(BeastSaberReader.NameKey, new BeastSaberFeedSettings(1) { MaxPages = OldConfig.MaxBookmarksPages }); } catch (AggregateException ae) { ae.WriteExceptions($"Exceptions downloading songs from BeastSaberFeed: Bookmarks."); } catch (Exception ex) { Logger.Exception($"Exception downloading BeastSaberFeed: Bookmarks", ex); } } if (OldConfig.SyncCuratorRecommendedFeed) { // Curator Recommended Console.WriteLine(); Logger.Info($"Downloading songs from {BeastSaberReader.Feeds[BeastSaberFeeds.CURATOR_RECOMMENDED].Name} feed..."); try { //ss.DownloadBeastSaberFeed(2, Web.BeastSaberReader.GetMaxBeastSaberPages(2)); ss.DownloadSongsFromFeed(BeastSaberReader.NameKey, new BeastSaberFeedSettings(2) { MaxPages = OldConfig.MaxCuratorRecommendedPages }); } catch (AggregateException ae) { ae.WriteExceptions($"Exceptions downloading songs from BeastSaberFeed: Curator Recommended."); } catch (Exception ex) { Logger.Exception($"Exception downloading BeastSaberFeed: Curator Recommended", ex); } } if (OldConfig.SyncTopPPFeed) { // ScoreSaber Top PP Console.WriteLine(); Logger.Info($"Downloading songs from {ScoreSaberReader.Feeds[ScoreSaberFeeds.TOP_RANKED].Name} feed..."); try { //ss.DownloadBeastSaberFeed(2, Web.BeastSaberReader.GetMaxBeastSaberPages(2)); ss.DownloadSongsFromFeed(ScoreSaberReader.NameKey, new ScoreSaberFeedSettings((int)ScoreSaberFeeds.TOP_RANKED) { MaxSongs = 1000,//Config.MaxScoreSaberSongs, SongsPerPage = 10, searchOnline = true }); } catch (AggregateException ae) { ae.WriteExceptions($"Exceptions downloading songs from ScoreSaberFeed: Top Ranked."); } catch (Exception ex) { Logger.Exception($"Exception downloading ScoreSaberFeed: Top Ranked.", ex); } } /* * Console.WriteLine(); * Logger.Info($"Downloading newest songs on Beat Saver..."); * try * { * ss.DownloadSongsFromFeed(BeatSaverReader.NameKey, new BeatSaverFeedSettings(1) { * MaxPages = Config.MaxBeatSaverPages * }); * } * * catch (Exception ex) * { * Logger.Exception("Exception downloading BeatSaver newest feed.", ex); * } */ sw.Stop(); var processingTime = new TimeSpan(sw.ElapsedTicks); Console.WriteLine(); Logger.Info($"Finished downloading songs in {(int)processingTime.TotalMinutes} min {processingTime.Seconds} sec"); } else { foreach (string e in OldConfig.Errors) { Logger.Error($"Invalid setting: {e} = {OldConfig.Setting[e]}"); } } ScrapedDataProvider.BeatSaverSongs.WriteFile(); ScrapedDataProvider.ScoreSaberSongs.WriteFile(); } catch (OutOfDateException ex) { Logger.Error(ex.Message); } catch (AggregateException ae) { ae.WriteExceptions($"Uncaught exceptions in Main()"); } catch (Exception ex) { Logger.Exception("Uncaught exception in Main()", ex); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public static void ConvertConfigs() { string[] dirs = Directory.GetDirectories(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "servers" + Path.DirectorySeparatorChar); foreach (string file in dirs) { var name = file + Path.DirectorySeparatorChar + "config.txt"; var backup = file + Path.DirectorySeparatorChar + "config.backup"; Write("Converting old config to YAML: " + file, ConsoleColor.Green); OldConfig config = new OldConfig(file + Path.DirectorySeparatorChar + "config.txt"); //var serializer = new SerializerBuilder().Build(); //var yaml = serializer.Serialize(config.values); //Write(yaml, ConsoleColor.White); string yaml = string.Empty; foreach (string line in config.GetRaw()) { try { string commentText = "//"; // Dunno if everyone uses that comment style, whatever if (line.Contains("=") && line.Contains(";") && line.IndexOf("=") < line.IndexOf(";")) // Matches format "key = value; //comment" { string keyandEquals = line.Substring(0, line.IndexOf("=")).Trim(); // "key " -> "key" string value = line.Substring(line.IndexOf("=") + 1, line.IndexOf(";") - (line.IndexOf("=") + 1)).Trim(); // " value" -> "value" string followingContent = line.Substring(line.IndexOf(";") + 1, line.Length - (line.IndexOf(";") + 1)).Trim(); // " //comment" -> "//comment" if (followingContent.StartsWith(commentText)) // "//comment" -> "comment" { followingContent = followingContent.Substring(commentText.Length).Trim(); } string newLine = keyandEquals + ": " + value; // Write any comments if (!string.IsNullOrEmpty(followingContent)) { yaml += (followingContent.StartsWith("#") ? string.Empty : "#") + followingContent + Environment.NewLine; } yaml += newLine + Environment.NewLine; } else { string newLine = line.Trim(); if (newLine.StartsWith(commentText)) // "//comment" -> "comment" { newLine = newLine.Substring(commentText.Length).Trim(); } newLine = (string.IsNullOrEmpty(newLine) ? string.Empty : (newLine.StartsWith("#") ? string.Empty : "#") + newLine); yaml += newLine + Environment.NewLine; } } catch (Exception e) { Write(e.Message); Write(e.Source); Write(e.StackTrace); } } File.Copy(name, backup); File.WriteAllText(name, yaml); Write(yaml, ConsoleColor.White); Write("Success!", ConsoleColor.Green); } }