Example #1
0
        /// <summary>
        /// Accepts a buddy request and notifies the sender (if online) and the receiver.
        /// </summary>
        /// <param name="Session">The Woodpecker.Sessions.Session object of the user that accepts the request.</param>
        /// <param name="senderID">The database ID of the user that sent the request.</param>
        public void acceptBuddyRequest(ref Session Session, int senderID)
        {
            Database Database = new Database(false, false);
            Database.addParameterWithValue("userid", Session.User.ID);
            Database.addParameterWithValue("senderid", senderID);
            Database.Open();

            if (Database.findsResult("SELECT userid FROM messenger_buddylist WHERE userid = @senderid AND buddyid = @userid AND accepted = '0' LIMIT 1"))
            {
                Database.runQuery("UPDATE messenger_buddylist SET accepted = '1' WHERE userid = @senderid AND buddyid = @userid LIMIT 1");
                Database.Close();

                serverMessage Message = new serverMessage();
                if (ObjectTree.Game.Users.userIsLoggedIn(senderID)) // Sender is online!
                {
                    Message.Initialize(137); // "BI"
                    Message.Append(getBuddy(Session.User.ID).ToString());
                    ObjectTree.Game.Users.trySendGameMessage(senderID, Message);
                }

                Message.Initialize(137); // "BI"
                Message.Append(getBuddy(senderID).ToString());
                Session.gameConnection.sendMessage(Message);
            }
            else
                Database.Close();
        }
Example #2
0
 /// <summary>
 /// Returns a boolean that indicates if a given IP address is present in the 'connections_blacklist' table of the database.
 /// </summary>
 /// <param name="IP">The IP address to check.</param>
 public bool ipIsBlacklisted(string IP)
 {
     Database Database = new Database(false, true);
     Database.addParameterWithValue("ip", IP);
     Database.Open();
     if (Database.Ready)
         return Database.findsResult("SELECT ip FROM connections_blacklist WHERE ip = @ip");
     else
         return false;
 }
Example #3
0
        /// <summary>
        /// Returns a boolean indicating if a given user owns a given room.
        /// </summary>
        /// <param name="userID">The database ID of the user to check.</param>
        /// <param name="roomID">The database ID of the room to check.</param>
        public bool userOwnsRoom(int userID, int roomID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("roomid", roomID);
            Database.Open();

            return Database.findsResult("SELECT id FROM rooms WHERE id = @roomid AND ownerid = @userid LIMIT 1");
        }
Example #4
0
        /// <summary>
        /// Returns a boolean indicating if a given user posesses a given badge.
        /// </summary>
        /// <param name="User">The database ID of the user to check.</param>
        /// <param name="Badge">The badge to check.</param>
        public bool userHasBadge(userInformation User, string Badge)
        {
            if ((Badge == "HC1" && User.hasClub) || (Badge == "HC2" && User.hasGoldClub)) // Club badge
                return true;

            if (ObjectTree.Game.Roles.roleHasBadge(User.Role, Badge)) // Role badge
                return true;

            // Private badge check
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", User.ID);
            Database.addParameterWithValue("badge", Badge);
            Database.Open();

            return Database.findsResult("SELECT userid FROM users_badges WHERE userid = @userid AND badge = @badge LIMIT 1"); // True if this user has the searched badge as private
        }
Example #5
0
 /// <summary>
 /// Returns a boolean that indicates if a user with a certain username exists in the 'users' table of the database.
 /// </summary>
 /// <param name="Username">The username to check.</param>
 public bool userExists(string Username)
 {
     Database Database = new Database(false, true);
     Database.addParameterWithValue("username", Username);
     Database.Open();
     return Database.findsResult("SELECT id FROM users WHERE username = @username");
 }
Example #6
0
        /// <summary>
        /// Gives a badge to user, after checking if the user doesn't already have this badge. A boolean is returned that indicates if the badge is given or not.
        /// </summary>
        /// <param name="userID">The database ID of the user to give the badge to.</param>
        /// <param name="Badge">The badge of the user to </param>
        public bool giveBadgeToUser(int userID, string Badge)
        {
            Database Database = new Database(false, false);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("badge", Badge);
            Database.Open();
            if (Database.Ready)
            {
                if (!Database.findsResult("SELECT userid FROM users_badges WHERE userid = @userid AND badge = @badge LIMIT 1"))
                {
                    Database.runQuery("INSERT INTO users_badges(userid,badge) VALUES (@userid,@badge)");
                    return true;
                }
                Database.Close();
            }

            return false;
        }
Example #7
0
        /// <summary>
        /// Returns a boolean indicating if two users (given by their ID) are buddies.
        /// </summary>
        /// <param name="userID">The database ID of user 1.</param>
        /// <param name="userID2">The database ID of user 2.</param>
        public bool areBuddies(int userID, int userID2, bool requestsCount)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("userid2", userID2);
            Database.Open();

            if(requestsCount)
                return Database.findsResult("SELECT userid FROM messenger_buddylist WHERE (userid = @userid AND buddyid = @userid2) OR (userid = @userid2 AND buddyid = @userid) LIMIT 1");
            else
                return Database.findsResult("SELECT userid FROM messenger_buddylist WHERE (userid = @userid AND buddyid = @userid2) OR (userid = @userid2 AND buddyid = @userid) AND accepted = '1' LIMIT 1");
        }