@@ -81,10 +81,6 @@ void DESC::Initialize()
8181 m_offtime = 0 ;
8282
8383 m_pkDisconnectEvent = NULL ;
84-
85- m_iFloodCheckPulse = 0 ;
86- m_dwFloodPacketCount = 0 ;
87- m_bIPCountTracked = false ;
8884}
8985
9086void DESC::Destroy ()
@@ -216,7 +212,6 @@ bool DESC::Setup(LPFDWATCH _fdw, socket_t _fd, const struct sockaddr_in & c_rSoc
216212
217213 m_pkPingEvent = event_create (ping_event, info, ping_event_second_cycle);
218214
219- // Set Phase to handshake and begin secure key exchange
220215 SetPhase (PHASE_HANDSHAKE);
221216 m_handshake_time = get_dword_time ();
222217 SendKeyChallenge ();
@@ -242,7 +237,6 @@ int DESC::ProcessInput()
242237 else if (bytes_read == 0 )
243238 return 0 ;
244239
245- // Decrypt only the newly received bytes before committing to the buffer
246240 if (m_secureCipher.IsActivated ()) {
247241 m_secureCipher.DecryptInPlace (m_inputBuffer.WritePtr (), bytes_read);
248242 }
@@ -328,7 +322,6 @@ void DESC::Packet(const void * c_pvData, int iSize)
328322 if (m_iPhase == PHASE_CLOSE)
329323 return ;
330324
331- // Log the packet for sequence tracking (only for real packet sends, not buffered flushes)
332325 if (!m_hasBufferedOutput && iSize >= (int )sizeof (uint16_t ) * 2 )
333326 {
334327 const uint16_t wHeader = *static_cast <const uint16_t *>(c_pvData);
@@ -465,54 +458,22 @@ bool DESC::IsExpiredHandshake() const
465458 return (m_handshake_time + (5 * 1000 )) < get_dword_time ();
466459}
467460
468- bool DESC::CheckPacketFlood ()
469- {
470- extern int g_iFloodMaxPacketsPerSec;
471-
472- // Use thecore_pulse() (cached per game-loop iteration) instead of
473- // get_dword_time() (gettimeofday syscall) to avoid per-packet syscall overhead.
474- int pulse = thecore_pulse ();
475- int pps = static_cast <int >(thecore_pulse_per_second ());
476-
477- if (pulse - m_iFloodCheckPulse >= pps)
478- {
479- m_iFloodCheckPulse = pulse;
480- m_dwFloodPacketCount = 1 ;
481- return false ;
482- }
483-
484- ++m_dwFloodPacketCount;
485-
486- if (m_dwFloodPacketCount > (uint32_t )g_iFloodMaxPacketsPerSec)
487- {
488- sys_log (0 , " FLOOD: %s exceeded %d packets/sec (count: %u), disconnecting" ,
489- GetHostName (), g_iFloodMaxPacketsPerSec, m_dwFloodPacketCount);
490- return true ;
491- }
492-
493- return false ;
494- }
495-
496461DWORD DESC::GetClientTime ()
497462{
498463 return m_dwClientTime;
499464}
500465
501- // Secure key exchange methods (libsodium/XChaCha20-Poly1305)
502466void DESC::SendKeyChallenge ()
503467{
504- // Initialize cipher and generate keypair
505468 if (!m_secureCipher.Initialize ())
506469 {
507470 sys_err (" Failed to initialize SecureCipher" );
508471 SetPhase (PHASE_CLOSE);
509472 return ;
510473 }
511474
512- // Generate challenge
513475 m_secureCipher.GenerateChallenge (m_challenge);
514476
515- // Build and send challenge packet
516477 TPacketGCKeyChallenge packet;
517478 packet.header = GC::KEY_CHALLENGE;
518479 packet.length = sizeof (packet);
@@ -529,14 +490,12 @@ void DESC::SendKeyChallenge()
529490
530491bool DESC::HandleKeyResponse (const uint8_t * client_pk, const uint8_t * challenge_response)
531492{
532- // Compute session keys from client's public key
533493 if (!m_secureCipher.ComputeServerKeys (client_pk))
534494 {
535495 sys_err (" Failed to compute server session keys for %s" , GetHostName ());
536496 return false ;
537497 }
538498
539- // Verify challenge response
540499 if (!m_secureCipher.VerifyChallengeResponse (m_challenge, challenge_response))
541500 {
542501 sys_err (" Challenge response verification failed for %s" , GetHostName ());
@@ -550,17 +509,14 @@ bool DESC::HandleKeyResponse(const uint8_t* client_pk, const uint8_t* challenge_
550509
551510void DESC::SendKeyComplete ()
552511{
553- // Generate session token
554512 uint8_t session_token[SecureCipher::SESSION_TOKEN_SIZE];
555513 randombytes_buf (session_token, sizeof (session_token));
556514 m_secureCipher.SetSessionToken (session_token);
557515
558- // Build and send complete packet
559516 TPacketGCKeyComplete packet;
560517 packet.header = GC::KEY_COMPLETE;
561518 packet.length = sizeof (packet);
562519
563- // Encrypt the session token
564520 if (!m_secureCipher.EncryptToken (session_token, sizeof (session_token),
565521 packet.encrypted_token , packet.nonce ))
566522 {
@@ -571,10 +527,7 @@ void DESC::SendKeyComplete()
571527
572528 Packet (&packet, sizeof (packet));
573529
574- // Flush before activating encryption
575530 ProcessOutput ();
576-
577- // Activate encryption
578531 m_secureCipher.SetActivated (true );
579532
580533 sys_log (0 , " [HANDSHAKE] Cipher ACTIVATED for %s (tx_nonce: %llu, rx_nonce: %llu)" ,
@@ -852,8 +805,6 @@ void DESC::ChatPacket(BYTE type, const char * format, ...)
852805 Packet (buf.read_peek (), buf.size ());
853806}
854807
855- // --- Packet sequence tracking ---
856-
857808void DESC::LogRecvPacket (uint16_t header, uint16_t length)
858809{
859810 auto & e = m_aRecentRecvPackets[m_dwRecvPacketSeq % PACKET_LOG_SIZE];
0 commit comments