Exemplo n.º 1
0
        /// <summary>
        /// Unban the user from the venue. The user can now rejoin the venue.
        /// </summary>
        /// <param name="userToUnban">User to unban.</param>
        /// <param name="DJKey">The DJKey for the venue.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJUnbanUser(User userToUnban, long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;
                // Attempt to convert DJKey to DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;
                r = db.MobileValidateID(userToUnban.userID);
                if (r.error)
                    return r;
                if (r.message.Length == 0)
                {
                    r.message = "Could not find that userID";
                    r.error = true;
                    return r;
                }

                bool isBanned;
                r = db.MobileIsBanned(DJID, userToUnban.userID, out isBanned);
                if (r.error)
                    return r;
                if (!isBanned)
                {
                    r.error = true;
                    r.message = "User is not banned!";
                    return r;
                }

                r = db.DJUnbanUser(DJID, userToUnban.userID);
                if (r.error)
                    return r;

                if (r.result != 1)
                {
                    r.message = "DB failed to unban user?";
                    r.error = true;
                    return r;
                }
                return r;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ban the user from the venue. The user is expelled from the queue and venue.
        /// The user is unallowed to join the venue while banned.
        /// </summary>
        /// <param name="userToBan">The user to ban.</param>
        /// <param name="DJKey">The DJKey for the venue.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJBanUser(User userToBan, long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;
                // Attempt to convert DJKey to DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;
                r = db.MobileValidateID(userToBan.userID);
                if (r.error)
                    return r;
                if (r.message.Length == 0)
                {
                    r.message = "Could not find that userID";
                    r.error = true;
                    return r;
                }
                r = db.DJBanUser(DJID, userToBan.userID);
                if (r.error)
                    return r;

                if (r.result != 1)
                {
                    r.message = "DB failed to ban user?";
                    r.error = true;
                    return r;
                }

                r = db.DJRemoveUserFromVenueIfAtVenue(DJID, userToBan.userID);
                if (r.error)
                    return r;

                DJRemoveUser(userToBan.userID, DJKey);

                Common.PushMessageToMobile(userToBan.userID, "exit", db);

                return r;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to sign in the DJ using the given credentials.
        /// If an error occurs, the LogInResponse will have the error field as true, and the error will be in message.
        /// </summary>
        /// <param name="username">Username to sign in with.</param>
        /// <param name="password">Password to sign in with.</param>
        /// <returns>LogInReponse returns the outcome. The UserKey sent back is used for all communicaiton in further methods.</returns>
        /// 
        public LogInResponse DJSignIn(string username, string password)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return new LogInResponse(r);

                // Get the salt from the database and salt/hash the password.
                string salt;
                r = db.DJGetSalt(username, out salt);
                if (r.error)
                    return new LogInResponse(r);
                string saltHashPassword = Common.CreatePasswordHash(password, salt);

                // See if the username/password combination is valid.
                // If it is valid, the DJID will be stored in r.message.
                // If it is not valid, r.message will be empty.
                r = db.DJValidateUsernamePassword(username, saltHashPassword);
                if (r.error)
                    return new LogInResponse(r);

                // If the username/password couldn't be found, inform user.
                if (r.message.Trim() == string.Empty)
                {
                    r.error = true;
                    r.message = "Username/Password is incorrect.";
                    return new LogInResponse(r);
                }

                // Get the DJID stored in r.message.
                if (!int.TryParse(r.message.Trim(), out DJID))
                {
                    r.error = true;
                    r.message = "Exception in DJSignIn: Unable to parse DJID from DB!";
                    return new LogInResponse(r);
                }

                // Make sure the DJ is not logged in. RIGHT NOW: JUST DON'T CHECK ANYTHING USEFUL TO ALLOW FOR LOGINS TO OCCUR WHEN LOGGED IN!
                r = DJValidateStatus(DJID, "!4", db);
                if (r.error)
                    return new LogInResponse(r);

                // Information seems valid, attempt to sign in.
                r = db.DJSetStatus(DJID, 1);
                if (r.error)
                    return new LogInResponse(r);

                // Attempt to change the DJID into a userKey
                long userKey;
                r = DJGenerateKey(DJID, out userKey, db);
                if (r.error)
                    return new LogInResponse(r);

                // If there was no error, create a loginResponse with the successful information.
                LogInResponse lr = new LogInResponse();
                lr.result = r.result;
                lr.userKey = userKey;
                User u = new User();
                u.userName = username;
                u.userID = DJID;
                return lr;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert the database representation of a queue to the object representation. Fill all fields except for path on disk.
        /// </summary>
        /// <param name="raw">The database representation.</param>
        /// <param name="queue">The out parameter to store the queue in.</param>
        /// <param name="DJID">The ID of the venue.</param>
        /// <param name="mobileID">The ID of the client.</param>
        /// <param name="db">The databse conenctivity to use.</param>
        /// <returns>The outcome of the operation.</returns>
        private Response DBToNearlyFullList(string raw, out List<queueSinger> queue, int DJID, int mobileID, DatabaseConnectivity db)
        {
            queue = new List<queueSinger>();
            Response r = new Response();
            int count = 0;

            string[] clientRequests = raw.Split('`');
            for (int i = 0; i < clientRequests.Length; i++)
            {
                string[] parts = clientRequests[i].Split('~');
                if (parts.Length == 0)
                {
                    r.error = true;
                    r.message = "Error in DBtoList 1";
                    return r;
                }

                queueSinger qs = new queueSinger();
                qs.songs = new List<Song>();
                User u = new User();
                u.userID = int.Parse(parts[0]);

                if (u.userID < 0)
                    r = db.DJGetTempUserName(u.userID, DJID);
                else
                    r = db.MobileIDtoUsername(u.userID);

                if (r.error)
                    return r;
                if (r.message.Trim().Length == 0)
                {
                    r.error = true;
                    r.message = "DB Username lookup exception in DJGetQueue!";
                    return r;
                }

                u.userName = r.message.Trim();
                qs.user = u;

                for (int j = 1; j < parts.Length; j++)
                {
                    Song song;
                    r = Common.GetSongInformation(int.Parse(parts[j]), DJID, mobileID, out song, db);
                    if (r.error)
                        return r;
                    qs.songs.Add(song);

                }
                queue.Add(qs);
                count++;
            }
            return r;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a song request.
        /// </summary>
        /// <param name="songID">The songID</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileSongRequest(int songID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Make sure the client isn't already logged out.
                r = MobileCheckStatus(mobileID, "!0", db);
                if (r.error)
                    return r;

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                venueID = r.result;

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db);
                if (r.error)
                    return r;

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.error = true;
                    r.message = "Could not find song";
                    return r;
                }

                // Get the current song Requests
                r = db.GetSongRequests(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                string requests = r.message;
                string newRequests = string.Empty;

                if (requests.Trim().Length == 0)
                {
                    requests = mobileID.ToString() + "~" + songID.ToString();
                    r = db.SetSongRequests(venueID, requests);
                    if (r.error)
                        return r;
                    r = Common.PushMessageToMobile(mobileID, "queue", db);
                    if (r.error)
                        Common.LogError(r.message, Environment.StackTrace, null, 0);
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == mobileID)
                    {
                        // Loop through the songs to see if the user is already singing this song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            if (queue[i].songs[j].ID == songID)
                            {
                                r.error = true;
                                r.message = "You are already in queue to sing that song";
                                return r;
                            }

                        }
                        // They dont' already have the song in the list, add them to the list
                        Song s = new Song();
                        s.ID = songID;
                        queue[i].songs.Add(s);
                        Common.MinimalListToDB(queue, out newRequests);
                        r = db.SetSongRequests(venueID, newRequests);
                        if(r.error)
                            return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                        Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                        return r;
                    }
                }

                queueSinger qs = new queueSinger();
                qs.songs = new List<Song>();

                User u = new User();
                u.userID = mobileID;
                qs.user = u;

                Song song = new Song();
                song.ID = songID;
                qs.songs.Add(song);

                queue.Add(qs);
                Common.MinimalListToDB(queue, out newRequests);
                r = db.SetSongRequests(venueID, newRequests);
                if(r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                return r;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Takes the database representation of the queue and expands it into a queue that is minimally
        /// filled with data. The queue is only filled to contain user IDs and song IDs. 
        /// </summary>
        /// <param name="raw">The database representation of the queue.</param>
        /// <param name="queue">Out object represenation of the queue.</param>
        /// <returns>The outcome of the operation.</returns>
        public static Response DBToMinimalList(string raw, out List<queueSinger> queue)
        {
            int count = 0;
            Response r = new Response();

            queue = new List<queueSinger>();
            string[] clientRequests = raw.Split('`');
            for (int i = 0; i < clientRequests.Length; i++)
            {
                string[] parts = clientRequests[i].Split('~');
                if (parts.Length == 0)
                {
                    r.error = true;
                    r.message = "Error in DBtoList 1";
                    return r;
                }

                queueSinger qs = new queueSinger();
                qs.songs = new List<Song>();
                User u = new User();
                u.userID = int.Parse(parts[0]);
                qs.user = u;

                for (int j = 1; j < parts.Length; j++)
                {
                    Song s = new Song();
                    s.ID = int.Parse(parts[j]);
                    qs.songs.Add(s);

                }
                queue.Add(qs);
                count++;
            }
            return r;
        }
Exemplo n.º 7
0
        internal ExpResponse DJGetBannedUsers(int DJID, out List<User> bannedUsers)
        {
            bannedUsers = new List<User>();
            ExpResponse r = new ExpResponse();
            SqlCommand cmd = new SqlCommand("select MobileID from DJBannedUsers where DJID = @DJID;", con);
            cmd.Parameters.AddWithValue("@DJID", DJID);

            try
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        User u = new User();
                        u.userID = reader.GetInt32(0);
                        bannedUsers.Add(u);
                    }
                }
                return r;
            }
            catch (Exception e)
            {
                r.setErMsgStk(true, "Exception in DJGetBannedUsers: " + e.Message, e.StackTrace);
                return r;
            }
        }