File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -501,6 +501,31 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecM
501501void CServer::OnCLClientIDReceived ( CHostAddress InetAddr, int iChanID, CTcpConnection* pTcpConnection )
502502{
503503 qDebug () << " - client ID" << iChanID << " received from" << InetAddr.toString () << " with TCP connection" << pTcpConnection;
504+
505+ if ( iChanID < 0 || iChanID >= iMaxNumChannels || !vecChannels[iChanID].IsConnected () )
506+ {
507+ // ID out of range or channel not connected - reject connection
508+ pTcpConnection->disconnectFromHost ();
509+ qDebug () << " - rejected invalid client ID" ;
510+ return ;
511+ }
512+
513+ CChannel* pChannel = &vecChannels[iChanID];
514+
515+ qDebug () << " - request to link TCP connection with UDP client at" << pChannel->GetAddress ().toString ();
516+
517+ // compare IP addresses, but not port numbers
518+ if ( InetAddr.InetAddr != pChannel->GetAddress ().InetAddr )
519+ {
520+ // IP address mismatch - reject connection
521+ pTcpConnection->disconnectFromHost ();
522+ qDebug () << " - rejected mismatched IP address" ;
523+ return ;
524+ }
525+
526+ // link TCP connection with UDP channel
527+ pTcpConnection->SetChannel ( pChannel );
528+ pChannel->SetTcpConnection ( pTcpConnection );
504529}
505530
506531void CServer::OnCLDisconnection ( CHostAddress InetAddr )
You can’t perform that action at this time.
0 commit comments