コード例 #1
0
        public override void Handle(LoginSession session, PacketReader packet)
        {
            session.Send(BannerListPacket.SetBanner());
            session.Send(ServerListPacket.SetServers(ServerName, ServerIPs));

            List <Player> characters = DatabaseManager.GetAccountCharacters(session.AccountId);

            session.Send(CharacterListPacket.SetMax(4, 6));
            session.Send(CharacterListPacket.StartList());
            // Send each character data
            session.Send(CharacterListPacket.AddEntries(characters));
            session.Send(CharacterListPacket.EndList());
        }
コード例 #2
0
        public override void Handle(LoginSession session, PacketReader packet)
        {
            byte   mode     = packet.ReadByte();
            string username = packet.ReadUnicodeString();
            string password = packet.ReadUnicodeString();

            // Hash the password with BCrypt
            string passwordHash = BCrypt.Net.BCrypt.HashPassword(password);

            // TODO: Change authenticate to return bool and add packet for wrong password
            Account account = DatabaseManager.Authenticate(username, password);

            // Auto add new accounts
            if (account == default)
            {
                account = new Account(username, passwordHash);
            }

            Logger.Debug($"Logging in with account ID: {account.Id}");
            session.AccountId = account.Id;

            switch (mode)
            {
            case 1:
                PacketWriter pWriter = PacketWriter.Of(SendOp.NPS_INFO);
                pWriter.WriteLong();
                pWriter.WriteUnicodeString(account.Username);

                session.Send(pWriter);

                List <Banner> banners = DatabaseManager.GetBanners();
                session.Send(BannerListPacket.SetBanner(banners));
                session.Send(ServerListPacket.SetServers(ServerName, ServerIPs));
                break;

            case 2:
                List <Player> characters = DatabaseManager.GetAccountCharacters(session.AccountId);

                Logger.Debug($"Initializing login with account id: {session.AccountId}");
                session.Send(LoginResultPacket.InitLogin(session.AccountId));
                session.Send(UgcPacket.SetEndpoint("http://127.0.0.1/ws.asmx?wsdl", "http://127.0.0.1"));
                session.Send(CharacterListPacket.SetMax(account.CharacterSlots));
                session.Send(CharacterListPacket.StartList());
                // Send each character data
                session.Send(CharacterListPacket.AddEntries(characters));
                session.Send(CharacterListPacket.EndList());
                break;
            }
        }
コード例 #3
0
        public override void Handle(LoginSession session, PacketReader packet)
        {
            byte   mode = packet.ReadByte();
            string user = packet.ReadUnicodeString();
            string pass = packet.ReadUnicodeString();

            logger.Debug($"Logging in with user:{user} pass:{pass}");
            // TODO: From this user/pass lookup we should be able to find the accountId
            if (string.IsNullOrEmpty(user) && string.IsNullOrEmpty(pass))
            {
                //session.AccountId = StaticAccountStorage.DEFAULT_ACCOUNT;

                logger.Info($"No user and password provide logging in with root account ");
            }
            else
            {
                logger.Info($"Success, with any string in user and pass");
                //session.AccountId = StaticAccountStorage.SECONDARY_ACCOUNT;
            }



            switch (mode)
            {
            case 1:
                session.Send(PacketWriter.Of(SendOp.NPS_INFO).WriteLong().WriteUnicodeString(""));
                session.Send(BannerListPacket.SetBanner());
                session.Send(ServerListPacket.SetServers(serverName, serverIps));
                break;

            case 2:
                List <Player> characters = new List <Player>();

                /*
                 * foreach (long characterId in accountStorage.ListCharacters(session.AccountId)) {
                 *  characters.Add(accountStorage.GetCharacter(characterId));
                 * }*/

                Console.WriteLine("Initializing login with " + session.AccountId);
                session.Send(LoginResultPacket.InitLogin(session.AccountId));
                session.Send(UgcPacket.SetEndpoint("http://127.0.0.1/ws.asmx?wsdl", "http://127.0.0.1"));
                session.Send(CharacterListPacket.SetMax(4, 6));
                session.Send(CharacterListPacket.StartList());
                // Send each character data
                session.Send(CharacterListPacket.AddEntries(characters));
                session.Send(CharacterListPacket.EndList());
                break;
            }
        }
コード例 #4
0
        public override void Handle(LoginSession session, PacketReader packet)
        {
            byte   mode     = packet.ReadByte();
            string username = packet.ReadUnicodeString();
            string password = packet.ReadUnicodeString();


            Account account = DatabaseManager.GetAccount(username, password);

            // Auto add new accounts
            if (account == default)
            {
                account = new Account(GuidGenerator.Long(), username, password);
                if (!DatabaseManager.Insert(account))
                {
                    throw new ArgumentException("Could not create account");
                }
            }

            Logger.Debug($"Logging in with account ID: {account.Id}");
            session.AccountId = account.Id;

            switch (mode)
            {
            case 1:
                PacketWriter pWriter = PacketWriter.Of(SendOp.NPS_INFO);
                pWriter.WriteLong();
                pWriter.WriteUnicodeString("");

                session.Send(pWriter);
                session.Send(BannerListPacket.SetBanner());
                session.Send(ServerListPacket.SetServers(ServerName, ServerIPs));
                break;

            case 2:
                List <Player> characters = DatabaseManager.GetAccountCharacters(session.AccountId);

                Logger.Debug($"Initializing login with account id: {session.AccountId}");
                session.Send(LoginResultPacket.InitLogin(session.AccountId));
                session.Send(UgcPacket.SetEndpoint("http://127.0.0.1/ws.asmx?wsdl", "http://127.0.0.1"));
                session.Send(CharacterListPacket.SetMax(4, 6));
                session.Send(CharacterListPacket.StartList());
                // Send each character data
                session.Send(CharacterListPacket.AddEntries(characters));
                session.Send(CharacterListPacket.EndList());
                break;
            }
        }
コード例 #5
0
        public override void Handle(LoginSession session, PacketReader packet) {
            session.Send(BannerListPacket.SetBanner());
            session.Send(ServerListPacket.SetServers(serverName, serverIps));

            List<Player> characters = new List<Player>();
            /*
            foreach (long characterId in accountStorage.ListCharacters(session.AccountId)) {
                characters.Add(accountStorage.GetCharacter(characterId));
            }*/

            session.Send(CharacterListPacket.SetMax(4, 6));
            session.Send(CharacterListPacket.StartList());
            // Send each character data
            session.Send(CharacterListPacket.AddEntries(characters));
            session.Send(CharacterListPacket.EndList());
        }
        public override void Handle(LoginSession session, PacketReader packet)
        {
            List <Banner> banners = DatabaseManager.Banners.FindAllBanners();

            session.Send(BannerListPacket.SetBanner(banners));
            session.Send(ServerListPacket.SetServers(ServerName, ServerIPs));

            List <Player> characters = DatabaseManager.Characters.FindAllByAccountId(session.AccountId);

            Account account = DatabaseManager.Accounts.FindById(session.AccountId);

            session.Send(CharacterListPacket.SetMax(account.CharacterSlots));
            session.Send(CharacterListPacket.StartList());
            // Send each character data
            session.Send(CharacterListPacket.AddEntries(characters));
            session.Send(CharacterListPacket.EndList());
        }
コード例 #7
0
        public override void Handle(LoginSession session, PacketReader packet)
        {
            byte   mode     = packet.ReadByte();
            string username = packet.ReadUnicodeString();
            string pass     = packet.ReadUnicodeString();

            Logger.Debug($"Logging in with username: '******' pass: '******'");

            // TODO: From this user/pass lookup we should be able to find the accountId
            if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(pass))
            {
                // send error / account credentials not found
            }

            session.AccountId = AccountStorage.DEFAULT_ACCOUNT_ID;

            switch (mode)
            {
            case 1:
                PacketWriter pWriter = PacketWriter.Of(SendOp.NPS_INFO);
                pWriter.WriteLong();
                pWriter.WriteUnicodeString("");

                session.Send(pWriter);
                session.Send(BannerListPacket.SetBanner());
                session.Send(ServerListPacket.SetServers(ServerName, ServerIPs));
                break;

            case 2:
                List <Player> characters = new List <Player>();
                foreach (long characterId in AccountStorage.ListCharacters(session.AccountId))
                {
                    characters.Add(AccountStorage.GetCharacter(characterId));
                }

                Logger.Debug($"Initializing login with account id: {session.AccountId}");
                session.Send(LoginResultPacket.InitLogin(session.AccountId));
                session.Send(UgcPacket.SetEndpoint("http://127.0.0.1/ws.asmx?wsdl", "http://127.0.0.1"));
                session.Send(CharacterListPacket.SetMax(4, 6));
                session.Send(CharacterListPacket.StartList());
                // Send each character data
                session.Send(CharacterListPacket.AddEntries(characters));
                session.Send(CharacterListPacket.EndList());
                break;
            }
        }
コード例 #8
0
        private void SendCharacters(LoginSession session, Account account)
        {
            string serverIp      = Environment.GetEnvironmentVariable("IP");
            string webServerPort = Environment.GetEnvironmentVariable("WEB_PORT");
            string url           = $"http://{serverIp}:{webServerPort}";

            List <Player> characters = DatabaseManager.Characters.FindAllByAccountId(session.AccountId);

            Logger.Debug("Initializing login with account id: {session.AccountId}", session.AccountId);
            session.Send(LoginResultPacket.InitLogin(session.AccountId));
            session.Send(UgcPacket.SetEndpoint($"{url}/ws.asmx?wsdl", url));
            session.Send(CharacterListPacket.SetMax(account.CharacterSlots));
            session.Send(CharacterListPacket.StartList());
            // Send each character data
            session.Send(CharacterListPacket.AddEntries(characters));
            session.Send(CharacterListPacket.EndList());
        }
コード例 #9
0
        public void HandleCreate(LoginSession session, PacketReader packet)
        {
            byte gender = packet.ReadByte();
            //packet.ReadShort(); // const?
            // var jobCode = (Job)packet.ReadShort();
            Job       job       = (Job)packet.ReadShort();
            string    name      = packet.ReadUnicodeString();
            SkinColor skinColor = packet.Read <SkinColor>();

            //packet.ReadShort(); // const?
            packet.Skip(2);
            Dictionary <ItemSlot, Item> equips = new Dictionary <ItemSlot, Item>();

            Logger.Info($"Creating character: {name}, gender: {gender}, skinColor: {skinColor}, job: {job}");

            int equipCount = packet.ReadByte();

            for (int i = 0; i < equipCount; i++)
            {
                uint   id      = packet.ReadUInt();
                string typeStr = packet.ReadUnicodeString();
                if (!Enum.TryParse(typeStr, out ItemSlot type))
                {
                    throw new ArgumentException($"Unknown equip type: {typeStr}");
                }
                EquipColor equipColor = packet.Read <EquipColor>();
                int        colorIndex = packet.ReadInt();

                switch (type)
                {
                case ItemSlot.HR:     // Hair
                    // Hair Length/Position
                    float  backLength         = BitConverter.ToSingle(packet.Read(4), 0);
                    byte[] backPositionArray  = packet.Read(24);
                    float  frontLength        = BitConverter.ToSingle(packet.Read(4), 0);
                    byte[] frontPositionArray = packet.Read(24);

                    equips.Add(ItemSlot.HR, new Item(Convert.ToInt32(id))
                    {
                        CreationTime = 1565575851,
                        Color        = equipColor,
                        HairD        = new HairData(backLength, frontLength, backPositionArray, frontPositionArray),
                        Stats        = new ItemStats(),
                        IsTemplate   = false,
                    });
                    break;

                case ItemSlot.FA:     // Face
                    equips.Add(ItemSlot.FA, new Item(Convert.ToInt32(id))
                    {
                        CreationTime = 1565575851,
                        Color        = equipColor,
                        Stats        = new ItemStats(),
                        IsTemplate   = false,
                    });
                    break;

                case ItemSlot.FD:                            // Face Decoration
                    byte[] faceDecoration = packet.Read(16); // Face decoration position
                    equips.Add(ItemSlot.FD, new Item(Convert.ToInt32(id))
                    {
                        CreationTime    = 1565575851,
                        Color           = equipColor,
                        FaceDecorationD = faceDecoration,
                        Stats           = new ItemStats(),
                        IsTemplate      = false,
                    });
                    break;

                case ItemSlot.CL:     // Clothes
                    equips.Add(ItemSlot.CL, new Item(Convert.ToInt32(id))
                    {
                        CreationTime = 1565575851,
                        Color        = equipColor,
                        Stats        = new ItemStats(),
                        IsTemplate   = false,
                    });
                    break;

                case ItemSlot.PA:     // Pants
                    equips.Add(ItemSlot.PA, new Item(Convert.ToInt32(id))
                    {
                        CreationTime = 1565575851,
                        Color        = equipColor,
                        Stats        = new ItemStats(),
                        IsTemplate   = false,
                    });
                    break;

                case ItemSlot.SH:     // Shoes
                    equips.Add(ItemSlot.SH, new Item(Convert.ToInt32(id))
                    {
                        CreationTime = 1565575851,
                        Color        = equipColor,
                        Stats        = new ItemStats(),
                        IsTemplate   = false,
                    });
                    break;

                case ItemSlot.ER:     // Ear
                    // Assign ER
                    equips.Add(ItemSlot.ER, new Item(Convert.ToInt32(id))
                    {
                        CreationTime = 1565575851,
                        Color        = equipColor,
                        Stats        = new ItemStats(),
                        IsTemplate   = false,
                    });
                    break;
                }
                Logger.Info($" > {type} - id: {id}, color: {equipColor}, colorIndex: {colorIndex}");
            }
            packet.ReadInt(); // const? (4)

            // Check if name is in use (currently just on local account)
            bool taken = false;

            foreach (Player character in AccountStorage.Characters.Values)
            {
                if (character.Name.ToLower().Equals(name.ToLower()))
                {
                    taken = true;
                }
            }

            if (taken)
            {
                session.Send(ResponseCharCreatePacket.NameTaken());
                return;
            }

            // Create new player object
            Player newCharacter = Player.NewCharacter(gender, job, name, skinColor, equips);

            // Add player object to account storage
            AccountStorage.AddCharacter(newCharacter);

            // Send updated CHAR_MAX_COUNT
            session.Send(CharacterListPacket.SetMax(4, 6));

            // Send CHARACTER_LIST for new character only (append)
            session.Send(CharacterListPacket.AppendEntry(newCharacter));
        }
コード例 #10
0
        public void HandleCreate(LoginSession session, PacketReader packet)
        {
            byte      gender    = packet.ReadByte();
            Job       job       = (Job)packet.ReadShort();
            string    name      = packet.ReadUnicodeString();
            SkinColor skinColor = packet.Read <SkinColor>();

            packet.Skip(2);
            Dictionary <ItemSlot, Item> cosmetics = new Dictionary <ItemSlot, Item>();

            Logger.Info($"Creating character: {name}, gender: {gender}, skinColor: {skinColor}, job: {job}");

            int equipCount = packet.ReadByte();

            for (int i = 0; i < equipCount; i++)
            {
                uint   id      = packet.ReadUInt();
                string typeStr = packet.ReadUnicodeString();
                if (!Enum.TryParse(typeStr, out ItemSlot type))
                {
                    throw new ArgumentException($"Unknown equip type: {typeStr}");
                }
                EquipColor equipColor = packet.Read <EquipColor>();

                switch (type)
                {
                case ItemSlot.HR:     // Hair
                    // Hair Length/Position
                    float  backLength            = BitConverter.ToSingle(packet.Read(4), 0);
                    CoordF backPositionCoord     = packet.Read <CoordF>();
                    CoordF backPositionRotation  = packet.Read <CoordF>();
                    float  frontLength           = BitConverter.ToSingle(packet.Read(4), 0);
                    CoordF frontPositionCoord    = packet.Read <CoordF>();
                    CoordF frontPositionRotation = packet.Read <CoordF>();

                    cosmetics.Add(ItemSlot.HR, new Item(Convert.ToInt32(id))
                    {
                        Color      = equipColor,
                        HairData   = new HairData(backLength, frontLength, backPositionCoord, backPositionRotation, frontPositionCoord, frontPositionRotation),
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.FA:     // Face
                    cosmetics.Add(ItemSlot.FA, new Item(Convert.ToInt32(id))
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.FD:                            // Face Decoration
                    byte[] faceDecoration = packet.Read(16); // Face decoration position
                    cosmetics.Add(ItemSlot.FD, new Item(Convert.ToInt32(id))
                    {
                        Color = equipColor,
                        FaceDecorationData = faceDecoration,
                        IsTemplate         = false,
                        IsEquipped         = true
                    });
                    break;

                case ItemSlot.CL:     // Clothes
                    cosmetics.Add(ItemSlot.CL, new Item(Convert.ToInt32(id))
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.PA:     // Pants
                    cosmetics.Add(ItemSlot.PA, new Item(Convert.ToInt32(id))
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.SH:     // Shoes
                    cosmetics.Add(ItemSlot.SH, new Item(Convert.ToInt32(id))
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.ER:     // Ear
                    // Assign ER
                    cosmetics.Add(ItemSlot.ER, new Item(Convert.ToInt32(id))
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;
                }
                Logger.Info($" > {type} - id: {id}, color: {equipColor}");
            }
            packet.ReadInt(); // const? (4)

            if (DatabaseManager.NameExists(name))
            {
                session.Send(ResponseCharCreatePacket.NameTaken());
                return;
            }

            Player newCharacter = new Player(session.AccountId, name, gender, job, skinColor);

            foreach (Item item in cosmetics.Values)
            {
                item.Owner = newCharacter;
            }
            newCharacter.Inventory.Cosmetics = cosmetics;
            DatabaseManager.UpdateCharacter(newCharacter);

            // Send updated CHAR_MAX_COUNT
            session.Send(CharacterListPacket.SetMax(4, 6));

            // Send CHARACTER_LIST for new character only (append)
            session.Send(CharacterListPacket.AppendEntry(newCharacter));
        }
        public static void HandleCreate(LoginSession session, PacketReader packet)
        {
            byte      gender    = packet.ReadByte();
            Job       job       = (Job)packet.ReadShort();
            string    name      = packet.ReadUnicodeString();
            SkinColor skinColor = packet.Read <SkinColor>();

            packet.Skip(2);

            if (DatabaseManager.Characters.NameExists(name))
            {
                session.Send(ResponseCharCreatePacket.NameTaken());
                return;
            }

            Account account      = DatabaseManager.Accounts.FindById(session.AccountId);
            Player  newCharacter = new Player(account, name, gender, job, skinColor);

            session.CharacterId = newCharacter.CharacterId;

            byte equipCount = packet.ReadByte();

            for (int i = 0; i < equipCount; i++)
            {
                int    id      = packet.ReadInt();
                string typeStr = packet.ReadUnicodeString();
                if (!Enum.TryParse(typeStr, out ItemSlot type))
                {
                    throw new ArgumentException($"Unknown equip type: {typeStr}");
                }

                EquipColor equipColor = packet.Read <EquipColor>();

                switch (type)
                {
                case ItemSlot.HR:     // Hair
                    // Hair Length/Position
                    float  backLength            = packet.ReadFloat();
                    CoordF backPositionCoord     = packet.Read <CoordF>();
                    CoordF backPositionRotation  = packet.Read <CoordF>();
                    float  frontLength           = packet.ReadFloat();
                    CoordF frontPositionCoord    = packet.Read <CoordF>();
                    CoordF frontPositionRotation = packet.Read <CoordF>();
                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.HR, new Item(id)
                    {
                        Color      = equipColor,
                        HairData   = new HairData(backLength, frontLength, backPositionCoord, backPositionRotation, frontPositionCoord, frontPositionRotation),
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.FA:     // Face
                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.FA, new Item(id)
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.FD:                            // Face Decoration
                    byte[] faceDecoration = packet.Read(16); // Face decoration position

                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.FD, new Item(id)
                    {
                        Color = equipColor,
                        FaceDecorationData = faceDecoration,
                        IsTemplate         = false,
                        IsEquipped         = true
                    });
                    break;

                case ItemSlot.CL:     // Clothes
                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.CL, new Item(id)
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.PA:     // Pants
                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.PA, new Item(id)
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.SH:     // Shoes
                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.SH, new Item(id)
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;

                case ItemSlot.ER:     // Ear
                    if (!DefaultItemsMetadataStorage.IsValid((int)job, id))
                    {
                        continue;
                    }

                    newCharacter.Inventory.Cosmetics.Add(ItemSlot.ER, new Item(id)
                    {
                        Color      = equipColor,
                        IsTemplate = false,
                        IsEquipped = true
                    });
                    break;
                }
            }
            packet.ReadInt(); // const? (4)

            DatabaseManager.Inventories.Update(newCharacter.Inventory);

            // Send updated CHAR_MAX_COUNT
            session.Send(CharacterListPacket.SetMax(account.CharacterSlots));

            // Send CHARACTER_LIST for new character only (append)
            session.Send(CharacterListPacket.AppendEntry(newCharacter));
        }