/// <summary> /// 加入黑名单 /// </summary> /// <param name="Openid"></param> /// <param name="TargetOpenid"></param> public bool AddBlackFriend(Player player, string TargetOpenid) { string Openid = player.Openid; FriendInfo TarInfo = new FriendInfo { data = GetUserData(TargetOpenid) }; try { Friend friend = GetFriend(Openid); bool F = friend.GoodList.ContainsKey(TargetOpenid); bool B = friend.BlackList.ContainsKey(TargetOpenid); if (B) { return(false); } friend.BlackList.Add(TargetOpenid, TarInfo); MySqlConnection mySql = new MySqlConnection(Sqlconnstr); mySql.Open(); string Fstr = string.Format("update Player set Friend=@Friend Where ID='{0}';", Openid); #pragma warning disable CA2100 // Review SQL queries for security vulnerabilities MySqlCommand command = new MySqlCommand(Fstr, mySql); #pragma warning restore CA2100 // Review SQL queries for security vulnerabilities command.Parameters.Add("@Friend", MySqlDbType.Blob); byte[] Fbyte = Serialize(friend); command.Parameters[0].Value = Fbyte; command.ExecuteNonQuery(); command.Dispose(); mySql.Close(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
/// <summary> /// 加入申请列表 /// Openid是请求者,TargetOpenid是被请求者 /// </summary> /// <param name="Openid"></param> /// <param name="TargetOpenid"></param> public bool AddApplyFriend(Player player, string TargetOpenid) { string Openid = player.Openid; FriendInfo OnselfInfo = new FriendInfo { data = player.UserData }; try { Friend friend = GetFriend(Openid); Friend Tarfriend = GetFriend(TargetOpenid); try { bool TG = Tarfriend.GoodList.ContainsKey(Openid); bool G = friend.GoodList.ContainsKey(TargetOpenid); bool B = friend.BlackList.ContainsKey(TargetOpenid); bool TB = Tarfriend.BlackList.ContainsKey(Openid); bool TA = Tarfriend.ApplyList.ContainsKey(Openid); if (TB || TA || G) { return(false); } if (B) { try { friend.BlackList.Remove(TargetOpenid); MySqlConnection mySql = new MySqlConnection(Sqlconnstr); mySql.Open(); string Fstr = string.Format("update Player set Friend=@Friend Where ID='{0}';", Openid); #pragma warning disable CA2100 // Review SQL queries for security vulnerabilities MySqlCommand command = new MySqlCommand(Fstr, mySql); #pragma warning restore CA2100 // Review SQL queries for security vulnerabilities command.Parameters.Add("@Friend", MySqlDbType.Blob); byte[] Fbyte = Serialize(friend); command.Parameters[0].Value = Fbyte; command.ExecuteNonQuery(); command.Dispose(); mySql.Close(); } catch (Exception e) { Console.WriteLine("AddApplyFriend openid" + e.Message); return(false); } } try { Tarfriend.ApplyList.Add(Openid, OnselfInfo); MySqlConnection mySql = new MySqlConnection(Sqlconnstr); mySql.Open(); string Tstr = string.Format("update Player set Friend=@Friend Where ID='{0}'", TargetOpenid); #pragma warning disable CA2100 // Review SQL queries for security vulnerabilities MySqlCommand TarCom = new MySqlCommand(Tstr, mySql); #pragma warning restore CA2100 // Review SQL queries for security vulnerabilities TarCom.Parameters.Add("@Friend", MySqlDbType.Blob); byte[] TarByte = Serialize(Tarfriend); TarCom.Parameters[0].Value = TarByte; TarCom.ExecuteNonQuery(); TarCom.Dispose(); mySql.Close(); return(true); } catch (Exception e) { Console.WriteLine("AddApplyFriend TargetOpenid" + e.Message); return(false); } } catch (Exception e) { Console.WriteLine("BOOL " + e.Message); return(false); } } catch (Exception e) { Console.WriteLine("AddApplyFriend : " + e.Message); return(false); } }