Ejemplo n.º 1
0
        public void ImportAccounts()
        {
            var acc1 = new AccountDto
            {
                Authority = AuthorityType.GameMaster,
                Name      = "admin",
                Password  = password
            };

            if (_accountDao.FirstOrDefault(s => s.Name == acc1.Name) == null)
            {
                _accountDao.InsertOrUpdate(ref acc1);
            }

            var acc2 = new AccountDto
            {
                Authority = AuthorityType.User,
                Name      = "test",
                Password  = password
            };

            if (_accountDao.FirstOrDefault(s => s.Name == acc1.Name) == null)
            {
                _accountDao.InsertOrUpdate(ref acc2);
            }
        }
Ejemplo n.º 2
0
        public IActionResult Delete(Guid id)
        {
            var rel = _characterRelationDao.FirstOrDefault(s =>
                                                           (s.CharacterRelationId == id) && (s.RelationType == CharacterRelationType.Friend));
            var rel2 = _characterRelationDao.FirstOrDefault(s =>
                                                            (s.CharacterId == rel.RelatedCharacterId) && (s.RelatedCharacterId == rel.CharacterId) &&
                                                            (s.RelationType == CharacterRelationType.Friend));

            _characterRelationDao.Delete(rel);
            _characterRelationDao.Delete(rel2);
            return(Ok());
        }
        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)));
        }
Ejemplo n.º 4
0
        public List <WarehouseLink> GetWarehouseItems(Guid?id, long?ownerId, WarehouseType warehouseType, byte?slot)
        {
            var list = new List <WarehouseLink>();

            if (id == null)
            {
                var warehouse = _warehouseDao.FirstOrDefault(s
                                                             => s.Type == warehouseType &&
                                                             s.CharacterId == (warehouseType == WarehouseType.FamilyWareHouse ? null : ownerId) &&
                                                             s.FamilyId == (warehouseType == WarehouseType.FamilyWareHouse ? ownerId : null));
                if (slot == null)
                {
                    //todo add
                }
                else
                {
                    //todo add
                }
            }
            else
            {
                var warehouseLink = new WarehouseLink();
                list.Add(warehouseLink);
            }

            return(list);
        }
Ejemplo n.º 5
0
        public IActionResult ConnectUser(string userName, string password)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(BadRequest(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.AUTH_ERROR))));
            }

            var account = _accountDao.FirstOrDefault(s => s.Name == userName);

            if (!(account?.Password.ToLower().Equals(password.ToSha512()) ?? false))
            {
                return(BadRequest(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.AUTH_INCORRECT)));
            }

            var claims = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.NameIdentifier, userName),
                new Claim(ClaimTypes.Role, account.Authority.ToString())
            });
            var keyByteArray  = Encoding.Default.GetBytes(_apiConfiguration.Password.ToSha512());
            var signinKey     = new SymmetricSecurityKey(keyByteArray);
            var handler       = new JwtSecurityTokenHandler();
            var securityToken = handler.CreateToken(new SecurityTokenDescriptor
            {
                Subject            = claims,
                Issuer             = "Issuer",
                Audience           = "Audience",
                SigningCredentials = new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256)
            });

            return(Ok(handler.WriteToken(securityToken)));
        }
Ejemplo n.º 6
0
        public void Test_Distant_Blacklist()
        {
            var targetSession = TestHelpers.Instance.GenerateSession();
            var blPacket      = new BlPacket
            {
                CharacterName = targetSession.Character.Name
            };

            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
                }
            }));
            _blPacketHandler.Execute(blPacket, _session);
            Assert.IsTrue(_characterRelationDao.FirstOrDefault(s =>
                                                               (s.CharacterId == _session.Character.CharacterId) &&
                                                               (s.RelatedCharacterId == targetSession.Character.CharacterId) &&
                                                               (s.RelationType == CharacterRelationType.Blocked)) != null);
        }
Ejemplo n.º 7
0
        public void Initialize()
        {
            NpcMonster = _npcMonsters.Find(s => s.NpcMonsterVNum == VNum);
            Mp         = NpcMonster?.MaxMp ?? 0;
            Hp         = NpcMonster?.MaxHp ?? 0;
            Speed      = NpcMonster?.Speed ?? 0;
            PositionX  = MapX;
            PositionY  = MapY;
            IsAlive    = true;
            Requests   = new Subject <RequestData>();
            Requests.Subscribe(ShowDialog);
            var shopObj = _shops.FirstOrDefault(s => s.MapNpcId == MapNpcId);

            if (shopObj != null)
            {
                var shopItemsDto  = _shopItems.Where(s => s.ShopId == shopObj.ShopId);
                var shopItemsList = new ConcurrentDictionary <int, ShopItem>();
                Parallel.ForEach(shopItemsDto, shopItemGrouping =>
                {
                    var shopItem          = shopItemGrouping.Adapt <ShopItem>();
                    shopItem.ItemInstance = _itemProvider.Create(shopItemGrouping.ItemVNum, -1);
                    shopItemsList[shopItemGrouping.ShopItemId] = shopItem;
                });
                _shop           = shopObj.Adapt <Shop>();
                _shop.ShopItems = shopItemsList;
            }
        }
Ejemplo n.º 8
0
        public IActionResult Delete(Guid id)
        {
            var rel = _characterRelationDao.FirstOrDefault(s =>
                                                           (s.CharacterRelationId == id) && (s.RelationType == CharacterRelationType.Blocked));

            _characterRelationDao.Delete(rel);
            return(Ok());
        }
Ejemplo n.º 9
0
        public void InsertMapMonster(List <string[]> packetList)
        {
            var   monsterCounter   = 0;
            short map              = 0;
            var   mobMvPacketsList = new List <int>();
            var   monsters         = new List <MapMonsterDto>();

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("mv") && o[1].Equals("3")))
            {
                if (!mobMvPacketsList.Contains(Convert.ToInt32(currentPacket[2])))
                {
                    mobMvPacketsList.Add(Convert.ToInt32(currentPacket[2]));
                }
            }

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("in") || o[0].Equals("at")))
            {
                if (currentPacket.Length > 5 && currentPacket[0] == "at")
                {
                    map = short.Parse(currentPacket[2]);
                    continue;
                }

                if (currentPacket.Length <= 7 || currentPacket[0] != "in" || currentPacket[1] != "3")
                {
                    continue;
                }

                var monster = new MapMonsterDto
                {
                    MapId        = map,
                    VNum         = short.Parse(currentPacket[2]),
                    MapMonsterId = int.Parse(currentPacket[3]),
                    MapX         = short.Parse(currentPacket[4]),
                    MapY         = short.Parse(currentPacket[5]),
                    Direction    = (byte)(currentPacket[6] == string.Empty ? 0 : byte.Parse(currentPacket[6])),
                    IsDisabled   = false
                };
                monster.IsMoving = mobMvPacketsList.Contains(monster.MapMonsterId);

                if (_npcMonsterDao.FirstOrDefault(s => s.NpcMonsterVNum.Equals(monster.VNum)) == null ||
                    _mapMonsterDao.FirstOrDefault(s => s.MapMonsterId.Equals(monster.MapMonsterId)) != null ||
                    monsters.Count(i => i.MapMonsterId == monster.MapMonsterId) != 0)
                {
                    continue;
                }

                monsters.Add(monster);
                monsterCounter++;
            }


            IEnumerable <MapMonsterDto> mapMonsterDtos = monsters;

            _mapMonsterDao.InsertOrUpdate(mapMonsterDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MONSTERS_PARSED),
                                monsterCounter);
        }
Ejemplo n.º 10
0
        public bool DeleteWarehouseItem(Guid id)
        {
            var item = _warehouseItemDao.FirstOrDefault(s => s.Id == id);

            _warehouseItemDao.Delete(item.Id);
            _warehouseDao.Delete(item.WarehouseId);
            _itemInstanceDao.Delete(item.ItemInstanceId);
            return(true);
        }
Ejemplo n.º 11
0
        public LanguageKey AddBazaar([FromBody] BazaarRequest bazaarRequest)
        {
            var items = _holder.BazaarItems.Values.Where(o => o.BazaarItem !.SellerId == bazaarRequest.CharacterId);

            if (items.Count() > 10 * (bazaarRequest.HasMedal ? 10 : 1) - 1)
            {
                return(LanguageKey.LIMIT_EXCEEDED);
            }

            var item = _itemInstanceDao.FirstOrDefault(s => s.Id == bazaarRequest.ItemInstanceId);

            if ((item == null) || (item.Amount < bazaarRequest.Amount) || (bazaarRequest.Amount < 0) ||
                (bazaarRequest.Price < 0))
            {
                throw new ArgumentException();
            }

            Guid itemId;

            if (item.Amount == bazaarRequest.Amount)
            {
                itemId = item.Id;
            }
            else
            {
                itemId       = item.Id;
                item.Amount -= bazaarRequest.Amount;
                _itemInstanceDao.InsertOrUpdate(ref item);
                item.Id = Guid.NewGuid();
            }

            _itemInstanceDao.InsertOrUpdate(ref item);

            var bazaarItem = new BazaarItemDto
            {
                Amount         = bazaarRequest.Amount,
                DateStart      = SystemTime.Now(),
                Duration       = bazaarRequest.Duration,
                IsPackage      = bazaarRequest.IsPackage,
                MedalUsed      = bazaarRequest.HasMedal,
                Price          = bazaarRequest.Price,
                SellerId       = bazaarRequest.CharacterId,
                ItemInstanceId = item.Id
            };

            _bazaarItemDao.InsertOrUpdate(ref bazaarItem);
            _holder.BazaarItems.TryAdd(bazaarItem.BazaarItemId,
                                       new BazaarLink
            {
                BazaarItem   = bazaarItem, SellerName = bazaarRequest.CharacterName,
                ItemInstance = item.Adapt <ItemInstanceDto>()
            });

            return(LanguageKey.OBJECT_IN_BAZAAR);
        }
Ejemplo n.º 12
0
        public static void Main()
        {
            try { Console.Title = Title; } catch (PlatformNotSupportedException) { }
            Core.I18N.Logger.PrintHeader(ConsoleText);
            InitializeConfiguration();
            TypeAdapterConfig.GlobalSettings.Default.IgnoreAttribute(typeof(I18NFromAttribute));
            LogLanguage.Language = DatabaseConfiguration.Language;
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <NosCoreContext>();
                optionsBuilder.UseNpgsql(DatabaseConfiguration.Database !.ConnectionString);
                DataAccessHelper.Instance.Initialize(optionsBuilder.Options);

                var npcMonsters = _npcMonsterDao.LoadAll().ToList();
                TypeAdapterConfig <MapMonsterDto, GameObject.MapMonster> .NewConfig().ConstructUsing(src => new GameObject.MapMonster(npcMonsters, Logger));

                TypeAdapterConfig <MapNpcDto, GameObject.MapNpc> .NewConfig().ConstructUsing(src => new GameObject.MapNpc(new Mock <IItemProvider>().Object, new Mock <IGenericDao <ShopDto> >().Object, new Mock <IGenericDao <ShopItemDto> >().Object, npcMonsters, Logger, new List <NpcTalkDto>()));

                while (true)
                {
                    Logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SELECT_MAPID));
                    var input = Console.ReadLine();
                    if ((input == null) || !int.TryParse(input, out var askMapId))
                    {
                        Logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.WRONG_SELECTED_MAPID));
                        continue;
                    }

                    var map = _mapDao.FirstOrDefault(m => m.MapId == askMapId)?.Adapt <GameObject.Map.Map>();

                    if ((!(map?.XLength > 0)) || (map.YLength <= 0))
                    {
                        continue;
                    }

                    if (_guiWindow?.Exists ?? false)
                    {
                        _guiWindow.Exit();
                    }

                    new Thread(() =>
                    {
                        _guiWindow = new GuiWindow(map, 4, map.XLength, map.YLength, GraphicsMode.Default,
                                                   $"NosCore Pathfinder GUI - Map {map.MapId}");
                        _guiWindow.Run(30);
                    }).Start();
                }
            }
            catch
            {
                Console.ReadKey();
            }
        }
Ejemplo n.º 13
0
        public override void Execute(PclPacket getGiftPacket, ClientSession clientSession)
        {
            var isCopy = getGiftPacket.Type == 2;
            var mail   = _mailHttpClient.GetGift(getGiftPacket.GiftId, clientSession.Character.VisualId, isCopy);

            if (mail == null)
            {
                return;
            }

            if ((getGiftPacket.Type == 4) && (mail.ItemInstance != null))
            {
                var itemInstance = _itemInstanceDao.FirstOrDefault(s => s.Id == mail.ItemInstance.Id);
                var item         = _itemProvider.Convert(itemInstance);
                item.Id = Guid.NewGuid();
                var newInv = clientSession.Character.InventoryService
                             .AddItemToPocket(InventoryItemInstance.Create(item, clientSession.Character.CharacterId))
                             .FirstOrDefault();
                if (newInv != null)
                {
                    clientSession.SendPacket(clientSession.Character.GenerateSay(
                                                 string.Format(
                                                     Language.Instance.GetMessageFromKey(LanguageKey.ITEM_RECEIVED,
                                                                                         clientSession.Account.Language),
                                                     newInv.ItemInstance.Item.Name, newInv.ItemInstance.Amount), SayColorType.Green));
                    clientSession.SendPacket(
                        new ParcelPacket {
                        Type = 2, Unknown = 1, Id = (short)getGiftPacket.GiftId
                    });
                    _mailHttpClient.DeleteGift(getGiftPacket.GiftId, clientSession.Character.VisualId, isCopy);
                }
                else
                {
                    clientSession.SendPacket(new ParcelPacket {
                        Type = 5, Unknown = 1, Id = 0
                    });
                    clientSession.SendPacket(new MsgPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_PLACE,
                                                                      clientSession.Account.Language),
                        Type = 0
                    });
                }
            }
            else if (getGiftPacket.Type == 5)
            {
                clientSession.SendPacket(new ParcelPacket {
                    Type = 7, Unknown = 1, Id = (short)getGiftPacket.GiftId
                });
                _mailHttpClient.DeleteGift(getGiftPacket.GiftId, clientSession.Character.VisualId, isCopy);
            }
        }
Ejemplo n.º 14
0
        public void AddThirdData(string[] currentLine)
        {
            _card.TimeoutBuff       = short.Parse(currentLine[2]);
            _card.TimeoutBuffChance = byte.Parse(currentLine[3]);
            // investigate
            if (_cardDao.FirstOrDefault(s => s.CardId == _card.CardId) == null)
            {
                Cards.Add(_card);
                _counter++;
            }

            _itemAreaBegin = false;
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Char_DEL packet
        /// </summary>
        /// <param name="characterDeletePacket"></param>
        public void DeleteCharacter(CharacterDeletePacket characterDeletePacket)
        {
            if (Session.HasCurrentMapInstance)
            {
                return;
            }

            var account = _accountDao
                          .FirstOrDefault(s => s.AccountId.Equals(Session.Account.AccountId));

            if (account == null)
            {
                return;
            }

            if (account.Password.ToLower() == characterDeletePacket.Password.ToSha512())
            {
                var character = _characterDao.FirstOrDefault(s =>
                                                             s.AccountId == account.AccountId && s.Slot == characterDeletePacket.Slot &&
                                                             s.State == CharacterState.Active);
                if (character == null)
                {
                    return;
                }

                character.State = CharacterState.Inactive;
                _characterDao.InsertOrUpdate(ref character);

                LoadCharacters(null);
            }
            else
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Session.GetMessageFromKey(LanguageKey.BAD_PASSWORD)
                });
            }
        }
Ejemplo n.º 16
0
        public void InsertShops(List <string[]> packetList)
        {
            int shopCounter = 0;
            var shops       = new List <ShopDto>();

            foreach (var currentPacket in packetList.Where(o => o.Length > 6 && o[0].Equals("shop") && o[1].Equals("2"))
                     )
            {
                short npcid = short.Parse(currentPacket[2]);
                var   npc   = _mapNpcDao.FirstOrDefault(s => s.MapNpcId == npcid);
                if (npc == null)
                {
                    continue;
                }

                StringBuilder name = new StringBuilder();
                for (int j = 6; j < currentPacket.Length; j++)
                {
                    name.Append($"{currentPacket[j]}");
                    if (j != currentPacket.Length - 1)
                    {
                        name.Append(" ");
                    }
                }

                var shop = new ShopDto
                {
                    Name     = name.ToString(),
                    MapNpcId = npc.MapNpcId,
                    MenuType = byte.Parse(currentPacket[4]),
                    ShopType = byte.Parse(currentPacket[5])
                };

                if (_shopDao.FirstOrDefault(s => s.MapNpcId == npc.MapNpcId) != null ||
                    shops.Any(s => s.MapNpcId == npc.MapNpcId))
                {
                    continue;
                }

                shops.Add(shop);
                shopCounter++;
            }

            IEnumerable <ShopDto> shopDtos = shops;

            _shopDao.InsertOrUpdate(shopDtos);

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SHOPS_PARSED),
                                shopCounter);
        }
Ejemplo n.º 17
0
        public override void Execute(CharNewJobPacket packet, ClientSession clientSession)
        {
            //TODO add a flag on Account
            if (_characterDao.FirstOrDefault(s =>
                                             s.Level >= 80 && s.AccountId == clientSession.Account.AccountId && s.State == CharacterState.Active) == null)
            {
                //Needs at least a level 80 to create a martial artist
                //TODO log
                return;
            }

            if (_characterDao.FirstOrDefault(s =>
                                             s.AccountId == clientSession.Account.AccountId &&
                                             s.Class == CharacterClassType.MartialArtist && s.State == CharacterState.Active) != null)
            {
                //If already a martial artist, can't create another
                //TODO log
                return;
            }
            //todo add cooldown for recreate 30days

            clientSession.HandlePackets(new[] { packet.Adapt <CharNewPacket>() });
        }
Ejemplo n.º 18
0
        public void Test_Add_Distant_Friend()
        {
            var targetSession       = TestHelpers.Instance.GenerateSession();
            var friendRequestHolder = new FriendRequestHolder();

            friendRequestHolder.FriendRequestCharacters.TryAdd(Guid.NewGuid(),
                                                               new Tuple <long, long>(targetSession.Character.CharacterId, _session.Character.CharacterId));
            var flPacket = new FlPacket
            {
                CharacterName = targetSession.Character.Name
            };

            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
                }
            }));
            TestHelpers.Instance.ConnectedAccountHttpClient
            .Setup(s => s.GetCharacter(_session.Character.CharacterId, null))
            .Returns((new ServerConfiguration(),
                      new ConnectedAccount
            {
                ChannelId = 1, ConnectedCharacter = new Character {
                    Id = _session.Character.CharacterId
                }
            }));
            using var friend = new FriendController(_logger, _characterRelationDao, TestHelpers.Instance.CharacterDao,
                                                    friendRequestHolder, TestHelpers.Instance.ConnectedAccountHttpClient.Object);
            TestHelpers.Instance.FriendHttpClient.Setup(s => s.AddFriend(It.IsAny <FriendShipRequest>()))
            .Returns(friend.AddFriend(new FriendShipRequest
            {
                CharacterId = _session.Character.CharacterId,
                FinsPacket  = new FinsPacket
                {
                    CharacterId = targetSession.Character.VisualId,
                    Type        = FinsPacketType.Accepted
                }
            }));

            _flPacketHandler.Execute(flPacket, _session);
            Assert.IsTrue(_characterRelationDao.FirstOrDefault(s =>
                                                               (s.CharacterId == _session.Character.CharacterId) &&
                                                               (s.RelatedCharacterId == targetSession.Character.CharacterId) &&
                                                               (s.RelationType == CharacterRelationType.Friend)) != null);
        }
Ejemplo n.º 19
0
        public override Task ExecuteAsync(CharNewJobPacket packet, ClientSession clientSession)
        {
            //TODO add a flag on Account
            if (_characterDao.FirstOrDefault(s =>
                                             (s.Level >= 80) && (s.AccountId == clientSession.Account.AccountId) &&
                                             (s.State == CharacterState.Active)) == null)
            {
                //Needs at least a level 80 to create a martial artist
                //TODO log
                return(Task.CompletedTask);
            }

            if (_characterDao.FirstOrDefault(s =>
                                             (s.AccountId == clientSession.Account.AccountId) &&
                                             (s.Class == CharacterClassType.MartialArtist) && (s.State == CharacterState.Active)) != null)
            {
                //If already a martial artist, can't create another
                //TODO log
                return(Task.CompletedTask);
            }
            //todo add cooldown for recreate 30days

            return(clientSession.HandlePacketsAsync(new[] { packet.Adapt <CharNewPacket>() }));
        }
Ejemplo n.º 20
0
        public MailData?ViewMail(long id, [FromBody] JsonPatchDocument <MailDto> mailData)
        {
            var mail = _mailDao.FirstOrDefault(s => s.MailId == id);

            if (mail == null)
            {
                return(null);
            }


            mailData.ApplyTo(mail);
            var bz = mail;

            _mailDao.InsertOrUpdate(ref bz);
            var savedData =
                _parcelHolder[mail.IsSenderCopy ? (long)mail.SenderId ! : mail.ReceiverId][mail.IsSenderCopy]
Ejemplo n.º 21
0
        private void Initialize()
        {
            var mails         = _mailDao.LoadAll().ToList();
            var idcopy        = 0;
            var idmail        = 0;
            var charactersIds = mails.Select(s => s.ReceiverId)
                                .Union(mails.Where(s => s.SenderId != null).Select(s => (long)s.SenderId !));
            var characternames = new Dictionary <long, string?>();

            foreach (var characterId in charactersIds)
            {
                characternames.Add(characterId, _characterDao.FirstOrDefault(s => s.CharacterId == characterId)?.Name);
            }

            foreach (var mail in mails)
            {
                var     itinst = _itemInstanceDao.FirstOrDefault(s => s.Id == mail.ItemInstanceId);
                ItemDto?it     = null;
                if (itinst != null)
                {
                    it = _items.FirstOrDefault(s => s.VNum == itinst.ItemVNum);
                }

                var senderName   = mail.SenderId == null ? "NOSMALL" : characternames[(long)mail.SenderId];
                var receiverName = characternames[mail.ReceiverId];
                var mailId       = mail.IsSenderCopy ? (short)idcopy : (short)idmail;
                this[mail.IsSenderCopy ? mail.SenderId ?? 0 : mail.ReceiverId][mail.IsSenderCopy].TryAdd(mailId,
                                                                                                         new MailData
                {
                    ItemInstance = itinst?.Adapt <ItemInstanceDto>(),
                    SenderName   = senderName,
                    ReceiverName = receiverName,
                    MailId       = mailId,
                    MailDto      = mail,
                    ItemType     = (short?)it?.ItemType ?? -1
                });
                if (mail.IsSenderCopy)
                {
                    idcopy++;
                }
                else
                {
                    idmail++;
                }
            }
        }
Ejemplo n.º 22
0
        public override void Execute(CharacterDeletePacket packet, ClientSession clientSession)
        {
            if (clientSession.HasCurrentMapInstance)
            {
                return;
            }

            var account = _accountDao
                          .FirstOrDefault(s => s.AccountId.Equals(clientSession.Account.AccountId));

            if (account == null)
            {
                return;
            }

            if ((account.Password.ToLower() == packet.Password.ToSha512()) || (account.Name == packet.Password))
            {
                var character = _characterDao.FirstOrDefault(s =>
                                                             (s.AccountId == account.AccountId) && (s.Slot == packet.Slot) &&
                                                             (s.State == CharacterState.Active));
                if (character == null)
                {
                    return;
                }

                character.State = CharacterState.Inactive;
                _characterDao.InsertOrUpdate(ref character);

                clientSession.HandlePackets(new[]
                {
                    new EntryPointPacket
                    {
                        Header = "EntryPoint",
                        Title  = "EntryPoint",
                        Name   = account.Name
                    }
                });
            }
            else
            {
                clientSession.SendPacket(new InfoPacket
                {
                    Message = clientSession.GetMessageFromKey(LanguageKey.BAD_PASSWORD)
                });
            }
        }
Ejemplo n.º 23
0
        public static void Main()
        {
            Console.Title = Title;
            Core.I18N.Logger.PrintHeader(ConsoleText);
            InitializeConfiguration();
            LogLanguage.Language = DatabaseConfiguration.Language;
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <NosCoreContext>();
                optionsBuilder.UseNpgsql(DatabaseConfiguration.Database.ConnectionString);
                DataAccessHelper.Instance.Initialize(optionsBuilder.Options);

                while (true)
                {
                    Logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SELECT_MAPID));
                    var input = Console.ReadLine();
                    if (input == null || !int.TryParse(input, out var askMapId))
                    {
                        Logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.WRONG_SELECTED_MAPID));
                        continue;
                    }

                    var map = (Map)_mapDao.FirstOrDefault(m => m.MapId == askMapId);

                    if (map?.XLength > 0 && map.YLength > 0)
                    {
                        if (_guiWindow?.Exists ?? false)
                        {
                            _guiWindow.Exit();
                        }

                        new Thread(() =>
                        {
                            _guiWindow = new GuiWindow(map, 4, map.XLength, map.YLength, GraphicsMode.Default,
                                                       $"NosCore Pathfinder GUI - Map {map.MapId}");
                            _guiWindow.Run(30);
                        }).Start();
                    }
                }
            }
            catch
            {
                Console.ReadKey();
            }
        }
Ejemplo n.º 24
0
        public List <CharacterRelationStatus> GetFriends(long id)
        {
            var charList = new List <CharacterRelationStatus>();
            var list     = _characterRelationDao
                           .Where(s => (s.CharacterId == id) && (s.RelationType != CharacterRelationType.Blocked));

            foreach (var rel in list)
            {
                charList.Add(new CharacterRelationStatus
                {
                    CharacterName       = _characterDao.FirstOrDefault(s => s.CharacterId == rel.RelatedCharacterId).Name,
                    CharacterId         = rel.RelatedCharacterId,
                    IsConnected         = _connectedAccountHttpClient.GetCharacter(rel.RelatedCharacterId, null).Item1 != null,
                    RelationType        = rel.RelationType,
                    CharacterRelationId = rel.CharacterRelationId
                });
            }

            return(charList);
        }
Ejemplo n.º 25
0
        public async Task <List <CharacterRelationStatus> > GetBlacklisted(long id)
        {
            var charList = new List <CharacterRelationStatus>();
            var list     = _characterRelationDao
                           .Where(s => (s.CharacterId == id) && (s.RelationType == CharacterRelationType.Blocked));

            foreach (var rel in list)
            {
                charList.Add(new CharacterRelationStatus
                {
                    CharacterName       = _characterDao.FirstOrDefault(s => s.CharacterId == rel.RelatedCharacterId)?.Name ?? "",
                    CharacterId         = rel.RelatedCharacterId,
                    IsConnected         = (await _connectedAccountHttpClient.GetCharacterAsync(rel.RelatedCharacterId, null).ConfigureAwait(false)).Item1 != null,
                    RelationType        = rel.RelationType,
                    CharacterRelationId = rel.CharacterRelationId
                });
            }

            return(charList);
        }
Ejemplo n.º 26
0
        public MailData ViewMail(long id, [FromBody] JsonPatchDocument <MailDto> mailData)
        {
            var mail = _mailDao.FirstOrDefault(s => s.MailId == id);

            if (mail != null)
            {
                mailData.ApplyTo(mail);
                var bz = mail;
                _mailDao.InsertOrUpdate(ref bz);
                var savedData =
                    _parcelHolder[mail.IsSenderCopy ? (long)mail.SenderId : mail.ReceiverId][mail.IsSenderCopy]
                    .FirstOrDefault(s => s.Value.MailDto.MailId == id);
                var maildata = GenerateMailData(mail, savedData.Value.ItemType, savedData.Value.ItemInstance,
                                                savedData.Value.ReceiverName);
                maildata.MailId = savedData.Value.MailId;
                _parcelHolder[mail.IsSenderCopy ? (long)mail.SenderId : mail.ReceiverId][mail.IsSenderCopy][
                    savedData.Key] = maildata;
                return(maildata);
            }

            return(null);
        }
Ejemplo n.º 27
0
        public override async Task ExecuteAsync(CharacterDeletePacket packet, ClientSession clientSession)
        {
            if (clientSession.HasSelectedCharacter)
            {
                return;
            }

            var account = _accountDao
                          .FirstOrDefault(s => s.AccountId.Equals(clientSession.Account.AccountId));

            if (account == null)
            {
                return;
            }

            if ((account.Password !.ToLower() == packet.Password !.ToSha512()) || (account.Name == packet.Password))
            {
                var character = _characterDao.FirstOrDefault(s =>
                                                             (s.AccountId == account.AccountId) && (s.Slot == packet.Slot) &&
                                                             (s.State == CharacterState.Active));
                if (character == null)
                {
                    return;
                }

                character.State = CharacterState.Inactive;
                _characterDao.InsertOrUpdate(ref character);

                await clientSession.HandlePacketsAsync(new[]
                {
                    new EntryPointPacket
                    {
                        Header = "EntryPoint",
                        Title  = "EntryPoint",
                        Name   = account.Name
                    }
                }).ConfigureAwait(false);
            }
Ejemplo n.º 28
0
        public Miniland Initialize(Character character)
        {
            var minilandInfoDto = _minilandDao.FirstOrDefault(s => s.OwnerId == character.CharacterId);

            if (minilandInfoDto == null)
            {
                throw new ArgumentException();
            }

            var map      = _maps.FirstOrDefault(s => s.MapId == 20001);
            var miniland = _mapInstanceProvider.CreateMapInstance(map.Adapt <Map.Map>(), Guid.NewGuid(), map.ShopAllowed,
                                                                  MapInstanceType.NormalInstance, new List <IMapInstanceEventHandler> {
                new MinilandEntranceHandler(this)
            });

            var minilandInfo = minilandInfoDto.Adapt <Miniland>();

            minilandInfo.MapInstanceId   = miniland.MapInstanceId;
            minilandInfo.CharacterEntity = character;

            _minilandIds.TryAdd(character.CharacterId, minilandInfo);
            _mapInstanceProvider.AddMapInstance(miniland);
            miniland.LoadHandlers();

            var listobjects        = character.InventoryService.Values.Where(s => s.Type == NoscorePocketType.Miniland).ToArray();
            var idlist             = listobjects.Select(s => s.Id).ToArray();
            var minilandObjectsDto = _minilandObjectsDao.Where(s => idlist.Contains((Guid)s.InventoryItemInstanceId))
                                     .ToList();

            foreach (var mlobjdto in minilandObjectsDto)
            {
                var mlobj = mlobjdto.Adapt <MapDesignObject>();
                AddMinilandObject(mlobj, character.CharacterId,
                                  listobjects.First(s => s.Id == mlobjdto.InventoryItemInstanceId));
            }

            return(minilandInfo);
        }
Ejemplo n.º 29
0
        public List <WarehouseItem> GetWarehouseItems(long characterId, WarehouseType warehouse)
        {
            var client   = Connect();
            var response = client
                           .GetAsync($"{ApiUrl}?id=null&ownerId={characterId}&warehouseType={warehouse}&slot=null")
                           .Result;

            if (response.IsSuccessStatusCode)
            {
                var warehouseItems = new List <WarehouseItem>();
                var warehouselinks =
                    JsonConvert.DeserializeObject <List <WarehouseLink> >(response.Content.ReadAsStringAsync().Result);
                foreach (var warehouselink in warehouselinks)
                {
                    var warehouseItem = warehouselink.Warehouse.Adapt <WarehouseItem>();
                    var itemInstance  = _itemInstanceDao.FirstOrDefault(s => s.Id == warehouselink.ItemInstance.Id);
                    warehouseItem.ItemInstance = _itemProvider.Convert(itemInstance);
                    warehouseItems.Add(warehouseItem);
                }
            }

            throw new ArgumentException();
        }
Ejemplo n.º 30
0
        /// <summary>
        ///     Char_NEW_JOB character creation character
        /// </summary>
        /// <param name="martialArtistCreatePacket"></param>
        public void CreateMartialArtist(CharNewJobPacket martialArtistCreatePacket)
        {
            //TODO add a flag on Account
            if (_characterDao.FirstOrDefault(s =>
                                             s.Level >= 80 && s.AccountId == Session.Account.AccountId && s.State == CharacterState.Active) == null)
            {
                //Needs at least a level 80 to create a martial artist
                //TODO log
                return;
            }

            if (_characterDao.FirstOrDefault(s =>
                                             s.AccountId == Session.Account.AccountId &&
                                             s.Class == CharacterClassType.MartialArtist && s.State == CharacterState.Active) != null)
            {
                //If already a martial artist, can't create another
                //TODO log
                return;
            }
            //todo add cooldown for recreate 30days

            CreateCharacter(martialArtistCreatePacket);
        }