From 2824febeb8db2f29cdf70227638c32e1916ff0c9 Mon Sep 17 00:00:00 2001 From: Ismael Barros Date: Mon, 11 Aug 2008 04:05:40 +0200 Subject: [PATCH] dplayx: Modified FP_IF_Receive to actually do something useful --- dlls/dplayx/dplay.c | 71 +++++++++++++++++++++++++++++++++------------- dlls/dplayx/dplay_global.h | 4 ++- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c index df37609685e..ef52b29826d 100644 --- a/dlls/dplayx/dplay.c +++ b/dlls/dplayx/dplay.c @@ -3138,37 +3138,42 @@ static HRESULT DP_IF_Receive return DPERR_UNINITIALIZED; } - if( dwFlags == 0 ) + if ( ( lpdwDataSize == NULL ) || + ( ( dwFlags & DPRECEIVE_FROMPLAYER ) && ( lpidFrom == NULL ) ) || + ( ( dwFlags & DPRECEIVE_TOPLAYER ) && ( lpidTo == NULL ) ) ) { - dwFlags = DPRECEIVE_ALL; + return DPERR_INVALIDPARAMS; } - /* If the lpData is NULL, we must be peeking the message */ - if( ( lpData == NULL ) && - !( dwFlags & DPRECEIVE_PEEK ) - ) + if( dwFlags == 0 ) { - return DPERR_INVALIDPARAMS; + dwFlags = DPRECEIVE_ALL; } if( dwFlags & DPRECEIVE_ALL ) { - lpMsg = This->dp2->receiveMsgs.lpQHFirst; - - if( !( dwFlags & DPRECEIVE_PEEK ) ) - { - FIXME( "Remove from queue\n" ); - } - } - else if( ( dwFlags & DPRECEIVE_TOPLAYER ) || - ( dwFlags & DPRECEIVE_FROMPLAYER ) - ) - { - FIXME( "Find matching message 0x%08x\n", dwFlags ); + lpMsg = DPQ_FIRST( This->dp2->receiveMsgs ); } else { - ERR( "Hmmm..dwFlags 0x%08x\n", dwFlags ); + if ( (lpMsg = DPQ_FIRST( This->dp2->receiveMsgs )) ) + { + do + { + if ( ( ( dwFlags & DPRECEIVE_FROMPLAYER ) && + ( dwFlags & DPRECEIVE_TOPLAYER ) && + ( lpMsg->idFrom == *lpidFrom ) && + ( lpMsg->idTo == *lpidTo ) ) || /* From & To */ + ( ( dwFlags & DPRECEIVE_FROMPLAYER ) && + ( lpMsg->idFrom == *lpidFrom ) ) || /* From */ + ( ( dwFlags & DPRECEIVE_TOPLAYER ) && + ( lpMsg->idTo == *lpidTo ) ) ) /* To */ + { + break; + } + } + while( (lpMsg = DPQ_NEXT( lpMsg->msgs )) ); + } } if( lpMsg == NULL ) @@ -3176,9 +3181,35 @@ static HRESULT DP_IF_Receive return DPERR_NOMESSAGES; } + /* Buffer size check */ + if ( ( lpData == NULL ) || + ( *lpdwDataSize < lpMsg->dwMsgSize ) ) + { + *lpdwDataSize = lpMsg->dwMsgSize; + return DPERR_BUFFERTOOSMALL; + } + /* Copy into the provided buffer */ if (lpData) CopyMemory( lpData, lpMsg->msg, *lpdwDataSize ); + /* Set players */ + if ( lpidFrom ) + { + *lpidFrom = lpMsg->idFrom; + } + if ( lpidTo ) + { + *lpidTo = lpMsg->idTo; + } + + /* Remove message from queue */ + if( !( dwFlags & DPRECEIVE_PEEK ) ) + { + HeapFree( GetProcessHeap(), 0, lpMsg->msg ); + DPQ_REMOVE( This->dp2->receiveMsgs, lpMsg, msgs ); + HeapFree( GetProcessHeap(), 0, lpMsg ); + } + return DP_OK; } diff --git a/dlls/dplayx/dplay_global.h b/dlls/dplayx/dplay_global.h index 9d3b0c57ca3..279520e778d 100644 --- a/dlls/dplayx/dplay_global.h +++ b/dlls/dplayx/dplay_global.h @@ -144,7 +144,9 @@ typedef struct GroupList* lpGroupList; struct DPMSG { DPQ_ENTRY( DPMSG ) msgs; - DPMSG_GENERIC* msg; + LPDPMSG_GENERIC msg; + DWORD dwMsgSize; + DPID idFrom, idTo; }; typedef struct DPMSG* LPDPMSG; -- 2.11.4.GIT