public void LoadSongQueue() { try { using (FileStream fs = new FileStream("UserData/TwitchIntegrationSavedQueue.json", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (fs.Length == 0) { return; } byte[] readBuffer = new byte[fs.Length]; fs.Read(readBuffer, 0, (int)fs.Length); string readString = Encoding.ASCII.GetString(readBuffer); JSONNode node = JSON.Parse(readString); foreach (var songNode in node.Values) { Song song = Song.FromSearchNode(songNode); SongQueueList.Add(song); } fs.Flush(); } } catch (Exception e) { Logger.Error("Error loading stored SongQueue. " + e.Message); } }
public void LoadBanList(string filePath) { try { using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { //Lets reset our list before we load. _bannedSongs = new List <string>(); //It didn't exist or there are no bans. if (fs.Length == 0) { return; } byte[] bannedSongBytes = new byte[fs.Length]; //This imposes a limit of 2,147,483,647 characters. Enough to not worry hopefully. fs.Read(bannedSongBytes, 0, (int)fs.Length); string bannedSongString = Encoding.ASCII.GetString(bannedSongBytes); _bannedSongs = JsonUtility.FromJson <BanList>(bannedSongString).GetBanList(); fs.Flush(); } } catch (Exception e) { Logger.Error("Error loading Banlist(" + filePath + "). " + e.Message); } }
public void RemoveSongFromQueue(Song song) { if (StaticData.UserRequestCount.ContainsKey(song.requestedBy)) { StaticData.UserRequestCount[song.requestedBy]--; } SongQueueList.Remove(song); Logger.Log("Removing song from Queue: " + song.songName); }
private void HandleSceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode) { try { Logger.Log($"Loaded scene \"{scene.name}\""); } catch (Exception e) { Logger.Exception("Exception on scene load: " + e); } }
public void CreateUI() { try { _mainMenuViewController = Resources.FindObjectsOfTypeAll <MainMenuViewController>().First(); _mainMenuRectTransform = _mainMenuViewController.transform as RectTransform; CreateTwitchButton(); } catch (Exception e) { Logger.Exception($"Unable to create UI! Exception: {e}"); } }
private void PrintConfigValuesToLog() { Logger.Log("Queue is Mod Only? " + StaticData.Config.ModOnly); Logger.Log("Queue is Sub Only? " + StaticData.Config.SubOnly); Logger.Log("Viewer Request Limits: " + StaticData.Config.ViewerLimit); Logger.Log("Sub Request Limits: " + StaticData.Config.SubLimit); Logger.Log("Moderator Request Limits: " + StaticData.Config.ModLimit); Logger.Log("Randomize Allowed? " + StaticData.Config.Randomize); Logger.Log("Randomize Request Limit: " + StaticData.Config.RandomizeLimit); Logger.Log("Request Multiple Random Queues already Chosen: " + StaticData.Config.BlockMultiRandomQueue); Logger.Log("Request Songs Already Played in Earlier Queues: " + StaticData.Config.OverrideSongInMultiQueue); Logger.Log("Shadow Queue Enabled? " + StaticData.Config.EnableShadowQueue); Logger.Log("Disable Mod Override: " + StaticData.Config.DisableModOverride); Logger.Log("Disable Return Chat Messages: " + StaticData.Config.AllowTwitchResponses); }
private void RefreshSongList() { StaticData.SongQueue.SongQueueList.ForEach(x => { foreach (CustomLevel z in SongLoader.CustomLevels) { Logger.Log("Custom Level Data: " + z); string customlvl = z.levelID.Substring(0, 32); if (x.hash.Equals(customlvl)) { Logger.Log("Song: " + x.songName + "Hash Checks: [" + x.hash + "] [" + customlvl + "]"); x.level = z; } } }); SongLoader.Instance.RefreshSongs(false); }
private void SceneManager_activeSceneChanged(Scene from, Scene to) { Logger.Log($"Active scene changed from \"{from.name}\" to \"{to.name}\""); if (from.name == "EmptyTransition" && to.name.Contains("Menu")) { try { Logger.Log("Start Loading UI Objects"); RequestUIController.Instance.OnLoad(); TwitchIntegrationUi.OnLoad(); } catch (Exception e) { Logger.Exception("Exception on scene change: " + e); } } }
public void SaveSongQueue() { try { using (FileStream fs = new FileStream("UserData/TwitchIntegrationSavedQueue.json", FileMode.Create, FileAccess.Write)) { JSONNode arrayNode = new JSONArray(); foreach (Song queuedSong in SongQueueList) { arrayNode.Add(queuedSong.ToJsonNode()); } byte[] buffer = Encoding.ASCII.GetBytes(arrayNode.ToString()); fs.Write(buffer, 0, buffer.Length); fs.Flush(); } } catch (Exception e) { Logger.Error("Error saving SongQueue. " + e.Message); } }
public void SaveBanList() { try { using (FileStream fs = new FileStream("UserData/TwitchIntegrationBans.json", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (File.Exists("UserData/TwitchIntegrationBans.json")) { byte[] readBuffer = new byte[fs.Length]; fs.Read(readBuffer, 0, readBuffer.Length); // Added a check to Length to avoid the mod hanging when trying to read an Empty File if (fs.Length != 0) { List <string> tempList = new List <string>(); string bannedSongString = Encoding.ASCII.GetString(readBuffer); tempList = JsonUtility.FromJson <BanList>(bannedSongString).GetBanList();; foreach (string bannedSong in tempList) { if (!_bannedSongs.Contains(bannedSong)) { _bannedSongs.Add(bannedSong); } } } } // We Set length to zero to wipe the file clean. // There was an issue with duplicates being written and I couldn't debug correctly at 2AM fs.SetLength(0); byte[] buffer = Encoding.ASCII.GetBytes(JsonUtility.ToJson(this, true)); fs.Write(buffer, 0, buffer.Length); fs.Flush(); } } catch (Exception e) { Logger.Error("Error saving Banlist. " + e.Message); } }