Skip to content

Commit 868416e

Browse files
committed
In server, link TCP channel to UDP channel by client ID
1 parent ac85be0 commit 868416e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/server.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,31 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecM
501501
void 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

506531
void CServer::OnCLDisconnection ( CHostAddress InetAddr )

0 commit comments

Comments
 (0)