diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c index e90b5ca..5fa9448 100644 --- a/dlls/dplayx/dplay.c +++ b/dlls/dplayx/dplay.c @@ -1612,6 +1612,11 @@ static HRESULT WINAPI DirectPlay2AImpl_CreatePlayer { IDirectPlay2Impl *This = (IDirectPlay2Impl *)iface; + if( lpidPlayer == NULL ) + { + return DPERR_INVALIDPARAMS; + } + if( dwFlags & DPPLAYER_SERVERPLAYER ) { *lpidPlayer = DPID_SERVERPLAYER; @@ -1631,6 +1636,11 @@ static HRESULT WINAPI DirectPlay2WImpl_CreatePlayer { IDirectPlay2Impl *This = (IDirectPlay2Impl *)iface; + if( lpidPlayer == NULL ) + { + return DPERR_INVALIDPARAMS; + } + if( dwFlags & DPPLAYER_SERVERPLAYER ) { *lpidPlayer = DPID_SERVERPLAYER; diff --git a/dlls/dplayx/tests/dplayx.c b/dlls/dplayx/tests/dplayx.c index 3f69569..8447bbd 100644 --- a/dlls/dplayx/tests/dplayx.c +++ b/dlls/dplayx/tests/dplayx.c @@ -1759,6 +1759,173 @@ static void test_SessionDesc() } +/* CreatePlayer */ + +static void test_CreatePlayer() +{ + + LPDIRECTPLAY4 pDP[2]; + DPSESSIONDESC2 dpsd; + DPNAME name; + DPID dpid; + HRESULT hr; + + + CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL, + &IID_IDirectPlay4A, (LPVOID*) &pDP[0] ); + CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL, + &IID_IDirectPlay4A, (LPVOID*) &pDP[1] ); + ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) ); + ZeroMemory( &name, sizeof(DPNAME) ); + + + /* Connection not initialized */ + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 ); + checkHR( DPERR_UNINITIALIZED, hr ); + + + init_TCPIP_provider( pDP[0], "127.0.0.1", 0 ); + init_TCPIP_provider( pDP[1], "127.0.0.1", 0 ); + + + /* Session not open */ + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 ); + todo_wine checkHR( DPERR_INVALIDPARAMS, hr ); + + if ( hr == DPERR_UNINITIALIZED ) + { + skip( "CreatePlayer not implemented\n" ); + return; + } + + dpsd.dwSize = sizeof(DPSESSIONDESC2); + dpsd.guidApplication = appGuid; + IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE ); + + + /* Player name */ + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 ); + checkHR( DP_OK, hr ); + + + name.dwSize = -1; + + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, &name, NULL, NULL, 0, 0 ); + checkHR( DP_OK, hr ); + + + name.dwSize = sizeof(DPNAME); + name.lpszShortNameA = (LPSTR) "test"; + name.lpszLongNameA = NULL; + + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, &name, NULL, NULL, + 0, 0 ); + checkHR( DP_OK, hr ); + + + /* Null dpid */ + hr = IDirectPlayX_CreatePlayer( pDP[0], NULL, NULL, NULL, NULL, + 0, 0 ); + checkHR( DPERR_INVALIDPARAMS, hr ); + + + /* There can only be one server player */ + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DP_OK, hr ); + check( DPID_SERVERPLAYER, dpid ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DPERR_CANTCREATEPLAYER, hr ); + + IDirectPlayX_DestroyPlayer( pDP[0], dpid ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DP_OK, hr ); + check( DPID_SERVERPLAYER, dpid ); + IDirectPlayX_DestroyPlayer( pDP[0], dpid ); + + + /* Flags */ + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, 0 ); + checkHR( DP_OK, hr ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DP_OK, hr ); + check( DPID_SERVERPLAYER, dpid ); + IDirectPlayX_DestroyPlayer( pDP[0], dpid ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SPECTATOR ); + checkHR( DP_OK, hr ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, ( DPPLAYER_SERVERPLAYER | + DPPLAYER_SPECTATOR ) ); + checkHR( DP_OK, hr ); + check( DPID_SERVERPLAYER, dpid ); + IDirectPlayX_DestroyPlayer( pDP[0], dpid ); + + + /* Session with DPSESSION_NEWPLAYERSDISABLED */ + IDirectPlayX_Close( pDP[0] ); + dpsd.dwFlags = DPSESSION_NEWPLAYERSDISABLED; + hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE ); + checkHR( DP_OK, hr ); + + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, 0 ); + checkHR( DPERR_CANTCREATEPLAYER, hr ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DPERR_CANTCREATEPLAYER, hr ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SPECTATOR ); + checkHR( DPERR_CANTCREATEPLAYER, hr ); + + + /* Creating players in a Client/Server session */ + IDirectPlayX_Close( pDP[0] ); + dpsd.dwFlags = DPSESSION_CLIENTSERVER; + hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE ); + checkHR( DP_OK, hr ); + hr = IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join, + (LPVOID) pDP[1], 0 ); + checkHR( DP_OK, hr ); + + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, 0 ); + checkHR( DPERR_ACCESSDENIED, hr ); + + hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DP_OK, hr ); + check( DPID_SERVERPLAYER, dpid ); + + hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid, NULL, NULL, NULL, + 0, DPPLAYER_SERVERPLAYER ); + checkHR( DPERR_INVALIDFLAGS, hr ); + + hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid, NULL, NULL, NULL, + 0, 0 ); + checkHR( DP_OK, hr ); + + + IDirectPlayX_Release( pDP[0] ); + IDirectPlayX_Release( pDP[1] ); + +} + START_TEST(dplayx) { @@ -1773,5 +1940,7 @@ START_TEST(dplayx) test_EnumSessions(); test_SessionDesc(); + test_CreatePlayer(); + CoUninitialize(); }