shourya90

Untitled

Jul 17th, 2021
1,459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 KB | None | 0 0
  1. public static void AcceipFriendRequest(Player player, int id)
  2.         {
  3.             FriendsVar FR = null;
  4.             foreach(FriendsVar F in PLAYER_FIREND_LIST)
  5.             {
  6.                 if(F.FOwner == Fun.GetPlayerSqlID(player))
  7.                 {
  8.                     if(F.FFriend == id)
  9.                     {
  10.                         FR = F;
  11.                         break;
  12.                     }
  13.                 }
  14.             }
  15.             if(FR != null)
  16.             {
  17.                 FR.FriendStatus = 1;
  18.                 using (var conns = Database.FriendsConn)
  19.                 {
  20.                     conns.Open();
  21.                     string Query = "UPDATE friends SET friendstatus = @friendstatus WHERE id = @id";
  22.                     using (MySqlCommand command = new MySqlCommand(Query, conns))
  23.                     {
  24.  
  25.                         command.Parameters.AddWithValue("@friendstatus", FR.FriendStatus);
  26.                         command.Parameters.AddWithValue("@id", FR.FID);
  27.                         command.ExecuteNonQuery();
  28.  
  29.                     }
  30.                     conns.Close();
  31.                 }
  32.                 Player Target = null;
  33.                 foreach(Player P in NAPI.Pools.GetAllPlayers())
  34.                 {
  35.                     if(id == Fun.GetPlayerSqlID(P))
  36.                     {
  37.                         if (Fun.IsPlayerLoggedIn(P))
  38.                         {
  39.                             Target = P;
  40.                             break;
  41.                         }
  42.                     }
  43.                    
  44.                 }
  45.                 if(Target != null)
  46.                 {
  47.                     using (var conns = Database.FriendsConn)
  48.                     {
  49.                         conns.Open();
  50.                         string Query = $"INSERT INTO `frends` (`owner`, `friend`, `friendstatus`, `mute`) VALUES(@owner, @friend, @friendstatus, @mute)";
  51.                         using (MySqlCommand command = new MySqlCommand(Query, conns))
  52.                         {
  53.  
  54.  
  55.                             command.Parameters.AddWithValue("@owner", Fun.GetPlayerSqlID(Target));
  56.                             command.Parameters.AddWithValue("@friend", Fun.GetPlayerSqlID(player));
  57.                             command.Parameters.AddWithValue("@friendstatus", 1);
  58.                             command.Parameters.AddWithValue("@mute", 0);
  59.  
  60.  
  61.                             command.ExecuteNonQuery();
  62.  
  63.                             FriendsVar Friend = new FriendsVar();
  64.                             Friend.FFriend = Fun.GetPlayerSqlID(player);
  65.                             Friend.FOwner = Fun.GetPlayerSqlID(Target);
  66.                             Friend.FriendStatus = 1;
  67.                             Friend.FMute = 0;
  68.                             Friend.FID = (int)command.LastInsertedId;
  69.                             PLAYER_FIREND_LIST.Add(Friend);
  70.                             Fun.SendNotification(Target, $"~y~{player.Name} ~w~has accept your friend request.");
  71.  
  72.  
  73.                         }
  74.                         conns.Close();
  75.                     }
  76.                 }
  77.                 else
  78.                 {
  79.                     using (var conns = Database.FriendsConn)
  80.                     {
  81.                         conns.Open();
  82.                         string Query = $"INSERT INTO `frends` (`owner`, `friend`, `friendstatus`, `mute`) VALUES(@owner, @friend, @friendstatus, @mute)";
  83.                         using (MySqlCommand command = new MySqlCommand(Query, conns))
  84.                         {
  85.  
  86.  
  87.                             command.Parameters.AddWithValue("@owner", id);
  88.                             command.Parameters.AddWithValue("@friend", Fun.GetPlayerSqlID(player));
  89.                             command.Parameters.AddWithValue("@friendstatus", 1);
  90.                             command.Parameters.AddWithValue("@mute", 0);
  91.                             command.ExecuteNonQuery();
  92.  
  93.                         }
  94.                         conns.Close();
  95.                     }
  96.                 }
  97.             }
  98.         }
Advertisement
Add Comment
Please, Sign In to add comment