예제 #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 static void Serialize(AuthClient client)
        {
            BigEndianWriter packet = new BigEndianWriter();

            packet.WriteByte(1);
            packet.WriteByte((byte)Config.VERSION[0]);
            packet.WriteUShort((ushort)Config.VERSION[1]);
            packet.WriteByte((byte)Config.VERSION[2]);
            packet.WriteString((string)Config.VERSION[3]);
            client.Send(MessageConstant.S_VERSION, packet);
        }
        public byte[] Serialize()
        {
            var bytes  = new byte[1000];
            var writer = new BigEndianWriter(new MemoryStream(bytes));

            writer.WriteByte(0);
            writer.WriteByte(0);
            writer.WriteByte(Convert.ToByte('m'));
            writer.WriteByte((byte)(462 >> 16));
            writer.WriteByte((byte)(462 >> 8));
            writer.WriteByte((byte)(462 & 0xFF));

            var loc1 = (int)0.580671702663404 * 16777215;

            writer.WriteByte((byte)(loc1 >> 16));
            writer.WriteByte((byte)(loc1 >> 8));
            writer.WriteByte((byte)(loc1 & 0xFF));

            writer.WriteString(this.Author);
            writer.WriteString(this.Message);

            return(bytes);
        }
예제 #4
0
        public static void Serialize(AuthClient client)
        {
            byte            i      = 0;
            BigEndianWriter packet = new BigEndianWriter();
            BigEndianWriter part2  = new BigEndianWriter();

            packet.WriteInt(World.Servers.Count);
            part2.WriteInt(World.Servers.Count);
            foreach (Models.Server server in World.Servers)
            {
                packet.WriteInt(server.ID);
                packet.WriteUTF(server.Name);
                packet.WriteInt((int)server.Community);
                packet.WriteUTF(server.Ip);
                packet.WriteInt(server.Ports.Count);
                foreach (int port in server.Ports)
                {
                    packet.WriteInt(port);
                }
                packet.WriteByte(i);

                part2.WriteInt(server.ID);
                BigEndianWriter version = new BigEndianWriter();
                version.WriteByte((byte)Config.VERSION[0]);
                version.WriteUShort((ushort)Config.VERSION[1]);
                version.WriteByte((byte)Config.VERSION[2]);
                version.WriteString((string)Config.VERSION[3]);
                part2.WriteInt(version.Data.Length);
                part2.WriteBytes(version.Data);
                BigEndianWriter propertys = new BigEndianWriter();
                propertys.WriteInt(server.Propertys.Count);
                foreach (KeyValuePair <PropertyID, string> prop in server.Propertys)
                {
                    propertys.WriteShort((short)prop.Key);
                    propertys.WriteUTF(prop.Value);
                }
                part2.WriteInt(propertys.Data.Length);
                part2.WriteBytes(propertys.Data);
                part2.WriteBoolean(server.Locked);
                i++;
            }
            packet.WriteBytes(part2.Data);
            client.Send(MessageConstant.S_LIST_SERVER, packet);
        }
예제 #5
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);
        }