Пример #1
0
        public static string GetPMKeyTag(string senderName, string receiverName)
        {
            try
            {
                string directmessage = "";

                int senderID = KeyTagID.GrabUserKeyTag(senderName);

                int receiverID = KeyTagID.GrabUserKeyTag(receiverName);

                if (senderID > receiverID)
                {
                    directmessage = senderID.ToString() + "28" + receiverID.ToString();
                }

                if (senderID < receiverID)
                {
                    directmessage = receiverID.ToString() + "28" + senderID.ToString();
                }

                string pmKeyTag = FriendsList.numToAlpha(directmessage);

                return(pmKeyTag);
            }
            catch (NpgsqlException e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Пример #2
0
        private void AddorRemoveFriendFR(string action, string user, string friend, int keyTag)
        {
            List <string> requestsOutList;
            List <string> requestsInList;

            string recipientUser;
            string friendsList;
            string input;

            if (KeyTagID.GrabUserKeyTag(friend) != 127)
            {
                try
                {
                    using (NpgsqlConnection connection = new NpgsqlConnection(Network.NpgSQLConnection))
                    {
                        connection.Open();

                        NpgsqlCommand myCommand = new NpgsqlCommand("SELECT * from embyrfriends.friends WHERE accountname = @accountname", connection);

                        myCommand.Parameters.Add(new NpgsqlParameter(":accountname", user));

                        NpgsqlDataReader requestOutReader = myCommand.ExecuteReader();

                        requestOutReader.Read();

                        input = requestOutReader[4].ToString();

                        requestsOutList = input.Split(GlobalVar.delimiterChars, System.StringSplitOptions.RemoveEmptyEntries).OfType <string>().ToList();

                        if (action == "ADDFR")
                        {
                            if (requestsOutList.Contains(friend) == false)
                            {
                                requestsOutList.Add(friend);
                            }
                        }

                        if (action == "REMOVEFR")
                        {
                            requestsOutList.Remove(friend);
                        }

                        friendsList = "";

                        foreach (string requestsO in requestsOutList)
                        {
                            friendsList = friendsList + GlobalVar.cValueR + requestsO;
                        }

                        requestOutReader.Close();

                        myCommand.CommandText = "UPDATE embyrfriends.friends set requestsout = :requestsout WHERE accountname = :accountname";

                        myCommand.Parameters.Add(new NpgsqlParameter(":accountname", user));

                        myCommand.Parameters.Add(new NpgsqlParameter(":requestsout", friendsList));

                        NpgsqlDataReader requestOutUpdater = myCommand.ExecuteReader();

                        requestOutUpdater.Read();

                        recipientUser = friend;

                        requestOutUpdater.Close();

                        //Friend Added to User's FriendsList

                        myCommand.CommandText = "SELECT * from embyrfriends.friends WHERE accountname = @accountnameR";

                        myCommand.Parameters.Add(new NpgsqlParameter(":accountnameR", recipientUser));

                        NpgsqlDataReader requestInReader = myCommand.ExecuteReader();

                        requestInReader.Read();

                        try
                        {
                            input = requestInReader[3].ToString(); //Fix here
                        }
                        catch
                        {
                            Console.WriteLine("User does not exist");
                        }

                        requestsInList = input.Split(GlobalVar.delimiterChars, System.StringSplitOptions.RemoveEmptyEntries).OfType <string>().ToList();

                        if (action == "ADDFR")
                        {
                            if (requestsInList.Contains(user) == false)
                            {
                                requestsInList.Add(user);
                            }
                        }

                        if (action == "REMOVEFR")
                        {
                            requestsInList.Remove(user);
                        }

                        friendsList = "";

                        foreach (string requestsI in requestsInList)
                        {
                            friendsList = friendsList + GlobalVar.cValueR + requestsI;
                        }

                        requestInReader.Close();

                        myCommand.CommandText = "UPDATE embyrfriends.friends set requestsin = :requestsin WHERE accountname = @accountnameR";

                        myCommand.Parameters.Add(new NpgsqlParameter(":accountnameR", recipientUser));

                        myCommand.Parameters.Add(new NpgsqlParameter(":requestsin", friendsList));

                        NpgsqlDataReader requestInUpdater = myCommand.ExecuteReader();

                        requestInUpdater.Read();

                        requestInUpdater.Close();

                        //User Added to Friend's FriendsList

                        connection.Close();
                    }
                }

                catch (NpgsqlException exc)
                {
                    Console.WriteLine(exc.ToString());
                }
            }
            else
            {
                Console.WriteLine("User does not exist");
            }
        }
Пример #3
0
        private void FriendAdder(string action, string username, string friend, int keyTag)
        {
            List <string> userFriendsSL;
            List <string> userRequestsSL;
            List <string> friendFriendsSL;
            List <string> friendRequestsSL;

            string userFriends    = "";
            string userRequests   = "";
            string friendFriends  = "";
            string friendRequests = "";

            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(Network.NpgSQLConnection))
                {
                    connection.Open();

                    NpgsqlCommand myCommand = new NpgsqlCommand("SELECT * from embyrfriends.friends WHERE accountname = @accountname", connection);

                    myCommand.Parameters.Add(new NpgsqlParameter(":accountname", username));

                    NpgsqlDataReader friendsReader = myCommand.ExecuteReader();

                    //Looking for user's friends

                    friendsReader.Read();

                    userFriends = friendsReader[2].ToString();

                    userRequests = friendsReader[3].ToString();

                    friendsReader.Close();

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    userFriendsSL = userFriends.Split(GlobalVar.delimiterChars, System.StringSplitOptions.RemoveEmptyEntries).OfType <string>().ToList();

                    userFriendsSL.Add(friend);

                    userFriends = "";

                    foreach (string k in userFriendsSL)
                    {
                        userFriends = userFriends + GlobalVar.cValueR + k;
                    }

                    userRequestsSL = userRequests.Split(GlobalVar.delimiterChars, System.StringSplitOptions.RemoveEmptyEntries).OfType <string>().ToList();

                    userRequestsSL.Remove(friend);

                    userRequests = "";

                    foreach (string k in userRequestsSL)
                    {
                        userRequests = userRequests + GlobalVar.cValueR + k;
                    }

                    myCommand.CommandText = "UPDATE embyrfriends.friends set friends = @friends, requestsin = @requestsin WHERE accountname = @accountnameR";

                    myCommand.Parameters.Add(new NpgsqlParameter(":accountnameR", username));

                    myCommand.Parameters.Add(new NpgsqlParameter(":friends", userFriends));

                    myCommand.Parameters.Add(new NpgsqlParameter(":requestsin", userRequests));

                    NpgsqlDataReader requestInUpdater = myCommand.ExecuteReader();

                    requestInUpdater.Read();

                    requestInUpdater.Close();

                    //Update for user complete!

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    myCommand.Parameters.Clear();

                    myCommand.CommandText = "SELECT * from embyrfriends.friends WHERE accountname = @accountnameF";

                    myCommand.Parameters.Add(new NpgsqlParameter(":accountnameF", friend));

                    NpgsqlDataReader friendsRReader = myCommand.ExecuteReader();

                    friendsRReader.Read();

                    friendFriends = friendsRReader[2].ToString();

                    friendRequests = friendsRReader[4].ToString();

                    friendsRReader.Close();

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    friendFriendsSL = friendFriends.Split(GlobalVar.delimiterChars, System.StringSplitOptions.RemoveEmptyEntries).OfType <string>().ToList();

                    friendFriendsSL.Add(username);

                    friendFriends = "";

                    foreach (string k in friendFriendsSL)
                    {
                        friendFriends = friendFriends + GlobalVar.cValueR + k;
                    }

                    friendRequestsSL = friendRequests.Split(GlobalVar.delimiterChars, System.StringSplitOptions.RemoveEmptyEntries).OfType <string>().ToList();

                    friendRequestsSL.Remove(username);

                    friendRequests = "";

                    foreach (string k in friendRequestsSL)
                    {
                        friendRequests = friendRequests + GlobalVar.cValueR + k;
                    }

                    myCommand.CommandText = "UPDATE embyrfriends.friends set friends = @friends, requestsout = @requestsout WHERE accountname = @accountnameR";

                    myCommand.Parameters.Add(new NpgsqlParameter(":accountnameR", friend));

                    myCommand.Parameters.Add(new NpgsqlParameter(":friends", friendFriends));

                    myCommand.Parameters.Add(new NpgsqlParameter(":requestsout", friendRequests));

                    NpgsqlDataReader requestOutUpdater = myCommand.ExecuteReader();

                    requestOutUpdater.Read();

                    requestOutUpdater.Close();

                    //Receiver update complete!

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    //Create PM Table

                    int    recipientKeyTag = 0;
                    string directmessage   = "";

                    recipientKeyTag = KeyTagID.GrabUserKeyTag(friend);

                    if (keyTag > recipientKeyTag)
                    {
                        directmessage = keyTag.ToString() + "28" + recipientKeyTag.ToString();
                    }

                    if (keyTag < recipientKeyTag)
                    {
                        directmessage = recipientKeyTag.ToString() + "28" + keyTag.ToString();
                    }

                    if (action == "in")
                    {
                        string pmKeyTag = numToAlpha(directmessage);
                        CreatePMAccess(pmKeyTag);
                    }

                    connection.Close();
                }
            }

            catch (NpgsqlException exc)
            {
                Console.WriteLine(exc.ToString());
            }
        }