// ReSharper disable UnusedParameter.Local private void ProcessFragment(ByteBuffer theData, SFragmentData sFragment, UInt32 type, UInt16 fragment, UInt16 fragmentId, UInt16 fragmentCount) // ReSharper restore UnusedParameter.Local { if (sFragment.FragmentId != fragment) { if (fragment > 0) Console.WriteLine("Dropped fragment: {0} vs {1}", sFragment.FragmentId, fragment); sFragment.FragmentId = fragment; sFragment.TotalSize = 0; sFragment.MapFragments.Clear(); } sFragment.MapFragments.Add(fragmentId, theData); sFragment.TotalSize += theData.GetBufferSize(); if (sFragment.MapFragments.Count == fragmentCount) { Console.WriteLine("Reassembling fragment {0} ({1} fragments", sFragment.FragmentId, fragmentCount); var combined = new ByteBuffer(sFragment.TotalSize); var off = 0U; for (var i = 0; i < sFragment.MapFragments.Count; ++i) { if (!sFragment.MapFragments.ContainsKey(i)) { Console.WriteLine("Big error! Fragment doesn't contain a buffer! Fragment: {0} | Index: {1}", fragment, i); return; } var buff = sFragment.MapFragments[i]; Array.Copy(buff.GetBuffer(), 0, combined.GetBuffer(), off, buff.GetBufferSize()); off += buff.GetBufferSize(); } sFragment.FragmentId = 0; sFragment.TotalSize = 0; sFragment.MapFragments.Clear(); HandlePacket(combined); } }
private static string byteBuffToString( ByteBuffer byteBuffer ) { if ( byteBuffer == null ) return ""; StringBuilder sb = new StringBuilder( 500 ); int i = 0; foreach ( byte b in byteBuffer.GetBuffer() ) { //sb.Append( b.ToString("X2") + "," ); sb.Append( b.ToString() + "," ); if ( i % 100 == 0 && i != 0 ) sb.Append( '\n' ); i++; } return sb.ToString(); }
private void HandlePacket(ByteBuffer buffer) { var packet = new Packet(buffer.GetBuffer()); Logger.WriteLog("Incoming Packet: {0}", LogType.Network, packet.Opcode); try { switch (packet.Opcode) { // Global case Opcode.LoginRequest: HandleLoginRequest(packet); break; case Opcode.LoginNewCharacter: HandleLoginNewCharacter(packet); break; case Opcode.LoginDeleteCharacter: HandleLoginDeleteCharacter(packet); break; case Opcode.News: HandleNews(packet); break; case Opcode.Login: HandleGlobalLogin(packet); break; case Opcode.Disconnect: HandleDisconnect(packet); break; case Opcode.Chat: ChatManager.HandleChat(this, packet); break; case Opcode.GetFriends: SocialManager.GetFriends(this); break; case Opcode.GetEnemies: SocialManager.GetEnemies(this); break; case Opcode.GetIgnored: SocialManager.GetIgnored(this); break; case Opcode.AddFriend: SocialManager.AddEntry(this, packet, SocialType.Friend); break; case Opcode.AddEnemy: SocialManager.AddEntry(this, packet, SocialType.Enemy); break; case Opcode.AddIgnore: SocialManager.AddEntry(this, packet, SocialType.Ignore); break; case Opcode.RemoveFriend: SocialManager.RemoveEntry(this, packet.ReadPadding(4).ReadLong(), SocialType.Friend); break; case Opcode.RemoveEnemy: SocialManager.RemoveEntry(this, packet.ReadPadding(4).ReadLong(), SocialType.Enemy); break; case Opcode.RemoveIgnore: SocialManager.RemoveEntry(this, packet.ReadPadding(4).ReadLong(), SocialType.Ignore); break; case Opcode.RequestClanInfo: ClanManager.RequestInfo(this); break; case Opcode.ConvoyMissionsRequest: ConvoyManager.MissionsRequest(this); break; // Sector case Opcode.TransferFromGlobal: HandleTransferFromGlobal(packet); break; case Opcode.TransferFromGlobalStage2: HandleTransferFromGlobalStage2(packet); break; case Opcode.TransferFromGlobalStage3: HandleTransferFromGlobalStage3(packet); break; case Opcode.UpdateFirstTimeFlagsRequest: HandleUpdateFirstTimeFlagsRequest(packet); break; case Opcode.Broadcast: ChatManager.HandleBroadcast(this, packet); break; default: Logger.WriteLog("Unhandled Opcode: {0}", LogType.Error, packet.Opcode); break; } } catch (Exception e) { Logger.WriteLog("Caught exception while handling packets!", LogType.Error); Logger.WriteLog("Exception: {0}", LogType.Error, e); } }