public override byte[] ProcessDataReceived( byte []data, int length ) { /* Console.WriteLine("ProcessDataReceived receive" ); HexViewer.View( data, 0, length ); Console.WriteLine("ProcessDataReceived end" );*/ // Console.WriteLine("ProcessDataReceived enter" ); if ( playerAccount == null ) { Console.WriteLine("playerAccount == null, IP={0}", IP.ToString() ); if ( ( data[ 0 ] == 0 || data[ 0 ] == 2 ) && data[ 2 ] == 0xed && data[ 3 ] == 0x1 ) { string username = ""; for(int t = 0xe;t < length;t++ ) { if ( data[ t ] == 0 ) break; username += "" + (char)data[ t ]; } playerAccount = World.allAccounts.FindByUserName( username ); Console.WriteLine("Player {0} with IP {1}", username, IP ); if ( playerAccount == null ) { Console.WriteLine("Strange bug, {0} was not found in the account list !", username ); return null; } playerAccount.Handler = this; playerAccount.PreLogin(); if ( playerAccount.packetHandler == null ) { Console.WriteLine("packetHandler cannot be null"); } if ( playerAccount.Packets.Count > 0 ) { Queue q = new Queue(); q.Enqueue( new Packet( data, length ) ); while( playerAccount.Packets.Count > 0 ) q.Enqueue( playerAccount.Packets.Dequeue() ); playerAccount.Packets = q; } // Console.WriteLine("Packets.Enqueue for {0} total {1}", playerAccount.Username, playerAccount.Packets.Count ); if ( playerAccount.Packets.Count > 100 ) { Console.WriteLine("Player {0} send too many packets !!! Kicked !!!" ); playerAccount.Packets.Clear(); this.Logout(); return null; } // playerAccount.Packets.Enqueue( new Packet( data, length ) ); // Console.Write( "{0}:{1}:{2}-{1} <-- ", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, this.IP.ToString() ); // HexViewer.View( data, 0, length ); key = new byte[]{ 0, 0, 0, 0 }; needEncode = true; needLog = true; dt = new DelaySend( this ); firstPacket = false; // playerAccount.PacketHandler(); return null; } else playerAccount = World.allAccounts.FindNotLoggedAccountByIp( IP );//, Port ); if ( playerAccount == null ) { Console.WriteLine( "IP doesn't match the prior IP client send !!!\nMake sure your IP match the IP in the realmlist.rtf" ); this.Dispose(); return null; } if ( !needEncode && playerAccount.packetHandler != null ) { // Console.WriteLine("!needEncode, playerAccount.packetHandler != null" ); playerAccount.packetHandler.Stop(); playerAccount.packetHandler = null; } if ( playerAccount != null && playerAccount.packetHandler == null ) { // Console.WriteLine("playerAccount.packetHandler == null" ); playerAccount.Handler = this; playerAccount.PreLogin(); } } // if ( playerAccount != null )//&& playerAccount.SelectedChar != null ) // { // Console.WriteLine("ExMutuel.WaitOne" ); // playerAccount.ExMutuel.WaitOne(); // Console.WriteLine("Packets.Enqueue for {0} total {1}", playerAccount.Username, playerAccount.Packets.Count ); if ( playerAccount == null ) Console.WriteLine("Loosing packet for {0}",IP.ToString() ); else { lock( playerAccount.Packets ) { playerAccount.Packets.Enqueue( new Packet( data, length ) ); } } // playerAccount.ExMutuel.ReleaseMutex(); // } // else // return DequeueData( data, length ); // Console.WriteLine("End" ); return null; }