Пример #1
0
        public byte[] Serialize()
        {
            var bytes  = new byte[(37 + this.Snake.Name.Length) + (2 * this.Snake.Parts.Count)];
            var writer = new BigEndianWriter(new MemoryStream(bytes));

            writer.WriteByte(0);
            writer.WriteByte(0);
            writer.WriteByte(Convert.ToByte(this.ProtocolId));
            writer.WriteShort((short)this.Snake.ID);
            writer.WriteInt24(3.1415926535 / Math.PI * 16777215);
            writer.WriteByte(0);
            writer.WriteInt24(3.1415926535 / Math.PI * 16777215);
            writer.WriteShort((short)this.Snake.Speed);
            writer.WriteInt24(0.028860630325116536 * 16777215);
            writer.WriteByte((byte)this.Snake.Skin);
            writer.WriteInt24(this.Snake.Position.X);
            writer.WriteInt24(this.Snake.Position.Y);
            writer.WriteString(this.Snake.Name);
            writer.WriteInt24(this.Snake.HeadPosition.X);
            writer.WriteInt24(this.Snake.HeadPosition.Y);
            foreach (var part in this.Snake.Parts)
            {
                writer.WriteByte((byte)part.Position.X);
                writer.WriteByte((byte)part.Position.Y);
            }

            return(bytes);
        }
Пример #2
0
        public byte[] Serialize()
        {
            var bytes  = new byte[30];
            var writer = new BigEndianWriter(new MemoryStream(bytes));

            writer.WriteByte(0);
            writer.WriteByte(0);
            writer.WriteByte(Convert.ToByte(this.ProtocolId));
            writer.WriteInt24(this.Radius);
            writer.WriteShort(411);
            writer.WriteShort(480);
            writer.WriteShort(130);
            writer.WriteByte((byte)4.8 * 10);
            writer.WriteShort((short)4.25 * 100);
            writer.WriteShort((short)0.5f * 100);
            writer.WriteShort((short)12 * 100);
            writer.WriteShort((short)(0.033 * 1E3));
            writer.WriteShort((short)(0.028 * 1E3));
            writer.WriteShort((short)(0.43 * 1E3));
            writer.WriteByte(Metadata.PROTOCOL_VERSION);

            return(bytes);
        }
Пример #3
0
        public byte[] Serialize()
        {
            var lengthOfUsername = 0;

            this.Snakes.ForEach(x => lengthOfUsername += x.Player.Username.Length);
            var bytes  = new byte[(8 + lengthOfUsername) + (this.Snakes.Count * 7)];
            var writer = new BigEndianWriter(new MemoryStream(bytes));

            writer.WriteByte(0);
            writer.WriteByte(0);
            writer.WriteByte(Convert.ToByte(this.ProtocolId));
            writer.WriteByte(0);
            writer.WriteShort(this.Rank);
            writer.WriteShort((short)this.Snakes.Count);
            foreach (var snake in this.Snakes)
            {
                writer.WriteShort(306);
                writer.WriteInt24(0.7810754645511785 * 16777215);
                writer.WriteByte((byte)snake.Skin);
                writer.WriteString(snake.Player.Username);
            }

            return(bytes);
        }