/// <summary> /// The function which is used to proceed an incoming packet to the active TCPConnection /// </summary> /// <param name="con">The connection which received the packet</param> /// <param name="buf">byte[] array containing the raw content of the received packet</param> /// <param name="start">Start of the content in buf, usually 0</param> /// <param name="size">Size of the packet (minus start)</param> /// <returns>PacketIn -> Converted raw package to MemoryStream based PacketIn</returns> public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size) { PacketIn packet = new PacketIn( buf, start, size ); switch ( packet.ID ) { case 0: // ResultMsg var res = new AUTH_PACKETS.RESULT( packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32() ); if ( res.nRequestPacket == 2005 ) { if ( res.nResult == 0 ) { con.SendTCP( CreateReportPacket() ); con.SendTCP( CreateCharacterListPacket() ); } else { con.Disconnect(); XLog.Log( "Can't connect to game server. Result: {0} - disconnecting...", res.nResult ); } } break; case 2004: // CharacterList m_iGameCharacterList = new GAME_PACKETS.CharacterList( packet ); XLog.Log( "Character selection. Please use /use ID to select a character." ); for ( int i = 0; i < m_iGameCharacterList.nCount; i++ ) { XLog.Log( "-> Character {0}: {1}", i + 1, m_iGameCharacterList.nList[i].szName ); } break; case 21: // ChatLocal var tmp = packet.ReadInt32(); string szSource = m_dHandles.ContainsKey( tmp ) ? m_dHandles[tmp] : "INVALID-HANDLE:" + tmp; int nLen = packet.ReadByte(); int nType = packet.ReadByte(); XLog.AddMessage( szSource, packet.ReadString( nLen ), nType ); break; case 22: // ChatMsg var pMessage = new GAME_PACKETS.ChatMessage( packet ); XLog.AddMessage( pMessage.szName, pMessage.szMessage, pMessage.nType ); break; case 3: // Enter: Handle -> Name, small hack so we don't have to read the full packet (which is f*****g large) if ( packet.ReadByte() == 0 ) { int key = packet.ReadInt32(); if ( m_dHandles.ContainsKey( key ) ) { m_dHandles.Remove( key ); } packet.Seek( 77, System.IO.SeekOrigin.Current ); string value = packet.ReadString( 19 ); m_dHandles.Add( key, value ); } break; case 507: // Property: Own Name -> Handle if ( m_dHandles.ContainsKey( 0 ) && m_tPingThread == null) { var szName = m_dHandles[0]; m_dHandles.Remove( 0 ); m_dHandles.Add( packet.ReadInt32(), szName ); m_tPingThread = new System.Threading.Thread( new System.Threading.ThreadStart( SendPingPacket ) ); m_tPingThread.IsBackground = true; m_tPingThread.Start(); } break; default: break; } return packet; }
public XClientGameEmulator(Config.ConfigNet conf, TCPManager man, XChat.XClientEmulator pBase, string pAccount, PacketOut pOut) { m_szAccount = pAccount; m_cGameConnection = new TCPConnection( man, null, this, conf ); try { m_cGameConnection.Start(); m_cGameConnection.SendTCP(CreateVersionPacket()); m_cGameConnection.SendTCP( pOut ); } catch { XLog.Log( "Can't connect to Game Server!" ); } }
public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size) { PacketIn packet = new PacketIn( buf, start, size ); switch ( packet.ID ) { case 72: // TS_AC_AES_KEY_IV var pAES = new AUTH_PACKETS.AES_KEY_IV( packet ); m_pAES_KEY = m_cRSA.PrivateDecrypt( pAES.nKey, OpenSSL.Crypto.RSA.Padding.PKCS1 ); GenerateLoginPacket( m_pAES_KEY, con ); break; case 10000: // TS_AC_RESULT var pResult = new AUTH_PACKETS.RESULT( packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32() ); if ( pResult.nLoginFlag == 1 ) { PacketOut o = new PacketOut( 10021 ); con.SendTCP( o ); } else { m_cAuthConnection.Disconnect(); XLog.Log( "Login failed. Result: {0} - Disconnecting...", pResult.nResult ); } m_szPassword = string.Empty; break; case 10022: // TS_AC_SERVER_LIST m_iAuthServerList = new AUTH_PACKETS.SERVER_LIST( packet ); XLog.Log( "Server selection. Please use /select ID to connect to one of the listed servers below." ); for ( int i = 0; i < m_iAuthServerList.count; i++ ) { XLog.Log( string.Format( "-> Server {0}: {1}", i + 1, m_iAuthServerList.list[i].server_name ) ); } break; case 10024: // TS_AC_SELECT_SERVER con.Disconnect(); var pSelectServer = new AUTH_PACKETS.SELECT_SERVER( packet, ref m_pAES_KEY ); Config.ConfigNet conf = new Config.ConfigNet(); conf.Port = m_iAuthServerList.list[m_nSelectedServerIdx].server_port; conf.ListenIp = System.Net.IPAddress.Parse( m_iAuthServerList.list[m_nSelectedServerIdx].server_ip ); PacketOut oEncrypt = new PacketOut( 2005 ); oEncrypt.FillString( m_szName, 61 ); oEncrypt.Write( pSelectServer.encrypted_data, 0, pSelectServer.encrypted_data.Length ); oEncrypt.FinalizeLengthAndChecksum(); con.Close(); m_cClientBase.CreateGameServerSession( oEncrypt, conf, m_szName ); break; default: break; } return packet; }
private void GenerateLoginPacket(byte[] key, TCPConnection con) { PacketOut o = new PacketOut( 10010 ); var a = EncryptAES( key, m_szPassword ); o.FillString( m_szName, 61 ); o.WriteInt32( a.Length ); o.Write( a, 0, a.Length ); o.Fill( 0, 61 - a.Length ); con.SendTCP( o ); }
public XClientAuthEmulator(TCPManager man, Config.ConfigNet conf, string pAccount, string pPassword, XChat.XClientEmulator cBase) { m_szName = pAccount; m_szPassword = pPassword; m_cClientBase = cBase; try { m_cAuthConnection = new TCPConnection( man, null, this, conf ); m_cAuthConnection.Start(); m_cAuthConnection.SendTCP( this.CreateVersionPacket() ); m_cAuthConnection.SendTCP( this.CreateAESPacket() ); } catch { XLog.Log( "Can't connect to Authentication Server!" ); } }