Пример #1
0
        public async Task <LoginReply> LoginToServer(ILoginParameters parameters)
        {
            var packet = new PacketBuilder(PacketFamily.Login, PacketAction.Request)
                         .AddBreakString(parameters.Username)
                         .AddBreakString(parameters.Password)
                         .Build();

            var response = await _packetSendService.SendEncodedPacketAndWaitAsync(packet);

            if (IsInvalidResponse(response))
            {
                throw new EmptyPacketReceivedException();
            }

            var data = _loginPacketTranslator.TranslatePacket(response);

            _characterSelectorRepository.Characters = data.Characters;

            if (data.Response == LoginReply.Ok)
            {
                _playerInfoRepository.LoggedInAccountName = parameters.Username;
                _playerInfoRepository.PlayerPassword      = parameters.Password;
            }

            return(data.Response);
        }
        //todo: this is almost identical to EndPlayerWarpHandler - see if there is some way to share
        public override bool HandlePacket(IPacket packet)
        {
            var data = _refreshReplyTranslator.TranslatePacket(packet);

            var updatedMainCharacter    = data.Characters.Single(IDMatches);
            var updatedRenderProperties = _characterRepository.MainCharacter.RenderProperties
                                          .WithMapX(updatedMainCharacter.RenderProperties.MapX)
                                          .WithMapY(updatedMainCharacter.RenderProperties.MapY);

            var withoutMainCharacter = data.Characters.Where(x => !IDMatches(x));

            data = data.WithCharacters(withoutMainCharacter);

            _characterRepository.MainCharacter = _characterRepository.MainCharacter
                                                 .WithRenderProperties(updatedRenderProperties);

            _currentMapStateRepository.Characters = data.Characters.ToList();
            _currentMapStateRepository.NPCs       = data.NPCs.ToList();
            _currentMapStateRepository.MapItems   = data.Items.ToList();

            foreach (var notifier in _mapChangedNotifiers)
            {
                notifier.NotifyMapChanged(differentMapID: false, warpAnimation: WarpAnimation.None);
            }

            return(true);
        }
Пример #3
0
        public async Task <CharacterReply> CreateCharacter(ICharacterCreateParameters parameters)
        {
            var packet = new PacketBuilder(PacketFamily.Character, PacketAction.Create)
                         .AddShort(255)
                         .AddShort((short)parameters.Gender)
                         .AddShort((short)parameters.HairStyle)
                         .AddShort((short)parameters.HairColor)
                         .AddShort((short)parameters.Race)
                         .AddByte(255)
                         .AddBreakString(parameters.Name)
                         .Build();
            var responsePacket = await _packetSendService.SendEncodedPacketAndWaitAsync(packet);

            var translatedData = _characterCreatePacketTranslator.TranslatePacket(responsePacket);

            if (translatedData.Characters.Any())
            {
                _characterSelectorRepository.Characters = translatedData.Characters;
            }
            return(translatedData.Response);
        }
Пример #4
0
        public async Task CompleteCharacterLogin()
        {
            var packet = new PacketBuilder(PacketFamily.Welcome, PacketAction.Message)
                         .AddThree(0x00123456) //?
                         .AddInt(_characterRepository.MainCharacter.ID)
                         .Build();

            var response = await _packetSendService.SendEncodedPacketAndWaitAsync(packet);

            if (IsInvalidWelcome(response))
            {
                throw new EmptyPacketReceivedException();
            }

            var data = _loginRequestCompletedPacketTranslator.TranslatePacket(response);

            _newsRepository.NewsHeader = data.News.First();
            _newsRepository.NewsText   = data.News.Except(new[] { data.News.First() }).ToList();
            AddDefaultTextToChat();

            var mainCharacter = data.MapCharacters.Single(
                x => x.Name.ToLower() == _characterRepository.MainCharacter.Name.ToLower());

            var stats = _characterRepository.MainCharacter.Stats
                        .WithNewStat(CharacterStat.Weight, data.CharacterWeight)
                        .WithNewStat(CharacterStat.MaxWeight, data.CharacterMaxWeight)
                        .WithNewStat(CharacterStat.Level, mainCharacter.Stats[CharacterStat.Level])
                        .WithNewStat(CharacterStat.HP, mainCharacter.Stats[CharacterStat.HP])
                        .WithNewStat(CharacterStat.MaxHP, mainCharacter.Stats[CharacterStat.MaxHP])
                        .WithNewStat(CharacterStat.TP, mainCharacter.Stats[CharacterStat.TP])
                        .WithNewStat(CharacterStat.MaxTP, mainCharacter.Stats[CharacterStat.MaxTP]);

            _characterRepository.MainCharacter = _characterRepository.MainCharacter
                                                 .WithID(mainCharacter.ID)
                                                 .WithName(mainCharacter.Name)
                                                 .WithMapID(mainCharacter.MapID)
                                                 .WithGuildTag(mainCharacter.GuildTag)
                                                 .WithStats(stats)
                                                 .WithRenderProperties(mainCharacter.RenderProperties);

            _characterInventoryRepository.ItemInventory  = data.CharacterItemInventory.ToList();
            _characterInventoryRepository.SpellInventory = data.CharacterSpellInventory.ToList();

            _currentMapStateRepository.Characters = data.MapCharacters.Except(new[] { mainCharacter }).ToList();
            _currentMapStateRepository.NPCs       = data.MapNPCs.ToList();
            _currentMapStateRepository.MapItems   = data.MapItems.ToList();

            _playerInfoRepository.PlayerIsInGame = true;
        }
Пример #5
0
        public async Task RequestCharacterLogin(ICharacter character)
        {
            var packet = new PacketBuilder(PacketFamily.Welcome, PacketAction.Request)
                         .AddInt(character.ID)
                         .Build();

            var response = await _packetSendService.SendEncodedPacketAndWaitAsync(packet);

            if (IsInvalidWelcome(response))
            {
                throw new EmptyPacketReceivedException();
            }

            var data = _loginRequestGrantedPacketTranslator.TranslatePacket(response);

            _characterRepository.MainCharacter = character
                                                 .WithID(data.CharacterID)
                                                 .WithName(data.Name)
                                                 .WithTitle(data.Title)
                                                 .WithGuildName(data.GuildName)
                                                 .WithGuildRank(data.GuildRank)
                                                 .WithGuildTag(data.GuildTag)
                                                 .WithClassID(data.ClassID)
                                                 .WithMapID(data.MapID)
                                                 .WithAdminLevel(data.AdminLevel)
                                                 .WithStats(data.CharacterStats);
            _paperdollRepository.MainCharacterPaperdoll = data.Paperdoll.ToList();

            _playerInfoRepository.PlayerID          = data.PlayerID;
            _playerInfoRepository.IsFirstTimePlayer = data.FirstTimePlayer;
            _currentMapStateRepository.CurrentMapID = data.MapID;

            _loginFileChecksumRepository.MapChecksum = data.MapRID.ToArray();
            _loginFileChecksumRepository.MapLength   = data.MapLen;

            _loginFileChecksumRepository.EIFChecksum = data.EifRid;
            _loginFileChecksumRepository.EIFLength   = data.EifLen;
            _loginFileChecksumRepository.ENFChecksum = data.EnfRid;
            _loginFileChecksumRepository.ENFLength   = data.EnfLen;
            _loginFileChecksumRepository.ESFChecksum = data.EsfRid;
            _loginFileChecksumRepository.ESFLength   = data.EsfLen;
            _loginFileChecksumRepository.ECFChecksum = data.EcfRid;
            _loginFileChecksumRepository.ECFLength   = data.EcfLen;
        }
Пример #6
0
        public override bool HandlePacket(IPacket packet)
        {
            _currentMapStateRepository.MapWarpState = WarpState.WarpCompleting;

            var warpAgreePacketData = _warpAgreePacketTranslator.TranslatePacket(packet);

            var updatedMainCharacter = warpAgreePacketData.Characters.Single(MainCharacterIDMatches);

            //character.renderproperties.isdead is set True by the attack handler
            //the character needs to be brought back to life when the are taken to the home map
            var bringBackToLife = _characterRepository.MainCharacter.RenderProperties.WithAlive();

            _characterRepository.MainCharacter = _characterRepository.MainCharacter
                                                 .WithRenderProperties(bringBackToLife)
                                                 .WithAppliedData(updatedMainCharacter);

            var withoutMainCharacter = warpAgreePacketData.Characters.Where(x => !MainCharacterIDMatches(x));

            warpAgreePacketData = warpAgreePacketData.WithCharacters(withoutMainCharacter);

            var differentMapID = _currentMapStateRepository.CurrentMapID != warpAgreePacketData.MapID;

            _currentMapStateRepository.CurrentMapID = warpAgreePacketData.MapID;
            _currentMapStateRepository.Characters   = warpAgreePacketData.Characters.ToList();
            _currentMapStateRepository.NPCs         = warpAgreePacketData.NPCs.ToList();
            _currentMapStateRepository.MapItems     = warpAgreePacketData.Items.ToList();
            _currentMapStateRepository.OpenDoors.Clear();
            _currentMapStateRepository.ShowMiniMap = _currentMapStateRepository.ShowMiniMap &&
                                                     _currentMapProvider.CurrentMap.Properties.MapAvailable;

            foreach (var notifier in _mapChangedNotifiers)
            {
                notifier.NotifyMapChanged(differentMapID: differentMapID,
                                          warpAnimation: warpAgreePacketData.WarpAnimation);
            }

            _currentMapStateRepository.MapWarpState = WarpState.None;

            return(true);
        }
        public async Task <IInitializationData> BeginHandshake()
        {
            var stupidHash     = _hashService.StupidHash(new Random().Next(6, 12));
            var hdSerialNumber = _hdSerialNumberService.GetHDSerialNumber();

            var packet = new PacketBuilder(PacketFamily.Init, PacketAction.Init)
                         .AddThree(stupidHash)
                         .AddChar(_configurationProvider.VersionMajor)
                         .AddChar(_configurationProvider.VersionMinor)
                         .AddChar(_configurationProvider.VersionBuild)
                         .AddChar(112)
                         .AddChar((byte)hdSerialNumber.Length)
                         .AddString(hdSerialNumber)
                         .Build();

            var responsePacket = await _packetSendService.SendRawPacketAndWaitAsync(packet);

            if (IsInvalidInitPacket(responsePacket))
            {
                throw new EmptyPacketReceivedException();
            }

            return(_initPacketTranslator.TranslatePacket(responsePacket));
        }