mirror of
https://github.com/g4klx/ircDDBGateway.git
synced 2026-01-07 16:59:58 +01:00
More meaningful variaable names ans recognize incoming UDP punch
This commit is contained in:
parent
c3427dbb08
commit
0e9c1bb2f2
|
|
@ -74,31 +74,36 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data)
|
|||
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
|
||||
}
|
||||
|
||||
G2_TYPE CG2ProtocolHandler::read(in_addr& incomingAddress, unsigned int& incomingPort)
|
||||
G2_TYPE CG2ProtocolHandler::read(in_addr& remoteAddress, unsigned int& remotePort)
|
||||
{
|
||||
bool res = true;
|
||||
|
||||
// Loop until we have no more data from the socket or we have data for the higher layers
|
||||
while (res)
|
||||
res = readPackets(incomingAddress, incomingPort);
|
||||
res = readPackets(remoteAddress, remotePort);
|
||||
|
||||
return m_type;
|
||||
}
|
||||
|
||||
bool CG2ProtocolHandler::readPackets(in_addr& incomingAddress, unsigned int& incomingPort)
|
||||
bool CG2ProtocolHandler::readPackets(in_addr& remoteAddress, unsigned int& remotePort)
|
||||
{
|
||||
m_type = GT_NONE;
|
||||
|
||||
incomingPort = 0;
|
||||
remotePort = 0;
|
||||
|
||||
// No more data?
|
||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, incomingAddress, incomingPort);
|
||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, remoteAddress, remotePort);
|
||||
if (length <= 0)
|
||||
return false;
|
||||
|
||||
if(length >= 1)
|
||||
wxLogMessage(wxT("bla %i"), length);
|
||||
|
||||
m_length = length;
|
||||
|
||||
if (m_buffer[0] != 'D' || m_buffer[1] != 'S' || m_buffer[2] != 'V' || m_buffer[3] != 'T') {
|
||||
if(length == 1 && m_buffer[0] == 0)
|
||||
return false;//we have been udp punched
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// Header or data packet type?
|
||||
|
|
@ -111,7 +116,7 @@ bool CG2ProtocolHandler::readPackets(in_addr& incomingAddress, unsigned int& inc
|
|||
}
|
||||
}
|
||||
|
||||
CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned int incomingPort)
|
||||
CHeaderData* CG2ProtocolHandler::readHeader(in_addr remoteAddress, unsigned int remotePort)
|
||||
{
|
||||
if (m_type != GT_HEADER)
|
||||
return NULL;
|
||||
|
|
@ -119,7 +124,7 @@ CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned in
|
|||
CHeaderData* header = new CHeaderData;
|
||||
|
||||
// G2 checksums are unreliable
|
||||
bool res = header->setG2Data(m_buffer, m_length, false, incomingAddress, incomingPort);
|
||||
bool res = header->setG2Data(m_buffer, m_length, false, remoteAddress, remotePort);
|
||||
if (!res) {
|
||||
delete header;
|
||||
return NULL;
|
||||
|
|
@ -128,14 +133,15 @@ CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned in
|
|||
return header;
|
||||
}
|
||||
|
||||
CAMBEData* CG2ProtocolHandler::readAMBE(in_addr incomingAddress, unsigned int incomingPort)
|
||||
CAMBEData* CG2ProtocolHandler::readAMBE(in_addr remoteAddress, unsigned int remotePort)
|
||||
{
|
||||
if (m_type != GT_AMBE)
|
||||
return NULL;
|
||||
|
||||
CAMBEData* data = new CAMBEData;
|
||||
|
||||
bool res = data->setG2Data(m_buffer, m_length, incomingAddress, incomingPort);
|
||||
bool res = data->setG2Data(m_buffer, m_length, remoteAddress, remotePort
|
||||
);
|
||||
if (!res) {
|
||||
delete data;
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Reference in a new issue