Ejemplo n.º 1
0
        /// <summary>
        /// Handles recieved packets.
        /// </summary>
        /// <param name="session">The session that received the packet.</param>
        /// <param name="packet">The packet data that was received.</param>
        public override void HandlePacket(ToffeeSession session, byte[] packet)
        {
            // Get the session
            ClientAgentSession sender = (ClientAgentSession)session;

            // Read the packet
            ToffeeClientPacketReadResult result = ToffeeClientPacket.Read(session, packet);

            // Was this a succcessful read?
            if (result.Success)
            {
                Log?.Debug("Received 0x{0:X2} from session {1}.", result.Header.OpCode, sender.SessionId);

                ToffeePacketIterator iterator = new ToffeePacketIterator(session, result.Data);
                switch (result.Header.OpCode)
                {
                case (ushort)ToffeeOpCode.ClientHello:
                    HandleClientHello(sender, iterator.ReadStruct <ClientHello>());
                    break;

                case (ushort)ToffeeOpCode.ClientHeartbeat:
                    HandleClientHeartbeat(sender);
                    break;
                }
            }
            else
            {
                Log?.Warning("Received corrupt packet from session {1}.", sender.SessionId);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a packet to the session.
        /// </summary>
        /// <param name="packet">The data to send.</param>
        public void Send(ToffeeClientPacket packet)
        {
            Send(packet.BuildPacket());

            // If we use encryption, make sure to set the last server timestamp
            if (UseEncryption)
            {
                Encryption.LastServerTimestamp = packet.LastHeader.Timestamp;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a packet, and sends it to the session.
        /// </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)
        {
            ToffeeClientPacket packet = ToffeeClientPacket.Create(this, opCode, o);

            Send(packet.BuildPacket());

            // If we use encryption, make sure to set the last server timestamp
            if (UseEncryption)
            {
                Encryption.LastServerTimestamp = packet.LastHeader.Timestamp;
            }
        }