public Player(Connection connection)
 {
     this.connection = connection; //without this, new Packets(this); wouldn't function.
     if (connection != null)
     {
         loginDetails = connection.getLoginDetails();
     }
     appearance       = new Appearance();
     follow           = new Follow(this);
     bank             = new Bank(this);
     inventory        = new Inventory(this);
     equipment        = new Equipment(this);
     friends          = new Friends(this);
     prayers          = new Prayers(this);
     skills           = new Skills(this);
     attackStyle      = new AttackStyle();
     packets          = new Packets(this);
     localEnvironment = new LocalEnvironment(this);
     updateFlags      = new AppearanceUpdateFlags(this);
     walkingQueue     = new WalkingQueue(this);
     specialAttack    = new SpecialAttack(this);
     chat             = true;
     split            = false;
     mouse            = true;
     aid                  = false;
     magicType            = 1;
     achievementDiaryTab  = false;
     forgeCharge          = 40;
     smallPouchAmount     = 0;
     mediumPouchAmount    = 0;
     largePouchAmount     = 0;
     giantPouchAmount     = 0;
     defenderWave         = 0;
     autoRetaliate        = false;
     vengeance            = false;
     lastVengeanceTime    = 0;
     poisonAmount         = 0;
     specialAmount        = 100;
     skullCycles          = 0;
     recoilCharges        = 40;
     barrowTunnel         = -1;
     barrowKillCount      = 0;
     barrowBrothersKilled = new bool[6];
     slayerPoints         = 0;
     removedSlayerTasks   = new string[4];
     for (int i = 0; i < removedSlayerTasks.Length; i++)
     {
         removedSlayerTasks[i] = "-";
     }
     agilityArenaStatus      = 0;
     taggedLastAgilityPillar = false;
     paidAgilityArena        = false;
     teleblockTime           = 0;
     lastHit               = -1;
     prayerDrainRate       = 0;
     superAntipoisonCycles = 0;
     antifireCycles        = 0;
     tradeRequests         = new List <Player>();
     duelRequests          = new List <Player>();
 }
 public Player(Connection connection)
 {
     this.connection = connection; //without this, new Packets(this); wouldn't function.
     if(connection != null)
         loginDetails = connection.getLoginDetails();
     appearance = new Appearance();
     follow = new Follow(this);
     bank = new Bank(this);
     inventory = new Inventory(this);
     equipment = new Equipment(this);
     friends = new Friends(this);
     prayers = new Prayers(this);
     skills = new Skills(this);
     attackStyle = new AttackStyle();
     packets = new Packets(this);
     localEnvironment = new LocalEnvironment(this);
     updateFlags = new AppearanceUpdateFlags(this);
     walkingQueue = new WalkingQueue(this);
     specialAttack = new SpecialAttack(this);
     chat = true;
     split = false;
     mouse = true;
     aid = false;
     magicType = 1;
     achievementDiaryTab = false;
     forgeCharge = 40;
     smallPouchAmount = 0;
     mediumPouchAmount = 0;
     largePouchAmount = 0;
     giantPouchAmount = 0;
     defenderWave = 0;
     autoRetaliate = false;
     vengeance = false;
     lastVengeanceTime = 0;
     poisonAmount = 0;
     specialAmount = 100;
     skullCycles = 0;
     recoilCharges = 40;
     barrowTunnel = -1;
     barrowKillCount = 0;
     barrowBrothersKilled = new bool[6];
     slayerPoints = 0;
     removedSlayerTasks = new string[4];
     for (int i = 0; i < removedSlayerTasks.Length; i++)
     {
         removedSlayerTasks[i] = "-";
     }
     agilityArenaStatus = 0;
     taggedLastAgilityPillar = false;
     paidAgilityArena = false;
     teleblockTime = 0;
     lastHit = -1;
     prayerDrainRate = 0;
     superAntipoisonCycles = 0;
     antifireCycles = 0;
     tradeRequests = new List<Player>();
     duelRequests = new List<Player>();
 }
 public void setLoginDetails(LoginDetails loginDetails)
 {
     this.loginDetails = loginDetails;
 }
 public void setLoginDetails(LoginDetails loginDetails)
 {
     this.loginDetails = loginDetails;
 }
        private void attemptPlayerLogin(Connection connection)
        {
            if (connection == null)
                return;

            if (connection.loginStage == 0) //Attempt login or update server.
            {
                Packet fill_2 = fillStream(connection, 2);
                if (fill_2 == null)
                    return;

                int connectionType = fill_2.readByte();

                if (connectionType == 15)
                { //it's update server
                    connection.loginStage = 1;
                    updateServer(connection);
                    return;
                }
                else if (connectionType == 255)
                {
                    connection.SendPacket(new PacketBuilder()
                        .setSize(Packet.Size.Bare)
                        .addBytes(misc.WORLD_LIST_DATA).toPacket());
                    connection.loginStage = 5;
                    updateServer(connection);
                    return;
                }
                else if (connectionType != 14)
                {
                    connection.loginStage = 255; //255 is used as fail.
                    return;
                }

                Random random = new Random();
                long serverSessionKey = ((long)(random.NextDouble() * 99999999D) << 32)
                    + (long)(random.NextDouble() * 99999999D);

                int longPlayerName = fill_2.readByte();

                PacketBuilder s1Response = new PacketBuilder();
                s1Response.setSize(Packet.Size.Bare).addByte((byte)0).addLong(serverSessionKey);
                connection.SendPacket(s1Response.toPacket());
                connection.loginStage = 2;
                attemptPlayerLogin(connection);
            }
            else if (connection.loginStage == 2)
            {
                Packet fill_1 = fillStream(connection, 1);
                if (fill_1 == null)
                    return;

                int loginType = fill_1.readByte();

                if (loginType != 16 && loginType != 18 && loginType != 14)
                {
                    connection.loginStage = 255; //255 is used as fail.
                    return;
                }
                connection.loginStage = 4;
                attemptPlayerLogin(connection);
            }
            else if (connection.loginStage == 4)
            {
                Packet fill_2 = fillStream(connection, 2);
                if (fill_2 == null)
                    return;

                int loginPacketSize = fill_2.readUShort();
                int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2);

                if (loginEncryptPacketSize <= 0)
                {
                    connection.loginStage = 255;
                    return;
                }
                Packet fill_loginPacketSize = fillStream(connection, loginPacketSize);
                if (fill_loginPacketSize == null)
                    return;

                int clientVersion = fill_loginPacketSize.readInt();

                if (clientVersion != 530)
                {
                    connection.loginStage = 255;
                    return;
                }

                byte junk1 = fill_loginPacketSize.readByte();
                byte lowMem = fill_loginPacketSize.readByte(); //0 is this still low mem ver?
                byte zero = fill_loginPacketSize.readByte();
                byte b1 = fill_loginPacketSize.readByte();
                ushort s1 = fill_loginPacketSize.readUShort();
                ushort s2 = fill_loginPacketSize.readUShort();
                byte b2 = fill_loginPacketSize.readByte(); 

                for (int i = 0; i < 24; i++)
                {
                    int cacheIDX = fill_loginPacketSize.readByte();
                }
                string appletSettings = fill_loginPacketSize.readRS2String(); //EkKmok3kJqOeN6D3mDdihco3oPeYN2KFy6W5--vZUbNA
                int someInt1 = fill_loginPacketSize.readInt();
                int someInt2 = fill_loginPacketSize.readInt();
                ushort short1 = fill_loginPacketSize.readUShort();

                for (int i = 0; i < 28; i++)
                {
                    int crcOfClientClasses = fill_loginPacketSize.readInt();
                }

                int junk2 = fill_loginPacketSize.readByte();
                int encryption = fill_loginPacketSize.readByte();

                if (encryption != 10 && encryption != 64)
                {
                    connection.loginStage = 255;
                    return;
                }

                long clientSessionKey = fill_loginPacketSize.readLong();
                long serverSessionKey = fill_loginPacketSize.readLong();
                LoginDetails loginDetails = new LoginDetails();
                loginDetails.setLongName(fill_loginPacketSize.readLong()); //must start a 225.
                loginDetails.setUsername(misc.longToPlayerName(loginDetails.getLongName()).ToLower().Replace("_", " ").Trim());
                loginDetails.setPassword(fill_loginPacketSize.readRS2String());

                Console.WriteLine("Attempting to login with Username: "******" Password: " + loginDetails.getPassword());
                connection.setLoginDetails(loginDetails);
                //start attempting to login the account.
                lock (playersToLoad)
                {
                    playersToLoad.Enqueue(connection);
                }

                connection.loginStage = 6;
            }

        }