From: Anton Baskanov baskanov@gmail.com
--- dlls/dplayx/dplay.c | 22 +++++++++++++++++++ dlls/dplayx/dplayx_messages.c | 41 +++++++++++++++++++++++++++++++++++ dlls/dplayx/dplayx_messages.h | 11 +++++++++- dlls/dplayx/tests/dplayx.c | 4 +--- 4 files changed, 74 insertions(+), 4 deletions(-)
diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c index 4dbbd722730..d1b56afa5c2 100644 --- a/dlls/dplayx/dplay.c +++ b/dlls/dplayx/dplay.c @@ -545,6 +545,28 @@ HRESULT DP_HandleMessage( IDirectPlayImpl *This, void *messageBody, DP_MSG_ToSelf( This, 1 ); /* This is a hack right now */ break;
+ case DPMSGCMD_PING: { + const DPSP_MSG_PING *msg; + + if( dwMessageBodySize < sizeof( DPSP_MSG_PING ) ) + return DPERR_GENERIC; + msg = (const DPSP_MSG_PING *)messageBody; + + EnterCriticalSection( &This->lock ); + + if ( !This->dp2->bConnectionOpen ) + { + LeaveCriticalSection( &This->lock ); + return DP_OK; + } + + LeaveCriticalSection( &This->lock ); + + DP_MSG_SendPingReply( This, msg->fromId, This->dp2->systemPlayerId, msg->tickCount ); + + break; + } + case DPMSGCMD_ADDFORWARD: { DPSP_MSG_ADDFORWARD *msg; DPPLAYERINFO playerInfo; diff --git a/dlls/dplayx/dplayx_messages.c b/dlls/dplayx/dplayx_messages.c index 52aea44a17f..3eeb8c23508 100644 --- a/dlls/dplayx/dplayx_messages.c +++ b/dlls/dplayx/dplayx_messages.c @@ -795,6 +795,47 @@ HRESULT DP_MSG_SendCreatePlayer( IDirectPlayImpl *This, DPID toId, DPID id, DWOR return DP_OK; }
+HRESULT DP_MSG_SendPingReply( IDirectPlayImpl *This, DPID toId, DPID fromId, DWORD tickCount ) +{ + SGBUFFER buffers[ 2 ] = { 0 }; + DPSP_SENDEXDATA sendData; + DPSP_MSG_PING msg; + HRESULT hr; + + msg.envelope.dwMagic = DPMSGMAGIC_DPLAYMSG; + msg.envelope.wCommandId = DPMSGCMD_PINGREPLY; + msg.envelope.wVersion = DPMSGVER_DP6; + msg.fromId = fromId; + msg.tickCount = tickCount; + + buffers[ 0 ].len = This->dp2->spData.dwSPHeaderSize; + buffers[ 0 ].pData = NULL; + buffers[ 1 ].len = sizeof( msg ); + buffers[ 1 ].pData = (UCHAR *)&msg; + + sendData.lpISP = This->dp2->spData.lpISP; + sendData.dwFlags = 0; + sendData.idPlayerTo = toId; + sendData.idPlayerFrom = This->dp2->systemPlayerId; + sendData.lpSendBuffers = buffers; + sendData.cBuffers = ARRAYSIZE( buffers ); + sendData.dwMessageSize = DP_MSG_ComputeMessageSize( sendData.lpSendBuffers, sendData.cBuffers ); + sendData.dwPriority = 0; + sendData.dwTimeout = 0; + sendData.lpDPContext = NULL; + sendData.lpdwSPMsgID = NULL; + sendData.bSystemMessage = TRUE; + + hr = (*This->dp2->spData.lpCB->SendEx)( &sendData ); + if( FAILED( hr ) ) + { + ERR( "Send failed: %s\n", DPLAYX_HresultToString( hr ) ); + return hr; + } + + return DP_OK; +} + HRESULT DP_MSG_SendAddForwardAck( IDirectPlayImpl *This, DPID id ) { SGBUFFER buffers[ 2 ] = { 0 }; diff --git a/dlls/dplayx/dplayx_messages.h b/dlls/dplayx/dplayx_messages.h index fd432e5cb6c..2a3a15d5c73 100644 --- a/dlls/dplayx/dplayx_messages.h +++ b/dlls/dplayx/dplayx_messages.h @@ -57,6 +57,7 @@ HRESULT DP_MSG_ForwardPlayerCreation( IDirectPlayImpl *This, DPID dpidServer, WC HRESULT DP_MSG_SendCreatePlayer( IDirectPlayImpl *This, DPID toId, DPID id, DWORD flags, DPNAME *name, void *playerData, DWORD playerDataSize, DPID systemPlayerId ); +HRESULT DP_MSG_SendPingReply( IDirectPlayImpl *This, DPID toId, DPID fromId, DWORD tickCount ); HRESULT DP_MSG_SendAddForwardAck( IDirectPlayImpl *This, DPID id );
void DP_MSG_ReplyReceived( IDirectPlayImpl *This, WORD wCommandId, @@ -107,7 +108,8 @@ typedef struct
#define DPMSGCMD_FORWARDADDPLAYER 19
-#define DPMSGCMD_PLAYERCHAT 22 +#define DPMSGCMD_PING 22 +#define DPMSGCMD_PINGREPLY 23
#define DPMSGCMD_FORWARDADDPLAYERNACK 36
@@ -268,6 +270,13 @@ typedef struct #define DPLAYI_SUPERPACKEDPLAYER_PARENT_ID_PRESENT 0x100 #define DPLAYI_SUPERPACKEDPLAYER_SHORTCUT_COUNT_SIZE( mask ) (((mask) >> 9) & 0x3)
+typedef struct +{ + DPMSG_SENDENVELOPE envelope; + DPID fromId; + DWORD tickCount; +} DPSP_MSG_PING; + typedef struct { DPMSG_SENDENVELOPE envelope; diff --git a/dlls/dplayx/tests/dplayx.c b/dlls/dplayx/tests/dplayx.c index 02746f2fe6a..da3a9b533c2 100644 --- a/dlls/dplayx/tests/dplayx.c +++ b/dlls/dplayx/tests/dplayx.c @@ -2031,9 +2031,7 @@ static unsigned short receivePingReply_( int line, SOCKET sock, DPID expectedFro int wsResult;
wsResult = receiveMessage_( line, sock, &request, sizeof( request ) ); - todo_wine ok_( __FILE__, line )( wsResult == sizeof( request ), "recv() returned %d.\n", wsResult ); - if ( wsResult == SOCKET_ERROR ) - return 0; + ok_( __FILE__, line )( wsResult == sizeof( request ), "recv() returned %d.\n", wsResult );
port = checkSpHeader_( line, &request.spHeader, sizeof( request ) ); checkMessageHeader_( line, &request.request.header, 23 );