コード例 #1
0
ファイル: ClientAgentServer.cs プロジェクト: Joshsora/Toffee
        /// <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);
            }
        }
コード例 #2
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
            ToffeeSession sender = session;

            // Read the packet
            ToffeeInternalPacketReadResult result = ToffeeInternalPacket.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.InternalHello:
                    break;
                }
            }
            else
            {
                Log?.Warning("Received corrupt packet from session {1}.", sender.SessionId);
            }
        }