public override async Task <ViewFriendsResponse> ViewFriends(ViewFriendsRequest request, ServerCallContext context) { DbUserModel dbUserModel = context.UserState["user"] as DbUserModel; if (dbUserModel == null) { return new ViewFriendsResponse() { Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED) } } ; ViewFriendsResponse response = new ViewFriendsResponse(); var friends = (await Task.WhenAll( (await dbUserModel.GetFriends()) .Select(async it => { return(it.PlayerId == dbUserModel.UserModel.Id ? (await DbUserModel.GetUserFromGuid(it.FriendId)).AsUser() : (await DbUserModel.GetUserFromGuid(it.PlayerId)).AsUser()); } ) )).ToList(); response.Friends.AddRange(friends); response.Status = ResponseFactory.createResponse(ResponseType.SUCCESS); return(response); }
public void BlockingAFriendRemovesThemAsAFriend() { client.SendFriendRequest(new SendFriendRequestRequest() { FriendId = authHelper.getAccountId("userTwo") }); authHelper.loginToAccount("userTwo"); client.AcceptFriendRequest(new AcceptFriendRequestRequest() { FriendId = authHelper.getAccountId("userOne"), }); // Ensure players are friends ViewFriendsResponse friends = client.ViewFriends(new ViewFriendsRequest()); Assert.AreEqual(friends.Status.IsSuccess, true); Assert.AreEqual(1, friends.Friends.Count); BlockPlayerResponse blockResponse = client.BlockPlayer(new BlockPlayerRequest() { UserIdToBlock = authHelper.getAccountId("userOne"), }); Assert.AreEqual(blockResponse.Status.IsSuccess, true); // Ensure players are not friends ViewFriendsResponse friendsAfterBlock = client.ViewFriends(new ViewFriendsRequest()); Assert.AreEqual(friendsAfterBlock.Status.IsSuccess, true); Assert.AreEqual(0, friendsAfterBlock.Friends.Count); }
public void OriginalPlayerCanViewFriendAfterOtherPlayerAcceptsRequest() { authHelper.loginToAccount("userOne"); SendFriendRequestRequest request = new SendFriendRequestRequest() { FriendId = authHelper.getAccountId("userTwo") }; SendFriendRequestResponse response = client.SendFriendRequest(request); Assert.AreEqual(response.Status.IsSuccess, true); authHelper.loginToAccount("userTwo"); AcceptFriendRequestRequest friendRequest = new AcceptFriendRequestRequest() { FriendId = authHelper.getAccountId("userOne"), }; AcceptFriendRequestResponse acceptResponse = client.AcceptFriendRequest(friendRequest); Assert.AreEqual(acceptResponse.Status.IsSuccess, true); authHelper.loginToAccount("userOne"); ViewFriendsResponse friendResponse = client.ViewFriends(new ViewFriendsRequest()); Assert.AreEqual(friendResponse.Status.IsSuccess, true); Assert.AreEqual(1, friendResponse.Friends.Count); Assert.IsTrue(friendResponse.Friends.Any((friend) => friend.Id == authHelper.getAccountId("userTwo"))); }
public void BlockingAPlayerRemovesThemAsAFriend() { authHelper.loginToAccount("userOne"); SendFriendRequestRequest request = new SendFriendRequestRequest() { FriendId = authHelper.getAccountId("userTwo") }; SendFriendRequestResponse response = client.SendFriendRequest(request); Assert.AreEqual(response.Status.IsSuccess, true); authHelper.loginToAccount("userTwo"); AcceptFriendRequestRequest friendRequest = new AcceptFriendRequestRequest() { FriendId = authHelper.getAccountId("userOne"), }; AcceptFriendRequestResponse acceptResponse = client.AcceptFriendRequest(friendRequest); Assert.AreEqual(acceptResponse.Status.IsSuccess, true); ViewFriendsResponse friendResponse = client.ViewFriends(new ViewFriendsRequest()); Assert.AreEqual(friendResponse.Status.IsSuccess, true); Assert.AreEqual(1, friendResponse.Friends.Count); Assert.IsTrue(friendResponse.Friends.Any((friend) => friend.Id == authHelper.getAccountId("userOne"))); BlockPlayerRequest blockRequest = new BlockPlayerRequest() { UserIdToBlock = authHelper.getAccountId("userOne") }; BlockPlayerResponse blockResponse = client.BlockPlayer(blockRequest); Assert.AreEqual(blockResponse.Status.IsSuccess, true); // Make sure the players are not friends. ViewFriendsResponse blockFriendListResponse = client.ViewFriends(new ViewFriendsRequest()); Assert.AreEqual(blockFriendListResponse.Status.IsSuccess, true); Assert.AreEqual(0, blockFriendListResponse.Friends.Count); authHelper.loginToAccount("userOne"); // Make sure the players are not friends. ViewFriendsResponse blockFriendListResponseUserOne = client.ViewFriends(new ViewFriendsRequest()); Assert.AreEqual(blockFriendListResponseUserOne.Status.IsSuccess, true); Assert.AreEqual(0, blockFriendListResponseUserOne.Friends.Count); }
public override async Task <ViewFriendsResponse> ViewFriends(ViewFriendsRequest request, ServerCallContext context) { RedisUserModel user = context.UserState["user"] as RedisUserModel; if (user == null) { return new ViewFriendsResponse() { Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED) } } ; ViewFriendsResponse response = new ViewFriendsResponse(); response.Friends.AddRange((await user.GetFriends()).ConvertAll(input => input.asUser())); response.Status = ResponseFactory.createResponse(ResponseType.SUCCESS); return(response); }
BattlenetRpcErrorCode HandleViewFriends(ViewFriendsRequest request, ViewFriendsResponse response) { Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method FriendsService.ViewFriends: {1}", GetCallerInfo(), request.ToString()); return(BattlenetRpcErrorCode.RpcNotImplemented); }
public override void CallServerMethod(uint token, uint methodId, CodedInputStream stream) { switch (methodId) { case 1: { SubscribeRequest request = new SubscribeRequest(); request.MergeFrom(stream); SubscribeResponse response = new SubscribeResponse(); BattlenetRpcErrorCode status = HandleSubscribe(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.Subscribe(bgs.protocol.friends.v1.SubscribeRequest: {1}) returned bgs.protocol.friends.v1.SubscribeResponse: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 2: { SendInvitationRequest request = new SendInvitationRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleSendInvitation(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.SendInvitation(bgs.protocol.SendInvitationRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 3: { GenericInvitationRequest request = new GenericInvitationRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleAcceptInvitation(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.AcceptInvitation(bgs.protocol.GenericInvitationRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 4: { GenericInvitationRequest request = new GenericInvitationRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleRevokeInvitation(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.RevokeInvitation(bgs.protocol.GenericInvitationRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 5: { GenericInvitationRequest request = new GenericInvitationRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleDeclineInvitation(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.DeclineInvitation(bgs.protocol.GenericInvitationRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 6: { GenericInvitationRequest request = new GenericInvitationRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleIgnoreInvitation(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.IgnoreInvitation(bgs.protocol.GenericInvitationRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 7: { AssignRoleRequest request = new AssignRoleRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleAssignRole(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.AssignRole(bgs.protocol.friends.v1.AssignRoleRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 8: { GenericFriendRequest request = new GenericFriendRequest(); request.MergeFrom(stream); GenericFriendResponse response = new GenericFriendResponse(); BattlenetRpcErrorCode status = HandleRemoveFriend(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.RemoveFriend(bgs.protocol.friends.v1.GenericFriendRequest: {1}) returned bgs.protocol.friends.v1.GenericFriendResponse: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 9: { ViewFriendsRequest request = new ViewFriendsRequest(); request.MergeFrom(stream); ViewFriendsResponse response = new ViewFriendsResponse(); BattlenetRpcErrorCode status = HandleViewFriends(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.ViewFriends(bgs.protocol.friends.v1.ViewFriendsRequest: {1}) returned bgs.protocol.friends.v1.ViewFriendsResponse: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 10: { UpdateFriendStateRequest request = new UpdateFriendStateRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleUpdateFriendState(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.UpdateFriendState(bgs.protocol.friends.v1.UpdateFriendStateRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 11: { UnsubscribeRequest request = new UnsubscribeRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleUnsubscribe(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.Unsubscribe(bgs.protocol.friends.v1.UnsubscribeRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } case 12: { GenericFriendRequest request = new GenericFriendRequest(); request.MergeFrom(stream); NoData response = new NoData(); BattlenetRpcErrorCode status = HandleRevokeAllInvitations(request, response); Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.RevokeAllInvitations(bgs.protocol.friends.v1.GenericFriendRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", GetCallerInfo(), request.ToString(), response.ToString(), status); if (status == 0) { SendResponse(token, response); } else { SendResponse(token, status); } break; } /*case 13: * { * GetFriendListRequest request = new GetFriendListRequest(); * request.MergeFrom(stream); * * * GetFriendListResponse response = new GetFriendListResponse(); * BattlenetRpcErrorCode status = HandleGetFriendList(request, response); * Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.GetFriendList(bgs.protocol.friends.v1.GetFriendListRequest: {1}) returned bgs.protocol.friends.v1.GetFriendListResponse: {2} status: {3}.", * GetCallerInfo(), request.ToString(), response.ToString(), status); * if (status == 0) * SendResponse(token, response); * else * SendResponse(token, status); * break; * } * case 14: * { * CreateFriendshipRequest request = new CreateFriendshipRequest(); * request.MergeFrom(stream); * * * NoData response = new NoData(); * BattlenetRpcErrorCode status = HandleCreateFriendship(request, response); * Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method FriendsService.CreateFriendship(bgs.protocol.friends.v1.CreateFriendshipRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.", * GetCallerInfo(), request.ToString(), response.ToString(), status); * if (status == 0) * SendResponse(token, response); * else * SendResponse(token, status); * break; * }*/ default: Log.outError(LogFilter.ServiceProtobuf, "Bad method id {0}.", methodId); SendResponse(token, BattlenetRpcErrorCode.RpcInvalidMethod); break; } }