Пример #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;
            }
        }
Пример #2
0
        /// <summary>
        /// Allow a client to join a venue via QR code.
        /// </summary>
        /// <param name="QR">The QR code of the venue.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileJoinVenue(string QR, long userKey)
        {
            int mobileID = -1;
            int venueID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Get the venue of this qr string.
                r = db.GetVenueIDByQR(QR.Trim());
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (r.message.Trim().Length == 0)
                {
                    r.setErMsg(true, Messages.ERR_QR_BAD);
                    return r;
                }

                // Parse the venueID.
                if (!int.TryParse(r.message.Trim(), out venueID))
                {
                    r.setErMsgStk(true, "QR code couldnot be parsed from db", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_VENUE_NO_SESSION);
                    return r;
                }

                // Check if the user is banned
                bool userBanned;
                r = db.MobileIsBanned(venueID, mobileID, out userBanned);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (userBanned)
                {
                    r.setErMsg(true, Messages.MSG_USER_BANNED);
                    return r;
                }

                // Set the venue of the client
                r = db.MobileSetVenue(mobileID, venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Run the achievements on this venue, upon error, simply log the error.
                r = Common.RunAchievements(venueID, db);
                if(r.error)
                    Common.LogErrorPassThru(r, Common.LogFile.Mobile);

                r = db.GetVenueName(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                r.result = venueID;
                return r;
            }
        }