Exemple #1
0
        public override Task <CreatePartyResponse> CreateParty(CreatePartyRequest request, ServerCallContext context)
        {
            var playerId = AuthHeaders.ExtractPlayerId(context);
            var pit      = AuthHeaders.ExtractPit(context);

            // TODO(iuliaharasim/dom): Move logic specific to party creation in a separate class.
            PartyDataModel party;

            try
            {
                party = new PartyDataModel(playerId, pit, request.MinMembers, request.MaxMembers, request.Metadata);
            }
            catch (ArgumentException exception)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, exception.Message));
            }

            var leader = party.GetLeader();

            using (var memClient = _memoryStoreClientManager.GetClient())
                using (var transaction = memClient.CreateTransaction())
                {
                    transaction.CreateAll(new List <Entry> {
                        party, leader
                    });
                }

            return(Task.FromResult(new CreatePartyResponse {
                PartyId = party.Id
            }));
        }
Exemple #2
0
 private static PartyProto ConvertToProto(PartyDataModel party)
 {
     return(new PartyProto
     {
         Id = party.Id,
         LeaderPlayerId = party.LeaderPlayerId,
         MinMembers = party.MinMembers,
         MaxMembers = party.MaxMembers,
         Metadata = { party.Metadata },
         MemberIds = { party.MemberIds },
         CurrentPhase = ConvertToProto(party.CurrentPhase)
     });
 }
Exemple #3
0
        public void SetUp()
        {
            _testParty = new PartyDataModel(TestInitiatorPlayerId, Pit);
            _testParty.AddPlayerToParty(TestEvictedPlayerId, Pit);

            _mockTransaction       = new Mock <ITransaction>(MockBehavior.Strict);
            _mockMemoryStoreClient = new Mock <IMemoryStoreClient>(MockBehavior.Strict);
            _mockMemoryStoreClient.Setup(client => client.Dispose()).Verifiable();
            _mockMemoryStoreClient.Setup(client => client.CreateTransaction()).Returns(_mockTransaction.Object);

            var memoryStoreClientManager = new Mock <IMemoryStoreClientManager <IMemoryStoreClient> >(MockBehavior.Strict);

            memoryStoreClientManager.Setup(manager => manager.GetClient()).Returns(_mockMemoryStoreClient.Object);
            _partyService = new PartyServiceImpl(memoryStoreClientManager.Object);
        }
Exemple #4
0
        public void SetUp()
        {
            _party = new PartyDataModel(SenderPlayerId, "PIT", 6, 28);
            _party.AddPlayerToParty("FR", "PIT");

            _mockTransaction       = new Mock <ITransaction>(MockBehavior.Strict);
            _mockMemoryStoreClient = new Mock <IMemoryStoreClient>(MockBehavior.Strict);
            _mockMemoryStoreClient.Setup(client => client.CreateTransaction()).Returns(_mockTransaction.Object);
            _mockMemoryStoreClient.Setup(client => client.Dispose()).Verifiable();

            var memoryStoreClientManager = new Mock <IMemoryStoreClientManager <IMemoryStoreClient> >(MockBehavior.Strict);

            memoryStoreClientManager.Setup(manager => manager.GetClient()).Returns(_mockMemoryStoreClient.Object);
            _inviteService = new InviteServiceImpl(memoryStoreClientManager.Object);
        }
Exemple #5
0
        public void SetUp()
        {
            _partyToJoin   = new PartyDataModel(TestLeaderId, Pit);
            _playerInvites = new PlayerInvites(TestPlayerId, ImmutableHashSet.Create("invite"), ImmutableHashSet <string> .Empty);
            _invite        = new Invite(TestLeaderId, TestPlayerId, _partyToJoin.Id);

            _mockTransaction       = new Mock <ITransaction>(MockBehavior.Strict);
            _mockMemoryStoreClient = new Mock <IMemoryStoreClient>(MockBehavior.Strict);
            _mockMemoryStoreClient.Setup(client => client.Dispose()).Verifiable();
            _mockMemoryStoreClient.Setup(client => client.CreateTransaction()).Returns(_mockTransaction.Object);

            var memoryStoreClientManager = new Mock <IMemoryStoreClientManager <IMemoryStoreClient> >(MockBehavior.Strict);

            memoryStoreClientManager.Setup(manager => manager.GetClient()).Returns(_mockMemoryStoreClient.Object);
            _partyService = new PartyServiceImpl(memoryStoreClientManager.Object);
        }
Exemple #6
0
        public override Task <CreatePartyResponse> CreateParty(CreatePartyRequest request, ServerCallContext context)
        {
            var playerId = AuthHeaders.ExtractPlayerId(context);
            var pit      = AuthHeaders.ExtractPit(context);

            // TODO(iuliaharasim/dom): Move logic specific to party creation in a separate class.
            PartyDataModel party;

            try
            {
                party = new PartyDataModel(playerId, pit, request.MinMembers, request.MaxMembers, request.Metadata);
            }
            catch (ArgumentException exception)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, exception.Message));
            }

            var leader = party.GetLeader();

            using (var memClient = _memoryStoreClientManager.GetClient())
                using (var transaction = memClient.CreateTransaction())
                {
                    transaction.CreateAll(new List <Entry> {
                        party, leader
                    });
                }

            var eventAttributes = new Dictionary <string, string>
            {
                { "partyId", party.Id }
            };

            string[] eventTypes = { "player_created_party", "player_joined_party", "party_created" };
            foreach (string eventType in eventTypes)
            {
                if (eventType == "party_created")
                {
                    eventAttributes.Add("partyPhase", party.CurrentPhase.ToString());
                }
                _analytics.Send(eventType, eventAttributes, playerId);
            }

            return(Task.FromResult(new CreatePartyResponse {
                PartyId = party.Id
            }));
        }
Exemple #7
0
        public void ReturnPermissionDeniedWhenThePlayerIsNotTheLeaderOfTheParty()
        {
            // Setup the client so that it will return a party which doesn't have the player set as its leader.
            var party = new PartyDataModel(_testParty);

            party.AddPlayerToParty("SomeoneElse", Pit);
            party.UpdatePartyLeader("SomeoneElse");

            _mockMemoryStoreClient.Setup(client => client.GetAsync <Member>(TestPlayerId))
            .ReturnsAsync(_testMember);
            _mockMemoryStoreClient.Setup(client => client.GetAsync <PartyDataModel>(_testMember.PartyId))
            .ReturnsAsync(party);

            // Check that an RpcException was thrown signalising that the player doesn't have the necessary permissions
            // to delete the party.
            var context   = Util.CreateFakeCallContext(TestPlayerId, Pit);
            var exception = Assert.ThrowsAsync <RpcException>(() =>
                                                              _partyService.DeleteParty(new DeletePartyRequest(), context));

            Assert.That(exception.Message, Contains.Substring("needs to be the leader"));
            Assert.AreEqual(StatusCode.PermissionDenied, exception.StatusCode);
        }
        public void ReturnAnEquivalentParty()
        {
            var metadata = new Dictionary <string, string> {
                { "pls", "thx" }
            };
            var party = new PartyDataModel("user", "pit", 100, 200, metadata)
            {
                CurrentPhase = PartyDataModel.Phase.Matchmaking
            };

            var serializedParty   = JsonConvert.SerializeObject(party);
            var deserializedParty = JsonConvert.DeserializeObject <PartyDataModel>(serializedParty);

            Assert.AreEqual(party.Id, deserializedParty.Id);
            Assert.AreEqual(party.LeaderPlayerId, deserializedParty.LeaderPlayerId);
            Assert.AreEqual(party.MinMembers, deserializedParty.MinMembers);
            Assert.AreEqual(party.MaxMembers, deserializedParty.MaxMembers);
            CollectionAssert.AreEquivalent(party.Metadata, deserializedParty.Metadata);
            CollectionAssert.AreEquivalent(party.MemberIdToPit, new Dictionary <string, string> {
                { "user", "pit" }
            });
            Assert.AreEqual(party.CurrentPhase, deserializedParty.CurrentPhase);
        }
Exemple #9
0
        private static IEnumerable <PlayerJoinRequest> CreateJoinRequestsForEachMember(PartyDataModel party,
                                                                                       string matchmakingType, Dictionary <string, string> matchmakingMetadata)
        {
            var entriesToCreate = new List <PlayerJoinRequest>();

            foreach (var(memberId, memberPit) in party.MemberIdToPit)
            {
                entriesToCreate.Add(new PlayerJoinRequest(memberId, memberPit, matchmakingType, matchmakingMetadata));
            }

            return(entriesToCreate);
        }