Ejemplo n.º 1
0
        private void ProcessPacket(XPacket xpacket)
        {
            foreach (Packet packet in ReadAllPackets(xpacket.data, XCript.ZoneServerPrivKey))
            {
                if (packet.body.Length < 10)
                {
                    return;
                }

                using (MemoryStream ms = new MemoryStream(packet.body))
                {
                    using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8))
                    {
                        int  client_token = br.ReadInt32();
                        int  id_idx       = br.ReadInt32();
                        byte hero_order   = br.ReadByte();
                        byte packet_type  = br.ReadByte();

                        if (!xpacket.client.zs_data.AUTHENTICATED)
                        {
                            xpacket.client.zs_data.HERO_ORDER = hero_order;
                        }

                        byte[] data = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
                        HandlePacket(data, packet_type, xpacket.client);
                    }
                }
                //Init.logger.ConsoleLog("Receive data: " + packet.Length, ConsoleColor.Yellow);
            }
        }
Ejemplo n.º 2
0
        private void MakePacketAndSend(Client MyClient, byte[] content)
        {
            short ContentLenght = (short)content.Length;
            byte  RandomPubKey  = XCript.AddRandPubKey();

            using (MemoryStream stream = new MemoryStream())
            {
                int len = 0;
                using (BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8))
                {
                    bw.Write((short)ContentLenght);
                    bw.Write((byte)RandomPubKey);
                    bw.Write(XCript.Encrypt(content, XCript.GetPubKeyIndex(RandomPubKey), XCript.ZoneServerPrivKey));
                    len = (int)bw.BaseStream.Length;
                }
                stream.Flush();
                byte[] buffer = stream.GetBuffer();
                Array.Resize(ref buffer, len);

                XPacket packet = new XPacket((short)buffer.Length, buffer, MyClient);

                this.AddPacket(packet);
            }
        }
Ejemplo n.º 3
0
 private void SendPacket(XPacket packet)
 {
     packet.client.SendData(packet.data);
 }
Ejemplo n.º 4
0
 public void AddPacket(XPacket packet)
 {
     packets.Enqueue(packet);
 }