public ChatMessage(PacketIn p) { szName = p.ReadString( 21 ); nSize = p.ReadInt16(); nType = (byte)p.ReadByte(); szMessage = p.ReadString( nSize ); }
/// <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 SERVER_LIST(PacketIn p) { last_login_idx = p.ReadUInt16(); count = p.ReadUInt16(); list = new SERVER_INFO[count]; for ( int i = 0; i < count; i++ ) { list[i] = new SERVER_INFO( p.ReadUInt16(), p.ReadString( 21 ), p.ReadByte() == 1 ? true : false, p.ReadString( 256 ), p.ReadString( 16 ), p.ReadInt32(), p.ReadUInt16() ); } }