diff --git a/src/protocol.cpp b/src/protocol.cpp index 8eb0cfe3..7c26b1f8 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -206,6 +206,12 @@ CONNECTION LESS MESSAGES note: does not have any data -> n = 0 +- PROTMESSID_CLM_SEND_EMPTY_MESSAGE: Send "empty message" message + + +--------------------+--------------+ + | 4 bytes IP address | 2 bytes port | + +--------------------+--------------+ + ****************************************************************************** * @@ -570,7 +576,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector& vecbyData, break; case PROTMESSID_CLM_SEND_EMPTY_MESSAGE: -// TODO + bRet = EvaluateCLSendEmptyMesMes ( InetAddr, vecData ); break; case PROTMESSID_CLM_REGISTER_SERVER: @@ -892,7 +898,7 @@ void CProtocol::CreatePingMes ( const int iMs ) // build data vector (4 bytes long) CVector vecData ( 4 ); - // byte-by-byte copying of the string data + // transmit time (4 bytes) PutValOnStream ( vecData, iPos, static_cast ( iMs ), 4 ); CreateAndSendMessage ( PROTMESSID_PING_MS, vecData ); @@ -1100,7 +1106,7 @@ void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) // build data vector (4 bytes long) CVector vecData ( 4 ); - // byte-by-byte copying of the string data + // transmit time (4 bytes) PutValOnStream ( vecData, iPos, static_cast ( iMs ), 4 ); CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS, @@ -1431,6 +1437,60 @@ bool CProtocol::EvaluateCLReqServerListMes ( const CHostAddress& InetAddr ) return false; // no error } +void CProtocol::CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr, + const CHostAddress& TargetInetAddr ) +{ + int iPos = 0; // init position pointer + + // build data vector (6 bytes long) + CVector vecData ( 6 ); + + // IP address (4 bytes) + PutValOnStream ( vecData, iPos, static_cast ( + TargetInetAddr.InetAddr.toIPv4Address() ), 4 ); + + // port number (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( TargetInetAddr.iPort ), 2 ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SEND_EMPTY_MESSAGE, + vecData, + InetAddr ); +} + +bool CProtocol::EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr, + const CVector& vecData ) +{ + int iPos = 0; // init position pointer + + // check size + if ( vecData.Size() != 6 ) + { + return true; // return error code + } + + // IP address (4 bytes) + const quint32 iIpAddr = + static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + + // port number (2 bytes) + const quint16 iPort = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // invoke message action + emit CLSendEmptyMes ( InetAddr, + CHostAddress ( QHostAddress ( iIpAddr ), iPort ) ); + + return false; // no error +} + +void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr ) +{ + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE, + CVector ( 0 ), + InetAddr ); +} + /******************************************************************************\ * Message generation and parsing * diff --git a/src/protocol.h b/src/protocol.h index 3284865b..56d8af09 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -57,12 +57,12 @@ // DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID #define PROTMESSID_CLM_PING_MS 1001 // for measuring ping time #define PROTMESSID_CLM_SERVER_FULL 1002 // server full message -#define PROTMESSID_CLM_SERVER_LIST 1003 // server list -#define PROTMESSID_CLM_REQ_SERVER_LIST 1004 // request server list -#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1005 // an empty message shall be send -#define PROTMESSID_CLM_EMPTY_MESSAGE 1006 // empty message -#define PROTMESSID_CLM_REGISTER_SERVER 1007 // register server -#define PROTMESSID_CLM_UNREGISTER_SERVER 1008 // unregister server -> TODO +#define PROTMESSID_CLM_REGISTER_SERVER 1003 // register server +#define PROTMESSID_CLM_UNREGISTER_SERVER 1004 // unregister server -> TODO +#define PROTMESSID_CLM_SERVER_LIST 1005 // server list +#define PROTMESSID_CLM_REQ_SERVER_LIST 1006 // request server list +#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1007 // an empty message shall be send +#define PROTMESSID_CLM_EMPTY_MESSAGE 1008 // empty message // lengths of message as defined in protocol.cpp file @@ -102,6 +102,9 @@ public: void CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo ); void CreateCLReqServerListMes ( const CHostAddress& InetAddr ); + void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr, + const CHostAddress& TargetInetAddr ); + void CreateCLEmptyMes ( const CHostAddress& InetAddr ); void CreateAndImmSendDisconnectionMes(); void CreateAndImmSendAcknMess ( const int& iID, @@ -207,6 +210,8 @@ protected: bool EvaluateCLServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr ); + bool EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr, + const CVector& vecData ); int iOldRecID; int iOldRecCnt; @@ -249,6 +254,8 @@ signals: void CLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); void CLReqServerList ( CHostAddress InetAddr ); + void CLSendEmptyMes ( CHostAddress InetAddr, + CHostAddress TargetInetAddr ); }; #endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */