From 9e4961df50b55806637807c36a93081b9b9ca192 Mon Sep 17 00:00:00 2001 From: Ismael Barros Date: Mon, 11 Aug 2008 04:15:27 +0200 Subject: [PATCH] dplayx: Modified reply functions to save also the header of the reply --- dlls/dplayx/dplay.c | 6 ++-- dlls/dplayx/dplay_global.h | 1 + dlls/dplayx/dplayx_messages.c | 66 +++++++++++++++++++++++++++---------------- dlls/dplayx/dplayx_messages.h | 5 ++-- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c index 7aac8403e01..fc7b240a6fe 100644 --- a/dlls/dplayx/dplay.c +++ b/dlls/dplayx/dplay.c @@ -755,7 +755,8 @@ HRESULT DP_HandleMessage( IDirectPlay2Impl* This, LPCVOID lpcMessageBody, case DPMSGCMD_REQUESTPLAYERREPLY: { - DP_MSG_ReplyReceived( This, wCommandId, lpcMessageBody, dwMessageBodySize ); + DP_MSG_ReplyReceived( This, wCommandId, lpcMessageHeader, + lpcMessageBody, dwMessageBodySize ); break; } @@ -780,7 +781,8 @@ HRESULT DP_HandleMessage( IDirectPlay2Impl* This, LPCVOID lpcMessageBody, case DPMSGCMD_SUPERENUMPLAYERSREPLY: { - DP_MSG_ReplyReceived( This, wCommandId, lpcMessageBody, dwMessageBodySize ); + DP_MSG_ReplyReceived( This, wCommandId, lpcMessageHeader, + lpcMessageBody, dwMessageBodySize ); break; } diff --git a/dlls/dplayx/dplay_global.h b/dlls/dplayx/dplay_global.h index 89887e710de..994cfd61fbc 100644 --- a/dlls/dplayx/dplay_global.h +++ b/dlls/dplayx/dplay_global.h @@ -60,6 +60,7 @@ typedef struct tagDP_MSG_REPLY_STRUCT { HANDLE hReceipt; WORD wExpectedReply; + LPVOID lpReplyHdr; LPVOID lpReplyMsg; DWORD dwMsgBodySize; /* FIXME: Is the message header required as well? */ diff --git a/dlls/dplayx/dplayx_messages.c b/dlls/dplayx/dplayx_messages.c index c7725dc5073..02b74b36814 100644 --- a/dlls/dplayx/dplayx_messages.c +++ b/dlls/dplayx/dplayx_messages.c @@ -48,7 +48,8 @@ typedef struct tagMSGTHREADINFO static DWORD CALLBACK DPL_MSG_ThreadMain( LPVOID lpContext ); static LPVOID DP_MSG_ExpectReply( IDirectPlay2AImpl* This, LPDPSP_SENDDATA data, DWORD dwWaitTime, WORD wReplyCommandId, - LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize ); + LPVOID* lplpReplyHdr, LPVOID* lplpReplyMsg, + LPDWORD lpdwMsgBodySize ); static DWORD DP_MSG_FillSuperPackedPlayer( IDirectPlay2Impl* lpDP, LPDPLAYI_SUPERPACKEDPLAYER lpPackedPlayer, LPVOID lpData, @@ -170,7 +171,8 @@ static HANDLE DP_MSG_BuildAndLinkReplyStruct( IDirectPlay2Impl* This, LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList, WORD wReplyCommandId ); static LPVOID DP_MSG_CleanReplyStruct( LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList, - LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize ); + LPVOID* lplpReplyHdr, LPVOID* lplpReplyMsg, + LPDWORD lpdwMsgBodySize ); static @@ -179,6 +181,7 @@ HANDLE DP_MSG_BuildAndLinkReplyStruct( IDirectPlay2Impl* This, { lpReplyStructList->replyExpected.hReceipt = CreateEventW( NULL, FALSE, FALSE, NULL ); lpReplyStructList->replyExpected.wExpectedReply = wReplyCommandId; + lpReplyStructList->replyExpected.lpReplyHdr = NULL; lpReplyStructList->replyExpected.lpReplyMsg = NULL; lpReplyStructList->replyExpected.dwMsgBodySize = 0; @@ -192,10 +195,16 @@ HANDLE DP_MSG_BuildAndLinkReplyStruct( IDirectPlay2Impl* This, static LPVOID DP_MSG_CleanReplyStruct( LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList, - LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize ) + LPVOID* lplpReplyHdr, LPVOID* lplpReplyMsg, + LPDWORD lpdwMsgBodySize ) { CloseHandle( lpReplyStructList->replyExpected.hReceipt ); + if ( lplpReplyHdr ) + { + *lplpReplyHdr = lpReplyStructList->replyExpected.lpReplyHdr; + } + *lplpReplyMsg = lpReplyStructList->replyExpected.lpReplyMsg; *lpdwMsgBodySize = lpReplyStructList->replyExpected.dwMsgBodySize; @@ -285,7 +294,7 @@ HRESULT DP_MSG_SendRequestPlayerId( IDirectPlay2AImpl* This, DWORD dwFlags, lpMsg = DP_MSG_ExpectReply( This, &data, DPMSG_RELIABLE_API_TIMER, DPMSGCMD_REQUESTPLAYERREPLY, - &lpMsg, &dwMsgSize ); + NULL, &lpMsg, &dwMsgSize ); } /* Examine reply */ @@ -343,7 +352,7 @@ HRESULT DP_MSG_ForwardPlayerCreation( IDirectPlay2AImpl* This, DPID dpidServer ) lpMsg = DP_MSG_ExpectReply( This, &data, DPMSG_RELIABLE_API_TIMER, DPMSGCMD_ADDFORWARD, - &lpMsg, &dwMsgSize ); + NULL, &lpMsg, &dwMsgSize ); } /* Need to examine the data and extract the new player id */ @@ -364,7 +373,8 @@ HRESULT DP_MSG_ForwardPlayerCreation( IDirectPlay2AImpl* This, DPID dpidServer ) static LPVOID DP_MSG_ExpectReply( IDirectPlay2AImpl* This, LPDPSP_SENDDATA lpData, DWORD dwWaitTime, WORD wReplyCommandId, - LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize ) + LPVOID* lplpReplyHdr, LPVOID* lplpReplyMsg, + LPDWORD lpdwMsgBodySize ) { HRESULT hr; HANDLE hMsgReceipt; @@ -400,15 +410,17 @@ LPVOID DP_MSG_ExpectReply( IDirectPlay2AImpl* This, LPDPSP_SENDDATA lpData, } /* Clean Up */ - return DP_MSG_CleanReplyStruct( &replyStructList, lplpReplyMsg, lpdwMsgBodySize ); + return DP_MSG_CleanReplyStruct( &replyStructList, lplpReplyHdr, + lplpReplyMsg, lpdwMsgBodySize ); } /* Determine if there is a matching request for this incoming message and then copy * all important data. It is quite silly to have to copy the message, but the documents * indicate that a copy is taken. Silly really. */ -void DP_MSG_ReplyReceived( IDirectPlay2AImpl* This, WORD wCommandId, - LPCVOID lpcMsgBody, DWORD dwMsgBodySize ) +BOOL DP_MSG_ReplyReceived( IDirectPlay2AImpl* This, WORD wCommandId, + LPCVOID lpcMsgHdr, LPCVOID lpcMsgBody, + DWORD dwMsgBodySize ) { LPDP_MSG_REPLY_STRUCT_LIST lpReplyList; @@ -420,23 +432,29 @@ void DP_MSG_ReplyReceived( IDirectPlay2AImpl* This, WORD wCommandId, ==, wCommandId, lpReplyList ); LeaveCriticalSection( &This->unk->DP_lock ); - if( lpReplyList != NULL ) + if( lpReplyList == NULL ) { - lpReplyList->replyExpected.dwMsgBodySize = dwMsgBodySize; - lpReplyList->replyExpected.lpReplyMsg = HeapAlloc( GetProcessHeap(), - HEAP_ZERO_MEMORY, - dwMsgBodySize ); - CopyMemory( lpReplyList->replyExpected.lpReplyMsg, - lpcMsgBody, dwMsgBodySize ); - - /* Signal the thread which sent the message that it has a reply */ - SetEvent( lpReplyList->replyExpected.hReceipt ); + TRACE( "No receipt event set for cmd 0x%x\n", wCommandId ); + return FALSE; } - else - { - ERR( "No receipt event set for cmd 0x%x, only expecting in reply mode\n", - wCommandId ); - }; + + lpReplyList->replyExpected.dwMsgBodySize = dwMsgBodySize; + /* TODO: Can we avoid theese allocations? */ + lpReplyList->replyExpected.lpReplyHdr = HeapAlloc( GetProcessHeap(), + HEAP_ZERO_MEMORY, + This->dp2->spData.dwSPHeaderSize ); + lpReplyList->replyExpected.lpReplyMsg = HeapAlloc( GetProcessHeap(), + HEAP_ZERO_MEMORY, + dwMsgBodySize ); + CopyMemory( lpReplyList->replyExpected.lpReplyHdr, + lpcMsgHdr, This->dp2->spData.dwSPHeaderSize ); + CopyMemory( lpReplyList->replyExpected.lpReplyMsg, + lpcMsgBody, dwMsgBodySize ); + + /* Signal the thread which sent the message that it has a reply */ + SetEvent( lpReplyList->replyExpected.hReceipt ); + + return TRUE; } DWORD DP_CopyString( LPVOID destination, LPVOID source, BOOL bAnsi ) diff --git a/dlls/dplayx/dplayx_messages.h b/dlls/dplayx/dplayx_messages.h index 28e32a7c251..014c8074892 100644 --- a/dlls/dplayx/dplayx_messages.h +++ b/dlls/dplayx/dplayx_messages.h @@ -38,8 +38,9 @@ HRESULT DP_MSG_ForwardPlayerCreation( IDirectPlay2AImpl* This, DPID dpidServer ) void DP_MSG_ReplyToEnumPlayersRequest( IDirectPlay2Impl* lpDP, LPVOID* lplpReply, LPDWORD lpdwMsgSize ); -void DP_MSG_ReplyReceived( IDirectPlay2AImpl* This, WORD wCommandId, - LPCVOID lpMsgBody, DWORD dwMsgBodySize ); +BOOL DP_MSG_ReplyReceived( IDirectPlay2AImpl* This, WORD wCommandId, + LPCVOID lpMsgHdr, LPCVOID lpMsgBody, + DWORD dwMsgBodySize ); void DP_MSG_ErrorReceived( IDirectPlay2AImpl* This, WORD wCommandId, LPCVOID lpMsgBody, DWORD dwMsgBodySize ); -- 2.11.4.GIT