Ejemplo n.º 1
0
        protected override byte[] BuildPacket(Packet packet)
        {
            var result = new byte[6 + packet.GetSize() + 4]; // header + packet + checksum
            result[0] = 0x88;
            System.Buffer.BlockCopy(BitConverter.GetBytes(result.Length), 0, result, 1, sizeof(int));
            packet.Build(ref result, 6);

            return result;
        }
        public void Handle(PdClient client, Packet packet)
        {
            PacketHandlerFunc handler;
            if (!_handlers.TryGetValue(packet.Op, out handler))
            {
                this.UnknownPacket(client, packet);
                return;
            }

            handler(client, packet);
        }
Ejemplo n.º 3
0
 public void Send(Packet packet)
 {
     this.Send(this.BuildPacket(packet));
 }
Ejemplo n.º 4
0
 private byte[] BuildPacket(Packet packet)
 {
     byte[] buffer = new byte[6 + packet.GetSize() + 4];
     buffer[0] = 136;
     System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, buffer, 1, 4);
     packet.Build(ref buffer, 6);
     return buffer;
 }
Ejemplo n.º 5
0
 public static void Login(PdClient client, byte passBin, bool register = false)
 {
     var packet = new Packet(Op.Login, 0);
     packet.PutByte(register ? (byte) LoginType.Register : (byte) LoginType.Login);
 }
Ejemplo n.º 6
0
 public static void ClientIdent(PdClient client)
 {
     var packet = new Packet(Op.ClientIdent, 0);
     packet.PutString("PDC_USA-0.0.0.1-Dev[PRK-496d6142726f6b6544756465]");
     packet.PutBin(Encoding.UTF8.GetBytes(HardwareHelper.GetMacAddress()));
 }
 public void UnknownPacket(PdClient client, Packet packet)
 {
     Log.Unimplemented("PacketHandlerManager: Handler for '{0:X4}'", packet.Op);
     Log.Debug(packet);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Builds packet, appending the overall header and checksum.
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 protected abstract byte[] BuildPacket(Packet packet);
Ejemplo n.º 9
0
        /// <summary>
        /// Builds buffer from packet and sends it.
        /// </summary>
        /// <param name="packet"></param>
        public virtual void Send(Packet packet)
        {
            // Don't log internal packets
            //if (packet.Op < Op.Internal.ServerIdentify)
            //    Log.Debug("S: " + packet);

            this.Send(this.BuildPacket(packet));
        }
Ejemplo n.º 10
0
        private void HandleBuffer(PdClient client, byte[] buffer)
        {
            var length = buffer.Length;

            Array.Resize(ref buffer, length -= 4);

            BitConverter.GetBytes(length).CopyTo(buffer, 1);

            if (buffer[5] == 0x01)
            {
                BitConverter.GetBytes(BitConverter.ToUInt32(buffer, 6) ^ 0x98BADCFE).CopyTo(buffer, 6);
                client.Socket.Send(buffer);
            }
            else
            {
                // First packet, skip challenge and send success msg.
                if (client.State == ClientState.BeingChecked)
                {
                    client.Send(new byte[] {0x88, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07});

                    client.State = ClientState.LoggingIn;
                }
                // Actual packets
                else
                {
                    // Start reading after the protocol header
                    var packet = new Packet(buffer, 6);

                    //Logger.Debug(packet);

                    try
                    {
                        this.Handlers.Handle(client, packet);
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex, "There has been a problem while handling '{0:X4}'.", packet.Op);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>Writes packet as bin and the length of it as int to buffer.</summary>
 public Packet PutBin(Packet packet)
 {
     var val = packet.Build();
     return PutInt(val.Length).PutBin(val);
 }