Exemplo n.º 1
0
        /// <summary>
        /// Starts a DJ session up. Mobile users can now make song requests, The DJ can now control the queue.
        /// </summary>
        /// <param name="DJKey">The DJ's assigned key.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJCreateSession(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;

                // Make sure the DJ is not logged out.
                r = DJValidateStatus(DJID, "!0", db);
                if (r.error)
                    return r;

                // Set the status of the DJ to accepting songs.
                r = db.DJSetStatus(DJID, 2);
                if (r.error)
                    return r;
                // Create a new field for song requests.
                r = db.DJOpenSongRequests(DJID);
                return r;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Close a DJ's session. The DJ must have a session running for this to work.
        /// </summary>
        /// <param name="DJKey">The DJKey assigned to the DJ.</param>
        /// <returns>The outcome of the operation.b</returns>
        public Response DJStopSession(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;

                // Make sure the DJ has a session running.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Set the status of the DJ to logged in.
                r = db.DJSetStatus(DJID, 1);
                if (r.error)
                    return r;

                Common.PushMessageToUsersOfDJ(DJID, "exit", db);

                // Delete the song request field.
                r = db.DJDeleteSongRequests(DJID);
                if (r.error)
                    return r;

                r = db.DJRemoveAllTempUsers(DJID);
                if (r.error)
                    return r;

                r = db.DJRemoveUsersFromVenue(DJID);
                if (r.error)
                    return r;

                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>
        /// Attempt to sign out the DJ. 
        /// </summary>
        /// <param name="DJKey">The DJKey of the DJ.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJSignOut(long DJKey)
        {
            int DJID;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ is not logged out.
                r = DJValidateStatus(DJID, "!0", db);
                if (r.error)
                    return r;

                // A sign out seems to be valid.
                r = db.DJSetStatus(DJID, 0);
                if (r.error)
                    return r;

                Common.PushMessageToUsersOfDJ(DJID, "exit", db);

                // Remove the key from the DB.
                r = db.DJSetKey(DJID, null);
                if (r.error)
                    return r;

                // Close out the song requests for this DJ.
                r = db.DJDeleteSongRequests(DJID);
                if (r.error)
                    return r;

                r = db.DJRemoveAllTempUsers(DJID);
                if (r.error)
                    return r;

                r = db.DJRemoveUsersFromVenue(DJID);
                if (r.error)
                    return r;

                return r;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Close a DJ's session. The DJ must have a session running for this to work.
        /// </summary>
        /// <param name="DJKey">The DJKey assigned to the DJ.</param>
        /// <returns>The outcome of the operation.b</returns>
        public Response DJStopSession(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;

                // Make sure the DJ has a session running.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Set the status of the DJ to logged in.
                r = db.DJSetStatus(DJID, 1);
                if (r.error)
                    return r;

                // Delete the song request field.
                r = db.DJCloseSongRequests(DJID);
                return r;
            }
        }