public override void SendInvitation(IRpcController controller, bnet.protocol.invitation.SendInvitationRequest request, Action <bnet.protocol.NoData> done) { /* * Error List: * The friends list is full. (Error 5000) * Too many sent invitations have been sent. (Error 5001) * Too many invitations have been received. (Error 5002) * This player is already a friend. (Error 5003) * This person was already invited to be a friend. (Error 5005) * The friend invitation was removed. (Error 5006) * Your friends list is full. (Error 5015) * The inviter's friends list is full. (Error 5016) * This account is already a friend. (Error 317201) * That friend invitation already exists. (Error 317200) * Unable to add self as a friend. (Error 317202) * The BattleTag does not exist. (Error 317203) */ // somehow protobuf lib doesnt handle this extension, so we're using a workaround to get that channelinfo. var extensionBytes = request.Params.UnknownFields.FieldDictionary[103].LengthDelimitedList[0].ToByteArray(); var friendRequest = bnet.protocol.friends.FriendInvitationParams.ParseFrom(extensionBytes); var response = bnet.protocol.NoData.CreateBuilder(); if (friendRequest.TargetEmail.ToLower() == this.Client.Account.Email.ToLower()) { this.Status = 317202; //Unable to add self as a friend. done(response.Build()); return; } if (friendRequest.TargetBattleTag == this.Client.Account.BattleTag) { this.Status = 317202; //Unable to add self as a friend. done(response.Build()); return; } Account invitee = null; if (friendRequest.HasTargetEmail) { invitee = AccountManager.GetAccountByEmail(friendRequest.TargetEmail); } else { invitee = AccountManager.GetAccountByBattletag(friendRequest.TargetBattleTag); } if (invitee == null) { if (friendRequest.HasTargetEmail) { this.Status = 4; //There was an error. Please try again. } else { this.Status = 317203; //The BattleTag does not exist. } done(response.Build()); return; } else if (FriendManager.AreFriends(this.Client.Account, invitee)) { if (friendRequest.HasTargetEmail) { this.Status = 317201; //This account is already a friend. email? } else { this.Status = 5003; //This player is already a friend. battletag? } done(response.Build()); return; } else if (FriendManager.InvitationExists(this.Client.Account, invitee)) { if (friendRequest.HasTargetEmail) { this.Status = 317200; //That friend invitation already exists. email? } else { this.Status = 5005; //This person was already invited to be a friend. battletag? } done(response.Build()); return; } Logger.Trace("{0} sent {1} friend invitation.", this.Client.Account, invitee); var invitation = bnet.protocol.invitation.Invitation.CreateBuilder() .SetId(FriendManager.InvitationIdCounter++) // we may actually need to store invitation ids in database with the actual invitation there. /raist. .SetInviterIdentity(this.Client.GetIdentity(true, false, false)) .SetInviterName(this.Client.Account.Email) // we shoulde be instead using account owner's name here. .SetInviteeIdentity(bnet.protocol.Identity.CreateBuilder().SetAccountId(invitee.BnetEntityId)) .SetInviteeName(invitee.Email) // again we should be instead using invitee's name. .SetInvitationMessage(request.Params.InvitationMessage) .SetCreationTime(DateTime.Now.ToUnixTime()) .SetExpirationTime(86400); done(response.Build()); // notify the invitee on invitation. FriendManager.HandleInvitation(this.Client, invitation.Build()); }