Esempio n. 1
0
        public async Task Test_Distant_BlacklistAsync()
        {
            var targetSession = await TestHelpers.Instance.GenerateSessionAsync().ConfigureAwait(false);

            var blPacket = new BlPacket
            {
                CharacterName = targetSession.Character.Name
            };

            TestHelpers.Instance.ConnectedAccountHttpClient
            .Setup(s => s.GetCharacterAsync(targetSession.Character.CharacterId, null))
            .ReturnsAsync(new Tuple <ServerConfiguration?, ConnectedAccount?>(new ServerConfiguration(),
                                                                              new ConnectedAccount
            {
                ChannelId = 1, ConnectedCharacter = new Character {
                    Id = targetSession.Character.CharacterId
                }
            }));
            using var blacklist = new BlacklistController(TestHelpers.Instance.ConnectedAccountHttpClient.Object,
                                                          _characterRelationDao !, TestHelpers.Instance.CharacterDao);
            TestHelpers.Instance.BlacklistHttpClient.Setup(s => s.AddToBlacklistAsync(It.IsAny <BlacklistRequest>()))
            .Returns(blacklist.AddBlacklistAsync(new BlacklistRequest
            {
                CharacterId = _session !.Character.CharacterId,
                BlInsPacket = new BlInsPacket
                {
                    CharacterId = targetSession.Character.VisualId
                }
            }));
        public void Test_Blacklist_Character()
        {
            var targetSession = TestHelpers.Instance.GenerateSession();

            TestHelpers.Instance.ConnectedAccountHttpClient
            .Setup(s => s.GetCharacter(targetSession.Character.CharacterId, null))
            .Returns((new ServerConfiguration(),
                      new ConnectedAccount
            {
                ChannelId = 1, ConnectedCharacter = new Character {
                    Id = targetSession.Character.CharacterId
                }
            }));
            using var blacklist = new BlacklistController(TestHelpers.Instance.ConnectedAccountHttpClient.Object,
                                                          _characterRelationDao, TestHelpers.Instance.CharacterDao);
            TestHelpers.Instance.BlacklistHttpClient.Setup(s => s.AddToBlacklist(It.IsAny <BlacklistRequest>()))
            .Returns(blacklist.AddBlacklist(new BlacklistRequest
            {
                CharacterId = _session.Character.CharacterId,
                BlInsPacket = new BlInsPacket
                {
                    CharacterId = targetSession.Character.VisualId
                }
            }));
            var blinsPacket = new BlInsPacket
            {
                CharacterId = targetSession.Character.CharacterId
            };

            _blInsPacketHandler.Execute(blinsPacket, _session);
            Assert.IsNotNull(
                _characterRelationDao.FirstOrDefault(s => (_session.Character.CharacterId == s.CharacterId) &&
                                                     (targetSession.Character.CharacterId == s.RelatedCharacterId) &&
                                                     (s.RelationType == CharacterRelationType.Blocked)));
        }
Esempio n. 3
0
        /// <summary>
        ///     blins packet
        /// </summary>
        /// <param name="blinsPacket"></param>
        public void BlackListAdd(BlInsPacket blinsPacket)
        {
            if (Session.Character.CharacterRelations.Values.Any(s =>
                                                                s.RelatedCharacterId == blinsPacket.CharacterId && s.RelationType != CharacterRelationType.Blocked))
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_BLOCK_FRIEND,
                                                                  Session.Account.Language)
                });
                return;
            }

            if (Session.Character.CharacterRelations.Values.Any(s =>
                                                                s.RelatedCharacterId == blinsPacket.CharacterId && s.RelationType == CharacterRelationType.Blocked))
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.ALREADY_BLACKLISTED,
                                                                  Session.Account.Language)
                });
                return;
            }

            Session.Character.AddRelation(blinsPacket.CharacterId, CharacterRelationType.Blocked);
            Session.SendPacket(new InfoPacket
            {
                Message = Language.Instance.GetMessageFromKey(LanguageKey.BLACKLIST_ADDED, Session.Account.Language)
            });
        }
Esempio n. 4
0
        public async Task Test_Blacklist_CharacterAsync()
        {
            var targetSession = await TestHelpers.Instance.GenerateSessionAsync().ConfigureAwait(false);

            TestHelpers.Instance.ConnectedAccountHttpClient
            .Setup(s => s.GetCharacterAsync(targetSession.Character.CharacterId, null))
            .ReturnsAsync(new Tuple <ServerConfiguration?, ConnectedAccount?>(new ServerConfiguration(),
                                                                              new ConnectedAccount
            {
                ChannelId = 1, ConnectedCharacter = new Character {
                    Id = targetSession.Character.CharacterId
                }
            }));
            var blacklist = new BlacklistService(TestHelpers.Instance.ConnectedAccountHttpClient.Object,
                                                 TestHelpers.Instance.CharacterRelationDao, TestHelpers.Instance.CharacterDao);

            TestHelpers.Instance.BlacklistHttpClient.Setup(s => s.AddToBlacklistAsync(It.IsAny <BlacklistRequest>()))
            .Returns(blacklist.BlacklistPlayerAsync(_session !.Character.CharacterId, targetSession.Character.VisualId));
            var blinsPacket = new BlInsPacket
            {
                CharacterId = targetSession.Character.CharacterId
            };

            await _blInsPacketHandler !.ExecuteAsync(blinsPacket, _session).ConfigureAwait(false);

            Assert.IsNotNull(
                TestHelpers.Instance.CharacterRelationDao.FirstOrDefaultAsync(s => (_session.Character.CharacterId == s.CharacterId) &&
                                                                              (targetSession.Character.CharacterId == s.RelatedCharacterId) &&
                                                                              (s.RelationType == CharacterRelationType.Blocked)));
        }
        public void Test_Blacklist_When_Disconnected()
        {
            var blinsPacket = new BlInsPacket
            {
                CharacterId = 2
            };

            _handler.BlackListAdd(blinsPacket);
            Assert.IsFalse(_session.Character.CharacterRelations.Any(s => s.Value.RelationType == CharacterRelationType.Blocked));
        }
        public void Test_Blacklist_Character()
        {
            var blinsPacket = new BlInsPacket
            {
                CharacterId = _targetSession.Character.CharacterId
            };

            _handler.BlackListAdd(blinsPacket);
            Assert.IsTrue(_session.Character.CharacterRelations.Any(s => s.Value.RelatedCharacterId == _targetSession.Character.CharacterId &&
                                                                    s.Value.RelationType == CharacterRelationType.Blocked));
        }
        public void Test_Blacklist_When_Disconnected()
        {
            var blinsPacket = new BlInsPacket
            {
                CharacterId = 2
            };

            _blInsPacketHandler.Execute(blinsPacket, _session);
            Assert.IsNull(
                _characterRelationDao.FirstOrDefault(s =>
                                                     (_session.Character.CharacterId == s.CharacterId) &&
                                                     (s.RelationType == CharacterRelationType.Blocked)));
        }
        public async Task Test_Blacklist_When_Disconnected()
        {
            var blinsPacket = new BlInsPacket
            {
                CharacterId = 2
            };

            await _blInsPacketHandler !.ExecuteAsync(blinsPacket, _session !).ConfigureAwait(false);

            Assert.IsNull(
                _characterRelationDao.FirstOrDefault(s =>
                                                     (_session !.Character.CharacterId == s.CharacterId) &&
                                                     (s.RelationType == CharacterRelationType.Blocked)));
        }
        public void Test_Delete_Blacklist()
        {
            var blinsPacket = new BlInsPacket
            {
                CharacterId = _targetSession.Character.CharacterId
            };

            _handler.BlackListAdd(blinsPacket);

            var bldelPacket = new BlDelPacket
            {
                CharacterId = _targetSession.Character.CharacterId
            };

            _handler.BlackListDelete(bldelPacket);
            Assert.IsTrue(_session.Character.CharacterRelations.All(s => s.Value.RelatedCharacterId != _targetSession.Character.CharacterId));
        }
Esempio n. 10
0
        /// <summary>
        ///     blPacket packet
        /// </summary>
        /// <param name="blPacket"></param>
        public void DistantBlackList(BlPacket blPacket)
        {
            ClientSession target = ServerManager.Instance.Sessions.Values.FirstOrDefault(s => s.Character.Name == blPacket.CharacterName);

            if (target == null)
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER, Session.Account.Language)
                });
                return;
            }

            var blinsPacket = new BlInsPacket
            {
                CharacterId = target.Character.CharacterId
            };

            BlackListAdd(blinsPacket);
        }
Esempio n. 11
0
        public override Task ExecuteAsync(BlPacket finsPacket, ClientSession session)
        {
            var target =
                Broadcaster.Instance.GetCharacter(s => s.Name == finsPacket.CharacterName);

            if (target == null)
            {
                return(session.SendPacketAsync(new InfoPacket
                {
                    Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER,
                                                                      session.Account.Language)
                }));
            }

            var blinsPacket = new BlInsPacket
            {
                CharacterId = target.VisualId
            };

            return(session.HandlePacketsAsync(new[] { blinsPacket }));
        }
Esempio n. 12
0
        /// <summary>
        ///     blPacket packet
        /// </summary>
        /// <param name="blPacket"></param>
        public void DistantBlackList(BlPacket blPacket)
        {
            var target =
                Broadcaster.Instance.GetCharacter(s => s.Name == blPacket.CharacterName);

            if (target == null)
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER,
                                                                  Session.Account.Language)
                });
                return;
            }

            var blinsPacket = new BlInsPacket
            {
                CharacterId = target.VisualId
            };

            BlackListAdd(blinsPacket);
        }