using System; using System.Text; using Ion.Storage; using System.Data; using Holo.Source; using Holo.Source.Virtual.Soundmachine; namespace Holo.Managers { /// /// Provides management for virtual sound machines and virtual songs. /// public static class soundMachineManager { /// /// Returns the string with all the soundsets in the Hand of a certain user. /// /// The database ID of the user to get the soundsets of. public static string getHandSoundsets(int userID) { using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) { DataTable table = dbClient.ReadDataTable("SELECT soundmachine_soundset FROM furniture WHERE ownerid = '" + userID + "' AND roomid = '0' AND soundmachine_soundset > 0 ORDER BY id ASC"); StringBuilder Soundsets = new StringBuilder(Encoding.encodeVL64(table.Rows.Count)); foreach (DataRow row in table.Rows) Soundsets.Append(Encoding.encodeVL64(Convert.ToInt32(row[0]))); return Soundsets.ToString(); } } /// /// Returns the length of a song in seconds as an integer. The length is calculated by counting the notes on the four tracks, if an error occurs here, then -1 is returned as length. /// /// The songdata. (all 4 tracks) public static int calculateSongLength(string Data) { int songLength = 0; try { string[] Track = Data.Split(':'); for (int i = 1; i < 8; i += 3) { int trackLength = 0; string[] Samples = Track[i].Split(';'); for (int j = 0; j < Samples.Length; j++) trackLength += int.Parse(Samples[j].Substring(Samples[j].IndexOf(",") + 1)); if (trackLength > songLength) songLength = trackLength; } return songLength; } catch { return -1; } } public static string getMachineSongList(int machineID) { using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) { FuseBuilder List = new FuseBuilder(); DataTable table = dbClient.ReadDataTable("SELECT id,length,title,burnt FROM soundmachine_songs WHERE machineid = '" + machineID + "' ORDER BY id ASC"); List.AppendWired(table.Rows.Count); foreach (DataRow row in table.Rows) { List.AppendWired(row[0]); List.AppendWired(row[1]); List.AppendString(row[2]); List.AppendWired(row[3]); } return List.ToString(); } } public static string getMachinePlaylist(int machineID) { using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) { FuseBuilder List = new FuseBuilder(); DataColumn column = dbClient.ReadDataColumn("SELECT songid FROM soundmachine_playlists WHERE machineid = '" + machineID + "' ORDER BY pos ASC"); List.AppendWired(0); List.AppendWired(column.Table.Rows.Count); int i = 1; foreach (DataRow row in column.Table.Rows) { List.AppendWired(row[0]); List.AppendWired(i); DataRow songrow = dbClient.ReadDataRow("SELECT userid,title FROM soundmachine_songs WHERE id = '" + row[0] + "'"); List.AppendString(songrow[1]); List.AppendString(dbClient.ReadString("SELECT name FROM users WHERE id = '" + songrow[0] + "'")); i++; } return List.ToString(); } } public static traxSong getTraxSong(int songID) { using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) return traxSong.Parse(dbClient.ReadDataRow("SELECT * FROM soundmachine_songs WHERE id = '" + songID + "'")); } public static string getSong(int songID) { using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) { DataRow row = dbClient.ReadDataRow("SELECT title,data FROM soundmachine_songs WHERE id = '" + songID + "'"); if (row != null) { FuseBuilder Song = new FuseBuilder(); Song.AppendWired(songID); Song.AppendString(row[0]); Song.AppendString(row[1]); return Song.ToString(); } else return "holo.cast.soundmachine.song.unknown"; } } public static string getJukeboxSongs(int jukeboxID) { DataTable table; using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) table = dbClient.ReadDataTable("SELECT * FROM jukebox_songs WHERE jukeboxid = " + jukeboxID); FuseBuilder Message = new FuseBuilder(334); // "EN" Message.AppendWired(10); // Slots open Message.AppendWired(table.Rows.Count); // Song count using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) foreach (DataRow row in table.Rows) { traxSong song = getTraxSong(Convert.ToInt32(row["songid"])); Message.AppendWired(row["slotid"]); // song slot Message.AppendWired(row["songid"]); // song ID? Message.AppendWired(9); Message.AppendString(song.Title); Message.AppendString(song.ComposerName); } return Message.ToString(); } public static string getUserCDs(int userID) { DataTable table; using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) table = dbClient.ReadDataTable("SELECT songid FROM furniture WHERE ownerid = " + userID + " AND roomid = 0 AND songid IS NOT NULL"); FuseBuilder Message = new FuseBuilder(333); // "EM" Message.AppendWired(table.Rows.Count); // song count using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient())) foreach (DataRow row in table.Rows) { DataRow songrow = dbClient.ReadDataRow("SELECT * FROM soundmachine_songs WHERE id = " + row[0]); Message.AppendWired(songrow["id"]); // song ID Message.AppendString(songrow["title"]); // song Name } return Message.ToString(); } } }