Esempio n. 1
0
        public static ToffeeClientPacket Create <T>(ToffeeParticipant sender, ushort opCode, T o)
        {
            ToffeeClientPacket packet = new ToffeeClientPacket(sender, opCode);

            packet.WriteStruct(o);
            return(packet);
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a heartbeat to the server.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendHeartbeat(object sender, ElapsedEventArgs e)
        {
            ToffeeClientPacket tcp = new ToffeeClientPacket(this, (ushort)ToffeeOpCode.ClientHeartbeat);

            Send(tcp.BuildPacket());
            PingWatch.Start();
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the decryption, decompression and basic decoding of received client packets.
        /// </summary>
        /// <param name="packet">The received packet.</param>
        sealed protected override void HandlePacket(byte[] packet)
        {
            // Read the packet
            ToffeeClientPacketReadResult result = ToffeeClientPacket.Read(this, packet);

            if (!result.Success)
            {
                // This packet was malformed..
                // TODO
                return;
            }

            // If we have encryption, set the last timestamp we received
            if (UseEncryption)
            {
                Encryption.LastServerTimestamp = result.Header.Timestamp;
            }

            // Handle the packet!
            HandlePacket(result.Header.OpCode, result.Data);
        }
Esempio n. 4
0
 /// <summary>
 /// Builds a packet, and sends it to the server.
 /// </summary>
 /// <param name="opCode">The OpCode of the packet to build.</param>
 /// <param name="o">The packet data.</param>
 public void Send <T>(ushort opCode, T o)
 {
     Send(ToffeeClientPacket.Create(this, opCode, o).BuildPacket());
 }
Esempio n. 5
0
 /// <summary>
 /// Sends a packet to the server.
 /// </summary>
 /// <param name="packet">The data to send.</param>
 public void Send(ToffeeClientPacket packet)
 {
     Send(packet.BuildPacket());
 }