예제 #1
0
        public Client(TcpClientIdentifier tcpID, Tcp.TcpClient tcpClient)
        {
            this.tcpID = tcpID;
            this.tcpClient = tcpClient;
            this.tcpClient.CustomHeaderSize = GetCustomPacketHeaderSize();
            this.packetModifiers = new PacketModifiers();

            //database = new MySql("localhost", 3306, "test", "root", "test");

            #if EVENTTHREAD
            eventThread = new PlayerEventThread(this);
            #endif

            AddEventHandlers();

            SetupPacketSecurity();
        }
예제 #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);
     }
 }
예제 #3
0
        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(PMU.Core.ByteEncoder.ByteArrayToString(packetBytes));
                    eventThread.AddEvent(playerEvent);
            #else
                    MessageProcessor.ProcessData(this, PMU.Core.ByteEncoder.ByteArrayToString(packetBytes));
            #endif
                }
            } catch (Exception ex) {
                Exceptions.ErrorLogger.WriteToErrorLog(ex, "Tcp_DataRecieved");
            }
        }