Exemplo n.º 1
0
        /// <summary>
        /// Processes the sending of a message.
        /// </summary>
        private void ProcessMessage()
        {
            if (input.StartsWith("::"))
            {
                var packet = new Packet(103);
                packet.WriteString(input.Substring(2), 10);
                GameContext.NetworkHandler.Write(packet);
            }
            else if (input.Length > 0)
            {
                var msg = new ChatMessage(MessageType.Player, name, input);
                msg.CrownIndex = GameContext.LocalRights;
                Add(msg);

                var self = GameContext.Self;
                if (self != null)
                {
                    self.SpokenMessage = input;
                    self.SpokenLife    = 150;
                    self.SpokenTex     = null;
                }

                var @out = new Packet(4);
                @out.WriteByte(0);
                var pos = @out.Position();
                @out.WriteByteS(0);
                @out.WriteByteS(0);
                var buf = new DefaultJagexBuffer(new byte[5000]);
                StringUtils.Pack(input, buf);
                @out.WriteBytesReversedA(buf.Array(), 0, buf.Position());
            }
        }
Exemplo n.º 2
0
        private void UpdatePlayerMask(int mask, int index, JagexBuffer b, Player p)
        {
            if ((mask & 0x400) != 0)
            {
                p.MoveStartX     = b.ReadUByteS();
                p.MoveStartY     = b.ReadUByteS();
                p.MoveEndX       = b.ReadUByteS();
                p.MoveEndY       = b.ReadUByteS();
                p.MoveCycleEnd   = b.ReadLEUShortA() + (int)GameContext.LoopCycle;
                p.MoveCycleStart = b.ReadUShortA() + (int)GameContext.LoopCycle;
                p.MoveDirection  = b.ReadUByteS();
                p.ResetQueuedMovements();
            }

            if ((mask & 0x100) != 0)
            {
                p.SpotAnimIndex = b.ReadLEUShort();
                var info = b.ReadInt();
                p.GraphicOffsetY   = info >> 16;
                p.SpotAnimCycleEnd = (int)GameContext.LoopCycle + (info & 0xffff);
                p.SpotAnimFrame    = 0;
                p.SpotAnimCycle    = 0;

                if (p.SpotAnimCycleEnd > GameContext.LoopCycle)
                {
                    p.SpotAnimFrame = -1;
                }

                if (p.SpotAnimIndex == 65535)
                {
                    p.SpotAnimIndex = -1;
                }
            }

            if ((mask & 8) != 0)
            {
                var seqIndex = b.ReadLEUShort();
                var delay    = b.ReadUByteC();
                if (seqIndex == 65535)
                {
                    seqIndex = -1;
                }

                var seq = GameContext.Cache.GetSeq(seqIndex);
                if (seq != null)
                {
                    if (seqIndex == p.SeqIndex && seqIndex != -1)
                    {
                        var type = seq.Type;
                        if (type == 1)
                        {
                            p.SeqFrame      = 0;
                            p.SeqCycle      = 0;
                            p.SeqDelayCycle = delay;
                            p.SeqResetCycle = 0;
                        }
                        else if (type == 2)
                        {
                            p.SeqResetCycle = 0;
                        }
                    }
                    else if (seqIndex == -1 || p.SeqIndex == -1 || (GameContext.Cache.GetSeq(p.SeqIndex) != null && seq.Priority >= GameContext.Cache.GetSeq(p.SeqIndex).Priority))
                    {
                        p.SeqIndex          = seqIndex;
                        p.SeqFrame          = 0;
                        p.SeqCycle          = 0;
                        p.SeqDelayCycle     = delay;
                        p.SeqResetCycle     = 0;
                        p.StillPathPosition = p.PathPosition;
                    }
                }
            }

            if ((mask & 4) != 0)
            {
                p.SpokenMessage = b.ReadString(10);

                if (p.SpokenMessage.ToCharArray()[0] == '~')
                {
                    p.SpokenMessage = p.SpokenMessage.Substring(1);
                    GameContext.Chat.Add(new ChatMessage(MessageType.Player, p.Name, p.SpokenMessage));
                }
                else if (p == GameContext.Self)
                {
                    GameContext.Chat.Add(new ChatMessage(MessageType.Player, p.Name, p.SpokenMessage));
                }

                p.SpokenColor  = 0;
                p.SpokenEffect = 0;
                p.SpokenLife   = 150;
            }

            if ((mask & 0x80) != 0)
            {
                var settings = b.ReadShort();
                var rights   = b.ReadByte();
                b.ReadByte();
                var length   = b.ReadUByteC();
                var startOff = b.Position();
                if (p.Name != null)
                {
                    var buf = new DefaultJagexBuffer(new byte[5000]);
                    b.ReadBytesReversed(buf.Array(), 0, length);
                    p.SpokenMessage = StringUtils.GetFormatted(length, buf);
                    p.SpokenEffect  = settings & 0xFF;
                    p.SpokenColor   = settings >> 8;
                    p.SpokenLife    = 150;

                    var sb = new StringBuilder();
                    sb.Append(p.Name);

                    var msg = new ChatMessage(MessageType.Player, sb.ToString(), p.SpokenMessage);
                    if (rights > 0)
                    {
                        msg.CrownIndex = rights;
                    }

                    GameContext.Chat.Add(msg);
                }

                b.Position(startOff + length);
            }

            if ((mask & 1) != 0)
            {
                p.FaceEntity = b.ReadLEUShort();

                if (p.FaceEntity == 65535)
                {
                    p.FaceEntity = -1;
                }
            }

            if ((mask & 0x10) != 0)
            {
                var payload = new byte[b.ReadUByteC()];
                b.ReadBytes(payload, 0, payload.Length);
                var pb = new DefaultJagexBuffer(payload);
                GameContext.PlayerBuffers[index] = pb;
                p.Update(pb);
            }

            if ((mask & 2) != 0)
            {
                p.FaceX = b.ReadLEUShortA();
                p.FaceY = b.ReadLEUShort();
            }

            if ((mask & 0x20) != 0)
            {
                var damage = b.ReadUShortA();
                var type   = b.ReadUByte();
                var icon   = b.ReadUByte();
                var soak   = b.ReadUShortA();
                p.QueueHit(type, damage, (int)GameContext.LoopCycle);
                p.CurrentHealth  = b.ReadUShortA();
                p.MaxHealth      = b.ReadUShortA();
                p.EndCombatCycle = (int)GameContext.LoopCycle + 300;
            }

            if ((mask & 0x200) != 0)
            {
                var damage = b.ReadUShortA();
                var type   = b.ReadUByte();
                var icon   = b.ReadUByte();
                var soak   = b.ReadUShortA();
                p.QueueHit(type, damage, (int)GameContext.LoopCycle);
                p.CurrentHealth  = b.ReadUShortA();
                p.MaxHealth      = b.ReadUShortA();
                p.EndCombatCycle = (int)GameContext.LoopCycle + 300;
            }
        }
Exemplo n.º 3
0
        public LoginResponse WriteAuthBlock(string username, string password)
        {
            var stream = client.GetStream();

            stream.ReadTimeout = 5000;

            var nameHash = StringUtils.StringToLong(username);
            var i        = (int)(nameHash >> 16 & 31L);

            var @out = new DefaultJagexBuffer(5000);

            @out.Position(0);
            @out.WriteByte(14);
            @out.WriteByte(i);
            stream.Write(@out.Array(), 0, @out.Position());
            @out.Position(0);
            stream.Flush();
            for (var j = 0; j < 8; j++)
            {
                stream.ReadByte();
            }

            int response = stream.ReadByte();

            if (response == 0)
            {
                InBuffer.Position(0);
                stream.Read(InBuffer.Array(), 0, 8);
                var serverSeed = InBuffer.ReadLong();

                var seed = new int[4];
                var rand = new System.Random();

                seed[0] = (int)(rand.NextDouble() * 9.9999999E7D);
                seed[1] = (int)(rand.NextDouble() * 9.9999999E7D);
                seed[2] = (int)(serverSeed >> 32);
                seed[3] = (int)(serverSeed);

                @out.Position(0);
                @out.WriteByte(10);
                @out.WriteInt(seed[0]);
                @out.WriteInt(seed[1]);
                @out.WriteInt(seed[2]);
                @out.WriteInt(seed[3]);
                @out.WriteInt(350 >> 2240);
                @out.WriteString(username, 10);
                @out.WriteString(password, 10);
                @out.WriteShort(222);
                @out.WriteByte(0);
                @out.RSA(GameConstants.LoginRsaExp, GameConstants.LoginRsaMod);

                wrapperBuffer.Position(0);
                wrapperBuffer.WriteByte(16);
                wrapperBuffer.WriteByte(@out.Position() + 36 + 1 + 2);
                wrapperBuffer.WriteByte(255);
                wrapperBuffer.WriteShort(13);
                wrapperBuffer.WriteByte(1);
                for (var j = 0; j < 9; j++)
                {
                    wrapperBuffer.WriteInt(0);
                }

                GameContext.OutCipher = new ISAACCipher(seed);
                for (var j = 0; j < seed.Length; j++)
                {
                    seed[j] += 50;
                }
                GameContext.InCipher = new ISAACCipher(seed);

                wrapperBuffer.WriteBytes(@out.Array(), 0, @out.Position());
                stream.Write(wrapperBuffer.Array(), 0, wrapperBuffer.Position());
                stream.Flush();

                response = stream.ReadByte();
                @out.Position(0);

                if (response == 2)
                {
                    GameContext.LocalRights = stream.ReadByte();
                    stream.ReadByte();
                    Connected = true;
                    return(LoginResponse.SuccessfulLogin);
                }
            }
            return(LoginResponse.Unknown);
        }