Example #1
0
		/// <summary>
		/// Returns friend for invitation, or null if the user doesn't exist.
		/// </summary>
		/// <param name="characterName"></param>
		/// <param name="server"></param>
		/// <returns></returns>
		public Friend GetFriendFromUser(string characterName, string server)
		{
			using (var conn = this.Connection)
			using (var mc = new MySqlCommand("SELECT * FROM `contacts` WHERE `characterName` = @characterName AND `server` = @server", conn))
			{
				mc.Parameters.AddWithValue("@characterName", characterName);
				mc.Parameters.AddWithValue("@server", server);

				using (var reader = mc.ExecuteReader())
				{
					if (!reader.Read())
						return null;

					var friend = new Friend();
					friend.AccountId = reader.GetString("accountId");
					friend.Name = characterName;
					friend.Server = server;
					friend.Id = reader.GetInt32("contactId");
					friend.Status = (ContactStatus)reader.GetByte("status");

					return friend;
				}
			}
		}
Example #2
0
		/// <summary>
		/// Returns list of friends for user.
		/// </summary>
		/// <param name="user"></param>
		/// <returns></returns>
		public List<Friend> GetFriends(User user)
		{
			var result = new List<Friend>();

			using (var conn = this.Connection)
			using (var mc = new MySqlCommand(
				"SELECT f.userId2 AS friendId, c.characterName AS friendName, c.server AS friendServer, f.groupId AS groupId, f.status AS status " +
				"FROM `friends` AS f " +
				"INNER JOIN `contacts` AS c ON `f`.`userId2` = `c`.`contactId` " +
				"WHERE `f`.`userId1` = @userId", conn))
			{
				mc.Parameters.AddWithValue("@userId", user.Id);

				using (var reader = mc.ExecuteReader())
				{
					while (reader.Read())
					{
						var friend = new Friend();
						friend.Id = reader.GetInt32("friendId");
						friend.Name = reader.GetStringSafe("friendName");
						friend.Server = reader.GetStringSafe("friendServer");
						friend.GroupId = reader.GetInt32("groupId");
						friend.FriendshipStatus = (FriendshipStatus)reader.GetByte("status");

						result.Add(friend);
					}
				}
			}

			return result;
		}
Example #3
0
		/// <summary>
		/// Response to FriendInvite.
		/// </summary>
		/// <param name="client"></param>
		/// <param name="result"></param>
		/// <param name="friend">Required for success, otherwise can be left null.</param>
		public static void FriendInviteR(MsgrClient client, FriendInviteResult result, Friend friend = null)
		{
			if (result == FriendInviteResult.Success && friend == null)
				throw new ArgumentNullException("friend");

			var packet = new Packet(Op.Msgr.FriendInviteR, 0);

			//packet.PutInt((int)result);
			packet.PutInt((int)result);
			if (result == FriendInviteResult.Success)
			{
				packet.PutInt(friend.Id);
				packet.PutString(friend.FullName);
				packet.PutByte((byte)friend.FriendshipStatus);
			}

			client.Send(packet);
		}