Ejemplo n.º 1
0
        public static void Game_Log_Req(InPacket lea, Client gc)
        {
            //int re = SearchBytes(lea.Content, new byte[] { 0x0 });
            string[]  data            = lea.ReadString(0x100 /*re*/).Split(new[] { (char)0x20 }, StringSplitOptions.None);
            int       encryptKey      = int.Parse(data[1]);
            string    username        = data[2];
            string    password        = data[4];
            int       selectCharacter = lea.ReadByte();
            IPAddress hostid          = lea.ReadIPAddress();

            gc.SetAccount(new Account(gc));

            try
            {
                gc.Account.Load(username);
                //var pe = new PasswordEncrypt(encryptKey);
                //string encryptPassword = pe.encrypt(gc.Account.Password, gc.RetryLoginCount > 0 ? password.ToCharArray() : null);

                if (password.Equals(gc.Account.Password))
                {
                    gc.Dispose();
                    Log.Error("Login Fail!");
                }
                else
                {
                    gc.Account.Characters = new List <Character>();
                    foreach (dynamic datum in new Datums("Characters").PopulateWith("id", "accountId = '{0}' ORDER BY position ASC", gc.Account.ID))
                    {
                        Character character = new Character(datum.id, gc);
                        character.Load(false);
                        character.IP = hostid;
                        gc.Account.Characters.Add(character);
                    }
                    gc.SetCharacter(gc.Account.Characters[selectCharacter]);
                }
                Log.Inform("Password = {0}", password);
                //Log.Inform("encryptKey = {0}", encryptKey);
                //Log.Inform("encryptPassword = {0}", encryptPassword);
            }
            catch (NoAccountException)
            {
                gc.Dispose();
                Log.Error("Login Fail!");
            }

            Character chr = gc.Character;

            chr.CharacterID = gc.CharacterID;
            MapFactory.AllCharacters.Add(chr);

            StatusPacket.UpdateHpMp(gc, 0, 0, 0, 0);
            GamePacket.FW_DISCOUNTFACTION(gc);
            StatusPacket.getStatusInfo(gc);
            InventoryPacket.getCharacterEquip(gc);
            SkillPacket.getSkillInfo(gc, chr.Skills.getSkills());
            QuestPacket.getQuestInfo(gc, chr.Quests.getQuests());
            GamePacket.getQuickSlot(gc, chr.Keymap);
            StoragePacket.getStoreInfo(gc);
            StoragePacket.getStoreMoney(gc);
            MapPacket.enterMapStart(gc);
            InventoryPacket.getInvenCash(gc);
            CashShopPacket.MgameCash(gc);
            CashShopPacket.GuiHonCash(gc);
            InventoryPacket.getInvenEquip(gc);
            InventoryPacket.getInvenEquip1(gc);
            InventoryPacket.getInvenEquip2(gc);
            InventoryPacket.getInvenSpend3(gc);
            InventoryPacket.getInvenOther4(gc);
            InventoryPacket.getInvenPet5(gc);
        }
Ejemplo n.º 2
0
        public static void Game_Log_Req(InPacket lea, Client gc)
        {
            string[] data       = lea.ReadString(50).Split(new[] { (char)0x20 }, StringSplitOptions.None);
            int      encryptKey = int.Parse(data[1]);


            string    username        = data[2];
            string    password        = data[4];
            int       selectCharacter = lea.ReadByte();
            IPAddress hostid          = lea.ReadIPAddress();

            Log.Debug(" Username : {0} ", username);
            Log.Debug(" Password : {0} ", password);
            Log.Debug(" selectCharacter : {0} ", selectCharacter);
            Log.Debug(" hostid : {0} ", hostid);



            gc.SetAccount(new Account(gc));


            try
            {
                gc.Account.Load(username);

                if (!password.Equals(password))
                {
                    gc.Dispose();
                    Log.Error("Login Fail!");
                }
                else
                {
                    Log.Debug("ID ---> {0}", gc.Account.ID);
                    gc.Account.Characters = new List <Character>();
                    foreach (dynamic datum in new Datums("Characters").PopulateWith("id", "accountId = '{0}' ORDER BY position ASC", gc.Account.ID))
                    {
                        Character character = new Character(datum.id, gc);
                        character.Load(false);
                        character.IP = hostid;
                        gc.Account.Characters.Add(character);
                    }
                    //	Log.Debug("Character List : {0}", gc.Account.Characters.IF);
                    gc.SetCharacter(gc.Account.Characters[selectCharacter]);
                }
                Log.Inform("Password = {0}", password);
                //Log.Inform("encryptKey = {0}", encryptKey);
                //Log.Inform("encryptPassword = {0}", encryptPassword);
            }
            catch (NoAccountException)
            {
                gc.Dispose();
                Log.Error("Login Fail!");
            }


            Character chr = gc.Character;

            chr.CharacterID = gc.CharacterID;
            GamePacket.Game_LoginStatus(gc);
            GamePacket.FW_MANAGER(gc);
            GamePacket.Game_ServerTime(gc);
            GamePacket.Game_LOAD_3(gc);
            System.Threading.Thread.Sleep(250);

            GamePacket.Game_LOAD_4(gc);
            GamePacket.Game_LOAD_5(gc);

            //Game_AvartarJarItem
            //    GamePacket.Game_login2_ack(gc);

            //MapFactory.AllCharacters.Add(chr);
            //StatusPacket.UpdateHpMp(gc, 0, 0, 0, 0);
            //GamePacket.FW_DISCOUNTFACTION(gc);
            //StatusPacket.getStatusInfo(gc);
            //InventoryPacket.getCharacterEquip(gc);
            //SkillPacket.getSkillInfo(gc, chr.Skills.getSkills());
            //QuestPacket.getQuestInfo(gc, chr.Quests.getQuests());
            //GamePacket.getQuickSlot(gc, chr.Keymap);   //TODO :
            //StoragePacket.getStoreInfo(gc);			 //TODO :
            //StoragePacket.getStoreMoney(gc);			 //TODO :
            //MapPacket.enterMapStart(gc);				 //TODO :
            //InventoryPacket.getInvenCash(gc);			//TODO :
            //CashShopPacket.MgameCash(gc);
            //CashShopPacket.GuiHonCash(gc);
            //InventoryPacket.getInvenEquip(gc);
            //InventoryPacket.getInvenEquip1(gc);
            //InventoryPacket.getInvenEquip2(gc);
            //InventoryPacket.getInvenSpend3(gc);
            //InventoryPacket.getInvenOther4(gc);
            //InventoryPacket.getInvenPet5(gc);
        }
        private void OnRegistrationRequest(InPacket inPacket)
        {
            ServerUtilities.ServerType type = (ServerUtilities.ServerType)inPacket.ReadByte();
            string     securityCode         = inPacket.ReadString();
            IPEndPoint endPoint             = new IPEndPoint(inPacket.ReadIPAddress(), inPacket.ReadUShort());
            World      world = LoginServer.Worlds.Next(type);

            bool worked = false;

            using (OutPacket outPacket = new OutPacket(InteroperabilityMessage.RegistrationResponse))
            {
                if (securityCode != LoginServer.SecurityCode)
                {
                    outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.InvalidCode);

                    Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities
                                                                                   .ServerRegistrationResponse.InvalidCode));
                }
                else if (world == null)
                {
                    outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.WorldsFull);

                    Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities
                                                                                   .ServerRegistrationResponse.WorldsFull));
                }
                else
                {
                    if (world.HostIP.ToString() != endPoint.Address.ToString())
                    {
                        outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.InvalidIP);

                        Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities
                                                                                       .ServerRegistrationResponse.InvalidIP));
                    }
                    else
                    {
                        this._type          = type;
                        this.RemoteEndPoint = endPoint;
                        this.WorldID        = world.ID;

                        switch (this._type)
                        {
                        case ServerUtilities.ServerType.Char:
                        {
                            this.World.CharServer = this;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);

                            worked = true;
                        }
                        break;

                        case ServerUtilities.ServerType.Game:
                        {
                            this.World.Add(this);
                            this._id = (byte)this.World.Count;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);
                            outPacket.WriteByte(this.ExternalID);
                            outPacket.WriteString(this.World.ScrollingHeader);
                            outPacket.WriteInt(this.World.Rates.Experience);
                            outPacket.WriteInt(this.World.Rates.QuestExperience);
                            outPacket.WriteInt(this.World.Rates.PartyQuestExperience);
                            outPacket.WriteInt(this.World.Rates.Meso);
                            outPacket.WriteInt(this.World.Rates.Loot);

                            worked = true;
                        }
                        break;

                        case ServerUtilities.ServerType.Message:
                        {
                            this.World.MessageServer = this;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);

                            worked = true;
                        }
                        break;

                        case ServerUtilities.ServerType.Shop:
                        {
                            this.World.ShopServer = this;

                            outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid);
                            outPacket.WriteByte(this.WorldID);

                            worked = true;
                        }
                        break;
                        }
                    }
                }

                this.Send(outPacket);
            }

            if (worked)
            {
                switch (this._type)
                {
                case ServerUtilities.ServerType.Char:
                {
                    Log.Success("Registered Char {0} at {1}.", this.World.Name, this.RemoteEndPoint);
                }
                break;

                case ServerUtilities.ServerType.Game:
                {
                    Log.Success("Registered Game {0}-{1} at {2}.", this.World.Name, this.ExternalID,
                                this.RemoteEndPoint);
                }
                break;

                case ServerUtilities.ServerType.Message:
                {
                    Log.Success("Registered Message {0} at {1}.", this.World.Name, this.RemoteEndPoint);
                }
                break;

                case ServerUtilities.ServerType.Shop:
                {
                    Log.Success("Registered Shop {0} at {1}.", this.World.Name, this.RemoteEndPoint);
                }
                break;
                }
            }
            else
            {
                Log.Warn("Server registration failed.");

                this.Stop();
            }
        }