예제 #1
0
파일: Client.cs 프로젝트: SupaFresh/Server
        void Tcp_DataReceived(object sender, Tcp.DataReceivedEventArgs e)
        {
            try
            {
                bool compression = false;
                if (e.CustomHeader[0] == 1)
                {
                    compression = true;
                }
                bool encryption = false;
                if (e.CustomHeader[1] == 1)
                {
                    encryption = true;
                }
                byte[] packetBytes = e.ByteData;
                if (compression)
                {
                    packetBytes = packetModifiers.DecompressPacket(packetBytes);
                }
                if (encryption)
                {
                    packetBytes = packetModifiers.DecryptPacket(packetBytes);
                }
                if (e.CustomHeader[2] == 1)
                {
                    // This was a packet list, process it
                    int position = 0;
                    while (position < packetBytes.Length)
                    {
                        int segmentSize = ByteEncoder.ByteArrayToInt(packetBytes, position);
                        position += 4;
#if EVENTTHREAD
                        PlayerEvent playerEvent = new PlayerEvent(ByteEncoder.ByteArrayToString(packetBytes, position, segmentSize));
                        eventThread.AddEvent(playerEvent);
#else
                        MessageProcessor.ProcessData(this, ByteEncoder.ByteArrayToString(packetBytes, position, segmentSize));
#endif
                        position += segmentSize;
                    }
                }
                else
                {
#if EVENTTHREAD
                    PlayerEvent playerEvent = new PlayerEvent(PMDCP.Core.ByteEncoder.ByteArrayToString(packetBytes));
                    eventThread.AddEvent(playerEvent);
#else
                    MessageProcessor.ProcessData(this, PMDCP.Core.ByteEncoder.ByteArrayToString(packetBytes));
#endif
                }
            }
            catch (Exception ex)
            {
                Exceptions.ErrorLogger.WriteToErrorLog(ex, "Tcp_DataRecieved");
            }
        }
예제 #2
0
 static void tcpClient_DataReceived(object sender, Tcp.DataReceivedEventArgs e)
 {
     try
     {
         bool compression = false;
         if (e.CustomHeader[0] == 1)
         {
             compression = true;
         }
         bool encryption = false;
         if (e.CustomHeader[1] == 1)
         {
             encryption = true;
         }
         byte[] packetBytes = e.ByteData;
         if (compression)
         {
             packetBytes = packetModifiers.DecompressPacket(packetBytes);
         }
         if (encryption)
         {
             packetBytes = packetModifiers.DecompressPacket(packetBytes);
         }
         if (e.CustomHeader[2] == 1)
         {
             // This was a packet list, process it
             int position = 0;
             while (position < packetBytes.Length)
             {
                 int segmentSize = ByteEncoder.ByteArrayToInt(packetBytes, position);
                 position += 4;
                 MessageProcessor.HandleData(ByteEncoder.ByteArrayToString(packetBytes, position, segmentSize));
                 position += segmentSize;
             }
         }
         else
         {
             MessageProcessor.HandleData(ByteEncoder.ByteArrayToString(packetBytes));
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Packet:");
         System.Diagnostics.Debug.WriteLine(ex.ToString());
         System.Diagnostics.Debug.WriteLine(ex.StackTrace);
     }
 }