wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / dplayx / dplay.c
blob7a796735ce824375433150042e298f126303e6aa
1 /* Direct Play 2,3,4 Implementation
3 * Copyright 1998,1999,2000,2001 - Peter Hunnisett
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
22 #include <stdarg.h>
23 #include <string.h>
25 #define NONAMELESSUNION
27 #include "windef.h"
28 #include "winerror.h"
29 #include "winbase.h"
30 #include "winnt.h"
31 #include "winreg.h"
32 #include "winnls.h"
33 #include "wine/debug.h"
35 #include "dplayx_global.h"
36 #include "name_server.h"
37 #include "dplayx_queue.h"
38 #include "wine/dplaysp.h"
39 #include "dplay_global.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
43 /* FIXME: Should this be externed? */
44 extern HRESULT DPL_CreateCompoundAddress
45 ( LPCDPCOMPOUNDADDRESSELEMENT lpElements, DWORD dwElementCount,
46 LPVOID lpAddress, LPDWORD lpdwAddressSize, BOOL bAnsiInterface );
49 /* Local function prototypes */
50 static lpPlayerList DP_FindPlayer( IDirectPlayImpl *This, DPID dpid );
51 static BOOL DP_CopyDPNAMEStruct( LPDPNAME lpDst, const DPNAME *lpSrc, BOOL bAnsi );
52 static void DP_SetGroupData( lpGroupData lpGData, DWORD dwFlags,
53 LPVOID lpData, DWORD dwDataSize );
54 static void DP_DeleteDPNameStruct( LPDPNAME lpDPName );
55 static BOOL CALLBACK cbDeletePlayerFromAllGroups( DPID dpId,
56 DWORD dwPlayerType,
57 LPCDPNAME lpName,
58 DWORD dwFlags,
59 LPVOID lpContext );
60 static lpGroupData DP_FindAnyGroup( IDirectPlayImpl *This, DPID dpid );
62 /* Helper methods for player/group interfaces */
63 static HRESULT DP_SetSessionDesc( IDirectPlayImpl *This, const DPSESSIONDESC2 *lpSessDesc,
64 DWORD dwFlags, BOOL bInitial, BOOL bAnsi );
65 static HRESULT DP_SP_SendEx( IDirectPlayImpl *This, DWORD dwFlags, void *lpData, DWORD dwDataSize,
66 DWORD dwPriority, DWORD dwTimeout, void *lpContext, DWORD *lpdwMsgID );
67 static BOOL DP_BuildSPCompoundAddr( LPGUID lpcSpGuid, LPVOID* lplpAddrBuf,
68 LPDWORD lpdwBufSize );
70 static DPID DP_GetRemoteNextObjectId(void);
72 static DWORD DP_CalcSessionDescSize( LPCDPSESSIONDESC2 lpSessDesc, BOOL bAnsi );
73 static void DP_CopySessionDesc( LPDPSESSIONDESC2 destSessionDesc,
74 LPCDPSESSIONDESC2 srcSessDesc, BOOL bAnsi );
77 #define DPID_NOPARENT_GROUP 0 /* Magic number to indicate no parent of group */
78 #define DPID_SYSTEM_GROUP DPID_NOPARENT_GROUP /* If system group is supported
79 we don't have to change much */
80 #define DPID_NAME_SERVER 0x19a9d65b /* Don't ask me why */
82 /* Strip out dwFlag values which cannot be sent in the CREATEGROUP msg */
83 #define DPMSG_CREATEGROUP_DWFLAGS(x) ( (x) & DPGROUP_HIDDEN )
85 /* Strip out all dwFlags values for CREATEPLAYER msg */
86 #define DPMSG_CREATEPLAYER_DWFLAGS(x) 0
88 static LONG kludgePlayerGroupId = 1000;
91 static inline IDirectPlayImpl *impl_from_IDirectPlay( IDirectPlay *iface )
93 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay_iface );
96 static inline IDirectPlayImpl *impl_from_IDirectPlay2( IDirectPlay2 *iface )
98 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay2_iface );
101 static inline IDirectPlayImpl *impl_from_IDirectPlay2A( IDirectPlay2A *iface )
103 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay2A_iface );
106 static inline IDirectPlayImpl *impl_from_IDirectPlay3A( IDirectPlay3A *iface )
108 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay3A_iface );
111 static inline IDirectPlayImpl *impl_from_IDirectPlay3( IDirectPlay3 *iface )
113 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay3_iface );
116 static inline IDirectPlayImpl *impl_from_IDirectPlay4A( IDirectPlay4A *iface )
118 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay4A_iface );
121 static inline IDirectPlayImpl *impl_from_IDirectPlay4( IDirectPlay4 *iface )
123 return CONTAINING_RECORD( iface, IDirectPlayImpl, IDirectPlay4_iface );
126 static BOOL DP_CreateDirectPlay2( LPVOID lpDP )
128 IDirectPlayImpl *This = lpDP;
130 This->dp2 = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->dp2) ) );
131 if ( This->dp2 == NULL )
133 return FALSE;
136 This->dp2->bConnectionOpen = FALSE;
138 This->dp2->hEnumSessionThread = INVALID_HANDLE_VALUE;
139 This->dp2->dwEnumSessionLock = 0;
141 This->dp2->bHostInterface = FALSE;
143 DPQ_INIT(This->dp2->receiveMsgs);
144 DPQ_INIT(This->dp2->sendMsgs);
145 DPQ_INIT(This->dp2->repliesExpected);
147 if( !NS_InitializeSessionCache( &This->dp2->lpNameServerData ) )
149 /* FIXME: Memory leak */
150 return FALSE;
153 /* Provide an initial session desc with nothing in it */
154 This->dp2->lpSessionDesc = HeapAlloc( GetProcessHeap(),
155 HEAP_ZERO_MEMORY,
156 sizeof( *This->dp2->lpSessionDesc ) );
157 if( This->dp2->lpSessionDesc == NULL )
159 /* FIXME: Memory leak */
160 return FALSE;
162 This->dp2->lpSessionDesc->dwSize = sizeof( *This->dp2->lpSessionDesc );
164 /* We are emulating a dp 6 implementation */
165 This->dp2->spData.dwSPVersion = DPSP_MAJORVERSION;
167 This->dp2->spData.lpCB = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
168 sizeof( *This->dp2->spData.lpCB ) );
169 This->dp2->spData.lpCB->dwSize = sizeof( *This->dp2->spData.lpCB );
170 This->dp2->spData.lpCB->dwVersion = DPSP_MAJORVERSION;
172 /* This is the pointer to the service provider */
173 if ( FAILED( dplaysp_create( &IID_IDirectPlaySP, (void**)&This->dp2->spData.lpISP, This ) ) )
175 /* FIXME: Memory leak */
176 return FALSE;
179 /* Setup lobby provider information */
180 This->dp2->dplspData.dwSPVersion = DPSP_MAJORVERSION;
181 This->dp2->dplspData.lpCB = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
182 sizeof( *This->dp2->dplspData.lpCB ) );
183 This->dp2->dplspData.lpCB->dwSize = sizeof( *This->dp2->dplspData.lpCB );
185 if( FAILED( dplobbysp_create( &IID_IDPLobbySP, (void**)&This->dp2->dplspData.lpISP, This ) )
188 /* FIXME: Memory leak */
189 return FALSE;
192 return TRUE;
195 /* Definition of the global function in dplayx_queue.h. #
196 * FIXME: Would it be better to have a dplayx_queue.c for this function? */
197 DPQ_DECL_DELETECB( cbDeleteElemFromHeap, LPVOID )
199 HeapFree( GetProcessHeap(), 0, elem );
202 static BOOL DP_DestroyDirectPlay2( LPVOID lpDP )
204 IDirectPlayImpl *This = lpDP;
206 if( This->dp2->hEnumSessionThread != INVALID_HANDLE_VALUE )
208 TerminateThread( This->dp2->hEnumSessionThread, 0 );
209 CloseHandle( This->dp2->hEnumSessionThread );
212 /* Finish with the SP - have it shutdown */
213 if( This->dp2->spData.lpCB->ShutdownEx )
215 DPSP_SHUTDOWNDATA data;
217 TRACE( "Calling SP ShutdownEx\n" );
219 data.lpISP = This->dp2->spData.lpISP;
221 (*This->dp2->spData.lpCB->ShutdownEx)( &data );
223 else if (This->dp2->spData.lpCB->Shutdown ) /* obsolete interface */
225 TRACE( "Calling obsolete SP Shutdown\n" );
226 (*This->dp2->spData.lpCB->Shutdown)();
229 /* Unload the SP (if it exists) */
230 if( This->dp2->hServiceProvider != 0 )
232 FreeLibrary( This->dp2->hServiceProvider );
235 /* Unload the Lobby Provider (if it exists) */
236 if( This->dp2->hDPLobbyProvider != 0 )
238 FreeLibrary( This->dp2->hDPLobbyProvider );
241 /* FIXME: Need to delete receive and send msgs queue contents */
243 NS_DeleteSessionCache( This->dp2->lpNameServerData );
245 HeapFree( GetProcessHeap(), 0, This->dp2->dplspData.lpCB);
246 HeapFree( GetProcessHeap(), 0, This->dp2->lpSessionDesc );
248 IDirectPlaySP_Release( This->dp2->spData.lpISP );
250 /* Delete the contents */
251 HeapFree( GetProcessHeap(), 0, This->dp2 );
253 return TRUE;
256 static void dplay_destroy(IDirectPlayImpl *obj)
258 DP_DestroyDirectPlay2( obj );
259 obj->lock.DebugInfo->Spare[0] = 0;
260 DeleteCriticalSection( &obj->lock );
261 HeapFree( GetProcessHeap(), 0, obj );
264 static inline DPID DP_NextObjectId(void)
266 return (DPID)InterlockedIncrement( &kludgePlayerGroupId );
269 /* *lplpReply will be non NULL iff there is something to reply */
270 HRESULT DP_HandleMessage( IDirectPlayImpl *This, const void *lpcMessageBody,
271 DWORD dwMessageBodySize, const void *lpcMessageHeader, WORD wCommandId, WORD wVersion,
272 void **lplpReply, DWORD *lpdwMsgSize )
274 TRACE( "(%p)->(%p,0x%08x,%p,%u,%u)\n",
275 This, lpcMessageBody, dwMessageBodySize, lpcMessageHeader, wCommandId,
276 wVersion );
278 switch( wCommandId )
280 /* Name server needs to handle this request */
281 case DPMSGCMD_ENUMSESSIONSREQUEST:
282 /* Reply expected */
283 NS_ReplyToEnumSessionsRequest( lpcMessageBody, lplpReply, lpdwMsgSize, This );
284 break;
286 /* Name server needs to handle this request */
287 case DPMSGCMD_ENUMSESSIONSREPLY:
288 /* No reply expected */
289 NS_AddRemoteComputerAsNameServer( lpcMessageHeader,
290 This->dp2->spData.dwSPHeaderSize,
291 lpcMessageBody,
292 This->dp2->lpNameServerData );
293 break;
295 case DPMSGCMD_REQUESTNEWPLAYERID:
297 LPCDPMSG_REQUESTNEWPLAYERID lpcMsg = lpcMessageBody;
299 LPDPMSG_NEWPLAYERIDREPLY lpReply;
301 *lpdwMsgSize = This->dp2->spData.dwSPHeaderSize + sizeof( *lpReply );
303 *lplpReply = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, *lpdwMsgSize );
305 FIXME( "Ignoring dwFlags 0x%08x in request msg\n",
306 lpcMsg->dwFlags );
308 /* Setup the reply */
309 lpReply = (LPDPMSG_NEWPLAYERIDREPLY)( (BYTE*)(*lplpReply) +
310 This->dp2->spData.dwSPHeaderSize );
312 lpReply->envelope.dwMagic = DPMSGMAGIC_DPLAYMSG;
313 lpReply->envelope.wCommandId = DPMSGCMD_NEWPLAYERIDREPLY;
314 lpReply->envelope.wVersion = DPMSGVER_DP6;
316 lpReply->dpidNewPlayerId = DP_NextObjectId();
318 TRACE( "Allocating new playerid 0x%08x from remote request\n",
319 lpReply->dpidNewPlayerId );
320 break;
323 case DPMSGCMD_GETNAMETABLEREPLY:
324 case DPMSGCMD_NEWPLAYERIDREPLY:
325 DP_MSG_ReplyReceived( This, wCommandId, lpcMessageBody, dwMessageBodySize );
326 break;
328 case DPMSGCMD_JUSTENVELOPE:
329 TRACE( "GOT THE SELF MESSAGE: %p -> 0x%08x\n", lpcMessageHeader, ((const DWORD *)lpcMessageHeader)[1] );
330 NS_SetLocalAddr( This->dp2->lpNameServerData, lpcMessageHeader, 20 );
331 DP_MSG_ReplyReceived( This, wCommandId, lpcMessageBody, dwMessageBodySize );
333 case DPMSGCMD_FORWARDADDPLAYER:
334 TRACE( "Sending message to self to get my addr\n" );
335 DP_MSG_ToSelf( This, 1 ); /* This is a hack right now */
336 break;
338 case DPMSGCMD_FORWARDADDPLAYERNACK:
339 DP_MSG_ErrorReceived( This, wCommandId, lpcMessageBody, dwMessageBodySize );
340 break;
342 default:
343 FIXME( "Unknown wCommandId %u. Ignoring message\n", wCommandId );
344 DebugBreak();
345 break;
348 /* FIXME: There is code in dplaysp.c to handle dplay commands. Move to here. */
350 return DP_OK;
354 static HRESULT WINAPI IDirectPlayImpl_QueryInterface( IDirectPlay *iface, REFIID riid, void **ppv )
356 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
357 return IDirectPlayX_QueryInterface( &This->IDirectPlay4_iface, riid, ppv );
360 static ULONG WINAPI IDirectPlayImpl_AddRef( IDirectPlay *iface )
362 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
363 ULONG ref = InterlockedIncrement( &This->ref );
365 TRACE( "(%p) ref=%d\n", This, ref );
367 if ( ref == 1 )
368 InterlockedIncrement( &This->numIfaces );
370 return ref;
373 static ULONG WINAPI IDirectPlayImpl_Release( IDirectPlay *iface )
375 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
376 ULONG ref = InterlockedDecrement( &This->ref );
378 TRACE( "(%p) ref=%d\n", This, ref );
380 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
381 dplay_destroy( This );
383 return ref;
386 static HRESULT WINAPI IDirectPlayImpl_AddPlayerToGroup( IDirectPlay *iface, DPID group,
387 DPID player )
389 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
390 FIXME( "(%p)->(0x%08x,0x%08x): stub\n", This, group, player );
391 return E_NOTIMPL;
394 static HRESULT WINAPI IDirectPlayImpl_Close( IDirectPlay *iface )
396 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
397 FIXME( "(%p): stub\n", This );
398 return E_NOTIMPL;
401 static HRESULT WINAPI IDirectPlayImpl_CreatePlayer( IDirectPlay *iface, DPID *player,
402 LPSTR name, LPSTR fullname, HANDLE *event )
404 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
405 FIXME( "(%p)->(%p,%s,%s,%p): stub\n", This, player, debugstr_a( name ), debugstr_a( fullname ),
406 event );
407 return E_NOTIMPL;
410 static HRESULT WINAPI IDirectPlayImpl_CreateGroup( IDirectPlay *iface, DPID *group, LPSTR name,
411 LPSTR fullname )
413 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
414 FIXME( "(%p)->(%p,%s,%s): stub\n", This, group, debugstr_a( name ), debugstr_a( fullname ) );
415 return E_NOTIMPL;
418 static HRESULT WINAPI IDirectPlayImpl_DeletePlayerFromGroup( IDirectPlay *iface, DPID group,
419 DPID player )
421 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
422 FIXME( "(%p)->(0x%08x,0x%08x): stub\n", This, group, player );
423 return E_NOTIMPL;
426 static HRESULT WINAPI IDirectPlayImpl_DestroyPlayer( IDirectPlay *iface, DPID player )
428 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
429 FIXME( "(%p)->(0x%08x): stub\n", This, player );
430 return E_NOTIMPL;
433 static HRESULT WINAPI IDirectPlayImpl_DestroyGroup( IDirectPlay *iface, DPID group )
435 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
436 FIXME( "(%p)->(0x%08x): stub\n", This, group );
437 return E_NOTIMPL;
440 static HRESULT WINAPI IDirectPlayImpl_EnableNewPlayers( IDirectPlay *iface, BOOL enable )
442 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
443 FIXME( "(%p)->(%d): stub\n", This, enable );
444 return E_NOTIMPL;
447 static HRESULT WINAPI IDirectPlayImpl_EnumGroupPlayers( IDirectPlay *iface, DPID group,
448 LPDPENUMPLAYERSCALLBACK enumplayercb, void *context, DWORD flags )
450 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
451 FIXME( "(%p)->(0x%08x,%p,%p,0x%08x): stub\n", This, group, enumplayercb, context, flags );
452 return E_NOTIMPL;
455 static HRESULT WINAPI IDirectPlayImpl_EnumGroups( IDirectPlay *iface, DWORD session,
456 LPDPENUMPLAYERSCALLBACK enumplayercb, void *context, DWORD flags )
458 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
459 FIXME( "(%p)->(0x%08x,%p,%p,0x%08x): stub\n", This, session, enumplayercb, context, flags );
460 return E_NOTIMPL;
463 static HRESULT WINAPI IDirectPlayImpl_EnumPlayers( IDirectPlay *iface, DWORD session,
464 LPDPENUMPLAYERSCALLBACK enumplayercb, void *context, DWORD flags )
466 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
467 FIXME( "(%p)->(0x%08x,%p,%p,0x%08x): stub\n", This, session, enumplayercb, context, flags );
468 return E_NOTIMPL;
471 static HRESULT WINAPI IDirectPlayImpl_EnumSessions( IDirectPlay *iface, DPSESSIONDESC *sdesc,
472 DWORD timeout, LPDPENUMSESSIONSCALLBACK enumsessioncb, void *context, DWORD flags )
474 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
475 FIXME( "(%p)->(%p,%u,%p,%p,0x%08x): stub\n", This, sdesc, timeout, enumsessioncb, context,
476 flags );
477 return E_NOTIMPL;
480 static HRESULT WINAPI IDirectPlayImpl_GetCaps( IDirectPlay *iface, DPCAPS *caps )
482 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
483 FIXME( "(%p)->(%p): stub\n", This, caps );
484 return E_NOTIMPL;
487 static HRESULT WINAPI IDirectPlayImpl_GetMessageCount( IDirectPlay *iface, DPID player,
488 DWORD *count )
490 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
491 FIXME( "(%p)->(0x%08x,%p): stub\n", This, player, count );
492 return E_NOTIMPL;
495 static HRESULT WINAPI IDirectPlayImpl_GetPlayerCaps( IDirectPlay *iface, DPID player, DPCAPS *caps )
497 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
498 FIXME( "(%p)->(0x%08x,%p): stub\n", This, player, caps );
499 return E_NOTIMPL;
502 static HRESULT WINAPI IDirectPlayImpl_GetPlayerName( IDirectPlay *iface, DPID player, LPSTR name,
503 DWORD *size_name, LPSTR fullname, DWORD *size_fullname )
505 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
506 FIXME( "(%p)->(0x%08x,%p,%p,%p,%p): stub\n", This, player, name, size_name, fullname,
507 size_fullname );
508 return E_NOTIMPL;
511 static HRESULT WINAPI IDirectPlayImpl_Initialize( IDirectPlay *iface, GUID *guid )
513 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
514 FIXME( "(%p)->(%p): stub\n", This, guid );
515 return E_NOTIMPL;
518 static HRESULT WINAPI IDirectPlayImpl_Open( IDirectPlay *iface, DPSESSIONDESC *sdesc )
520 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
521 FIXME( "(%p)->(%p): stub\n", This, sdesc );
522 return E_NOTIMPL;
525 static HRESULT WINAPI IDirectPlayImpl_Receive( IDirectPlay *iface, DPID *from, DPID *to,
526 DWORD flags, void *data, DWORD *size )
528 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
529 FIXME( "(%p)->(%p,%p,0x%08x,%p,%p): stub\n", This, from, to, flags, data, size );
530 return E_NOTIMPL;
533 static HRESULT WINAPI IDirectPlayImpl_SaveSession( IDirectPlay *iface, LPSTR reserved )
535 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
536 FIXME( "(%p)->(%p): stub\n", This, reserved );
537 return E_NOTIMPL;
540 static HRESULT WINAPI IDirectPlayImpl_Send( IDirectPlay *iface, DPID from, DPID to, DWORD flags,
541 void *data, DWORD size )
543 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
544 FIXME( "(%p)->(0x%08x,0x%08x,0x%08x,%p,%u): stub\n", This, from, to, flags, data, size );
545 return E_NOTIMPL;
548 static HRESULT WINAPI IDirectPlayImpl_SetPlayerName( IDirectPlay *iface, DPID player, LPSTR name,
549 LPSTR fullname )
551 IDirectPlayImpl *This = impl_from_IDirectPlay( iface );
552 FIXME( "(%p)->(0x%08x,%s,%s): stub\n", This, player, debugstr_a( name ),
553 debugstr_a ( fullname ) );
554 return E_NOTIMPL;
557 static const IDirectPlayVtbl dp_vt =
559 IDirectPlayImpl_QueryInterface,
560 IDirectPlayImpl_AddRef,
561 IDirectPlayImpl_Release,
562 IDirectPlayImpl_AddPlayerToGroup,
563 IDirectPlayImpl_Close,
564 IDirectPlayImpl_CreatePlayer,
565 IDirectPlayImpl_CreateGroup,
566 IDirectPlayImpl_DeletePlayerFromGroup,
567 IDirectPlayImpl_DestroyPlayer,
568 IDirectPlayImpl_DestroyGroup,
569 IDirectPlayImpl_EnableNewPlayers,
570 IDirectPlayImpl_EnumGroupPlayers,
571 IDirectPlayImpl_EnumGroups,
572 IDirectPlayImpl_EnumPlayers,
573 IDirectPlayImpl_EnumSessions,
574 IDirectPlayImpl_GetCaps,
575 IDirectPlayImpl_GetMessageCount,
576 IDirectPlayImpl_GetPlayerCaps,
577 IDirectPlayImpl_GetPlayerName,
578 IDirectPlayImpl_Initialize,
579 IDirectPlayImpl_Open,
580 IDirectPlayImpl_Receive,
581 IDirectPlayImpl_SaveSession,
582 IDirectPlayImpl_Send,
583 IDirectPlayImpl_SetPlayerName,
587 static HRESULT WINAPI IDirectPlay2AImpl_QueryInterface( IDirectPlay2A *iface, REFIID riid,
588 void **ppv )
590 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
591 return IDirectPlayX_QueryInterface( &This->IDirectPlay4_iface, riid, ppv );
594 static HRESULT WINAPI IDirectPlay2Impl_QueryInterface( IDirectPlay2 *iface, REFIID riid,
595 void **ppv )
597 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
598 return IDirectPlayX_QueryInterface( &This->IDirectPlay4_iface, riid, ppv );
601 static HRESULT WINAPI IDirectPlay3AImpl_QueryInterface( IDirectPlay3A *iface, REFIID riid,
602 void **ppv )
604 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
605 return IDirectPlayX_QueryInterface( &This->IDirectPlay4_iface, riid, ppv );
608 static HRESULT WINAPI IDirectPlay3Impl_QueryInterface( IDirectPlay3 *iface, REFIID riid,
609 void **ppv )
611 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
612 return IDirectPlayX_QueryInterface( &This->IDirectPlay4_iface, riid, ppv );
615 static HRESULT WINAPI IDirectPlay4AImpl_QueryInterface( IDirectPlay4A *iface, REFIID riid,
616 void **ppv )
618 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
619 return IDirectPlayX_QueryInterface( &This->IDirectPlay4_iface, riid, ppv );
622 static HRESULT WINAPI IDirectPlay4Impl_QueryInterface( IDirectPlay4 *iface, REFIID riid,
623 void **ppv )
625 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
627 if ( IsEqualGUID( &IID_IUnknown, riid ) )
629 TRACE( "(%p)->(IID_IUnknown %p)\n", This, ppv );
630 *ppv = &This->IDirectPlay_iface;
632 else if ( IsEqualGUID( &IID_IDirectPlay, riid ) )
634 TRACE( "(%p)->(IID_IDirectPlay %p)\n", This, ppv );
635 *ppv = &This->IDirectPlay_iface;
637 else if ( IsEqualGUID( &IID_IDirectPlay2A, riid ) )
639 TRACE( "(%p)->(IID_IDirectPlay2A %p)\n", This, ppv );
640 *ppv = &This->IDirectPlay2A_iface;
642 else if ( IsEqualGUID( &IID_IDirectPlay2, riid ) )
644 TRACE( "(%p)->(IID_IDirectPlay2 %p)\n", This, ppv );
645 *ppv = &This->IDirectPlay2_iface;
647 else if ( IsEqualGUID( &IID_IDirectPlay3A, riid ) )
649 TRACE( "(%p)->(IID_IDirectPlay3A %p)\n", This, ppv );
650 *ppv = &This->IDirectPlay3A_iface;
652 else if ( IsEqualGUID( &IID_IDirectPlay3, riid ) )
654 TRACE( "(%p)->(IID_IDirectPlay3 %p)\n", This, ppv );
655 *ppv = &This->IDirectPlay3_iface;
657 else if ( IsEqualGUID( &IID_IDirectPlay4A, riid ) )
659 TRACE( "(%p)->(IID_IDirectPlay4A %p)\n", This, ppv );
660 *ppv = &This->IDirectPlay4A_iface;
662 else if ( IsEqualGUID( &IID_IDirectPlay4, riid ) )
664 TRACE( "(%p)->(IID_IDirectPlay4 %p)\n", This, ppv );
665 *ppv = &This->IDirectPlay4_iface;
667 else
669 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
670 *ppv = NULL;
671 return E_NOINTERFACE;
674 IUnknown_AddRef((IUnknown*)*ppv);
675 return S_OK;
678 static ULONG WINAPI IDirectPlay2AImpl_AddRef( IDirectPlay2A *iface )
680 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
681 ULONG ref = InterlockedIncrement( &This->ref2A );
683 TRACE( "(%p) ref2A=%d\n", This, ref );
685 if ( ref == 1 )
686 InterlockedIncrement( &This->numIfaces );
688 return ref;
691 static ULONG WINAPI IDirectPlay2Impl_AddRef( IDirectPlay2 *iface )
693 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
694 ULONG ref = InterlockedIncrement( &This->ref2 );
696 TRACE( "(%p) ref2=%d\n", This, ref );
698 if ( ref == 1 )
699 InterlockedIncrement( &This->numIfaces );
701 return ref;
704 static ULONG WINAPI IDirectPlay3AImpl_AddRef( IDirectPlay3A *iface )
706 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
707 ULONG ref = InterlockedIncrement( &This->ref3A );
709 TRACE( "(%p) ref3A=%d\n", This, ref );
711 if ( ref == 1 )
712 InterlockedIncrement( &This->numIfaces );
714 return ref;
717 static ULONG WINAPI IDirectPlay3Impl_AddRef( IDirectPlay3 *iface )
719 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
720 ULONG ref = InterlockedIncrement( &This->ref3 );
722 TRACE( "(%p) ref3=%d\n", This, ref );
724 if ( ref == 1 )
725 InterlockedIncrement( &This->numIfaces );
727 return ref;
730 static ULONG WINAPI IDirectPlay4AImpl_AddRef(IDirectPlay4A *iface)
732 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
733 ULONG ref = InterlockedIncrement( &This->ref4A );
735 TRACE( "(%p) ref4A=%d\n", This, ref );
737 if ( ref == 1 )
738 InterlockedIncrement( &This->numIfaces );
740 return ref;
743 static ULONG WINAPI IDirectPlay4Impl_AddRef(IDirectPlay4 *iface)
745 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
746 ULONG ref = InterlockedIncrement( &This->ref4 );
748 TRACE( "(%p) ref4=%d\n", This, ref );
750 if ( ref == 1 )
751 InterlockedIncrement( &This->numIfaces );
753 return ref;
756 static ULONG WINAPI IDirectPlay2AImpl_Release( IDirectPlay2A *iface )
758 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
759 ULONG ref = InterlockedDecrement( &This->ref2A );
761 TRACE( "(%p) ref2A=%d\n", This, ref );
763 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
764 dplay_destroy( This );
766 return ref;
769 static ULONG WINAPI IDirectPlay2Impl_Release( IDirectPlay2 *iface )
771 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
772 ULONG ref = InterlockedDecrement( &This->ref2 );
774 TRACE( "(%p) ref2=%d\n", This, ref );
776 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
777 dplay_destroy( This );
779 return ref;
782 static ULONG WINAPI IDirectPlay3AImpl_Release( IDirectPlay3A *iface )
784 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
785 ULONG ref = InterlockedDecrement( &This->ref3A );
787 TRACE( "(%p) ref3A=%d\n", This, ref );
789 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
790 dplay_destroy( This );
792 return ref;
795 static ULONG WINAPI IDirectPlay3Impl_Release( IDirectPlay3 *iface )
797 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
798 ULONG ref = InterlockedDecrement( &This->ref3 );
800 TRACE( "(%p) ref3=%d\n", This, ref );
802 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
803 dplay_destroy( This );
805 return ref;
808 static ULONG WINAPI IDirectPlay4AImpl_Release(IDirectPlay4A *iface)
810 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
811 ULONG ref = InterlockedDecrement( &This->ref4A );
813 TRACE( "(%p) ref4A=%d\n", This, ref );
815 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
816 dplay_destroy( This );
818 return ref;
821 static ULONG WINAPI IDirectPlay4Impl_Release(IDirectPlay4 *iface)
823 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
824 ULONG ref = InterlockedDecrement( &This->ref4 );
826 TRACE( "(%p) ref4=%d\n", This, ref );
828 if ( !ref && !InterlockedDecrement( &This->numIfaces ) )
829 dplay_destroy( This );
831 return ref;
834 static HRESULT WINAPI IDirectPlay2AImpl_AddPlayerToGroup( IDirectPlay2A *iface, DPID group,
835 DPID player )
837 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
838 return IDirectPlayX_AddPlayerToGroup( &This->IDirectPlay4A_iface, group, player );
841 static HRESULT WINAPI IDirectPlay2Impl_AddPlayerToGroup( IDirectPlay2 *iface, DPID group,
842 DPID player )
844 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
845 return IDirectPlayX_AddPlayerToGroup( &This->IDirectPlay4_iface, group, player );
848 static HRESULT WINAPI IDirectPlay3AImpl_AddPlayerToGroup( IDirectPlay3A *iface, DPID group,
849 DPID player )
851 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
852 return IDirectPlayX_AddPlayerToGroup( &This->IDirectPlay4_iface, group, player );
855 static HRESULT WINAPI IDirectPlay3Impl_AddPlayerToGroup( IDirectPlay3 *iface, DPID group,
856 DPID player )
858 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
859 return IDirectPlayX_AddPlayerToGroup( &This->IDirectPlay4_iface, group, player );
862 static HRESULT WINAPI IDirectPlay4AImpl_AddPlayerToGroup( IDirectPlay4A *iface, DPID group,
863 DPID player )
865 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
866 return IDirectPlayX_AddPlayerToGroup( &This->IDirectPlay4_iface, group, player );
869 static HRESULT WINAPI IDirectPlay4Impl_AddPlayerToGroup( IDirectPlay4 *iface, DPID group,
870 DPID player )
872 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
873 lpGroupData gdata;
874 lpPlayerList plist;
875 lpPlayerList newplist;
877 TRACE( "(%p)->(0x%08x,0x%08x)\n", This, group, player );
879 if ( This->dp2->connectionInitialized == NO_PROVIDER )
880 return DPERR_UNINITIALIZED;
882 /* Find the group */
883 if ( ( gdata = DP_FindAnyGroup( This, group ) ) == NULL )
884 return DPERR_INVALIDGROUP;
886 /* Find the player */
887 if ( ( plist = DP_FindPlayer( This, player ) ) == NULL )
888 return DPERR_INVALIDPLAYER;
890 /* Create a player list (ie "shortcut" ) */
891 newplist = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *newplist ) );
892 if ( !newplist )
893 return DPERR_CANTADDPLAYER;
895 /* Add the shortcut */
896 plist->lpPData->uRef++;
897 newplist->lpPData = plist->lpPData;
899 /* Add the player to the list of players for this group */
900 DPQ_INSERT(gdata->players, newplist, players);
902 /* Let the SP know that we've added a player to the group */
903 if ( This->dp2->spData.lpCB->AddPlayerToGroup )
905 DPSP_ADDPLAYERTOGROUPDATA data;
907 TRACE( "Calling SP AddPlayerToGroup\n" );
909 data.idPlayer = player;
910 data.idGroup = group;
911 data.lpISP = This->dp2->spData.lpISP;
913 (*This->dp2->spData.lpCB->AddPlayerToGroup)( &data );
916 /* Inform all other peers of the addition of player to the group. If there are
917 * no peers keep this event quiet.
918 * Also, if this event was the result of another machine sending it to us,
919 * don't bother rebroadcasting it.
921 if ( This->dp2->lpSessionDesc &&
922 ( This->dp2->lpSessionDesc->dwFlags & DPSESSION_MULTICASTSERVER ) )
924 DPMSG_ADDPLAYERTOGROUP msg;
925 msg.dwType = DPSYS_ADDPLAYERTOGROUP;
927 msg.dpIdGroup = group;
928 msg.dpIdPlayer = player;
930 /* FIXME: Correct to just use send effectively? */
931 /* FIXME: Should size include data w/ message or just message "header" */
932 /* FIXME: Check return code */
933 IDirectPlayX_SendEx( iface, DPID_SERVERPLAYER, DPID_ALLPLAYERS, 0, &msg, sizeof( msg ),
934 0, 0, NULL, NULL );
937 return DP_OK;
940 static HRESULT WINAPI IDirectPlay2AImpl_Close( IDirectPlay2A *iface )
942 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
943 return IDirectPlayX_Close( &This->IDirectPlay4A_iface );
946 static HRESULT WINAPI IDirectPlay2Impl_Close( IDirectPlay2 *iface )
948 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
949 return IDirectPlayX_Close( &This->IDirectPlay4_iface );
952 static HRESULT WINAPI IDirectPlay3AImpl_Close( IDirectPlay3A *iface )
954 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
955 return IDirectPlayX_Close( &This->IDirectPlay4_iface );
958 static HRESULT WINAPI IDirectPlay3Impl_Close( IDirectPlay3 *iface )
960 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
961 return IDirectPlayX_Close( &This->IDirectPlay4_iface );
964 static HRESULT WINAPI IDirectPlay4AImpl_Close( IDirectPlay4A *iface )
966 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
967 return IDirectPlayX_Close( &This->IDirectPlay4_iface);
970 static HRESULT WINAPI IDirectPlay4Impl_Close( IDirectPlay4 *iface )
972 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
973 HRESULT hr = DP_OK;
975 TRACE( "(%p)\n", This );
977 /* FIXME: Need to find a new host I assume (how?) */
978 /* FIXME: Need to destroy all local groups */
979 /* FIXME: Need to migrate all remotely visible players to the new host */
981 /* Invoke the SP callback to inform of session close */
982 if( This->dp2->spData.lpCB->CloseEx )
984 DPSP_CLOSEDATA data;
986 TRACE( "Calling SP CloseEx\n" );
987 data.lpISP = This->dp2->spData.lpISP;
988 hr = (*This->dp2->spData.lpCB->CloseEx)( &data );
990 else if ( This->dp2->spData.lpCB->Close ) /* Try obsolete version */
992 TRACE( "Calling SP Close (obsolete interface)\n" );
993 hr = (*This->dp2->spData.lpCB->Close)();
996 return hr;
999 static lpGroupData DP_CreateGroup( IDirectPlayImpl *This, const DPID *lpid, const DPNAME *lpName,
1000 DWORD dwFlags, DPID idParent, BOOL bAnsi )
1002 lpGroupData lpGData;
1004 /* Allocate the new space and add to end of high level group list */
1005 lpGData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpGData ) );
1007 if( lpGData == NULL )
1009 return NULL;
1012 DPQ_INIT(lpGData->groups);
1013 DPQ_INIT(lpGData->players);
1015 /* Set the desired player ID - no sanity checking to see if it exists */
1016 lpGData->dpid = *lpid;
1018 DP_CopyDPNAMEStruct( &lpGData->name, lpName, bAnsi );
1020 /* FIXME: Should we check that the parent exists? */
1021 lpGData->parent = idParent;
1023 /* FIXME: Should we validate the dwFlags? */
1024 lpGData->dwFlags = dwFlags;
1026 TRACE( "Created group id 0x%08x\n", *lpid );
1028 return lpGData;
1031 /* This method assumes that all links to it are already deleted */
1032 static void DP_DeleteGroup( IDirectPlayImpl *This, DPID dpid )
1034 lpGroupList lpGList;
1036 TRACE( "(%p)->(0x%08x)\n", This, dpid );
1038 DPQ_REMOVE_ENTRY( This->dp2->lpSysGroup->groups, groups, lpGData->dpid, ==, dpid, lpGList );
1040 if( lpGList == NULL )
1042 ERR( "DPID 0x%08x not found\n", dpid );
1043 return;
1046 if( --(lpGList->lpGData->uRef) )
1048 FIXME( "Why is this not the last reference to group?\n" );
1049 DebugBreak();
1052 /* Delete player */
1053 DP_DeleteDPNameStruct( &lpGList->lpGData->name );
1054 HeapFree( GetProcessHeap(), 0, lpGList->lpGData );
1056 /* Remove and Delete Player List object */
1057 HeapFree( GetProcessHeap(), 0, lpGList );
1061 static lpGroupData DP_FindAnyGroup( IDirectPlayImpl *This, DPID dpid )
1063 lpGroupList lpGroups;
1065 TRACE( "(%p)->(0x%08x)\n", This, dpid );
1067 if( dpid == DPID_SYSTEM_GROUP )
1069 return This->dp2->lpSysGroup;
1071 else
1073 DPQ_FIND_ENTRY( This->dp2->lpSysGroup->groups, groups, lpGData->dpid, ==, dpid, lpGroups );
1076 if( lpGroups == NULL )
1078 return NULL;
1081 return lpGroups->lpGData;
1084 static HRESULT DP_IF_CreateGroup( IDirectPlayImpl *This, void *lpMsgHdr, DPID *lpidGroup,
1085 DPNAME *lpGroupName, void *lpData, DWORD dwDataSize, DWORD dwFlags, BOOL bAnsi )
1087 lpGroupData lpGData;
1089 TRACE( "(%p)->(%p,%p,%p,%p,0x%08x,0x%08x,%u)\n",
1090 This, lpMsgHdr, lpidGroup, lpGroupName, lpData, dwDataSize,
1091 dwFlags, bAnsi );
1093 if( This->dp2->connectionInitialized == NO_PROVIDER )
1095 return DPERR_UNINITIALIZED;
1098 /* If the name is not specified, we must provide one */
1099 if( DPID_UNKNOWN == *lpidGroup )
1101 /* If we are the name server, we decide on the group ids. If not, we
1102 * must ask for one before attempting a creation.
1104 if( This->dp2->bHostInterface )
1106 *lpidGroup = DP_NextObjectId();
1108 else
1110 *lpidGroup = DP_GetRemoteNextObjectId();
1114 lpGData = DP_CreateGroup( This, lpidGroup, lpGroupName, dwFlags,
1115 DPID_NOPARENT_GROUP, bAnsi );
1117 if( lpGData == NULL )
1119 return DPERR_CANTADDPLAYER; /* yes player not group */
1122 if( DPID_SYSTEM_GROUP == *lpidGroup )
1124 This->dp2->lpSysGroup = lpGData;
1125 TRACE( "Inserting system group\n" );
1127 else
1129 /* Insert into the system group */
1130 lpGroupList lpGroup = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpGroup ) );
1131 lpGroup->lpGData = lpGData;
1133 DPQ_INSERT( This->dp2->lpSysGroup->groups, lpGroup, groups );
1136 /* Something is now referencing this data */
1137 lpGData->uRef++;
1139 /* Set all the important stuff for the group */
1140 DP_SetGroupData( lpGData, DPSET_REMOTE, lpData, dwDataSize );
1142 /* FIXME: We should only create the system group if GetCaps returns
1143 * DPCAPS_GROUPOPTIMIZED.
1146 /* Let the SP know that we've created this group */
1147 if( This->dp2->spData.lpCB->CreateGroup )
1149 DPSP_CREATEGROUPDATA data;
1150 DWORD dwCreateFlags = 0;
1152 TRACE( "Calling SP CreateGroup\n" );
1154 if( *lpidGroup == DPID_NOPARENT_GROUP )
1155 dwCreateFlags |= DPLAYI_GROUP_SYSGROUP;
1157 if( lpMsgHdr == NULL )
1158 dwCreateFlags |= DPLAYI_PLAYER_PLAYERLOCAL;
1160 if( dwFlags & DPGROUP_HIDDEN )
1161 dwCreateFlags |= DPLAYI_GROUP_HIDDEN;
1163 data.idGroup = *lpidGroup;
1164 data.dwFlags = dwCreateFlags;
1165 data.lpSPMessageHeader = lpMsgHdr;
1166 data.lpISP = This->dp2->spData.lpISP;
1168 (*This->dp2->spData.lpCB->CreateGroup)( &data );
1171 /* Inform all other peers of the creation of a new group. If there are
1172 * no peers keep this event quiet.
1173 * Also if this message was sent to us, don't rebroadcast.
1175 if( ( lpMsgHdr == NULL ) &&
1176 This->dp2->lpSessionDesc &&
1177 ( This->dp2->lpSessionDesc->dwFlags & DPSESSION_MULTICASTSERVER ) )
1179 DPMSG_CREATEPLAYERORGROUP msg;
1180 msg.dwType = DPSYS_CREATEPLAYERORGROUP;
1182 msg.dwPlayerType = DPPLAYERTYPE_GROUP;
1183 msg.dpId = *lpidGroup;
1184 msg.dwCurrentPlayers = 0; /* FIXME: Incorrect? */
1185 msg.lpData = lpData;
1186 msg.dwDataSize = dwDataSize;
1187 msg.dpnName = *lpGroupName;
1188 msg.dpIdParent = DPID_NOPARENT_GROUP;
1189 msg.dwFlags = DPMSG_CREATEGROUP_DWFLAGS( dwFlags );
1191 /* FIXME: Correct to just use send effectively? */
1192 /* FIXME: Should size include data w/ message or just message "header" */
1193 /* FIXME: Check return code */
1194 IDirectPlayX_SendEx( &This->IDirectPlay4_iface, DPID_SERVERPLAYER, DPID_ALLPLAYERS, 0, &msg,
1195 sizeof( msg ), 0, 0, NULL, NULL );
1198 return DP_OK;
1201 static HRESULT WINAPI IDirectPlay2AImpl_CreateGroup( IDirectPlay2A *iface, DPID *lpidGroup,
1202 DPNAME *name, void *data, DWORD size, DWORD flags )
1204 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
1205 return IDirectPlayX_CreateGroup( &This->IDirectPlay4A_iface, lpidGroup, name, data, size,
1206 flags );
1209 static HRESULT WINAPI IDirectPlay2Impl_CreateGroup( IDirectPlay2 *iface, DPID *lpidGroup,
1210 DPNAME *name, void *data, DWORD size, DWORD flags )
1212 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
1213 return IDirectPlayX_CreateGroup( &This->IDirectPlay4_iface, lpidGroup, name, data, size,
1214 flags );
1217 static HRESULT WINAPI IDirectPlay3AImpl_CreateGroup( IDirectPlay3A *iface, DPID *group,
1218 DPNAME *name, void *data, DWORD size, DWORD flags )
1220 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
1221 return IDirectPlayX_CreateGroup( &This->IDirectPlay4_iface, group, name, data, size,
1222 flags );
1225 static HRESULT WINAPI IDirectPlay3Impl_CreateGroup( IDirectPlay3 *iface, DPID *lpidGroup,
1226 DPNAME *name, void *data, DWORD size, DWORD flags )
1228 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
1229 return IDirectPlayX_CreateGroup( &This->IDirectPlay4_iface, lpidGroup, name, data, size,
1230 flags );
1233 static HRESULT WINAPI IDirectPlay4AImpl_CreateGroup( IDirectPlay4A *iface, DPID *lpidGroup,
1234 DPNAME *lpGroupName, void *lpData, DWORD dwDataSize, DWORD dwFlags )
1236 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
1238 *lpidGroup = DPID_UNKNOWN;
1240 return DP_IF_CreateGroup( This, NULL, lpidGroup, lpGroupName, lpData, dwDataSize, dwFlags,
1241 TRUE );
1244 static HRESULT WINAPI IDirectPlay4Impl_CreateGroup( IDirectPlay4 *iface, DPID *lpidGroup,
1245 DPNAME *lpGroupName, void *lpData, DWORD dwDataSize, DWORD dwFlags )
1247 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
1249 *lpidGroup = DPID_UNKNOWN;
1251 return DP_IF_CreateGroup( This, NULL, lpidGroup, lpGroupName, lpData, dwDataSize, dwFlags,
1252 FALSE );
1256 static void
1257 DP_SetGroupData( lpGroupData lpGData, DWORD dwFlags,
1258 LPVOID lpData, DWORD dwDataSize )
1260 /* Clear out the data with this player */
1261 if( dwFlags & DPSET_LOCAL )
1263 if ( lpGData->dwLocalDataSize != 0 )
1265 HeapFree( GetProcessHeap(), 0, lpGData->lpLocalData );
1266 lpGData->lpLocalData = NULL;
1267 lpGData->dwLocalDataSize = 0;
1270 else
1272 if( lpGData->dwRemoteDataSize != 0 )
1274 HeapFree( GetProcessHeap(), 0, lpGData->lpRemoteData );
1275 lpGData->lpRemoteData = NULL;
1276 lpGData->dwRemoteDataSize = 0;
1280 /* Reallocate for new data */
1281 if( lpData != NULL )
1283 if( dwFlags & DPSET_LOCAL )
1285 lpGData->lpLocalData = lpData;
1286 lpGData->dwLocalDataSize = dwDataSize;
1288 else
1290 lpGData->lpRemoteData = HeapAlloc( GetProcessHeap(), 0, dwDataSize );
1291 CopyMemory( lpGData->lpRemoteData, lpData, dwDataSize );
1292 lpGData->dwRemoteDataSize = dwDataSize;
1298 /* This function will just create the storage for the new player. */
1299 static lpPlayerData DP_CreatePlayer( IDirectPlayImpl *This, DPID *lpid, DPNAME *lpName,
1300 DWORD dwFlags, HANDLE hEvent, BOOL bAnsi )
1302 lpPlayerData lpPData;
1304 TRACE( "(%p)->(%p,%p,%u)\n", This, lpid, lpName, bAnsi );
1306 /* Allocate the storage for the player and associate it with list element */
1307 lpPData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpPData ) );
1308 if( lpPData == NULL )
1310 return NULL;
1313 /* Set the desired player ID */
1314 lpPData->dpid = *lpid;
1316 DP_CopyDPNAMEStruct( &lpPData->name, lpName, bAnsi );
1318 lpPData->dwFlags = dwFlags;
1320 /* If we were given an event handle, duplicate it */
1321 if( hEvent != 0 )
1323 if( !DuplicateHandle( GetCurrentProcess(), hEvent,
1324 GetCurrentProcess(), &lpPData->hEvent,
1325 0, FALSE, DUPLICATE_SAME_ACCESS )
1328 /* FIXME: Memory leak */
1329 ERR( "Can't duplicate player msg handle %p\n", hEvent );
1333 /* Initialize the SP data section */
1334 lpPData->lpSPPlayerData = DPSP_CreateSPPlayerData();
1336 TRACE( "Created player id 0x%08x\n", *lpid );
1338 if( ~dwFlags & DPLAYI_PLAYER_SYSPLAYER )
1339 This->dp2->lpSessionDesc->dwCurrentPlayers++;
1341 return lpPData;
1344 /* Delete the contents of the DPNAME struct */
1345 static void
1346 DP_DeleteDPNameStruct( LPDPNAME lpDPName )
1348 HeapFree( GetProcessHeap(), HEAP_ZERO_MEMORY, lpDPName->u1.lpszShortNameA );
1349 HeapFree( GetProcessHeap(), HEAP_ZERO_MEMORY, lpDPName->u2.lpszLongNameA );
1352 /* This method assumes that all links to it are already deleted */
1353 static void DP_DeletePlayer( IDirectPlayImpl *This, DPID dpid )
1355 lpPlayerList lpPList;
1357 TRACE( "(%p)->(0x%08x)\n", This, dpid );
1359 DPQ_REMOVE_ENTRY( This->dp2->lpSysGroup->players, players, lpPData->dpid, ==, dpid, lpPList );
1361 if( lpPList == NULL )
1363 ERR( "DPID 0x%08x not found\n", dpid );
1364 return;
1367 /* Verify that this is the last reference to the data */
1368 if( --(lpPList->lpPData->uRef) )
1370 FIXME( "Why is this not the last reference to player?\n" );
1371 DebugBreak();
1374 /* Delete player */
1375 DP_DeleteDPNameStruct( &lpPList->lpPData->name );
1377 CloseHandle( lpPList->lpPData->hEvent );
1378 HeapFree( GetProcessHeap(), 0, lpPList->lpPData );
1380 /* Delete Player List object */
1381 HeapFree( GetProcessHeap(), 0, lpPList );
1384 static lpPlayerList DP_FindPlayer( IDirectPlayImpl *This, DPID dpid )
1386 lpPlayerList lpPlayers;
1388 TRACE( "(%p)->(0x%08x)\n", This, dpid );
1390 if(This->dp2->lpSysGroup == NULL)
1391 return NULL;
1393 DPQ_FIND_ENTRY( This->dp2->lpSysGroup->players, players, lpPData->dpid, ==, dpid, lpPlayers );
1395 return lpPlayers;
1398 /* Basic area for Dst must already be allocated */
1399 static BOOL DP_CopyDPNAMEStruct( LPDPNAME lpDst, const DPNAME *lpSrc, BOOL bAnsi )
1401 if( lpSrc == NULL )
1403 ZeroMemory( lpDst, sizeof( *lpDst ) );
1404 lpDst->dwSize = sizeof( *lpDst );
1405 return TRUE;
1408 if( lpSrc->dwSize != sizeof( *lpSrc) )
1410 return FALSE;
1413 /* Delete any existing pointers */
1414 HeapFree( GetProcessHeap(), 0, lpDst->u1.lpszShortNameA );
1415 HeapFree( GetProcessHeap(), 0, lpDst->u2.lpszLongNameA );
1417 /* Copy as required */
1418 CopyMemory( lpDst, lpSrc, lpSrc->dwSize );
1420 if( bAnsi )
1422 if( lpSrc->u1.lpszShortNameA )
1424 lpDst->u1.lpszShortNameA = HeapAlloc( GetProcessHeap(), 0,
1425 strlen(lpSrc->u1.lpszShortNameA)+1 );
1426 strcpy( lpDst->u1.lpszShortNameA, lpSrc->u1.lpszShortNameA );
1428 if( lpSrc->u2.lpszLongNameA )
1430 lpDst->u2.lpszLongNameA = HeapAlloc( GetProcessHeap(), 0,
1431 strlen(lpSrc->u2.lpszLongNameA)+1 );
1432 strcpy( lpDst->u2.lpszLongNameA, lpSrc->u2.lpszLongNameA );
1435 else
1437 if( lpSrc->u1.lpszShortNameA )
1439 lpDst->u1.lpszShortName = HeapAlloc( GetProcessHeap(), 0,
1440 (lstrlenW(lpSrc->u1.lpszShortName)+1)*sizeof(WCHAR) );
1441 lstrcpyW( lpDst->u1.lpszShortName, lpSrc->u1.lpszShortName );
1443 if( lpSrc->u2.lpszLongNameA )
1445 lpDst->u2.lpszLongName = HeapAlloc( GetProcessHeap(), 0,
1446 (lstrlenW(lpSrc->u2.lpszLongName)+1)*sizeof(WCHAR) );
1447 lstrcpyW( lpDst->u2.lpszLongName, lpSrc->u2.lpszLongName );
1451 return TRUE;
1454 static void
1455 DP_SetPlayerData( lpPlayerData lpPData, DWORD dwFlags,
1456 LPVOID lpData, DWORD dwDataSize )
1458 /* Clear out the data with this player */
1459 if( dwFlags & DPSET_LOCAL )
1461 if ( lpPData->dwLocalDataSize != 0 )
1463 HeapFree( GetProcessHeap(), 0, lpPData->lpLocalData );
1464 lpPData->lpLocalData = NULL;
1465 lpPData->dwLocalDataSize = 0;
1468 else
1470 if( lpPData->dwRemoteDataSize != 0 )
1472 HeapFree( GetProcessHeap(), 0, lpPData->lpRemoteData );
1473 lpPData->lpRemoteData = NULL;
1474 lpPData->dwRemoteDataSize = 0;
1478 /* Reallocate for new data */
1479 if( lpData != NULL )
1482 if( dwFlags & DPSET_LOCAL )
1484 lpPData->lpLocalData = lpData;
1485 lpPData->dwLocalDataSize = dwDataSize;
1487 else
1489 lpPData->lpRemoteData = HeapAlloc( GetProcessHeap(), 0, dwDataSize );
1490 CopyMemory( lpPData->lpRemoteData, lpData, dwDataSize );
1491 lpPData->dwRemoteDataSize = dwDataSize;
1497 /* Note: lpMsgHdr is NULL for local creation, non NULL for remote creation */
1498 static HRESULT DP_IF_CreatePlayer( IDirectPlayImpl *This, void *lpMsgHdr, DPID *lpidPlayer,
1499 DPNAME *lpPlayerName, HANDLE hEvent, void *lpData, DWORD dwDataSize, DWORD dwFlags,
1500 BOOL bAnsi )
1502 HRESULT hr = DP_OK;
1503 lpPlayerData lpPData;
1504 lpPlayerList lpPList;
1505 DWORD dwCreateFlags = 0;
1507 TRACE( "(%p)->(%p,%p,%p,%p,0x%08x,0x%08x,%u)\n",
1508 This, lpidPlayer, lpPlayerName, hEvent, lpData,
1509 dwDataSize, dwFlags, bAnsi );
1510 if( This->dp2->connectionInitialized == NO_PROVIDER )
1512 return DPERR_UNINITIALIZED;
1515 if( dwFlags == 0 )
1517 dwFlags = DPPLAYER_SPECTATOR;
1520 if( lpidPlayer == NULL )
1522 return DPERR_INVALIDPARAMS;
1526 /* Determine the creation flags for the player. These will be passed
1527 * to the name server if requesting a player id and to the SP when
1528 * informing it of the player creation
1531 if( dwFlags & DPPLAYER_SERVERPLAYER )
1533 if( *lpidPlayer == DPID_SERVERPLAYER )
1535 /* Server player for the host interface */
1536 dwCreateFlags |= DPLAYI_PLAYER_APPSERVER;
1538 else if( *lpidPlayer == DPID_NAME_SERVER )
1540 /* Name server - master of everything */
1541 dwCreateFlags |= (DPLAYI_PLAYER_NAMESRVR|DPLAYI_PLAYER_SYSPLAYER);
1543 else
1545 /* Server player for a non host interface */
1546 dwCreateFlags |= DPLAYI_PLAYER_SYSPLAYER;
1550 if( lpMsgHdr == NULL )
1551 dwCreateFlags |= DPLAYI_PLAYER_PLAYERLOCAL;
1554 /* Verify we know how to handle all the flags */
1555 if( !( ( dwFlags & DPPLAYER_SERVERPLAYER ) ||
1556 ( dwFlags & DPPLAYER_SPECTATOR )
1560 /* Assume non fatal failure */
1561 ERR( "unknown dwFlags = 0x%08x\n", dwFlags );
1564 /* If the name is not specified, we must provide one */
1565 if( *lpidPlayer == DPID_UNKNOWN )
1567 /* If we are the session master, we dish out the group/player ids */
1568 if( This->dp2->bHostInterface )
1570 *lpidPlayer = DP_NextObjectId();
1572 else
1574 hr = DP_MSG_SendRequestPlayerId( This, dwCreateFlags, lpidPlayer );
1576 if( FAILED(hr) )
1578 ERR( "Request for ID failed: %s\n", DPLAYX_HresultToString( hr ) );
1579 return hr;
1583 else
1585 /* FIXME: Would be nice to perhaps verify that we don't already have
1586 * this player.
1590 /* We pass creation flags, so we can distinguish sysplayers and not count them in the current
1591 player total */
1592 lpPData = DP_CreatePlayer( This, lpidPlayer, lpPlayerName, dwCreateFlags,
1593 hEvent, bAnsi );
1594 /* Create the list object and link it in */
1595 lpPList = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpPList ) );
1596 if( !lpPData || !lpPList )
1598 HeapFree( GetProcessHeap(), 0, lpPData );
1599 HeapFree( GetProcessHeap(), 0, lpPList );
1600 return DPERR_CANTADDPLAYER;
1603 lpPData->uRef = 1;
1604 lpPList->lpPData = lpPData;
1606 /* Add the player to the system group */
1607 DPQ_INSERT( This->dp2->lpSysGroup->players, lpPList, players );
1609 /* Update the information and send it to all players in the session */
1610 DP_SetPlayerData( lpPData, DPSET_REMOTE, lpData, dwDataSize );
1612 /* Let the SP know that we've created this player */
1613 if( This->dp2->spData.lpCB->CreatePlayer )
1615 DPSP_CREATEPLAYERDATA data;
1617 data.idPlayer = *lpidPlayer;
1618 data.dwFlags = dwCreateFlags;
1619 data.lpSPMessageHeader = lpMsgHdr;
1620 data.lpISP = This->dp2->spData.lpISP;
1622 TRACE( "Calling SP CreatePlayer 0x%08x: dwFlags: 0x%08x lpMsgHdr: %p\n",
1623 *lpidPlayer, data.dwFlags, data.lpSPMessageHeader );
1625 hr = (*This->dp2->spData.lpCB->CreatePlayer)( &data );
1628 if( FAILED(hr) )
1630 ERR( "Failed to create player with sp: %s\n", DPLAYX_HresultToString(hr) );
1631 return hr;
1634 /* Now let the SP know that this player is a member of the system group */
1635 if( This->dp2->spData.lpCB->AddPlayerToGroup )
1637 DPSP_ADDPLAYERTOGROUPDATA data;
1639 data.idPlayer = *lpidPlayer;
1640 data.idGroup = DPID_SYSTEM_GROUP;
1641 data.lpISP = This->dp2->spData.lpISP;
1643 TRACE( "Calling SP AddPlayerToGroup (sys group)\n" );
1645 hr = (*This->dp2->spData.lpCB->AddPlayerToGroup)( &data );
1648 if( FAILED(hr) )
1650 ERR( "Failed to add player to sys group with sp: %s\n",
1651 DPLAYX_HresultToString(hr) );
1652 return hr;
1655 #if 1
1656 if( !This->dp2->bHostInterface )
1658 /* Let the name server know about the creation of this player */
1659 /* FIXME: Is this only to be done for the creation of a server player or
1660 * is this used for regular players? If only for server players, move
1661 * this call to DP_SecureOpen(...);
1663 #if 0
1664 TRACE( "Sending message to self to get my addr\n" );
1665 DP_MSG_ToSelf( This, *lpidPlayer ); /* This is a hack right now */
1666 #endif
1668 hr = DP_MSG_ForwardPlayerCreation( This, *lpidPlayer);
1670 #else
1671 /* Inform all other peers of the creation of a new player. If there are
1672 * no peers keep this quiet.
1673 * Also, if this was a remote event, no need to rebroadcast it.
1675 if( ( lpMsgHdr == NULL ) &&
1676 This->dp2->lpSessionDesc &&
1677 ( This->dp2->lpSessionDesc->dwFlags & DPSESSION_MULTICASTSERVER ) )
1679 DPMSG_CREATEPLAYERORGROUP msg;
1680 msg.dwType = DPSYS_CREATEPLAYERORGROUP;
1682 msg.dwPlayerType = DPPLAYERTYPE_PLAYER;
1683 msg.dpId = *lpidPlayer;
1684 msg.dwCurrentPlayers = 0; /* FIXME: Incorrect */
1685 msg.lpData = lpData;
1686 msg.dwDataSize = dwDataSize;
1687 msg.dpnName = *lpPlayerName;
1688 msg.dpIdParent = DPID_NOPARENT_GROUP;
1689 msg.dwFlags = DPMSG_CREATEPLAYER_DWFLAGS( dwFlags );
1691 /* FIXME: Correct to just use send effectively? */
1692 /* FIXME: Should size include data w/ message or just message "header" */
1693 /* FIXME: Check return code */
1694 hr = IDirectPlayX_SendEx( &This->IDirectPlay4_iface, DPID_SERVERPLAYER, DPID_ALLPLAYERS, 0,
1695 &msg, sizeof( msg ), 0, 0, NULL, NULL );
1697 #endif
1699 return hr;
1702 static HRESULT WINAPI IDirectPlay2AImpl_CreatePlayer( IDirectPlay2A *iface, DPID *lpidPlayer,
1703 DPNAME *name, HANDLE event, void *data, DWORD size, DWORD flags )
1705 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
1706 return IDirectPlayX_CreatePlayer( &This->IDirectPlay4A_iface, lpidPlayer, name, event, data,
1707 size, flags );
1710 static HRESULT WINAPI IDirectPlay2Impl_CreatePlayer( IDirectPlay2 *iface, DPID *lpidPlayer,
1711 DPNAME *name, HANDLE event, void *data, DWORD size, DWORD flags )
1713 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
1714 return IDirectPlayX_CreatePlayer( &This->IDirectPlay4_iface, lpidPlayer, name, event, data,
1715 size, flags );
1718 static HRESULT WINAPI IDirectPlay3AImpl_CreatePlayer( IDirectPlay3A *iface, DPID *lpidPlayer,
1719 DPNAME *name, HANDLE event, void *data, DWORD size, DWORD flags )
1721 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
1722 return IDirectPlayX_CreatePlayer( &This->IDirectPlay4_iface, lpidPlayer, name, event, data,
1723 size, flags );
1726 static HRESULT WINAPI IDirectPlay3Impl_CreatePlayer( IDirectPlay3 *iface, DPID *lpidPlayer,
1727 DPNAME *name, HANDLE event, void *data, DWORD size, DWORD flags )
1729 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
1730 return IDirectPlayX_CreatePlayer( &This->IDirectPlay4_iface, lpidPlayer, name, event, data,
1731 size, flags );
1734 static HRESULT WINAPI IDirectPlay4AImpl_CreatePlayer( IDirectPlay4A *iface, DPID *lpidPlayer,
1735 DPNAME *lpPlayerName, HANDLE hEvent, void *lpData, DWORD dwDataSize, DWORD dwFlags )
1737 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
1739 if( lpidPlayer == NULL )
1741 return DPERR_INVALIDPARAMS;
1744 if( dwFlags & DPPLAYER_SERVERPLAYER )
1746 *lpidPlayer = DPID_SERVERPLAYER;
1748 else
1750 *lpidPlayer = DPID_UNKNOWN;
1753 return DP_IF_CreatePlayer( This, NULL, lpidPlayer, lpPlayerName, hEvent,
1754 lpData, dwDataSize, dwFlags, TRUE );
1757 static HRESULT WINAPI IDirectPlay4Impl_CreatePlayer( IDirectPlay4 *iface, DPID *lpidPlayer,
1758 DPNAME *lpPlayerName, HANDLE hEvent, void *lpData, DWORD dwDataSize, DWORD dwFlags )
1760 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
1762 if( lpidPlayer == NULL )
1764 return DPERR_INVALIDPARAMS;
1767 if( dwFlags & DPPLAYER_SERVERPLAYER )
1769 *lpidPlayer = DPID_SERVERPLAYER;
1771 else
1773 *lpidPlayer = DPID_UNKNOWN;
1776 return DP_IF_CreatePlayer( This, NULL, lpidPlayer, lpPlayerName, hEvent,
1777 lpData, dwDataSize, dwFlags, FALSE );
1780 static DPID DP_GetRemoteNextObjectId(void)
1782 FIXME( ":stub\n" );
1784 /* Hack solution */
1785 return DP_NextObjectId();
1788 static HRESULT WINAPI IDirectPlay2AImpl_DeletePlayerFromGroup( IDirectPlay2A *iface, DPID group,
1789 DPID player )
1791 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
1792 return IDirectPlayX_DeletePlayerFromGroup( &This->IDirectPlay4A_iface, group, player );
1795 static HRESULT WINAPI IDirectPlay2Impl_DeletePlayerFromGroup( IDirectPlay2 *iface, DPID group,
1796 DPID player )
1798 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
1799 return IDirectPlayX_DeletePlayerFromGroup( &This->IDirectPlay4_iface, group, player );
1802 static HRESULT WINAPI IDirectPlay3AImpl_DeletePlayerFromGroup( IDirectPlay3A *iface, DPID group,
1803 DPID player )
1805 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
1806 return IDirectPlayX_DeletePlayerFromGroup( &This->IDirectPlay4_iface, group, player );
1809 static HRESULT WINAPI IDirectPlay3Impl_DeletePlayerFromGroup( IDirectPlay3 *iface, DPID group,
1810 DPID player )
1812 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
1813 return IDirectPlayX_DeletePlayerFromGroup( &This->IDirectPlay4_iface, group, player );
1816 static HRESULT WINAPI IDirectPlay4AImpl_DeletePlayerFromGroup( IDirectPlay4A *iface, DPID group,
1817 DPID player )
1819 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
1820 return IDirectPlayX_DeletePlayerFromGroup( &This->IDirectPlay4_iface, group, player );
1823 static HRESULT WINAPI IDirectPlay4Impl_DeletePlayerFromGroup( IDirectPlay4 *iface, DPID group,
1824 DPID player )
1826 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
1827 HRESULT hr = DP_OK;
1829 lpGroupData gdata;
1830 lpPlayerList plist;
1832 TRACE( "(%p)->(0x%08x,0x%08x)\n", This, group, player );
1834 /* Find the group */
1835 if ( ( gdata = DP_FindAnyGroup( This, group ) ) == NULL )
1836 return DPERR_INVALIDGROUP;
1838 /* Find the player */
1839 if ( DP_FindPlayer( This, player ) == NULL )
1840 return DPERR_INVALIDPLAYER;
1842 /* Remove the player shortcut from the group */
1843 DPQ_REMOVE_ENTRY( gdata->players, players, lpPData->dpid, ==, player, plist );
1845 if ( !plist )
1846 return DPERR_INVALIDPLAYER;
1848 /* One less reference */
1849 plist->lpPData->uRef--;
1851 /* Delete the Player List element */
1852 HeapFree( GetProcessHeap(), 0, plist );
1854 /* Inform the SP if they care */
1855 if ( This->dp2->spData.lpCB->RemovePlayerFromGroup )
1857 DPSP_REMOVEPLAYERFROMGROUPDATA data;
1859 TRACE( "Calling SP RemovePlayerFromGroup\n" );
1860 data.idPlayer = player;
1861 data.idGroup = group;
1862 data.lpISP = This->dp2->spData.lpISP;
1863 hr = (*This->dp2->spData.lpCB->RemovePlayerFromGroup)( &data );
1866 /* Need to send a DELETEPLAYERFROMGROUP message */
1867 FIXME( "Need to send a message\n" );
1869 return hr;
1872 typedef struct _DPRGOPContext
1874 IDirectPlayImpl *This;
1875 BOOL bAnsi;
1876 DPID idGroup;
1877 } DPRGOPContext, *lpDPRGOPContext;
1879 static BOOL CALLBACK
1880 cbRemoveGroupOrPlayer(
1881 DPID dpId,
1882 DWORD dwPlayerType,
1883 LPCDPNAME lpName,
1884 DWORD dwFlags,
1885 LPVOID lpContext )
1887 lpDPRGOPContext lpCtxt = (lpDPRGOPContext)lpContext;
1889 TRACE( "Removing element:0x%08x (type:0x%08x) from element:0x%08x\n",
1890 dpId, dwPlayerType, lpCtxt->idGroup );
1892 if( dwPlayerType == DPPLAYERTYPE_GROUP )
1894 if ( FAILED( IDirectPlayX_DeleteGroupFromGroup( &lpCtxt->This->IDirectPlay4_iface,
1895 lpCtxt->idGroup, dpId ) ) )
1896 ERR( "Unable to delete group 0x%08x from group 0x%08x\n", dpId, lpCtxt->idGroup );
1898 else if ( FAILED( IDirectPlayX_DeletePlayerFromGroup( &lpCtxt->This->IDirectPlay4_iface,
1899 lpCtxt->idGroup, dpId ) ) )
1900 ERR( "Unable to delete player 0x%08x from grp 0x%08x\n", dpId, lpCtxt->idGroup );
1902 return TRUE; /* Continue enumeration */
1905 static HRESULT DP_IF_DestroyGroup( IDirectPlayImpl *This, void *lpMsgHdr, DPID idGroup, BOOL bAnsi )
1907 lpGroupData lpGData;
1908 DPRGOPContext context;
1910 FIXME( "(%p)->(%p,0x%08x,%u): semi stub\n",
1911 This, lpMsgHdr, idGroup, bAnsi );
1913 /* Find the group */
1914 if( ( lpGData = DP_FindAnyGroup( This, idGroup ) ) == NULL )
1916 return DPERR_INVALIDPLAYER; /* yes player */
1919 context.This = This;
1920 context.bAnsi = bAnsi;
1921 context.idGroup = idGroup;
1923 /* Remove all players that this group has */
1924 IDirectPlayX_EnumGroupPlayers( &This->IDirectPlay4_iface, idGroup, NULL, cbRemoveGroupOrPlayer,
1925 &context, 0 );
1927 /* Remove all links to groups that this group has since this is dp3 */
1928 IDirectPlayX_EnumGroupsInGroup( &This->IDirectPlay4_iface, idGroup, NULL, cbRemoveGroupOrPlayer,
1929 (void*)&context, 0 );
1931 /* Remove this group from the parent group - if it has one */
1932 if( ( idGroup != DPID_SYSTEM_GROUP ) && ( lpGData->parent != DPID_SYSTEM_GROUP ) )
1933 IDirectPlayX_DeleteGroupFromGroup( &This->IDirectPlay4_iface, lpGData->parent, idGroup );
1935 /* Now delete this group data and list from the system group */
1936 DP_DeleteGroup( This, idGroup );
1938 /* Let the SP know that we've destroyed this group */
1939 if( This->dp2->spData.lpCB->DeleteGroup )
1941 DPSP_DELETEGROUPDATA data;
1943 FIXME( "data.dwFlags is incorrect\n" );
1945 data.idGroup = idGroup;
1946 data.dwFlags = 0;
1947 data.lpISP = This->dp2->spData.lpISP;
1949 (*This->dp2->spData.lpCB->DeleteGroup)( &data );
1952 FIXME( "Send out a DESTORYPLAYERORGROUP message\n" );
1954 return DP_OK;
1957 static HRESULT WINAPI IDirectPlay2AImpl_DestroyGroup( IDirectPlay2A *iface, DPID group )
1959 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
1960 return IDirectPlayX_DestroyGroup( &This->IDirectPlay4A_iface, group );
1963 static HRESULT WINAPI IDirectPlay2Impl_DestroyGroup( IDirectPlay2 *iface, DPID group )
1965 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
1966 return IDirectPlayX_DestroyGroup( &This->IDirectPlay4_iface, group );
1969 static HRESULT WINAPI IDirectPlay3AImpl_DestroyGroup( IDirectPlay3A *iface, DPID group )
1971 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
1972 return IDirectPlayX_DestroyGroup( &This->IDirectPlay4_iface, group );
1975 static HRESULT WINAPI IDirectPlay3Impl_DestroyGroup( IDirectPlay3 *iface, DPID group )
1977 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
1978 return IDirectPlayX_DestroyGroup( &This->IDirectPlay4_iface, group );
1981 static HRESULT WINAPI IDirectPlay4AImpl_DestroyGroup( IDirectPlay4A *iface, DPID idGroup )
1983 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
1984 return DP_IF_DestroyGroup( This, NULL, idGroup, TRUE );
1987 static HRESULT WINAPI IDirectPlay4Impl_DestroyGroup( IDirectPlay4 *iface, DPID idGroup )
1989 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
1990 return DP_IF_DestroyGroup( This, NULL, idGroup, FALSE );
1993 typedef struct _DPFAGContext
1995 IDirectPlayImpl *This;
1996 DPID idPlayer;
1997 BOOL bAnsi;
1998 } DPFAGContext, *lpDPFAGContext;
2000 static HRESULT DP_IF_DestroyPlayer( IDirectPlayImpl *This, void *lpMsgHdr, DPID idPlayer,
2001 BOOL bAnsi )
2003 DPFAGContext cbContext;
2005 FIXME( "(%p)->(%p,0x%08x,%u): semi stub\n",
2006 This, lpMsgHdr, idPlayer, bAnsi );
2008 if( This->dp2->connectionInitialized == NO_PROVIDER )
2010 return DPERR_UNINITIALIZED;
2013 if( DP_FindPlayer( This, idPlayer ) == NULL )
2015 return DPERR_INVALIDPLAYER;
2018 /* FIXME: If the player is remote, we must be the host to delete this */
2020 cbContext.This = This;
2021 cbContext.idPlayer = idPlayer;
2022 cbContext.bAnsi = bAnsi;
2024 /* Find each group and call DeletePlayerFromGroup if the player is a
2025 member of the group */
2026 IDirectPlayX_EnumGroups( &This->IDirectPlay4_iface, NULL, cbDeletePlayerFromAllGroups, &cbContext,
2027 DPENUMGROUPS_ALL );
2029 /* Now delete player and player list from the sys group */
2030 DP_DeletePlayer( This, idPlayer );
2032 /* Let the SP know that we've destroyed this group */
2033 if( This->dp2->spData.lpCB->DeletePlayer )
2035 DPSP_DELETEPLAYERDATA data;
2037 FIXME( "data.dwFlags is incorrect\n" );
2039 data.idPlayer = idPlayer;
2040 data.dwFlags = 0;
2041 data.lpISP = This->dp2->spData.lpISP;
2043 (*This->dp2->spData.lpCB->DeletePlayer)( &data );
2046 FIXME( "Send a DELETEPLAYERORGROUP msg\n" );
2048 return DP_OK;
2051 static BOOL CALLBACK
2052 cbDeletePlayerFromAllGroups(
2053 DPID dpId,
2054 DWORD dwPlayerType,
2055 LPCDPNAME lpName,
2056 DWORD dwFlags,
2057 LPVOID lpContext )
2059 lpDPFAGContext lpCtxt = (lpDPFAGContext)lpContext;
2061 if( dwPlayerType == DPPLAYERTYPE_GROUP )
2063 IDirectPlayX_DeletePlayerFromGroup( &lpCtxt->This->IDirectPlay4_iface, dpId, lpCtxt->idPlayer );
2065 /* Enumerate all groups in this group since this will normally only
2066 * be called for top level groups
2068 IDirectPlayX_EnumGroupsInGroup( &lpCtxt->This->IDirectPlay4_iface, dpId, NULL,
2069 cbDeletePlayerFromAllGroups, lpContext, DPENUMGROUPS_ALL);
2072 else
2074 ERR( "Group callback has dwPlayerType = 0x%08x\n", dwPlayerType );
2077 return TRUE;
2080 static HRESULT WINAPI IDirectPlay2AImpl_DestroyPlayer( IDirectPlay2A *iface, DPID player )
2082 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2083 return IDirectPlayX_DestroyPlayer( &This->IDirectPlay4A_iface, player );
2086 static HRESULT WINAPI IDirectPlay2Impl_DestroyPlayer( IDirectPlay2 *iface, DPID player )
2088 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2089 return IDirectPlayX_DestroyPlayer( &This->IDirectPlay4_iface, player );
2092 static HRESULT WINAPI IDirectPlay3AImpl_DestroyPlayer( IDirectPlay3A *iface, DPID player )
2094 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2095 return IDirectPlayX_DestroyPlayer( &This->IDirectPlay4_iface, player );
2098 static HRESULT WINAPI IDirectPlay3Impl_DestroyPlayer( IDirectPlay3 *iface, DPID player )
2100 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2101 return IDirectPlayX_DestroyPlayer( &This->IDirectPlay4_iface, player );
2104 static HRESULT WINAPI IDirectPlay4AImpl_DestroyPlayer( IDirectPlay4A *iface, DPID idPlayer )
2106 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2107 return DP_IF_DestroyPlayer( This, NULL, idPlayer, TRUE );
2110 static HRESULT WINAPI IDirectPlay4Impl_DestroyPlayer( IDirectPlay4 *iface, DPID idPlayer )
2112 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2113 return DP_IF_DestroyPlayer( This, NULL, idPlayer, FALSE );
2116 static HRESULT WINAPI IDirectPlay2AImpl_EnumGroupPlayers( IDirectPlay2A *iface, DPID group,
2117 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2119 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2120 return IDirectPlayX_EnumGroupPlayers( &This->IDirectPlay4A_iface, group, instance,
2121 enumplayercb, context, flags );
2124 static HRESULT WINAPI IDirectPlay2Impl_EnumGroupPlayers( IDirectPlay2 *iface, DPID group,
2125 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2127 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2128 return IDirectPlayX_EnumGroupPlayers( &This->IDirectPlay4_iface, group, instance,
2129 enumplayercb, context, flags );
2132 static HRESULT WINAPI IDirectPlay3AImpl_EnumGroupPlayers( IDirectPlay3A *iface, DPID group,
2133 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2135 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2136 return IDirectPlayX_EnumGroupPlayers( &This->IDirectPlay4_iface, group, instance,
2137 enumplayercb, context, flags );
2140 static HRESULT WINAPI IDirectPlay3Impl_EnumGroupPlayers( IDirectPlay3 *iface, DPID group,
2141 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2143 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2144 return IDirectPlayX_EnumGroupPlayers( &This->IDirectPlay4_iface, group, instance,
2145 enumplayercb, context, flags );
2148 static HRESULT WINAPI IDirectPlay4AImpl_EnumGroupPlayers( IDirectPlay4A *iface, DPID group,
2149 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2151 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2152 return IDirectPlayX_EnumGroupPlayers( &This->IDirectPlay4_iface, group, instance, enumplayercb,
2153 context, flags );
2156 static HRESULT WINAPI IDirectPlay4Impl_EnumGroupPlayers( IDirectPlay4 *iface, DPID group,
2157 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2159 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2160 lpGroupData gdata;
2161 lpPlayerList plist;
2163 FIXME( "(%p)->(0x%08x,%p,%p,%p,0x%08x): semi stub\n", This, group, instance, enumplayercb,
2164 context, flags );
2166 if ( This->dp2->connectionInitialized == NO_PROVIDER )
2167 return DPERR_UNINITIALIZED;
2169 /* Find the group */
2170 if ( ( gdata = DP_FindAnyGroup( This, group ) ) == NULL )
2171 return DPERR_INVALIDGROUP;
2173 if ( DPQ_IS_EMPTY( gdata->players ) )
2174 return DP_OK;
2176 /* Walk the players in this group */
2177 for( plist = DPQ_FIRST( gdata->players ); ; plist = DPQ_NEXT( plist->players ) )
2179 /* We do not enum the name server or app server as they are of no
2180 * consequence to the end user.
2182 if ( ( plist->lpPData->dpid != DPID_NAME_SERVER ) &&
2183 ( plist->lpPData->dpid != DPID_SERVERPLAYER ) )
2185 /* FIXME: Need to add stuff for flags checking */
2186 if ( !enumplayercb( plist->lpPData->dpid, DPPLAYERTYPE_PLAYER,
2187 &plist->lpPData->name, plist->lpPData->dwFlags, context ) )
2188 /* User requested break */
2189 return DP_OK;
2192 if ( DPQ_IS_ENDOFLIST( plist->players ) )
2193 break;
2195 return DP_OK;
2198 /* NOTE: This only enumerates top level groups (created with CreateGroup) */
2199 static HRESULT WINAPI IDirectPlay2AImpl_EnumGroups( IDirectPlay2A *iface, GUID *instance,
2200 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2202 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2203 return IDirectPlayX_EnumGroups( &This->IDirectPlay4A_iface, instance, enumplayercb, context,
2204 flags );
2207 static HRESULT WINAPI IDirectPlay2Impl_EnumGroups( IDirectPlay2 *iface, GUID *instance,
2208 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2210 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2211 return IDirectPlayX_EnumGroups( &This->IDirectPlay4_iface, instance, enumplayercb, context,
2212 flags );
2215 static HRESULT WINAPI IDirectPlay3AImpl_EnumGroups( IDirectPlay3A *iface, GUID *instance,
2216 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2218 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2219 return IDirectPlayX_EnumGroups( &This->IDirectPlay4_iface, instance, enumplayercb, context,
2220 flags );
2223 static HRESULT WINAPI IDirectPlay3Impl_EnumGroups( IDirectPlay3 *iface, GUID *instance,
2224 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2226 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2227 return IDirectPlayX_EnumGroups( &This->IDirectPlay4_iface, instance, enumplayercb, context,
2228 flags );
2231 static HRESULT WINAPI IDirectPlay4AImpl_EnumGroups( IDirectPlay4A *iface, GUID *instance,
2232 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2234 return IDirectPlayX_EnumGroupsInGroup( iface, DPID_SYSTEM_GROUP, instance, enumplayercb,
2235 context, flags );
2238 static HRESULT WINAPI IDirectPlay4Impl_EnumGroups ( IDirectPlay4 *iface, GUID *instance,
2239 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2241 return IDirectPlayX_EnumGroupsInGroup( iface, DPID_SYSTEM_GROUP, instance, enumplayercb,
2242 context, flags );
2245 static HRESULT WINAPI IDirectPlay2AImpl_EnumPlayers( IDirectPlay2A *iface, GUID *instance,
2246 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2248 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2249 return IDirectPlayX_EnumPlayers( &This->IDirectPlay4A_iface, instance, enumplayercb, context,
2250 flags );
2253 static HRESULT WINAPI IDirectPlay2Impl_EnumPlayers( IDirectPlay2 *iface, GUID *instance,
2254 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2256 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2257 return IDirectPlayX_EnumPlayers( &This->IDirectPlay4_iface, instance, enumplayercb, context,
2258 flags );
2261 static HRESULT WINAPI IDirectPlay3AImpl_EnumPlayers( IDirectPlay3A *iface, GUID *instance,
2262 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2264 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2265 return IDirectPlayX_EnumPlayers( &This->IDirectPlay4_iface, instance, enumplayercb, context,
2266 flags );
2269 static HRESULT WINAPI IDirectPlay3Impl_EnumPlayers( IDirectPlay3 *iface, GUID *instance,
2270 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2272 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2273 return IDirectPlayX_EnumPlayers( &This->IDirectPlay4_iface, instance, enumplayercb, context,
2274 flags );
2277 static HRESULT WINAPI IDirectPlay4AImpl_EnumPlayers( IDirectPlay4A *iface, GUID *instance,
2278 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2280 return IDirectPlayX_EnumGroupPlayers( iface, DPID_SYSTEM_GROUP, instance, enumplayercb,
2281 context, flags );
2284 static HRESULT WINAPI IDirectPlay4Impl_EnumPlayers( IDirectPlay4 *iface, GUID *instance,
2285 LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
2287 return IDirectPlayX_EnumGroupPlayers( iface, DPID_SYSTEM_GROUP, instance, enumplayercb,
2288 context, flags );
2291 /* This function should call the registered callback function that the user
2292 passed into EnumSessions for each entry available.
2294 static void DP_InvokeEnumSessionCallbacks
2295 ( LPDPENUMSESSIONSCALLBACK2 lpEnumSessionsCallback2,
2296 LPVOID lpNSInfo,
2297 DWORD dwTimeout,
2298 LPVOID lpContext )
2300 LPDPSESSIONDESC2 lpSessionDesc;
2302 FIXME( ": not checking for conditions\n" );
2304 /* Not sure if this should be pruning but it's convenient */
2305 NS_PruneSessionCache( lpNSInfo );
2307 NS_ResetSessionEnumeration( lpNSInfo );
2309 /* Enumerate all sessions */
2310 /* FIXME: Need to indicate ANSI */
2311 while( (lpSessionDesc = NS_WalkSessions( lpNSInfo ) ) != NULL )
2313 TRACE( "EnumSessionsCallback2 invoked\n" );
2314 if( !lpEnumSessionsCallback2( lpSessionDesc, &dwTimeout, 0, lpContext ) )
2316 return;
2320 /* Invoke one last time to indicate that there is no more to come */
2321 lpEnumSessionsCallback2( NULL, &dwTimeout, DPESC_TIMEDOUT, lpContext );
2324 static DWORD CALLBACK DP_EnumSessionsSendAsyncRequestThread( LPVOID lpContext )
2326 EnumSessionAsyncCallbackData* data = lpContext;
2327 HANDLE hSuicideRequest = data->hSuicideRequest;
2328 DWORD dwTimeout = data->dwTimeout;
2330 TRACE( "Thread started with timeout = 0x%08x\n", dwTimeout );
2332 for( ;; )
2334 HRESULT hr;
2336 /* Sleep up to dwTimeout waiting for request to terminate thread */
2337 if( WaitForSingleObject( hSuicideRequest, dwTimeout ) == WAIT_OBJECT_0 )
2339 TRACE( "Thread terminating on terminate request\n" );
2340 break;
2343 /* Now resend the enum request */
2344 hr = NS_SendSessionRequestBroadcast( &data->requestGuid,
2345 data->dwEnumSessionFlags,
2346 data->lpSpData );
2348 if( FAILED(hr) )
2350 ERR( "Enum broadcase request failed: %s\n", DPLAYX_HresultToString(hr) );
2351 /* FIXME: Should we kill this thread? How to inform the main thread? */
2356 TRACE( "Thread terminating\n" );
2358 /* Clean up the thread data */
2359 CloseHandle( hSuicideRequest );
2360 HeapFree( GetProcessHeap(), 0, lpContext );
2362 /* FIXME: Need to have some notification to main app thread that this is
2363 * dead. It would serve two purposes. 1) allow sync on termination
2364 * so that we don't actually send something to ourselves when we
2365 * become name server (race condition) and 2) so that if we die
2366 * abnormally something else will be able to tell.
2369 return 1;
2372 static void DP_KillEnumSessionThread( IDirectPlayImpl *This )
2374 /* Does a thread exist? If so we were doing an async enum session */
2375 if( This->dp2->hEnumSessionThread != INVALID_HANDLE_VALUE )
2377 TRACE( "Killing EnumSession thread %p\n",
2378 This->dp2->hEnumSessionThread );
2380 /* Request that the thread kill itself nicely */
2381 SetEvent( This->dp2->hKillEnumSessionThreadEvent );
2382 CloseHandle( This->dp2->hKillEnumSessionThreadEvent );
2384 /* We no longer need to know about the thread */
2385 CloseHandle( This->dp2->hEnumSessionThread );
2387 This->dp2->hEnumSessionThread = INVALID_HANDLE_VALUE;
2391 static HRESULT WINAPI IDirectPlay2AImpl_EnumSessions( IDirectPlay2A *iface, DPSESSIONDESC2 *sdesc,
2392 DWORD timeout, LPDPENUMSESSIONSCALLBACK2 enumsessioncb, void *context, DWORD flags )
2394 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2395 return IDirectPlayX_EnumSessions( &This->IDirectPlay4A_iface, sdesc, timeout, enumsessioncb,
2396 context, flags );
2399 static HRESULT WINAPI IDirectPlay2Impl_EnumSessions( IDirectPlay2 *iface, DPSESSIONDESC2 *sdesc,
2400 DWORD timeout, LPDPENUMSESSIONSCALLBACK2 enumsessioncb, void *context, DWORD flags )
2402 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2403 return IDirectPlayX_EnumSessions( &This->IDirectPlay4_iface, sdesc, timeout, enumsessioncb,
2404 context, flags );
2407 static HRESULT WINAPI IDirectPlay3AImpl_EnumSessions( IDirectPlay3A *iface, DPSESSIONDESC2 *sdesc,
2408 DWORD timeout, LPDPENUMSESSIONSCALLBACK2 enumsessioncb, void *context, DWORD flags )
2410 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2411 return IDirectPlayX_EnumSessions( &This->IDirectPlay4_iface, sdesc, timeout, enumsessioncb,
2412 context, flags );
2415 static HRESULT WINAPI IDirectPlay3Impl_EnumSessions( IDirectPlay3 *iface, DPSESSIONDESC2 *sdesc,
2416 DWORD timeout, LPDPENUMSESSIONSCALLBACK2 enumsessioncb, void *context, DWORD flags )
2418 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2419 return IDirectPlayX_EnumSessions( &This->IDirectPlay4_iface, sdesc, timeout, enumsessioncb,
2420 context, flags );
2423 static HRESULT WINAPI IDirectPlay4AImpl_EnumSessions( IDirectPlay4A *iface, DPSESSIONDESC2 *sdesc,
2424 DWORD timeout, LPDPENUMSESSIONSCALLBACK2 enumsessioncb, void *context, DWORD flags )
2426 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2427 return IDirectPlayX_EnumSessions( &This->IDirectPlay4_iface, sdesc, timeout, enumsessioncb,
2428 context, flags );
2431 static HRESULT WINAPI IDirectPlay4Impl_EnumSessions( IDirectPlay4 *iface, DPSESSIONDESC2 *sdesc,
2432 DWORD timeout, LPDPENUMSESSIONSCALLBACK2 enumsessioncb, void *context, DWORD flags )
2434 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2435 void *connection;
2436 DWORD size;
2437 HRESULT hr = DP_OK;
2439 TRACE( "(%p)->(%p,0x%08x,%p,%p,0x%08x)\n", This, sdesc, timeout, enumsessioncb,
2440 context, flags );
2442 if ( This->dp2->connectionInitialized == NO_PROVIDER )
2443 return DPERR_UNINITIALIZED;
2445 /* Can't enumerate if the interface is already open */
2446 if ( This->dp2->bConnectionOpen )
2447 return DPERR_GENERIC;
2449 /* The loading of a lobby provider _seems_ to require a backdoor loading
2450 * of the service provider to also associate with this DP object. This is
2451 * because the app doesn't seem to have to call EnumConnections and
2452 * InitializeConnection for the SP before calling this method. As such
2453 * we'll do their dirty work for them with a quick hack so as to always
2454 * load the TCP/IP service provider.
2456 * The correct solution would seem to involve creating a dialog box which
2457 * contains the possible SPs. These dialog boxes most likely follow SDK
2458 * examples.
2460 if ( This->dp2->bDPLSPInitialized && !This->dp2->bSPInitialized )
2462 WARN( "Hack providing TCP/IP SP for lobby provider activated\n" );
2464 if ( !DP_BuildSPCompoundAddr( (GUID*)&DPSPGUID_TCPIP, &connection, &size ) )
2466 ERR( "Can't build compound addr\n" );
2467 return DPERR_GENERIC;
2470 hr = IDirectPlayX_InitializeConnection( &This->IDirectPlay4_iface, connection, 0 );
2471 if ( FAILED(hr) )
2472 return hr;
2474 HeapFree( GetProcessHeap(), 0, connection );
2475 This->dp2->bSPInitialized = TRUE;
2479 /* Use the service provider default? */
2480 if ( !timeout )
2482 DPCAPS caps;
2483 caps.dwSize = sizeof( caps );
2485 IDirectPlayX_GetCaps( &This->IDirectPlay4_iface, &caps, 0 );
2486 timeout = caps.dwTimeout;
2487 if ( !timeout )
2488 timeout = DPMSG_WAIT_5_SECS; /* Provide the TCP/IP default */
2491 if ( flags & DPENUMSESSIONS_STOPASYNC )
2493 DP_KillEnumSessionThread( This );
2494 return hr;
2497 if ( flags & DPENUMSESSIONS_ASYNC )
2499 /* Enumerate everything presently in the local session cache */
2500 DP_InvokeEnumSessionCallbacks( enumsessioncb, This->dp2->lpNameServerData, timeout,
2501 context );
2503 if ( This->dp2->dwEnumSessionLock )
2504 return DPERR_CONNECTING;
2506 /* See if we've already created a thread to service this interface */
2507 if ( This->dp2->hEnumSessionThread == INVALID_HANDLE_VALUE )
2509 DWORD tid;
2510 This->dp2->dwEnumSessionLock++;
2512 /* Send the first enum request inline since the user may cancel a dialog
2513 * if one is presented. Also, may also have a connecting return code.
2515 hr = NS_SendSessionRequestBroadcast( &sdesc->guidApplication, flags,
2516 &This->dp2->spData );
2518 if ( SUCCEEDED(hr) )
2520 EnumSessionAsyncCallbackData* data = HeapAlloc( GetProcessHeap(),
2521 HEAP_ZERO_MEMORY, sizeof( *data ) );
2522 /* FIXME: need to kill the thread on object deletion */
2523 data->lpSpData = &This->dp2->spData;
2524 data->requestGuid = sdesc->guidApplication;
2525 data->dwEnumSessionFlags = flags;
2526 data->dwTimeout = timeout;
2528 This->dp2->hKillEnumSessionThreadEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
2529 if ( !DuplicateHandle( GetCurrentProcess(), This->dp2->hKillEnumSessionThreadEvent,
2530 GetCurrentProcess(), &data->hSuicideRequest, 0, FALSE,
2531 DUPLICATE_SAME_ACCESS ) )
2532 ERR( "Can't duplicate thread killing handle\n" );
2534 TRACE( ": creating EnumSessionsRequest thread\n" );
2535 This->dp2->hEnumSessionThread = CreateThread( NULL, 0,
2536 DP_EnumSessionsSendAsyncRequestThread, data, 0, &tid );
2538 This->dp2->dwEnumSessionLock--;
2541 else
2543 /* Invalidate the session cache for the interface */
2544 NS_InvalidateSessionCache( This->dp2->lpNameServerData );
2545 /* Send the broadcast for session enumeration */
2546 hr = NS_SendSessionRequestBroadcast( &sdesc->guidApplication, flags, &This->dp2->spData );
2547 SleepEx( timeout, FALSE );
2548 DP_InvokeEnumSessionCallbacks( enumsessioncb, This->dp2->lpNameServerData, timeout,
2549 context );
2552 return hr;
2555 static HRESULT WINAPI IDirectPlay2AImpl_GetCaps( IDirectPlay2A *iface, DPCAPS *caps, DWORD flags )
2557 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2558 return IDirectPlayX_GetCaps( &This->IDirectPlay4A_iface, caps, flags );
2561 static HRESULT WINAPI IDirectPlay2Impl_GetCaps( IDirectPlay2 *iface, DPCAPS *caps, DWORD flags )
2563 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2564 return IDirectPlayX_GetCaps( &This->IDirectPlay4_iface, caps, flags );
2567 static HRESULT WINAPI IDirectPlay3AImpl_GetCaps( IDirectPlay3A *iface, DPCAPS *caps, DWORD flags )
2569 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2570 return IDirectPlayX_GetCaps( &This->IDirectPlay4_iface, caps, flags );
2573 static HRESULT WINAPI IDirectPlay3Impl_GetCaps( IDirectPlay3 *iface, DPCAPS *caps, DWORD flags )
2575 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2576 return IDirectPlayX_GetCaps( &This->IDirectPlay4_iface, caps, flags );
2579 static HRESULT WINAPI IDirectPlay4AImpl_GetCaps( IDirectPlay4A *iface, DPCAPS *caps, DWORD flags )
2581 return IDirectPlayX_GetPlayerCaps( iface, DPID_ALLPLAYERS, caps, flags );
2584 static HRESULT WINAPI IDirectPlay4Impl_GetCaps( IDirectPlay4 *iface, DPCAPS *caps, DWORD flags )
2586 return IDirectPlayX_GetPlayerCaps( iface, DPID_ALLPLAYERS, caps, flags );
2589 static HRESULT WINAPI IDirectPlay2AImpl_GetGroupData( IDirectPlay2A *iface, DPID group, void *data,
2590 DWORD *size, DWORD flags )
2592 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2593 return IDirectPlayX_GetGroupData( &This->IDirectPlay4A_iface, group, data, size, flags );
2596 static HRESULT WINAPI IDirectPlay2Impl_GetGroupData( IDirectPlay2 *iface, DPID group, void *data,
2597 DWORD *size, DWORD flags )
2599 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2600 return IDirectPlayX_GetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
2603 static HRESULT WINAPI IDirectPlay3AImpl_GetGroupData( IDirectPlay3A *iface, DPID group, void *data,
2604 DWORD *size, DWORD flags )
2606 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2607 return IDirectPlayX_GetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
2610 static HRESULT WINAPI IDirectPlay3Impl_GetGroupData( IDirectPlay3 *iface, DPID group, void *data,
2611 DWORD *size, DWORD flags )
2613 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2614 return IDirectPlayX_GetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
2617 static HRESULT WINAPI IDirectPlay4AImpl_GetGroupData( IDirectPlay4A *iface, DPID group,
2618 void *data, DWORD *size, DWORD flags )
2620 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2621 return IDirectPlayX_GetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
2624 static HRESULT WINAPI IDirectPlay4Impl_GetGroupData( IDirectPlay4 *iface, DPID group,
2625 void *data, DWORD *size, DWORD flags )
2627 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2628 lpGroupData gdata;
2629 DWORD bufsize;
2630 void *src;
2632 TRACE( "(%p)->(0x%08x,%p,%p,0x%08x)\n", This, group, data, size, flags );
2634 if ( ( gdata = DP_FindAnyGroup( This, group ) ) == NULL )
2635 return DPERR_INVALIDGROUP;
2637 /* How much buffer is required? */
2638 if ( flags & DPSET_LOCAL )
2640 bufsize = gdata->dwLocalDataSize;
2641 src = gdata->lpLocalData;
2643 else
2645 bufsize = gdata->dwRemoteDataSize;
2646 src = gdata->lpRemoteData;
2649 /* Is the user requesting to know how big a buffer is required? */
2650 if ( !data || *size < bufsize )
2652 *size = bufsize;
2653 return DPERR_BUFFERTOOSMALL;
2656 CopyMemory( data, src, bufsize );
2658 return DP_OK;
2661 static HRESULT DP_IF_GetGroupName( IDirectPlayImpl *This, DPID idGroup, void *lpData,
2662 DWORD *lpdwDataSize, BOOL bAnsi )
2664 lpGroupData lpGData;
2665 LPDPNAME lpName = lpData;
2666 DWORD dwRequiredDataSize;
2668 FIXME("(%p)->(0x%08x,%p,%p,%u) ANSI ignored\n",
2669 This, idGroup, lpData, lpdwDataSize, bAnsi );
2671 if( ( lpGData = DP_FindAnyGroup( This, idGroup ) ) == NULL )
2673 return DPERR_INVALIDGROUP;
2676 dwRequiredDataSize = lpGData->name.dwSize;
2678 if( lpGData->name.u1.lpszShortNameA )
2680 dwRequiredDataSize += strlen( lpGData->name.u1.lpszShortNameA ) + 1;
2683 if( lpGData->name.u2.lpszLongNameA )
2685 dwRequiredDataSize += strlen( lpGData->name.u2.lpszLongNameA ) + 1;
2688 if( ( lpData == NULL ) ||
2689 ( *lpdwDataSize < dwRequiredDataSize )
2692 *lpdwDataSize = dwRequiredDataSize;
2693 return DPERR_BUFFERTOOSMALL;
2696 /* Copy the structure */
2697 CopyMemory( lpName, &lpGData->name, lpGData->name.dwSize );
2699 if( lpGData->name.u1.lpszShortNameA )
2701 strcpy( ((char*)lpName)+lpGData->name.dwSize,
2702 lpGData->name.u1.lpszShortNameA );
2704 else
2706 lpName->u1.lpszShortNameA = NULL;
2709 if( lpGData->name.u1.lpszShortNameA )
2711 strcpy( ((char*)lpName)+lpGData->name.dwSize,
2712 lpGData->name.u1.lpszShortNameA );
2714 else
2716 lpName->u2.lpszLongNameA = NULL;
2719 return DP_OK;
2722 static HRESULT WINAPI IDirectPlay2AImpl_GetGroupName( IDirectPlay2A *iface, DPID group, void *data,
2723 DWORD *size )
2725 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2726 return IDirectPlayX_GetGroupName( &This->IDirectPlay4A_iface, group, data, size );
2729 static HRESULT WINAPI IDirectPlay2Impl_GetGroupName( IDirectPlay2 *iface, DPID group, void *data,
2730 DWORD *size )
2732 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2733 return IDirectPlayX_GetGroupName( &This->IDirectPlay4_iface, group, data, size );
2736 static HRESULT WINAPI IDirectPlay3AImpl_GetGroupName( IDirectPlay3A *iface, DPID group, void *data,
2737 DWORD *size )
2739 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2740 return IDirectPlayX_GetGroupName( &This->IDirectPlay4_iface, group, data, size );
2743 static HRESULT WINAPI IDirectPlay3Impl_GetGroupName( IDirectPlay3 *iface, DPID group, void *data,
2744 DWORD *size )
2746 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2747 return IDirectPlayX_GetGroupName( &This->IDirectPlay4_iface, group, data, size );
2750 static HRESULT WINAPI IDirectPlay4AImpl_GetGroupName( IDirectPlay4A *iface, DPID idGroup,
2751 void *lpData, DWORD *lpdwDataSize )
2753 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2754 return DP_IF_GetGroupName( This, idGroup, lpData, lpdwDataSize, TRUE );
2757 static HRESULT WINAPI IDirectPlay4Impl_GetGroupName( IDirectPlay4 *iface, DPID idGroup,
2758 void *lpData, DWORD *lpdwDataSize )
2760 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2761 return DP_IF_GetGroupName( This, idGroup, lpData, lpdwDataSize, FALSE );
2764 static HRESULT WINAPI IDirectPlay2AImpl_GetMessageCount( IDirectPlay2A *iface, DPID player,
2765 DWORD *count )
2767 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2768 return IDirectPlayX_GetMessageCount( &This->IDirectPlay4A_iface, player, count );
2771 static HRESULT WINAPI IDirectPlay2Impl_GetMessageCount( IDirectPlay2 *iface, DPID player,
2772 DWORD *count )
2774 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2775 return IDirectPlayX_GetMessageCount( &This->IDirectPlay4_iface, player, count );
2778 static HRESULT WINAPI IDirectPlay3AImpl_GetMessageCount( IDirectPlay3A *iface, DPID player,
2779 DWORD *count )
2781 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2782 return IDirectPlayX_GetMessageCount( &This->IDirectPlay4_iface, player, count );
2785 static HRESULT WINAPI IDirectPlay3Impl_GetMessageCount( IDirectPlay3 *iface, DPID player,
2786 DWORD *count )
2788 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2789 return IDirectPlayX_GetMessageCount( &This->IDirectPlay4_iface, player, count );
2792 static HRESULT WINAPI IDirectPlay4AImpl_GetMessageCount( IDirectPlay4A *iface, DPID player,
2793 DWORD *count )
2795 return IDirectPlayX_GetMessageQueue( iface, 0, player, DPMESSAGEQUEUE_RECEIVE, count, NULL );
2798 static HRESULT WINAPI IDirectPlay4Impl_GetMessageCount( IDirectPlay4 *iface, DPID player,
2799 DWORD *count )
2801 return IDirectPlayX_GetMessageQueue( iface, 0, player, DPMESSAGEQUEUE_RECEIVE, count, NULL );
2804 static HRESULT WINAPI IDirectPlay2AImpl_GetPlayerAddress( IDirectPlay2A *iface, DPID player,
2805 void *data, DWORD *size )
2807 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2808 return IDirectPlayX_GetPlayerAddress( &This->IDirectPlay4A_iface, player, data, size );
2811 static HRESULT WINAPI IDirectPlay2Impl_GetPlayerAddress( IDirectPlay2 *iface, DPID player,
2812 void *data, DWORD *size )
2814 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2815 return IDirectPlayX_GetPlayerAddress( &This->IDirectPlay4_iface, player, data, size );
2818 static HRESULT WINAPI IDirectPlay3AImpl_GetPlayerAddress( IDirectPlay3A *iface, DPID player,
2819 void *data, DWORD *size )
2821 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2822 return IDirectPlayX_GetPlayerAddress( &This->IDirectPlay4_iface, player, data, size );
2825 static HRESULT WINAPI IDirectPlay3Impl_GetPlayerAddress( IDirectPlay3 *iface, DPID player,
2826 void *data, DWORD *size )
2828 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2829 return IDirectPlayX_GetPlayerAddress( &This->IDirectPlay4_iface, player, data, size );
2832 static HRESULT WINAPI IDirectPlay4AImpl_GetPlayerAddress( IDirectPlay4A *iface, DPID player,
2833 void *data, DWORD *size )
2835 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2836 FIXME("(%p)->(0x%08x,%p,%p): stub\n", This, player, data, size );
2837 return DP_OK;
2840 static HRESULT WINAPI IDirectPlay4Impl_GetPlayerAddress( IDirectPlay4 *iface, DPID player,
2841 void *data, DWORD *size )
2843 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2844 FIXME( "(%p)->(0x%08x,%p,%p): stub\n", This, player, data, size );
2845 return DP_OK;
2848 static HRESULT WINAPI IDirectPlay2AImpl_GetPlayerCaps( IDirectPlay2A *iface, DPID player,
2849 DPCAPS *caps, DWORD flags )
2851 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2852 return IDirectPlayX_GetPlayerCaps( &This->IDirectPlay4A_iface, player, caps, flags );
2855 static HRESULT WINAPI IDirectPlay2Impl_GetPlayerCaps( IDirectPlay2 *iface, DPID player,
2856 DPCAPS *caps, DWORD flags )
2858 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2859 return IDirectPlayX_GetPlayerCaps( &This->IDirectPlay4_iface, player, caps, flags );
2862 static HRESULT WINAPI IDirectPlay3AImpl_GetPlayerCaps( IDirectPlay3A *iface, DPID player,
2863 DPCAPS *caps, DWORD flags )
2865 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2866 return IDirectPlayX_GetPlayerCaps( &This->IDirectPlay4_iface, player, caps, flags );
2869 static HRESULT WINAPI IDirectPlay3Impl_GetPlayerCaps( IDirectPlay3 *iface, DPID player,
2870 DPCAPS *caps, DWORD flags )
2872 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2873 return IDirectPlayX_GetPlayerCaps( &This->IDirectPlay4_iface, player, caps, flags );
2876 static HRESULT WINAPI IDirectPlay4AImpl_GetPlayerCaps( IDirectPlay4A *iface, DPID player,
2877 DPCAPS *caps, DWORD flags )
2879 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2880 return IDirectPlayX_GetPlayerCaps( &This->IDirectPlay4_iface, player, caps, flags );
2883 static HRESULT WINAPI IDirectPlay4Impl_GetPlayerCaps( IDirectPlay4 *iface, DPID player,
2884 DPCAPS *caps, DWORD flags )
2886 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2887 DPSP_GETCAPSDATA data;
2889 TRACE( "(%p)->(0x%08x,%p,0x%08x)\n", This, player, caps, flags);
2891 if ( !caps )
2892 return DPERR_INVALIDPARAMS;
2894 if ( This->dp2->connectionInitialized == NO_PROVIDER )
2895 return DPERR_UNINITIALIZED;
2897 if( caps->dwSize != sizeof(DPCAPS) )
2898 return DPERR_INVALIDPARAMS;
2900 /* Query the service provider */
2901 data.idPlayer = player;
2902 data.dwFlags = flags;
2903 data.lpCaps = caps;
2904 data.lpISP = This->dp2->spData.lpISP;
2906 return (*This->dp2->spData.lpCB->GetCaps)( &data );
2909 static HRESULT WINAPI IDirectPlay2AImpl_GetPlayerData( IDirectPlay2A *iface, DPID player,
2910 void *data, DWORD *size, DWORD flags )
2912 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
2913 return IDirectPlayX_GetPlayerData( &This->IDirectPlay4A_iface, player, data, size, flags );
2916 static HRESULT WINAPI IDirectPlay2Impl_GetPlayerData( IDirectPlay2 *iface, DPID player,
2917 void *data, DWORD *size, DWORD flags )
2919 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
2920 return IDirectPlayX_GetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
2923 static HRESULT WINAPI IDirectPlay3AImpl_GetPlayerData( IDirectPlay3A *iface, DPID player,
2924 void *data, DWORD *size, DWORD flags )
2926 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
2927 return IDirectPlayX_GetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
2930 static HRESULT WINAPI IDirectPlay3Impl_GetPlayerData( IDirectPlay3 *iface, DPID player,
2931 void *data, DWORD *size, DWORD flags )
2933 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
2934 return IDirectPlayX_GetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
2937 static HRESULT WINAPI IDirectPlay4AImpl_GetPlayerData( IDirectPlay4A *iface, DPID player,
2938 void *data, DWORD *size, DWORD flags )
2940 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
2941 return IDirectPlayX_GetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
2944 static HRESULT WINAPI IDirectPlay4Impl_GetPlayerData( IDirectPlay4 *iface, DPID player,
2945 void *data, DWORD *size, DWORD flags )
2947 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
2948 lpPlayerList plist;
2949 DWORD bufsize;
2950 void *src;
2952 TRACE( "(%p)->(0x%08x,%p,%p,0x%08x)\n", This, player, data, size, flags );
2954 if ( This->dp2->connectionInitialized == NO_PROVIDER )
2955 return DPERR_UNINITIALIZED;
2957 if ( ( plist = DP_FindPlayer( This, player ) ) == NULL )
2958 return DPERR_INVALIDPLAYER;
2960 if ( flags & DPSET_LOCAL )
2962 bufsize = plist->lpPData->dwLocalDataSize;
2963 src = plist->lpPData->lpLocalData;
2965 else
2967 bufsize = plist->lpPData->dwRemoteDataSize;
2968 src = plist->lpPData->lpRemoteData;
2971 /* Is the user requesting to know how big a buffer is required? */
2972 if ( !data || *size < bufsize )
2974 *size = bufsize;
2975 return DPERR_BUFFERTOOSMALL;
2978 CopyMemory( data, src, bufsize );
2980 return DP_OK;
2983 static HRESULT DP_IF_GetPlayerName( IDirectPlayImpl *This, DPID idPlayer, void *lpData,
2984 DWORD *lpdwDataSize, BOOL bAnsi )
2986 lpPlayerList lpPList;
2987 LPDPNAME lpName = lpData;
2988 DWORD dwRequiredDataSize;
2990 FIXME( "(%p)->(0x%08x,%p,%p,%u): ANSI\n",
2991 This, idPlayer, lpData, lpdwDataSize, bAnsi );
2993 if( This->dp2->connectionInitialized == NO_PROVIDER )
2995 return DPERR_UNINITIALIZED;
2998 if( ( lpPList = DP_FindPlayer( This, idPlayer ) ) == NULL )
3000 return DPERR_INVALIDPLAYER;
3003 dwRequiredDataSize = lpPList->lpPData->name.dwSize;
3005 if( lpPList->lpPData->name.u1.lpszShortNameA )
3007 dwRequiredDataSize += strlen( lpPList->lpPData->name.u1.lpszShortNameA ) + 1;
3010 if( lpPList->lpPData->name.u2.lpszLongNameA )
3012 dwRequiredDataSize += strlen( lpPList->lpPData->name.u2.lpszLongNameA ) + 1;
3015 if( ( lpData == NULL ) ||
3016 ( *lpdwDataSize < dwRequiredDataSize )
3019 *lpdwDataSize = dwRequiredDataSize;
3020 return DPERR_BUFFERTOOSMALL;
3023 /* Copy the structure */
3024 CopyMemory( lpName, &lpPList->lpPData->name, lpPList->lpPData->name.dwSize );
3026 if( lpPList->lpPData->name.u1.lpszShortNameA )
3028 strcpy( ((char*)lpName)+lpPList->lpPData->name.dwSize,
3029 lpPList->lpPData->name.u1.lpszShortNameA );
3031 else
3033 lpName->u1.lpszShortNameA = NULL;
3036 if( lpPList->lpPData->name.u1.lpszShortNameA )
3038 strcpy( ((char*)lpName)+lpPList->lpPData->name.dwSize,
3039 lpPList->lpPData->name.u2.lpszLongNameA );
3041 else
3043 lpName->u2.lpszLongNameA = NULL;
3046 return DP_OK;
3049 static HRESULT WINAPI IDirectPlay2AImpl_GetPlayerName( IDirectPlay2A *iface, DPID player,
3050 void *data, DWORD *size )
3052 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3053 return IDirectPlayX_GetPlayerName( &This->IDirectPlay4A_iface, player, data, size );
3056 static HRESULT WINAPI IDirectPlay2Impl_GetPlayerName( IDirectPlay2 *iface, DPID player,
3057 void *data, DWORD *size )
3059 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3060 return IDirectPlayX_GetPlayerName( &This->IDirectPlay4_iface, player, data, size );
3063 static HRESULT WINAPI IDirectPlay3AImpl_GetPlayerName( IDirectPlay3A *iface, DPID player,
3064 void *data, DWORD *size )
3066 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3067 return IDirectPlayX_GetPlayerName( &This->IDirectPlay4_iface, player, data, size );
3070 static HRESULT WINAPI IDirectPlay3Impl_GetPlayerName( IDirectPlay3 *iface, DPID player,
3071 void *data, DWORD *size )
3073 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3074 return IDirectPlayX_GetPlayerName( &This->IDirectPlay4_iface, player, data, size );
3077 static HRESULT WINAPI IDirectPlay4AImpl_GetPlayerName( IDirectPlay4A *iface, DPID idPlayer,
3078 void *lpData, DWORD *lpdwDataSize )
3080 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3081 return DP_IF_GetPlayerName( This, idPlayer, lpData, lpdwDataSize, TRUE );
3084 static HRESULT WINAPI IDirectPlay4Impl_GetPlayerName( IDirectPlay4 *iface, DPID idPlayer,
3085 void *lpData, DWORD *lpdwDataSize )
3087 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3088 return DP_IF_GetPlayerName( This, idPlayer, lpData, lpdwDataSize, FALSE );
3091 static HRESULT DP_GetSessionDesc( IDirectPlayImpl *This, void *lpData, DWORD *lpdwDataSize,
3092 BOOL bAnsi )
3094 DWORD dwRequiredSize;
3096 TRACE( "(%p)->(%p,%p,%u)\n", This, lpData, lpdwDataSize, bAnsi );
3098 if( This->dp2->connectionInitialized == NO_PROVIDER )
3100 return DPERR_UNINITIALIZED;
3103 if( ( lpData == NULL ) && ( lpdwDataSize == NULL ) )
3105 return DPERR_INVALIDPARAMS;
3108 /* FIXME: Get from This->dp2->lpSessionDesc */
3109 dwRequiredSize = DP_CalcSessionDescSize( This->dp2->lpSessionDesc, bAnsi );
3111 if ( ( lpData == NULL ) ||
3112 ( *lpdwDataSize < dwRequiredSize )
3115 *lpdwDataSize = dwRequiredSize;
3116 return DPERR_BUFFERTOOSMALL;
3119 DP_CopySessionDesc( lpData, This->dp2->lpSessionDesc, bAnsi );
3121 return DP_OK;
3124 static HRESULT WINAPI IDirectPlay2AImpl_GetSessionDesc( IDirectPlay2A *iface, void *data,
3125 DWORD *size )
3127 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3128 return IDirectPlayX_GetSessionDesc( &This->IDirectPlay4A_iface, data, size );
3131 static HRESULT WINAPI IDirectPlay2Impl_GetSessionDesc( IDirectPlay2 *iface, void *data,
3132 DWORD *size )
3134 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3135 return IDirectPlayX_GetSessionDesc( &This->IDirectPlay4_iface, data, size );
3138 static HRESULT WINAPI IDirectPlay3AImpl_GetSessionDesc( IDirectPlay3A *iface, void *data,
3139 DWORD *size )
3141 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3142 return IDirectPlayX_GetSessionDesc( &This->IDirectPlay4_iface, data, size );
3145 static HRESULT WINAPI IDirectPlay3Impl_GetSessionDesc( IDirectPlay3 *iface, void *data,
3146 DWORD *size )
3148 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3149 return IDirectPlayX_GetSessionDesc( &This->IDirectPlay4_iface, data, size );
3152 static HRESULT WINAPI IDirectPlay4AImpl_GetSessionDesc( IDirectPlay4A *iface, void *lpData,
3153 DWORD *lpdwDataSize )
3155 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3156 return DP_GetSessionDesc( This, lpData, lpdwDataSize, TRUE );
3159 static HRESULT WINAPI IDirectPlay4Impl_GetSessionDesc( IDirectPlay4 *iface, void *lpData,
3160 DWORD *lpdwDataSize )
3162 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3163 return DP_GetSessionDesc( This, lpData, lpdwDataSize, TRUE );
3166 static HRESULT WINAPI IDirectPlay2AImpl_Initialize( IDirectPlay2A *iface, GUID *guid )
3168 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3169 return IDirectPlayX_Initialize( &This->IDirectPlay4A_iface, guid );
3172 static HRESULT WINAPI IDirectPlay2Impl_Initialize( IDirectPlay2 *iface, GUID *guid )
3174 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3175 return IDirectPlayX_Initialize( &This->IDirectPlay4_iface, guid );
3178 static HRESULT WINAPI IDirectPlay3AImpl_Initialize( IDirectPlay3A *iface, GUID *guid )
3180 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3181 return IDirectPlayX_Initialize( &This->IDirectPlay4_iface, guid );
3184 static HRESULT WINAPI IDirectPlay3Impl_Initialize( IDirectPlay3 *iface, GUID *guid )
3186 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3187 return IDirectPlayX_Initialize( &This->IDirectPlay4_iface, guid );
3190 /* Intended only for COM compatibility. Always returns an error. */
3191 static HRESULT WINAPI IDirectPlay4AImpl_Initialize( IDirectPlay4A *iface, GUID *guid )
3193 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3194 TRACE("(%p)->(%p): no-op\n", This, guid );
3195 return DPERR_ALREADYINITIALIZED;
3198 static HRESULT WINAPI IDirectPlay4Impl_Initialize( IDirectPlay4 *iface, GUID *guid )
3200 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3201 TRACE( "(%p)->(%p): no-op\n", This, guid );
3202 return DPERR_ALREADYINITIALIZED;
3206 static HRESULT DP_SecureOpen( IDirectPlayImpl *This, const DPSESSIONDESC2 *lpsd, DWORD dwFlags,
3207 const DPSECURITYDESC *lpSecurity, const DPCREDENTIALS *lpCredentials, BOOL bAnsi )
3209 HRESULT hr = DP_OK;
3211 FIXME( "(%p)->(%p,0x%08x,%p,%p): partial stub\n",
3212 This, lpsd, dwFlags, lpSecurity, lpCredentials );
3214 if( This->dp2->connectionInitialized == NO_PROVIDER )
3216 return DPERR_UNINITIALIZED;
3219 if( lpsd->dwSize != sizeof(DPSESSIONDESC2) )
3221 TRACE( ": rejecting invalid dpsd size (%d).\n", lpsd->dwSize );
3222 return DPERR_INVALIDPARAMS;
3225 if( This->dp2->bConnectionOpen )
3227 TRACE( ": rejecting already open connection.\n" );
3228 return DPERR_ALREADYINITIALIZED;
3231 /* If we're enumerating, kill the thread */
3232 DP_KillEnumSessionThread( This );
3234 if( dwFlags & DPOPEN_CREATE )
3236 /* Rightoo - this computer is the host and the local computer needs to be
3237 the name server so that others can join this session */
3238 NS_SetLocalComputerAsNameServer( lpsd, This->dp2->lpNameServerData );
3240 This->dp2->bHostInterface = TRUE;
3242 hr = DP_SetSessionDesc( This, lpsd, 0, TRUE, bAnsi );
3243 if( FAILED( hr ) )
3245 ERR( "Unable to set session desc: %s\n", DPLAYX_HresultToString( hr ) );
3246 return hr;
3250 /* Invoke the conditional callback for the service provider */
3251 if( This->dp2->spData.lpCB->Open )
3253 DPSP_OPENDATA data;
3255 FIXME( "Not all data fields are correct. Need new parameter\n" );
3257 data.bCreate = (dwFlags & DPOPEN_CREATE ) != 0;
3258 data.lpSPMessageHeader = (dwFlags & DPOPEN_CREATE ) ? NULL
3259 : NS_GetNSAddr( This->dp2->lpNameServerData );
3260 data.lpISP = This->dp2->spData.lpISP;
3261 data.bReturnStatus = (dwFlags & DPOPEN_RETURNSTATUS) != 0;
3262 data.dwOpenFlags = dwFlags;
3263 data.dwSessionFlags = This->dp2->lpSessionDesc->dwFlags;
3265 hr = (*This->dp2->spData.lpCB->Open)(&data);
3266 if( FAILED( hr ) )
3268 ERR( "Unable to open session: %s\n", DPLAYX_HresultToString( hr ) );
3269 return hr;
3274 /* Create the system group of which everything is a part of */
3275 DPID systemGroup = DPID_SYSTEM_GROUP;
3277 hr = DP_IF_CreateGroup( This, NULL, &systemGroup, NULL,
3278 NULL, 0, 0, TRUE );
3282 if( dwFlags & DPOPEN_JOIN )
3284 DPID dpidServerId = DPID_UNKNOWN;
3286 /* Create the server player for this interface. This way we can receive
3287 * messages for this session.
3289 /* FIXME: I suppose that we should be setting an event for a receive
3290 * type of thing. That way the messaging thread could know to wake
3291 * up. DPlay would then trigger the hEvent for the player the
3292 * message is directed to.
3294 hr = DP_IF_CreatePlayer( This, NULL, &dpidServerId, NULL, 0, NULL,
3296 DPPLAYER_SERVERPLAYER | DPPLAYER_LOCAL , bAnsi );
3299 else if( dwFlags & DPOPEN_CREATE )
3301 DPID dpidNameServerId = DPID_NAME_SERVER;
3303 hr = DP_IF_CreatePlayer( This, NULL, &dpidNameServerId, NULL, 0, NULL,
3304 0, DPPLAYER_SERVERPLAYER, bAnsi );
3307 if( FAILED(hr) )
3309 ERR( "Couldn't create name server/system player: %s\n",
3310 DPLAYX_HresultToString(hr) );
3313 return hr;
3316 static HRESULT WINAPI IDirectPlay2AImpl_Open( IDirectPlay2A *iface, DPSESSIONDESC2 *sdesc,
3317 DWORD flags )
3319 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3320 return IDirectPlayX_Open( &This->IDirectPlay4A_iface, sdesc, flags );
3323 static HRESULT WINAPI IDirectPlay2Impl_Open( IDirectPlay2 *iface, DPSESSIONDESC2 *sdesc,
3324 DWORD flags )
3326 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3327 return IDirectPlayX_Open( &This->IDirectPlay4_iface, sdesc, flags );
3330 static HRESULT WINAPI IDirectPlay3AImpl_Open( IDirectPlay3A *iface, DPSESSIONDESC2 *sdesc,
3331 DWORD flags )
3333 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3334 return IDirectPlayX_Open( &This->IDirectPlay4_iface, sdesc, flags );
3337 static HRESULT WINAPI IDirectPlay3Impl_Open( IDirectPlay3 *iface, DPSESSIONDESC2 *sdesc,
3338 DWORD flags )
3340 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3341 return IDirectPlayX_Open( &This->IDirectPlay4_iface, sdesc, flags );
3344 static HRESULT WINAPI IDirectPlay4AImpl_Open( IDirectPlay4A *iface, DPSESSIONDESC2 *sdesc,
3345 DWORD flags )
3347 return IDirectPlayX_SecureOpen( iface, sdesc, flags, NULL, NULL );
3350 static HRESULT WINAPI IDirectPlay4Impl_Open( IDirectPlay4 *iface, DPSESSIONDESC2 *sdesc,
3351 DWORD flags )
3353 return IDirectPlayX_SecureOpen( iface, sdesc, flags, NULL, NULL );
3356 static HRESULT DP_IF_Receive( IDirectPlayImpl *This, DPID *lpidFrom, DPID *lpidTo, DWORD dwFlags,
3357 void *lpData, DWORD *lpdwDataSize, BOOL bAnsi )
3359 LPDPMSG lpMsg = NULL;
3361 FIXME( "(%p)->(%p,%p,0x%08x,%p,%p,%u): stub\n",
3362 This, lpidFrom, lpidTo, dwFlags, lpData, lpdwDataSize, bAnsi );
3364 if( This->dp2->connectionInitialized == NO_PROVIDER )
3366 return DPERR_UNINITIALIZED;
3369 if( dwFlags == 0 )
3371 dwFlags = DPRECEIVE_ALL;
3374 /* If the lpData is NULL, we must be peeking the message */
3375 if( ( lpData == NULL ) &&
3376 !( dwFlags & DPRECEIVE_PEEK )
3379 return DPERR_INVALIDPARAMS;
3382 if( dwFlags & DPRECEIVE_ALL )
3384 lpMsg = This->dp2->receiveMsgs.lpQHFirst;
3386 if( !( dwFlags & DPRECEIVE_PEEK ) )
3388 FIXME( "Remove from queue\n" );
3391 else if( ( dwFlags & DPRECEIVE_TOPLAYER ) ||
3392 ( dwFlags & DPRECEIVE_FROMPLAYER )
3395 FIXME( "Find matching message 0x%08x\n", dwFlags );
3397 else
3399 ERR( "Hmmm..dwFlags 0x%08x\n", dwFlags );
3402 if( lpMsg == NULL )
3404 return DPERR_NOMESSAGES;
3407 /* Copy into the provided buffer */
3408 if (lpData) CopyMemory( lpData, lpMsg->msg, *lpdwDataSize );
3410 return DP_OK;
3413 static HRESULT WINAPI IDirectPlay2AImpl_Receive( IDirectPlay2A *iface, DPID *from, DPID *to,
3414 DWORD flags, void *data, DWORD *size )
3416 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3417 return IDirectPlayX_Receive( &This->IDirectPlay4A_iface, from, to, flags, data, size );
3420 static HRESULT WINAPI IDirectPlay2Impl_Receive( IDirectPlay2 *iface, DPID *from, DPID *to,
3421 DWORD flags, void *data, DWORD *size )
3423 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3424 return IDirectPlayX_Receive( &This->IDirectPlay4_iface, from, to, flags, data, size );
3427 static HRESULT WINAPI IDirectPlay3AImpl_Receive( IDirectPlay3A *iface, DPID *from, DPID *to,
3428 DWORD flags, void *data, DWORD *size )
3430 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3431 return IDirectPlayX_Receive( &This->IDirectPlay4_iface, from, to, flags, data, size );
3434 static HRESULT WINAPI IDirectPlay3Impl_Receive( IDirectPlay3 *iface, DPID *from, DPID *to,
3435 DWORD flags, void *data, DWORD *size )
3437 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3438 return IDirectPlayX_Receive( &This->IDirectPlay4_iface, from, to, flags, data, size );
3441 static HRESULT WINAPI IDirectPlay4AImpl_Receive( IDirectPlay4A *iface, DPID *lpidFrom,
3442 DPID *lpidTo, DWORD dwFlags, void *lpData, DWORD *lpdwDataSize )
3444 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3445 return DP_IF_Receive( This, lpidFrom, lpidTo, dwFlags, lpData, lpdwDataSize, TRUE );
3448 static HRESULT WINAPI IDirectPlay4Impl_Receive( IDirectPlay4 *iface, DPID *lpidFrom,
3449 DPID *lpidTo, DWORD dwFlags, void *lpData, DWORD *lpdwDataSize )
3451 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3452 return DP_IF_Receive( This, lpidFrom, lpidTo, dwFlags, lpData, lpdwDataSize, FALSE );
3455 static HRESULT WINAPI IDirectPlay2AImpl_Send( IDirectPlay2A *iface, DPID from, DPID to,
3456 DWORD flags, void *data, DWORD size )
3458 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3459 return IDirectPlayX_Send( &This->IDirectPlay4A_iface, from, to, flags, data, size );
3462 static HRESULT WINAPI IDirectPlay2Impl_Send( IDirectPlay2 *iface, DPID from, DPID to,
3463 DWORD flags, void *data, DWORD size )
3465 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3466 return IDirectPlayX_Send( &This->IDirectPlay4_iface, from, to, flags, data, size );
3469 static HRESULT WINAPI IDirectPlay3AImpl_Send( IDirectPlay3A *iface, DPID from, DPID to,
3470 DWORD flags, void *data, DWORD size )
3472 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3473 return IDirectPlayX_Send( &This->IDirectPlay4_iface, from, to, flags, data, size );
3476 static HRESULT WINAPI IDirectPlay3Impl_Send( IDirectPlay3 *iface, DPID from, DPID to,
3477 DWORD flags, void *data, DWORD size )
3479 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3480 return IDirectPlayX_Send( &This->IDirectPlay4_iface, from, to, flags, data, size );
3483 static HRESULT WINAPI IDirectPlay4AImpl_Send( IDirectPlay4A *iface, DPID from, DPID to,
3484 DWORD flags, void *data, DWORD size )
3486 return IDirectPlayX_SendEx( iface, from, to, flags, data, size, 0, 0, NULL, NULL );
3489 static HRESULT WINAPI IDirectPlay4Impl_Send( IDirectPlay4 *iface, DPID from, DPID to,
3490 DWORD flags, void *data, DWORD size )
3492 return IDirectPlayX_SendEx( iface, from, to, flags, data, size, 0, 0, NULL, NULL );
3495 static HRESULT WINAPI IDirectPlay2AImpl_SetGroupData( IDirectPlay2A *iface, DPID group, void *data,
3496 DWORD size, DWORD flags )
3498 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3499 return IDirectPlayX_SetGroupData( &This->IDirectPlay4A_iface, group, data, size, flags );
3502 static HRESULT WINAPI IDirectPlay2Impl_SetGroupData( IDirectPlay2 *iface, DPID group, void *data,
3503 DWORD size, DWORD flags )
3505 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3506 return IDirectPlayX_SetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
3509 static HRESULT WINAPI IDirectPlay3AImpl_SetGroupData( IDirectPlay3A *iface, DPID group, void *data,
3510 DWORD size, DWORD flags )
3512 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3513 return IDirectPlayX_SetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
3516 static HRESULT WINAPI IDirectPlay3Impl_SetGroupData( IDirectPlay3 *iface, DPID group, void *data,
3517 DWORD size, DWORD flags )
3519 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3520 return IDirectPlayX_SetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
3523 static HRESULT WINAPI IDirectPlay4AImpl_SetGroupData( IDirectPlay4A *iface, DPID group, void *data,
3524 DWORD size, DWORD flags )
3526 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3527 return IDirectPlayX_SetGroupData( &This->IDirectPlay4_iface, group, data, size, flags );
3530 static HRESULT WINAPI IDirectPlay4Impl_SetGroupData( IDirectPlay4 *iface, DPID group, void *data,
3531 DWORD size, DWORD flags )
3533 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3534 lpGroupData gdata;
3536 TRACE( "(%p)->(0x%08x,%p,0x%08x,0x%08x)\n", This, group, data, size, flags );
3538 /* Parameter check */
3539 if ( !data && size )
3540 return DPERR_INVALIDPARAMS;
3542 /* Find the pointer to the data for this player */
3543 if ( ( gdata = DP_FindAnyGroup( This, group ) ) == NULL )
3544 return DPERR_INVALIDOBJECT;
3546 if ( !(flags & DPSET_LOCAL) )
3548 FIXME( "Was this group created by this interface?\n" );
3549 /* FIXME: If this is a remote update need to allow it but not
3550 * send a message.
3554 DP_SetGroupData( gdata, flags, data, size );
3556 /* FIXME: Only send a message if this group is local to the session otherwise
3557 * it will have been rejected above
3559 if ( !(flags & DPSET_LOCAL) )
3560 FIXME( "Send msg?\n" );
3562 return DP_OK;
3565 static HRESULT DP_IF_SetGroupName( IDirectPlayImpl *This, DPID idGroup, DPNAME *lpGroupName,
3566 DWORD dwFlags, BOOL bAnsi )
3568 lpGroupData lpGData;
3570 TRACE( "(%p)->(0x%08x,%p,0x%08x,%u)\n", This, idGroup,
3571 lpGroupName, dwFlags, bAnsi );
3573 if( ( lpGData = DP_FindAnyGroup( This, idGroup ) ) == NULL )
3575 return DPERR_INVALIDGROUP;
3578 DP_CopyDPNAMEStruct( &lpGData->name, lpGroupName, bAnsi );
3580 /* Should send a DPMSG_SETPLAYERORGROUPNAME message */
3581 FIXME( "Message not sent and dwFlags ignored\n" );
3583 return DP_OK;
3586 static HRESULT WINAPI IDirectPlay2AImpl_SetGroupName( IDirectPlay2A *iface, DPID group,
3587 DPNAME *name, DWORD flags )
3589 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3590 return IDirectPlayX_SetGroupName( &This->IDirectPlay4A_iface, group, name, flags );
3593 static HRESULT WINAPI IDirectPlay2Impl_SetGroupName( IDirectPlay2 *iface, DPID group,
3594 DPNAME *name, DWORD flags )
3596 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3597 return IDirectPlayX_SetGroupName( &This->IDirectPlay4_iface, group, name, flags );
3600 static HRESULT WINAPI IDirectPlay3AImpl_SetGroupName( IDirectPlay3A *iface, DPID group,
3601 DPNAME *name, DWORD flags )
3603 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3604 return IDirectPlayX_SetGroupName( &This->IDirectPlay4_iface, group, name, flags );
3607 static HRESULT WINAPI IDirectPlay3Impl_SetGroupName( IDirectPlay3 *iface, DPID group,
3608 DPNAME *name, DWORD flags )
3610 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3611 return IDirectPlayX_SetGroupName( &This->IDirectPlay4_iface, group, name, flags );
3614 static HRESULT WINAPI IDirectPlay4AImpl_SetGroupName( IDirectPlay4A *iface, DPID idGroup,
3615 DPNAME *lpGroupName, DWORD dwFlags )
3617 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3618 return DP_IF_SetGroupName( This, idGroup, lpGroupName, dwFlags, TRUE );
3621 static HRESULT WINAPI IDirectPlay4Impl_SetGroupName( IDirectPlay4 *iface, DPID idGroup,
3622 DPNAME *lpGroupName, DWORD dwFlags )
3624 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3625 return DP_IF_SetGroupName( This, idGroup, lpGroupName, dwFlags, FALSE );
3628 static HRESULT WINAPI IDirectPlay2AImpl_SetPlayerData( IDirectPlay2A *iface, DPID player,
3629 void *data, DWORD size, DWORD flags )
3631 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3632 return IDirectPlayX_SetPlayerData( &This->IDirectPlay4A_iface, player, data, size, flags );
3635 static HRESULT WINAPI IDirectPlay2Impl_SetPlayerData( IDirectPlay2 *iface, DPID player,
3636 void *data, DWORD size, DWORD flags )
3638 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3639 return IDirectPlayX_SetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
3642 static HRESULT WINAPI IDirectPlay3AImpl_SetPlayerData( IDirectPlay3A *iface, DPID player,
3643 void *data, DWORD size, DWORD flags )
3645 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3646 return IDirectPlayX_SetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
3649 static HRESULT WINAPI IDirectPlay3Impl_SetPlayerData( IDirectPlay3 *iface, DPID player,
3650 void *data, DWORD size, DWORD flags )
3652 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3653 return IDirectPlayX_SetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
3656 static HRESULT WINAPI IDirectPlay4AImpl_SetPlayerData( IDirectPlay4A *iface, DPID player,
3657 void *data, DWORD size, DWORD flags )
3659 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3660 return IDirectPlayX_SetPlayerData( &This->IDirectPlay4_iface, player, data, size, flags );
3663 static HRESULT WINAPI IDirectPlay4Impl_SetPlayerData( IDirectPlay4 *iface, DPID player,
3664 void *data, DWORD size, DWORD flags )
3666 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3667 lpPlayerList plist;
3669 TRACE( "(%p)->(0x%08x,%p,0x%08x,0x%08x)\n", This, player, data, size, flags );
3671 if ( This->dp2->connectionInitialized == NO_PROVIDER )
3672 return DPERR_UNINITIALIZED;
3674 /* Parameter check */
3675 if ( !data && size )
3676 return DPERR_INVALIDPARAMS;
3678 /* Find the pointer to the data for this player */
3679 if ( (plist = DP_FindPlayer( This, player )) == NULL )
3680 return DPERR_INVALIDPLAYER;
3682 if ( !(flags & DPSET_LOCAL) )
3684 FIXME( "Was this group created by this interface?\n" );
3685 /* FIXME: If this is a remote update need to allow it but not
3686 * send a message.
3690 DP_SetPlayerData( plist->lpPData, flags, data, size );
3692 if ( !(flags & DPSET_LOCAL) )
3693 FIXME( "Send msg?\n" );
3695 return DP_OK;
3698 static HRESULT DP_IF_SetPlayerName( IDirectPlayImpl *This, DPID idPlayer, DPNAME *lpPlayerName,
3699 DWORD dwFlags, BOOL bAnsi )
3701 lpPlayerList lpPList;
3703 TRACE( "(%p)->(0x%08x,%p,0x%08x,%u)\n",
3704 This, idPlayer, lpPlayerName, dwFlags, bAnsi );
3706 if( This->dp2->connectionInitialized == NO_PROVIDER )
3708 return DPERR_UNINITIALIZED;
3711 if( ( lpPList = DP_FindPlayer( This, idPlayer ) ) == NULL )
3713 return DPERR_INVALIDGROUP;
3716 DP_CopyDPNAMEStruct( &lpPList->lpPData->name, lpPlayerName, bAnsi );
3718 /* Should send a DPMSG_SETPLAYERORGROUPNAME message */
3719 FIXME( "Message not sent and dwFlags ignored\n" );
3721 return DP_OK;
3724 static HRESULT WINAPI IDirectPlay2AImpl_SetPlayerName( IDirectPlay2A *iface, DPID player,
3725 DPNAME *name, DWORD flags )
3727 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3728 return IDirectPlayX_SetPlayerName( &This->IDirectPlay4A_iface, player, name, flags );
3731 static HRESULT WINAPI IDirectPlay2Impl_SetPlayerName( IDirectPlay2 *iface, DPID player,
3732 DPNAME *name, DWORD flags )
3734 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3735 return IDirectPlayX_SetPlayerName( &This->IDirectPlay4_iface, player, name, flags );
3738 static HRESULT WINAPI IDirectPlay3AImpl_SetPlayerName( IDirectPlay3A *iface, DPID player,
3739 DPNAME *name, DWORD flags )
3741 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3742 return IDirectPlayX_SetPlayerName( &This->IDirectPlay4_iface, player, name, flags );
3745 static HRESULT WINAPI IDirectPlay3Impl_SetPlayerName( IDirectPlay3 *iface, DPID player,
3746 DPNAME *name, DWORD flags )
3748 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3749 return IDirectPlayX_SetPlayerName( &This->IDirectPlay4_iface, player, name, flags );
3752 static HRESULT WINAPI IDirectPlay4AImpl_SetPlayerName( IDirectPlay4A *iface, DPID idPlayer,
3753 DPNAME *lpPlayerName, DWORD dwFlags )
3755 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3756 return DP_IF_SetPlayerName( This, idPlayer, lpPlayerName, dwFlags, TRUE );
3759 static HRESULT WINAPI IDirectPlay4Impl_SetPlayerName( IDirectPlay4 *iface, DPID idPlayer,
3760 DPNAME *lpPlayerName, DWORD dwFlags )
3762 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3763 return DP_IF_SetPlayerName( This, idPlayer, lpPlayerName, dwFlags, FALSE );
3766 static HRESULT DP_SetSessionDesc( IDirectPlayImpl *This, const DPSESSIONDESC2 *lpSessDesc,
3767 DWORD dwFlags, BOOL bInitial, BOOL bAnsi )
3769 DWORD dwRequiredSize;
3770 LPDPSESSIONDESC2 lpTempSessDesc;
3772 TRACE( "(%p)->(%p,0x%08x,%u,%u)\n",
3773 This, lpSessDesc, dwFlags, bInitial, bAnsi );
3775 if( This->dp2->connectionInitialized == NO_PROVIDER )
3777 return DPERR_UNINITIALIZED;
3780 if( dwFlags )
3782 return DPERR_INVALIDPARAMS;
3785 /* Only the host is allowed to update the session desc */
3786 if( !This->dp2->bHostInterface )
3788 return DPERR_ACCESSDENIED;
3791 /* FIXME: Copy into This->dp2->lpSessionDesc */
3792 dwRequiredSize = DP_CalcSessionDescSize( lpSessDesc, bAnsi );
3793 lpTempSessDesc = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwRequiredSize );
3795 if( lpTempSessDesc == NULL )
3797 return DPERR_OUTOFMEMORY;
3800 /* Free the old */
3801 HeapFree( GetProcessHeap(), 0, This->dp2->lpSessionDesc );
3803 This->dp2->lpSessionDesc = lpTempSessDesc;
3804 /* Set the new */
3805 DP_CopySessionDesc( This->dp2->lpSessionDesc, lpSessDesc, bAnsi );
3806 if( bInitial )
3808 /*Initializing session GUID*/
3809 CoCreateGuid( &(This->dp2->lpSessionDesc->guidInstance) );
3811 /* If this is an external invocation of the interface, we should be
3812 * letting everyone know that things have changed. Otherwise this is
3813 * just an initialization and it doesn't need to be propagated.
3815 if( !bInitial )
3817 FIXME( "Need to send a DPMSG_SETSESSIONDESC msg to everyone\n" );
3820 return DP_OK;
3823 static HRESULT WINAPI IDirectPlay2AImpl_SetSessionDesc( IDirectPlay2A *iface, DPSESSIONDESC2 *sdesc,
3824 DWORD flags )
3826 IDirectPlayImpl *This = impl_from_IDirectPlay2A( iface );
3827 return IDirectPlayX_SetSessionDesc( &This->IDirectPlay4A_iface, sdesc, flags );
3830 static HRESULT WINAPI IDirectPlay2Impl_SetSessionDesc( IDirectPlay2 *iface, DPSESSIONDESC2 *sdesc,
3831 DWORD flags )
3833 IDirectPlayImpl *This = impl_from_IDirectPlay2( iface );
3834 return IDirectPlayX_SetSessionDesc( &This->IDirectPlay4_iface, sdesc, flags );
3837 static HRESULT WINAPI IDirectPlay3AImpl_SetSessionDesc( IDirectPlay3A *iface, DPSESSIONDESC2 *sdesc,
3838 DWORD flags )
3840 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3841 return IDirectPlayX_SetSessionDesc( &This->IDirectPlay4_iface, sdesc, flags );
3844 static HRESULT WINAPI IDirectPlay3Impl_SetSessionDesc( IDirectPlay3 *iface, DPSESSIONDESC2 *sdesc,
3845 DWORD flags )
3847 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3848 return IDirectPlayX_SetSessionDesc( &This->IDirectPlay4_iface, sdesc, flags );
3851 static HRESULT WINAPI IDirectPlay4AImpl_SetSessionDesc( IDirectPlay4A *iface,
3852 DPSESSIONDESC2 *lpSessDesc, DWORD dwFlags )
3854 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3855 return DP_SetSessionDesc( This, lpSessDesc, dwFlags, FALSE, TRUE );
3858 static HRESULT WINAPI IDirectPlay4Impl_SetSessionDesc( IDirectPlay4 *iface,
3859 DPSESSIONDESC2 *lpSessDesc, DWORD dwFlags )
3861 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3862 return DP_SetSessionDesc( This, lpSessDesc, dwFlags, FALSE, TRUE );
3865 /* FIXME: See about merging some of this stuff with dplayx_global.c stuff */
3866 static DWORD DP_CalcSessionDescSize( LPCDPSESSIONDESC2 lpSessDesc, BOOL bAnsi )
3868 DWORD dwSize = 0;
3870 if( lpSessDesc == NULL )
3872 /* Hmmm..don't need any size? */
3873 ERR( "NULL lpSessDesc\n" );
3874 return dwSize;
3877 dwSize += sizeof( *lpSessDesc );
3879 if( bAnsi )
3881 if( lpSessDesc->u1.lpszSessionNameA )
3883 dwSize += lstrlenA( lpSessDesc->u1.lpszSessionNameA ) + 1;
3886 if( lpSessDesc->u2.lpszPasswordA )
3888 dwSize += lstrlenA( lpSessDesc->u2.lpszPasswordA ) + 1;
3891 else /* UNICODE */
3893 if( lpSessDesc->u1.lpszSessionName )
3895 dwSize += sizeof( WCHAR ) *
3896 ( lstrlenW( lpSessDesc->u1.lpszSessionName ) + 1 );
3899 if( lpSessDesc->u2.lpszPassword )
3901 dwSize += sizeof( WCHAR ) *
3902 ( lstrlenW( lpSessDesc->u2.lpszPassword ) + 1 );
3906 return dwSize;
3909 /* Assumes that contiguous buffers are already allocated. */
3910 static void DP_CopySessionDesc( LPDPSESSIONDESC2 lpSessionDest,
3911 LPCDPSESSIONDESC2 lpSessionSrc, BOOL bAnsi )
3913 BYTE* lpStartOfFreeSpace;
3915 if( lpSessionDest == NULL )
3917 ERR( "NULL lpSessionDest\n" );
3918 return;
3921 CopyMemory( lpSessionDest, lpSessionSrc, sizeof( *lpSessionSrc ) );
3923 lpStartOfFreeSpace = ((BYTE*)lpSessionDest) + sizeof( *lpSessionSrc );
3925 if( bAnsi )
3927 if( lpSessionSrc->u1.lpszSessionNameA )
3929 lstrcpyA( (LPSTR)lpStartOfFreeSpace,
3930 lpSessionDest->u1.lpszSessionNameA );
3931 lpSessionDest->u1.lpszSessionNameA = (LPSTR)lpStartOfFreeSpace;
3932 lpStartOfFreeSpace +=
3933 lstrlenA( lpSessionDest->u1.lpszSessionNameA ) + 1;
3936 if( lpSessionSrc->u2.lpszPasswordA )
3938 lstrcpyA( (LPSTR)lpStartOfFreeSpace,
3939 lpSessionDest->u2.lpszPasswordA );
3940 lpSessionDest->u2.lpszPasswordA = (LPSTR)lpStartOfFreeSpace;
3943 else /* UNICODE */
3945 if( lpSessionSrc->u1.lpszSessionName )
3947 lstrcpyW( (LPWSTR)lpStartOfFreeSpace,
3948 lpSessionDest->u1.lpszSessionName );
3949 lpSessionDest->u1.lpszSessionName = (LPWSTR)lpStartOfFreeSpace;
3950 lpStartOfFreeSpace += sizeof(WCHAR) *
3951 ( lstrlenW( lpSessionDest->u1.lpszSessionName ) + 1 );
3954 if( lpSessionSrc->u2.lpszPassword )
3956 lstrcpyW( (LPWSTR)lpStartOfFreeSpace,
3957 lpSessionDest->u2.lpszPassword );
3958 lpSessionDest->u2.lpszPassword = (LPWSTR)lpStartOfFreeSpace;
3963 static HRESULT WINAPI IDirectPlay3AImpl_AddGroupToGroup( IDirectPlay3A *iface, DPID parent,
3964 DPID group )
3966 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
3967 return IDirectPlayX_AddGroupToGroup( &This->IDirectPlay4A_iface, parent, group );
3970 static HRESULT WINAPI IDirectPlay3Impl_AddGroupToGroup( IDirectPlay3 *iface, DPID parent,
3971 DPID group )
3973 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
3974 return IDirectPlayX_AddGroupToGroup( &This->IDirectPlay4_iface, parent, group );
3977 static HRESULT WINAPI IDirectPlay4AImpl_AddGroupToGroup( IDirectPlay4A *iface, DPID parent,
3978 DPID group )
3980 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
3981 return IDirectPlayX_AddGroupToGroup( &This->IDirectPlay4_iface, parent, group );
3984 static HRESULT WINAPI IDirectPlay4Impl_AddGroupToGroup( IDirectPlay4 *iface, DPID parent,
3985 DPID group )
3987 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
3988 lpGroupData gdata;
3989 lpGroupList glist;
3991 TRACE( "(%p)->(0x%08x,0x%08x)\n", This, parent, group );
3993 if ( This->dp2->connectionInitialized == NO_PROVIDER )
3994 return DPERR_UNINITIALIZED;
3996 if ( !DP_FindAnyGroup(This, parent ) )
3997 return DPERR_INVALIDGROUP;
3999 if ( ( gdata = DP_FindAnyGroup(This, group ) ) == NULL )
4000 return DPERR_INVALIDGROUP;
4002 /* Create a player list (ie "shortcut" ) */
4003 glist = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *glist ) );
4004 if ( !glist )
4005 return DPERR_CANTADDPLAYER;
4007 /* Add the shortcut */
4008 gdata->uRef++;
4009 glist->lpGData = gdata;
4011 /* Add the player to the list of players for this group */
4012 DPQ_INSERT( gdata->groups, glist, groups );
4014 /* Send a ADDGROUPTOGROUP message */
4015 FIXME( "Not sending message\n" );
4017 return DP_OK;
4020 static HRESULT DP_IF_CreateGroupInGroup( IDirectPlayImpl *This, void *lpMsgHdr, DPID idParentGroup,
4021 DPID *lpidGroup, DPNAME *lpGroupName, void *lpData, DWORD dwDataSize, DWORD dwFlags,
4022 BOOL bAnsi )
4024 lpGroupData lpGParentData;
4025 lpGroupList lpGList;
4026 lpGroupData lpGData;
4028 TRACE( "(%p)->(0x%08x,%p,%p,%p,0x%08x,0x%08x,%u)\n",
4029 This, idParentGroup, lpidGroup, lpGroupName, lpData,
4030 dwDataSize, dwFlags, bAnsi );
4032 if( This->dp2->connectionInitialized == NO_PROVIDER )
4034 return DPERR_UNINITIALIZED;
4037 /* Verify that the specified parent is valid */
4038 if( ( lpGParentData = DP_FindAnyGroup(This, idParentGroup ) ) == NULL )
4039 return DPERR_INVALIDGROUP;
4041 lpGData = DP_CreateGroup(This, lpidGroup, lpGroupName, dwFlags, idParentGroup, bAnsi );
4043 if( lpGData == NULL )
4045 return DPERR_CANTADDPLAYER; /* yes player not group */
4048 /* Something else is referencing this data */
4049 lpGData->uRef++;
4051 DP_SetGroupData( lpGData, DPSET_REMOTE, lpData, dwDataSize );
4053 /* The list has now been inserted into the interface group list. We now
4054 need to put a "shortcut" to this group in the parent group */
4055 lpGList = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpGList ) );
4056 if( lpGList == NULL )
4058 FIXME( "Memory leak\n" );
4059 return DPERR_CANTADDPLAYER; /* yes player not group */
4062 lpGList->lpGData = lpGData;
4064 DPQ_INSERT( lpGParentData->groups, lpGList, groups );
4066 /* Let the SP know that we've created this group */
4067 if( This->dp2->spData.lpCB->CreateGroup )
4069 DPSP_CREATEGROUPDATA data;
4071 TRACE( "Calling SP CreateGroup\n" );
4073 data.idGroup = *lpidGroup;
4074 data.dwFlags = dwFlags;
4075 data.lpSPMessageHeader = lpMsgHdr;
4076 data.lpISP = This->dp2->spData.lpISP;
4078 (*This->dp2->spData.lpCB->CreateGroup)( &data );
4081 /* Inform all other peers of the creation of a new group. If there are
4082 * no peers keep this quiet.
4084 if( This->dp2->lpSessionDesc &&
4085 ( This->dp2->lpSessionDesc->dwFlags & DPSESSION_MULTICASTSERVER ) )
4087 DPMSG_CREATEPLAYERORGROUP msg;
4089 msg.dwType = DPSYS_CREATEPLAYERORGROUP;
4090 msg.dwPlayerType = DPPLAYERTYPE_GROUP;
4091 msg.dpId = *lpidGroup;
4092 msg.dwCurrentPlayers = idParentGroup; /* FIXME: Incorrect? */
4093 msg.lpData = lpData;
4094 msg.dwDataSize = dwDataSize;
4095 msg.dpnName = *lpGroupName;
4097 /* FIXME: Correct to just use send effectively? */
4098 /* FIXME: Should size include data w/ message or just message "header" */
4099 /* FIXME: Check return code */
4100 IDirectPlayX_SendEx( &This->IDirectPlay4_iface, DPID_SERVERPLAYER, DPID_ALLPLAYERS, 0, &msg,
4101 sizeof( msg ), 0, 0, NULL, NULL );
4104 return DP_OK;
4107 static HRESULT WINAPI IDirectPlay3AImpl_CreateGroupInGroup( IDirectPlay3A *iface, DPID parent,
4108 DPID *group, DPNAME *name, void *data, DWORD size, DWORD flags )
4110 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4111 return IDirectPlayX_CreateGroupInGroup( &This->IDirectPlay4A_iface, parent, group, name,
4112 data, size, flags );
4115 static HRESULT WINAPI IDirectPlay3Impl_CreateGroupInGroup( IDirectPlay3 *iface, DPID parent,
4116 DPID *group, DPNAME *name, void *data, DWORD size, DWORD flags )
4118 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4119 return IDirectPlayX_CreateGroupInGroup( &This->IDirectPlay4_iface, parent, group, name,
4120 data, size, flags );
4123 static HRESULT WINAPI IDirectPlay4AImpl_CreateGroupInGroup( IDirectPlay4A *iface,
4124 DPID idParentGroup, DPID *lpidGroup, DPNAME *lpGroupName, void *lpData, DWORD dwDataSize,
4125 DWORD dwFlags )
4127 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4129 *lpidGroup = DPID_UNKNOWN;
4131 return DP_IF_CreateGroupInGroup( This, NULL, idParentGroup, lpidGroup, lpGroupName, lpData,
4132 dwDataSize, dwFlags, TRUE );
4135 static HRESULT WINAPI IDirectPlay4Impl_CreateGroupInGroup( IDirectPlay4 *iface, DPID idParentGroup,
4136 DPID *lpidGroup, DPNAME *lpGroupName, void *lpData, DWORD dwDataSize, DWORD dwFlags )
4138 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4140 *lpidGroup = DPID_UNKNOWN;
4142 return DP_IF_CreateGroupInGroup( This, NULL, idParentGroup, lpidGroup, lpGroupName, lpData,
4143 dwDataSize, dwFlags, FALSE );
4146 static HRESULT WINAPI IDirectPlay3AImpl_DeleteGroupFromGroup( IDirectPlay3A *iface, DPID parent,
4147 DPID group )
4149 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4150 return IDirectPlayX_DeleteGroupFromGroup( &This->IDirectPlay4A_iface, parent, group );
4153 static HRESULT WINAPI IDirectPlay3Impl_DeleteGroupFromGroup( IDirectPlay3 *iface, DPID parent,
4154 DPID group )
4156 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4157 return IDirectPlayX_DeleteGroupFromGroup( &This->IDirectPlay4_iface, parent, group );
4160 static HRESULT WINAPI IDirectPlay4AImpl_DeleteGroupFromGroup( IDirectPlay4A *iface, DPID parent,
4161 DPID group )
4163 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4164 return IDirectPlayX_DeleteGroupFromGroup( &This->IDirectPlay4_iface, parent, group );
4167 static HRESULT WINAPI IDirectPlay4Impl_DeleteGroupFromGroup( IDirectPlay4 *iface, DPID parent,
4168 DPID group )
4170 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4171 lpGroupList glist;
4172 lpGroupData parentdata;
4174 TRACE("(%p)->(0x%08x,0x%08x)\n", This, parent, group );
4176 /* Is the parent group valid? */
4177 if ( ( parentdata = DP_FindAnyGroup(This, parent ) ) == NULL )
4178 return DPERR_INVALIDGROUP;
4180 /* Remove the group from the parent group queue */
4181 DPQ_REMOVE_ENTRY( parentdata->groups, groups, lpGData->dpid, ==, group, glist );
4183 if ( glist == NULL )
4184 return DPERR_INVALIDGROUP;
4186 /* Decrement the ref count */
4187 glist->lpGData->uRef--;
4189 /* Free up the list item */
4190 HeapFree( GetProcessHeap(), 0, glist );
4192 /* Should send a DELETEGROUPFROMGROUP message */
4193 FIXME( "message not sent\n" );
4195 return DP_OK;
4198 static BOOL DP_BuildSPCompoundAddr( LPGUID lpcSpGuid, LPVOID* lplpAddrBuf,
4199 LPDWORD lpdwBufSize )
4201 DPCOMPOUNDADDRESSELEMENT dpCompoundAddress;
4202 HRESULT hr;
4204 dpCompoundAddress.dwDataSize = sizeof( GUID );
4205 dpCompoundAddress.guidDataType = DPAID_ServiceProvider;
4206 dpCompoundAddress.lpData = lpcSpGuid;
4208 *lplpAddrBuf = NULL;
4209 *lpdwBufSize = 0;
4211 hr = DPL_CreateCompoundAddress( &dpCompoundAddress, 1, *lplpAddrBuf,
4212 lpdwBufSize, TRUE );
4214 if( hr != DPERR_BUFFERTOOSMALL )
4216 ERR( "can't get buffer size: %s\n", DPLAYX_HresultToString( hr ) );
4217 return FALSE;
4220 /* Now allocate the buffer */
4221 *lplpAddrBuf = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
4222 *lpdwBufSize );
4224 hr = DPL_CreateCompoundAddress( &dpCompoundAddress, 1, *lplpAddrBuf,
4225 lpdwBufSize, TRUE );
4226 if( FAILED(hr) )
4228 ERR( "can't create address: %s\n", DPLAYX_HresultToString( hr ) );
4229 return FALSE;
4232 return TRUE;
4235 static HRESULT WINAPI IDirectPlay3AImpl_EnumConnections( IDirectPlay3A *iface,
4236 const GUID *application, LPDPENUMCONNECTIONSCALLBACK enumcb, void *context, DWORD flags )
4238 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4239 return IDirectPlayX_EnumConnections( &This->IDirectPlay4A_iface, application, enumcb, context,
4240 flags );
4243 static HRESULT WINAPI IDirectPlay3Impl_EnumConnections( IDirectPlay3 *iface,
4244 const GUID *application, LPDPENUMCONNECTIONSCALLBACK enumcb, void *context, DWORD flags )
4246 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4247 return IDirectPlayX_EnumConnections( &This->IDirectPlay4_iface, application, enumcb, context,
4248 flags );
4251 static HRESULT WINAPI IDirectPlay4AImpl_EnumConnections( IDirectPlay4A *iface,
4252 const GUID *lpguidApplication, LPDPENUMCONNECTIONSCALLBACK lpEnumCallback, void *lpContext,
4253 DWORD dwFlags )
4255 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4256 TRACE("(%p)->(%p,%p,%p,0x%08x)\n", This, lpguidApplication, lpEnumCallback, lpContext, dwFlags );
4258 /* A default dwFlags (0) is backwards compatible -- DPCONNECTION_DIRECTPLAY */
4259 if( dwFlags == 0 )
4261 dwFlags = DPCONNECTION_DIRECTPLAY;
4264 if( ! ( ( dwFlags & DPCONNECTION_DIRECTPLAY ) ||
4265 ( dwFlags & DPCONNECTION_DIRECTPLAYLOBBY ) )
4268 return DPERR_INVALIDFLAGS;
4271 if( !lpEnumCallback )
4273 return DPERR_INVALIDPARAMS;
4276 /* Enumerate DirectPlay service providers */
4277 if( dwFlags & DPCONNECTION_DIRECTPLAY )
4279 HKEY hkResult;
4280 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
4281 LPCSTR guidDataSubKey = "Guid";
4282 char subKeyName[51];
4283 DWORD dwIndex, sizeOfSubKeyName=50;
4284 FILETIME filetime;
4286 /* Need to loop over the service providers in the registry */
4287 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
4288 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
4290 /* Hmmm. Does this mean that there are no service providers? */
4291 ERR(": no service providers?\n");
4292 return DP_OK;
4296 /* Traverse all the service providers we have available */
4297 for( dwIndex=0;
4298 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
4299 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
4300 ++dwIndex, sizeOfSubKeyName=51 )
4303 HKEY hkServiceProvider;
4304 GUID serviceProviderGUID;
4305 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
4306 char returnBuffer[51];
4307 WCHAR buff[51];
4308 DPNAME dpName;
4309 BOOL bBuildPass;
4311 LPVOID lpAddressBuffer = NULL;
4312 DWORD dwAddressBufferSize = 0;
4314 TRACE(" this time through: %s\n", subKeyName );
4316 /* Get a handle for this particular service provider */
4317 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
4318 &hkServiceProvider ) != ERROR_SUCCESS )
4320 ERR(": what the heck is going on?\n" );
4321 continue;
4324 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
4325 NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
4326 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
4328 ERR(": missing GUID registry data members\n" );
4329 RegCloseKey(hkServiceProvider);
4330 continue;
4332 RegCloseKey(hkServiceProvider);
4334 /* FIXME: Check return types to ensure we're interpreting data right */
4335 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, ARRAY_SIZE( buff ));
4336 CLSIDFromString( buff, &serviceProviderGUID );
4337 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
4339 /* Fill in the DPNAME struct for the service provider */
4340 dpName.dwSize = sizeof( dpName );
4341 dpName.dwFlags = 0;
4342 dpName.u1.lpszShortNameA = subKeyName;
4343 dpName.u2.lpszLongNameA = NULL;
4345 /* Create the compound address for the service provider.
4346 * NOTE: This is a gruesome architectural scar right now. DP
4347 * uses DPL and DPL uses DP. Nasty stuff. This may be why the
4348 * native dll just gets around this little bit by allocating an
4349 * 80 byte buffer which isn't even filled with a valid compound
4350 * address. Oh well. Creating a proper compound address is the
4351 * way to go anyways despite this method taking slightly more
4352 * heap space and realtime :) */
4354 bBuildPass = DP_BuildSPCompoundAddr( &serviceProviderGUID,
4355 &lpAddressBuffer,
4356 &dwAddressBufferSize );
4357 if( !bBuildPass )
4359 ERR( "Can't build compound addr\n" );
4360 return DPERR_GENERIC;
4363 /* The enumeration will return FALSE if we are not to continue */
4364 if( !lpEnumCallback( &serviceProviderGUID, lpAddressBuffer, dwAddressBufferSize,
4365 &dpName, dwFlags, lpContext ) )
4367 HeapFree( GetProcessHeap(), 0, lpAddressBuffer );
4368 return DP_OK;
4370 HeapFree( GetProcessHeap(), 0, lpAddressBuffer );
4374 /* Enumerate DirectPlayLobby service providers */
4375 if( dwFlags & DPCONNECTION_DIRECTPLAYLOBBY )
4377 HKEY hkResult;
4378 LPCSTR searchSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Lobby Providers";
4379 LPCSTR guidDataSubKey = "Guid";
4380 char subKeyName[51];
4381 DWORD dwIndex, sizeOfSubKeyName=50;
4382 FILETIME filetime;
4384 /* Need to loop over the service providers in the registry */
4385 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
4386 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
4388 TRACE("No Lobby Providers have been registered.\n");
4389 return DP_OK;
4393 /* Traverse all the lobby providers we have available */
4394 for( dwIndex=0;
4395 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
4396 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
4397 ++dwIndex, sizeOfSubKeyName=51 )
4400 HKEY hkServiceProvider;
4401 GUID serviceProviderGUID;
4402 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
4403 char returnBuffer[51];
4404 WCHAR buff[51];
4405 DPNAME dpName;
4406 HRESULT hr;
4408 DPCOMPOUNDADDRESSELEMENT dpCompoundAddress;
4409 LPVOID lpAddressBuffer = NULL;
4410 DWORD dwAddressBufferSize = 0;
4412 TRACE(" this time through: %s\n", subKeyName );
4414 /* Get a handle for this particular service provider */
4415 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
4416 &hkServiceProvider ) != ERROR_SUCCESS )
4418 ERR(": what the heck is going on?\n" );
4419 continue;
4422 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
4423 NULL, &returnTypeGUID, (LPBYTE)returnBuffer,
4424 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
4426 ERR(": missing GUID registry data members\n" );
4427 RegCloseKey(hkServiceProvider);
4428 continue;
4430 RegCloseKey(hkServiceProvider);
4432 /* FIXME: Check return types to ensure we're interpreting data right */
4433 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, ARRAY_SIZE( buff ));
4434 CLSIDFromString( buff, &serviceProviderGUID );
4435 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
4437 /* Fill in the DPNAME struct for the service provider */
4438 dpName.dwSize = sizeof( dpName );
4439 dpName.dwFlags = 0;
4440 dpName.u1.lpszShortNameA = subKeyName;
4441 dpName.u2.lpszLongNameA = NULL;
4443 /* Create the compound address for the service provider.
4444 NOTE: This is a gruesome architectural scar right now. DP uses DPL and DPL uses DP
4445 nast stuff. This may be why the native dll just gets around this little bit by
4446 allocating an 80 byte buffer which isn't even a filled with a valid compound
4447 address. Oh well. Creating a proper compound address is the way to go anyways
4448 despite this method taking slightly more heap space and realtime :) */
4450 dpCompoundAddress.guidDataType = DPAID_LobbyProvider;
4451 dpCompoundAddress.dwDataSize = sizeof( GUID );
4452 dpCompoundAddress.lpData = &serviceProviderGUID;
4454 if( ( hr = DPL_CreateCompoundAddress( &dpCompoundAddress, 1, lpAddressBuffer,
4455 &dwAddressBufferSize, TRUE ) ) != DPERR_BUFFERTOOSMALL )
4457 ERR( "can't get buffer size: %s\n", DPLAYX_HresultToString( hr ) );
4458 return hr;
4461 /* Now allocate the buffer */
4462 lpAddressBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwAddressBufferSize );
4464 if( ( hr = DPL_CreateCompoundAddress( &dpCompoundAddress, 1, lpAddressBuffer,
4465 &dwAddressBufferSize, TRUE ) ) != DP_OK )
4467 ERR( "can't create address: %s\n", DPLAYX_HresultToString( hr ) );
4468 HeapFree( GetProcessHeap(), 0, lpAddressBuffer );
4469 return hr;
4472 /* The enumeration will return FALSE if we are not to continue */
4473 if( !lpEnumCallback( &serviceProviderGUID, lpAddressBuffer, dwAddressBufferSize,
4474 &dpName, dwFlags, lpContext ) )
4476 HeapFree( GetProcessHeap(), 0, lpAddressBuffer );
4477 return DP_OK;
4479 HeapFree( GetProcessHeap(), 0, lpAddressBuffer );
4483 return DP_OK;
4486 static HRESULT WINAPI IDirectPlay4Impl_EnumConnections( IDirectPlay4 *iface,
4487 const GUID *application, LPDPENUMCONNECTIONSCALLBACK enumcb, void *context, DWORD flags )
4489 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4490 return IDirectPlayX_EnumConnections( &This->IDirectPlay4A_iface, application, enumcb, context,
4491 flags );
4494 static HRESULT WINAPI IDirectPlay3AImpl_EnumGroupsInGroup( IDirectPlay3A *iface, DPID group,
4495 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
4497 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4498 return IDirectPlayX_EnumGroupsInGroup( &This->IDirectPlay4A_iface, group, instance,
4499 enumplayercb, context, flags );
4502 static HRESULT WINAPI IDirectPlay3Impl_EnumGroupsInGroup( IDirectPlay3 *iface, DPID group,
4503 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
4505 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4506 return IDirectPlayX_EnumGroupsInGroup( &This->IDirectPlay4_iface, group, instance,
4507 enumplayercb, context, flags );
4510 static HRESULT WINAPI IDirectPlay4AImpl_EnumGroupsInGroup( IDirectPlay4A *iface, DPID group,
4511 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
4513 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4514 return IDirectPlayX_EnumGroupsInGroup( &This->IDirectPlay4_iface, group, instance,
4515 enumplayercb, context, flags );
4518 static HRESULT WINAPI IDirectPlay4Impl_EnumGroupsInGroup( IDirectPlay4 *iface, DPID group,
4519 GUID *instance, LPDPENUMPLAYERSCALLBACK2 enumplayercb, void *context, DWORD flags )
4521 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4522 lpGroupList glist;
4523 lpGroupData gdata;
4525 FIXME( "(%p)->(0x%08x,%p,%p,%p,0x%08x): semi stub\n", This, group, instance, enumplayercb,
4526 context, flags );
4528 if ( This->dp2->connectionInitialized == NO_PROVIDER )
4529 return DPERR_UNINITIALIZED;
4531 if ( ( gdata = DP_FindAnyGroup(This, group ) ) == NULL )
4532 return DPERR_INVALIDGROUP;
4534 if ( DPQ_IS_EMPTY( gdata->groups ) )
4535 return DP_OK;
4538 for( glist = DPQ_FIRST( gdata->groups ); ; glist = DPQ_NEXT( glist->groups ) )
4540 /* FIXME: Should check flags for match here */
4541 if ( !(*enumplayercb)( glist->lpGData->dpid, DPPLAYERTYPE_GROUP, &glist->lpGData->name,
4542 flags, context ) )
4543 return DP_OK; /* User requested break */
4545 if ( DPQ_IS_ENDOFLIST( glist->groups ) )
4546 break;
4549 return DP_OK;
4552 static HRESULT WINAPI IDirectPlay3AImpl_GetGroupConnectionSettings( IDirectPlay3A *iface,
4553 DWORD flags, DPID group, void *data, DWORD *size )
4555 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4556 return IDirectPlayX_GetGroupConnectionSettings( &This->IDirectPlay4A_iface, flags, group,
4557 data, size );
4560 static HRESULT WINAPI IDirectPlay3Impl_GetGroupConnectionSettings( IDirectPlay3 *iface,
4561 DWORD flags, DPID group, void *data, DWORD *size )
4563 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4564 return IDirectPlayX_GetGroupConnectionSettings( &This->IDirectPlay4_iface, flags, group,
4565 data, size );
4568 static HRESULT WINAPI IDirectPlay4AImpl_GetGroupConnectionSettings( IDirectPlay4A *iface,
4569 DWORD flags, DPID group, void *data, DWORD *size )
4571 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4572 FIXME("(%p)->(0x%08x,0x%08x,%p,%p): stub\n", This, flags, group, data, size );
4573 return DP_OK;
4576 static HRESULT WINAPI IDirectPlay4Impl_GetGroupConnectionSettings( IDirectPlay4 *iface, DWORD flags,
4577 DPID group, void *data, DWORD *size )
4579 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4580 FIXME( "(%p)->(0x%08x,0x%08x,%p,%p): stub\n", This, flags, group, data, size );
4581 return DP_OK;
4584 static BOOL CALLBACK DP_GetSpLpGuidFromCompoundAddress(
4585 REFGUID guidDataType,
4586 DWORD dwDataSize,
4587 LPCVOID lpData,
4588 LPVOID lpContext )
4590 /* Looking for the GUID of the provider to load */
4591 if( ( IsEqualGUID( guidDataType, &DPAID_ServiceProvider ) ) ||
4592 ( IsEqualGUID( guidDataType, &DPAID_LobbyProvider ) )
4595 TRACE( "Found SP/LP (%s) %s (data size = 0x%08x)\n",
4596 debugstr_guid( guidDataType ), debugstr_guid( lpData ), dwDataSize );
4598 if( dwDataSize != sizeof( GUID ) )
4600 ERR( "Invalid sp/lp guid size 0x%08x\n", dwDataSize );
4603 memcpy( lpContext, lpData, dwDataSize );
4605 /* There shouldn't be more than 1 GUID/compound address */
4606 return FALSE;
4609 /* Still waiting for what we want */
4610 return TRUE;
4614 /* Find and perform a LoadLibrary on the requested SP or LP GUID */
4615 static HMODULE DP_LoadSP( LPCGUID lpcGuid, LPSPINITDATA lpSpData, LPBOOL lpbIsDpSp )
4617 UINT i;
4618 LPCSTR spSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Service Providers";
4619 LPCSTR lpSubKey = "SOFTWARE\\Microsoft\\DirectPlay\\Lobby Providers";
4620 LPCSTR guidDataSubKey = "Guid";
4621 LPCSTR majVerDataSubKey = "dwReserved1";
4622 LPCSTR minVerDataSubKey = "dwReserved2";
4623 LPCSTR pathSubKey = "Path";
4625 TRACE( " request to load %s\n", debugstr_guid( lpcGuid ) );
4627 /* FIXME: Cloned code with a quick hack. */
4628 for( i=0; i<2; i++ )
4630 HKEY hkResult;
4631 LPCSTR searchSubKey;
4632 char subKeyName[51];
4633 DWORD dwIndex, sizeOfSubKeyName=50;
4634 FILETIME filetime;
4636 (i == 0) ? (searchSubKey = spSubKey ) : (searchSubKey = lpSubKey );
4637 *lpbIsDpSp = (i == 0);
4640 /* Need to loop over the service providers in the registry */
4641 if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, searchSubKey,
4642 0, KEY_READ, &hkResult ) != ERROR_SUCCESS )
4644 /* Hmmm. Does this mean that there are no service providers? */
4645 ERR(": no service providers?\n");
4646 return 0;
4649 /* Traverse all the service providers we have available */
4650 for( dwIndex=0;
4651 RegEnumKeyExA( hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
4652 NULL, NULL, NULL, &filetime ) != ERROR_NO_MORE_ITEMS;
4653 ++dwIndex, sizeOfSubKeyName=51 )
4656 HKEY hkServiceProvider;
4657 GUID serviceProviderGUID;
4658 DWORD returnType, sizeOfReturnBuffer = 255;
4659 char returnBuffer[256];
4660 WCHAR buff[51];
4661 DWORD dwTemp, len;
4663 TRACE(" this time through: %s\n", subKeyName );
4665 /* Get a handle for this particular service provider */
4666 if( RegOpenKeyExA( hkResult, subKeyName, 0, KEY_READ,
4667 &hkServiceProvider ) != ERROR_SUCCESS )
4669 ERR(": what the heck is going on?\n" );
4670 continue;
4673 if( RegQueryValueExA( hkServiceProvider, guidDataSubKey,
4674 NULL, &returnType, (LPBYTE)returnBuffer,
4675 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
4677 ERR(": missing GUID registry data members\n" );
4678 continue;
4681 /* FIXME: Check return types to ensure we're interpreting data right */
4682 MultiByteToWideChar( CP_ACP, 0, returnBuffer, -1, buff, ARRAY_SIZE( buff ));
4683 CLSIDFromString( buff, &serviceProviderGUID );
4684 /* FIXME: Have I got a memory leak on the serviceProviderGUID? */
4686 /* Determine if this is the Service Provider that the user asked for */
4687 if( !IsEqualGUID( &serviceProviderGUID, lpcGuid ) )
4689 continue;
4692 if( i == 0 ) /* DP SP */
4694 len = MultiByteToWideChar( CP_ACP, 0, subKeyName, -1, NULL, 0 );
4695 lpSpData->lpszName = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
4696 MultiByteToWideChar( CP_ACP, 0, subKeyName, -1, lpSpData->lpszName, len );
4699 sizeOfReturnBuffer = 255;
4701 /* Get dwReserved1 */
4702 if( RegQueryValueExA( hkServiceProvider, majVerDataSubKey,
4703 NULL, &returnType, (LPBYTE)returnBuffer,
4704 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
4706 ERR(": missing dwReserved1 registry data members\n") ;
4707 continue;
4710 if( i == 0 )
4711 memcpy( &lpSpData->dwReserved1, returnBuffer, sizeof(lpSpData->dwReserved1) );
4713 sizeOfReturnBuffer = 255;
4715 /* Get dwReserved2 */
4716 if( RegQueryValueExA( hkServiceProvider, minVerDataSubKey,
4717 NULL, &returnType, (LPBYTE)returnBuffer,
4718 &sizeOfReturnBuffer ) != ERROR_SUCCESS )
4720 ERR(": missing dwReserved1 registry data members\n") ;
4721 continue;
4724 if( i == 0 )
4725 memcpy( &lpSpData->dwReserved2, returnBuffer, sizeof(lpSpData->dwReserved2) );
4727 sizeOfReturnBuffer = 255;
4729 /* Get the path for this service provider */
4730 if( ( dwTemp = RegQueryValueExA( hkServiceProvider, pathSubKey,
4731 NULL, NULL, (LPBYTE)returnBuffer,
4732 &sizeOfReturnBuffer ) ) != ERROR_SUCCESS )
4734 ERR(": missing PATH registry data members: 0x%08x\n", dwTemp );
4735 continue;
4738 TRACE( "Loading %s\n", returnBuffer );
4739 return LoadLibraryA( returnBuffer );
4743 return 0;
4746 static HRESULT DP_InitializeDPSP( IDirectPlayImpl *This, HMODULE hServiceProvider )
4748 HRESULT hr;
4749 LPDPSP_SPINIT SPInit;
4751 /* Initialize the service provider by calling SPInit */
4752 SPInit = (LPDPSP_SPINIT)GetProcAddress( hServiceProvider, "SPInit" );
4754 if( SPInit == NULL )
4756 ERR( "Service provider doesn't provide SPInit interface?\n" );
4757 FreeLibrary( hServiceProvider );
4758 return DPERR_UNAVAILABLE;
4761 TRACE( "Calling SPInit (DP SP entry point)\n" );
4763 hr = (*SPInit)( &This->dp2->spData );
4765 if( FAILED(hr) )
4767 ERR( "DP SP Initialization failed: %s\n", DPLAYX_HresultToString(hr) );
4768 FreeLibrary( hServiceProvider );
4769 return hr;
4772 /* FIXME: Need to verify the sanity of the returned callback table
4773 * using IsBadCodePtr */
4774 This->dp2->bSPInitialized = TRUE;
4776 /* This interface is now initialized as a DP object */
4777 This->dp2->connectionInitialized = DP_SERVICE_PROVIDER;
4779 /* Store the handle of the module so that we can unload it later */
4780 This->dp2->hServiceProvider = hServiceProvider;
4782 return hr;
4785 static HRESULT DP_InitializeDPLSP( IDirectPlayImpl *This, HMODULE hLobbyProvider )
4787 HRESULT hr;
4788 LPSP_INIT DPLSPInit;
4790 /* Initialize the service provider by calling SPInit */
4791 DPLSPInit = (LPSP_INIT)GetProcAddress( hLobbyProvider, "DPLSPInit" );
4793 if( DPLSPInit == NULL )
4795 ERR( "Service provider doesn't provide DPLSPInit interface?\n" );
4796 FreeLibrary( hLobbyProvider );
4797 return DPERR_UNAVAILABLE;
4800 TRACE( "Calling DPLSPInit (DPL SP entry point)\n" );
4802 hr = (*DPLSPInit)( &This->dp2->dplspData );
4804 if( FAILED(hr) )
4806 ERR( "DPL SP Initialization failed: %s\n", DPLAYX_HresultToString(hr) );
4807 FreeLibrary( hLobbyProvider );
4808 return hr;
4811 /* FIXME: Need to verify the sanity of the returned callback table
4812 * using IsBadCodePtr */
4814 This->dp2->bDPLSPInitialized = TRUE;
4816 /* This interface is now initialized as a lobby object */
4817 This->dp2->connectionInitialized = DP_LOBBY_PROVIDER;
4819 /* Store the handle of the module so that we can unload it later */
4820 This->dp2->hDPLobbyProvider = hLobbyProvider;
4822 return hr;
4825 static HRESULT WINAPI IDirectPlay3AImpl_InitializeConnection( IDirectPlay3A *iface,
4826 void *connection, DWORD flags )
4828 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4829 return IDirectPlayX_InitializeConnection( &This->IDirectPlay4A_iface, connection, flags );
4832 static HRESULT WINAPI IDirectPlay3Impl_InitializeConnection( IDirectPlay3 *iface,
4833 void *connection, DWORD flags )
4835 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4836 return IDirectPlayX_InitializeConnection( &This->IDirectPlay4_iface, connection, flags );
4839 static HRESULT WINAPI IDirectPlay4AImpl_InitializeConnection( IDirectPlay4A *iface,
4840 void *connection, DWORD flags )
4842 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4843 return IDirectPlayX_InitializeConnection( &This->IDirectPlay4_iface, connection, flags );
4846 static HRESULT WINAPI IDirectPlay4Impl_InitializeConnection( IDirectPlay4 *iface,
4847 void *connection, DWORD flags )
4849 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4850 HMODULE servprov;
4851 GUID sp;
4852 const DWORD size = 80; /* FIXME: Need to calculate it correctly */
4853 BOOL is_dp_sp; /* TRUE if Direct Play SP, FALSE if Direct Play Lobby SP */
4854 HRESULT hr;
4856 TRACE( "(%p)->(%p,0x%08x)\n", This, connection, flags );
4858 if ( !connection )
4859 return DPERR_INVALIDPARAMS;
4861 if ( flags )
4862 return DPERR_INVALIDFLAGS;
4864 if ( This->dp2->connectionInitialized != NO_PROVIDER )
4865 return DPERR_ALREADYINITIALIZED;
4867 /* Find out what the requested SP is and how large this buffer is */
4868 hr = DPL_EnumAddress( DP_GetSpLpGuidFromCompoundAddress, connection, size, &sp );
4870 if ( FAILED(hr) )
4872 ERR( "Invalid compound address?\n" );
4873 return DPERR_UNAVAILABLE;
4876 /* Load the service provider */
4877 servprov = DP_LoadSP( &sp, &This->dp2->spData, &is_dp_sp );
4879 if ( !servprov )
4881 ERR( "Unable to load service provider %s\n", debugstr_guid(&sp) );
4882 return DPERR_UNAVAILABLE;
4885 if ( is_dp_sp )
4887 /* Fill in what we can of the Service Provider required information.
4888 * The rest was be done in DP_LoadSP
4890 This->dp2->spData.lpAddress = connection;
4891 This->dp2->spData.dwAddressSize = size;
4892 This->dp2->spData.lpGuid = &sp;
4893 hr = DP_InitializeDPSP( This, servprov );
4895 else
4897 This->dp2->dplspData.lpAddress = connection;
4898 hr = DP_InitializeDPLSP( This, servprov );
4901 if ( FAILED(hr) )
4902 return hr;
4904 return DP_OK;
4907 static HRESULT WINAPI IDirectPlay3AImpl_SecureOpen( IDirectPlay3A *iface,
4908 const DPSESSIONDESC2 *sdesc, DWORD flags, const DPSECURITYDESC *security,
4909 const DPCREDENTIALS *credentials )
4911 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4912 return IDirectPlayX_SecureOpen( &This->IDirectPlay4A_iface, sdesc, flags, security,
4913 credentials );
4916 static HRESULT WINAPI IDirectPlay3Impl_SecureOpen( IDirectPlay3 *iface,
4917 const DPSESSIONDESC2 *sdesc, DWORD flags, const DPSECURITYDESC *security,
4918 const DPCREDENTIALS *credentials )
4920 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4921 return IDirectPlayX_SecureOpen( &This->IDirectPlay4_iface, sdesc, flags, security,
4922 credentials );
4925 static HRESULT WINAPI IDirectPlay4AImpl_SecureOpen( IDirectPlay4A *iface,
4926 const DPSESSIONDESC2 *lpsd, DWORD dwFlags, const DPSECURITYDESC *lpSecurity,
4927 const DPCREDENTIALS *lpCredentials )
4929 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4930 return DP_SecureOpen( This, lpsd, dwFlags, lpSecurity, lpCredentials, TRUE );
4933 static HRESULT WINAPI IDirectPlay4Impl_SecureOpen( IDirectPlay4 *iface,
4934 const DPSESSIONDESC2 *lpsd, DWORD dwFlags, const DPSECURITYDESC *lpSecurity,
4935 const DPCREDENTIALS *lpCredentials )
4937 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4938 return DP_SecureOpen( This, lpsd, dwFlags, lpSecurity, lpCredentials, FALSE );
4941 static HRESULT WINAPI IDirectPlay3AImpl_SendChatMessage( IDirectPlay3A *iface, DPID from, DPID to,
4942 DWORD flags, DPCHAT *chatmsg )
4944 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4945 return IDirectPlayX_SendChatMessage( &This->IDirectPlay4A_iface, from, to, flags, chatmsg );
4948 static HRESULT WINAPI IDirectPlay3Impl_SendChatMessage( IDirectPlay3 *iface, DPID from, DPID to,
4949 DWORD flags, DPCHAT *chatmsg )
4951 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4952 return IDirectPlayX_SendChatMessage( &This->IDirectPlay4_iface, from, to, flags, chatmsg );
4955 static HRESULT WINAPI IDirectPlay4AImpl_SendChatMessage( IDirectPlay4A *iface, DPID from,
4956 DPID to, DWORD flags, DPCHAT *chatmsg )
4958 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4959 FIXME("(%p)->(0x%08x,0x%08x,0x%08x,%p): stub\n", This, from, to, flags, chatmsg );
4960 return DP_OK;
4963 static HRESULT WINAPI IDirectPlay4Impl_SendChatMessage( IDirectPlay4 *iface, DPID from, DPID to,
4964 DWORD flags, DPCHAT *chatmsg )
4966 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4967 FIXME( "(%p)->(0x%08x,0x%08x,0x%08x,%p): stub\n", This, from, to, flags, chatmsg );
4968 return DP_OK;
4971 static HRESULT WINAPI IDirectPlay3AImpl_SetGroupConnectionSettings( IDirectPlay3A *iface,
4972 DWORD flags, DPID group, DPLCONNECTION *connection )
4974 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
4975 return IDirectPlayX_SetGroupConnectionSettings( &This->IDirectPlay4A_iface, flags, group,
4976 connection );
4979 static HRESULT WINAPI IDirectPlay3Impl_SetGroupConnectionSettings( IDirectPlay3 *iface,
4980 DWORD flags, DPID group, DPLCONNECTION *connection )
4982 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
4983 return IDirectPlayX_SetGroupConnectionSettings( &This->IDirectPlay4_iface, flags, group,
4984 connection );
4987 static HRESULT WINAPI IDirectPlay4AImpl_SetGroupConnectionSettings( IDirectPlay4A *iface,
4988 DWORD flags, DPID group, DPLCONNECTION *connection )
4990 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
4991 FIXME("(%p)->(0x%08x,0x%08x,%p): stub\n", This, flags, group, connection );
4992 return DP_OK;
4995 static HRESULT WINAPI IDirectPlay4Impl_SetGroupConnectionSettings( IDirectPlay4 *iface, DWORD flags,
4996 DPID group, DPLCONNECTION *connection )
4998 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
4999 FIXME( "(%p)->(0x%08x,0x%08x,%p): stub\n", This, flags, group, connection );
5000 return DP_OK;
5003 static HRESULT WINAPI IDirectPlay3AImpl_StartSession( IDirectPlay3A *iface, DWORD flags,
5004 DPID group )
5006 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
5007 return IDirectPlayX_StartSession( &This->IDirectPlay4A_iface, flags, group );
5010 static HRESULT WINAPI IDirectPlay3Impl_StartSession( IDirectPlay3 *iface, DWORD flags,
5011 DPID group )
5013 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
5014 return IDirectPlayX_StartSession( &This->IDirectPlay4_iface, flags, group );
5017 static HRESULT WINAPI IDirectPlay4AImpl_StartSession( IDirectPlay4A *iface, DWORD flags,
5018 DPID group )
5020 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5021 return IDirectPlayX_StartSession( &This->IDirectPlay4_iface, flags, group );
5024 static HRESULT WINAPI IDirectPlay4Impl_StartSession( IDirectPlay4 *iface, DWORD flags, DPID group )
5026 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5027 FIXME( "(%p)->(0x%08x,0x%08x): stub\n", This, flags, group );
5028 return DP_OK;
5031 static HRESULT WINAPI IDirectPlay3AImpl_GetGroupFlags( IDirectPlay3A *iface, DPID group,
5032 DWORD *flags )
5034 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
5035 return IDirectPlayX_GetGroupFlags( &This->IDirectPlay4A_iface, group, flags );
5038 static HRESULT WINAPI IDirectPlay3Impl_GetGroupFlags( IDirectPlay3 *iface, DPID group,
5039 DWORD *flags )
5041 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
5042 return IDirectPlayX_GetGroupFlags( &This->IDirectPlay4_iface, group, flags );
5045 static HRESULT WINAPI IDirectPlay4AImpl_GetGroupFlags( IDirectPlay4A *iface, DPID group,
5046 DWORD *flags )
5048 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5049 return IDirectPlayX_GetGroupFlags( &This->IDirectPlay4_iface, group, flags );
5052 static HRESULT WINAPI IDirectPlay4Impl_GetGroupFlags( IDirectPlay4 *iface, DPID group,
5053 DWORD *flags )
5055 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5056 FIXME( "(%p)->(0x%08x,%p): stub\n", This, group, flags );
5057 return DP_OK;
5060 static HRESULT WINAPI IDirectPlay3AImpl_GetGroupParent( IDirectPlay3A *iface, DPID group,
5061 DPID *parent )
5063 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
5064 return IDirectPlayX_GetGroupParent( &This->IDirectPlay4A_iface, group, parent );
5067 static HRESULT WINAPI IDirectPlay3Impl_GetGroupParent( IDirectPlay3 *iface, DPID group,
5068 DPID *parent )
5070 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
5071 return IDirectPlayX_GetGroupParent( &This->IDirectPlay4_iface, group, parent );
5074 static HRESULT WINAPI IDirectPlay4AImpl_GetGroupParent( IDirectPlay4A *iface, DPID group,
5075 DPID *parent )
5077 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5078 return IDirectPlayX_GetGroupParent( &This->IDirectPlay4_iface, group, parent );
5081 static HRESULT WINAPI IDirectPlay4Impl_GetGroupParent( IDirectPlay4 *iface, DPID group,
5082 DPID *parent )
5084 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5085 lpGroupData gdata;
5087 TRACE( "(%p)->(0x%08x,%p)\n", This, group, parent );
5089 if ( ( gdata = DP_FindAnyGroup( This, group ) ) == NULL )
5090 return DPERR_INVALIDGROUP;
5092 *parent = gdata->dpid;
5094 return DP_OK;
5097 static HRESULT WINAPI IDirectPlay3AImpl_GetPlayerAccount( IDirectPlay3A *iface, DPID player,
5098 DWORD flags, void *data, DWORD *size )
5100 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
5101 return IDirectPlayX_GetPlayerAccount( &This->IDirectPlay4A_iface, player, flags, data, size );
5104 static HRESULT WINAPI IDirectPlay3Impl_GetPlayerAccount( IDirectPlay3 *iface, DPID player,
5105 DWORD flags, void *data, DWORD *size )
5107 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
5108 return IDirectPlayX_GetPlayerAccount( &This->IDirectPlay4_iface, player, flags, data, size );
5111 static HRESULT WINAPI IDirectPlay4AImpl_GetPlayerAccount( IDirectPlay4A *iface, DPID player,
5112 DWORD flags, void *data, DWORD *size )
5114 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5115 FIXME("(%p)->(0x%08x,0x%08x,%p,%p): stub\n", This, player, flags, data, size );
5116 return DP_OK;
5119 static HRESULT WINAPI IDirectPlay4Impl_GetPlayerAccount( IDirectPlay4 *iface, DPID player,
5120 DWORD flags, void *data, DWORD *size )
5122 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5123 FIXME( "(%p)->(0x%08x,0x%08x,%p,%p): stub\n", This, player, flags, data, size );
5124 return DP_OK;
5127 static HRESULT WINAPI IDirectPlay3AImpl_GetPlayerFlags( IDirectPlay3A *iface, DPID player,
5128 DWORD *flags )
5130 IDirectPlayImpl *This = impl_from_IDirectPlay3A( iface );
5131 return IDirectPlayX_GetPlayerFlags( &This->IDirectPlay4A_iface, player, flags );
5134 static HRESULT WINAPI IDirectPlay3Impl_GetPlayerFlags( IDirectPlay3 *iface, DPID player,
5135 DWORD *flags )
5137 IDirectPlayImpl *This = impl_from_IDirectPlay3( iface );
5138 return IDirectPlayX_GetPlayerFlags( &This->IDirectPlay4_iface, player, flags );
5141 static HRESULT WINAPI IDirectPlay4AImpl_GetPlayerFlags( IDirectPlay4A *iface, DPID player,
5142 DWORD *flags )
5144 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5145 return IDirectPlayX_GetPlayerFlags( &This->IDirectPlay4_iface, player, flags );
5148 static HRESULT WINAPI IDirectPlay4Impl_GetPlayerFlags( IDirectPlay4 *iface, DPID player,
5149 DWORD *flags )
5151 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5152 FIXME( "(%p)->(0x%08x,%p): stub\n", This, player, flags );
5153 return DP_OK;
5156 static HRESULT WINAPI IDirectPlay4AImpl_GetGroupOwner( IDirectPlay4A *iface, DPID group,
5157 DPID *owner )
5159 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5160 return IDirectPlayX_GetGroupOwner( &This->IDirectPlay4_iface, group, owner );
5163 static HRESULT WINAPI IDirectPlay4Impl_GetGroupOwner( IDirectPlay4 *iface, DPID group,
5164 DPID *owner )
5166 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5167 FIXME( "(%p)->(0x%08x,%p): stub\n", This, group, owner );
5168 return DP_OK;
5171 static HRESULT WINAPI IDirectPlay4AImpl_SetGroupOwner( IDirectPlay4A *iface, DPID group,
5172 DPID owner )
5174 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5175 return IDirectPlayX_SetGroupOwner( &This->IDirectPlay4_iface, group, owner );
5178 static HRESULT WINAPI IDirectPlay4Impl_SetGroupOwner( IDirectPlay4 *iface, DPID group ,
5179 DPID owner )
5181 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5182 FIXME( "(%p)->(0x%08x,0x%08x): stub\n", This, group, owner );
5183 return DP_OK;
5186 static HRESULT WINAPI IDirectPlay4AImpl_SendEx( IDirectPlay4A *iface, DPID from, DPID to,
5187 DWORD flags, void *data, DWORD size, DWORD priority, DWORD timeout, void *context,
5188 DWORD *msgid )
5190 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5191 return IDirectPlayX_SendEx( &This->IDirectPlay4_iface, from, to, flags, data, size, priority,
5192 timeout, context, msgid );
5195 static HRESULT WINAPI IDirectPlay4Impl_SendEx( IDirectPlay4 *iface, DPID from, DPID to,
5196 DWORD flags, void *data, DWORD size, DWORD priority, DWORD timeout, void *context,
5197 DWORD *msgid )
5199 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5201 FIXME( "(%p)->(0x%08x,0x%08x,0x%08x,%p,0x%08x,0x%08x,0x%08x,%p,%p): semi-stub\n",
5202 This, from, to, flags, data, size, priority, timeout, context, msgid );
5204 if ( This->dp2->connectionInitialized == NO_PROVIDER )
5205 return DPERR_UNINITIALIZED;
5207 /* FIXME: Add parameter checking */
5208 /* FIXME: First call to this needs to acquire a message id which will be
5209 * used for multiple sends
5212 /* NOTE: Can't send messages to yourself - this will be trapped in receive */
5214 /* Verify that the message is being sent from a valid local player. The
5215 * from player may be anonymous DPID_UNKNOWN
5217 if ( from != DPID_UNKNOWN && !DP_FindPlayer( This, from ) )
5219 WARN( "INFO: Invalid from player 0x%08x\n", from );
5220 return DPERR_INVALIDPLAYER;
5223 /* Verify that the message is being sent to a valid player, group or to
5224 * everyone. If it's valid, send it to those players.
5226 if ( to == DPID_ALLPLAYERS )
5228 /* See if SP has the ability to multicast. If so, use it */
5229 if ( This->dp2->spData.lpCB->SendToGroupEx )
5230 FIXME( "Use group sendex to group 0\n" );
5231 else if ( This->dp2->spData.lpCB->SendToGroup ) /* obsolete interface */
5232 FIXME( "Use obsolete group send to group 0\n" );
5233 else /* No multicast, multiplicate */
5234 FIXME( "Send to all players using EnumPlayersInGroup\n" );
5236 else if ( DP_FindPlayer( This, to ) )
5238 /* Have the service provider send this message */
5239 /* FIXME: Could optimize for local interface sends */
5240 return DP_SP_SendEx( This, flags, data, size, priority, timeout, context, msgid );
5242 else if ( DP_FindAnyGroup( This, to ) )
5244 /* See if SP has the ability to multicast. If so, use it */
5245 if ( This->dp2->spData.lpCB->SendToGroupEx )
5246 FIXME( "Use group sendex\n" );
5247 else if ( This->dp2->spData.lpCB->SendToGroup ) /* obsolete interface */
5248 FIXME( "Use obsolete group send to group\n" );
5249 else /* No multicast, multiplicate */
5250 FIXME( "Send to all players using EnumPlayersInGroup\n" );
5253 else
5254 return DPERR_INVALIDPLAYER;
5256 /* FIXME: Should return what the send returned */
5257 return DP_OK;
5260 static HRESULT DP_SP_SendEx( IDirectPlayImpl *This, DWORD dwFlags, void *lpData, DWORD dwDataSize,
5261 DWORD dwPriority, DWORD dwTimeout, void *lpContext, DWORD *lpdwMsgID )
5263 LPDPMSG lpMElem;
5265 FIXME( ": stub\n" );
5267 /* FIXME: This queuing should only be for async messages */
5269 lpMElem = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpMElem ) );
5270 lpMElem->msg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
5272 CopyMemory( lpMElem->msg, lpData, dwDataSize );
5274 /* FIXME: Need to queue based on priority */
5275 DPQ_INSERT( This->dp2->sendMsgs, lpMElem, msgs );
5277 return DP_OK;
5280 static HRESULT WINAPI IDirectPlay4AImpl_GetMessageQueue( IDirectPlay4A *iface, DPID from, DPID to,
5281 DWORD flags, DWORD *msgs, DWORD *bytes )
5283 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5284 return IDirectPlayX_GetMessageQueue( &This->IDirectPlay4_iface, from, to, flags, msgs, bytes );
5287 static HRESULT WINAPI IDirectPlay4Impl_GetMessageQueue( IDirectPlay4 *iface, DPID from, DPID to,
5288 DWORD flags, DWORD *msgs, DWORD *bytes )
5290 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5291 HRESULT hr = DP_OK;
5293 FIXME( "(%p)->(0x%08x,0x%08x,0x%08x,%p,%p): semi-stub\n", This, from, to, flags, msgs, bytes );
5295 /* FIXME: Do we need to do from and to sanity checking here? */
5296 /* FIXME: What about sends which are not immediate? */
5298 if ( This->dp2->spData.lpCB->GetMessageQueue )
5300 DPSP_GETMESSAGEQUEUEDATA data;
5302 FIXME( "Calling SP GetMessageQueue - is it right?\n" );
5304 /* FIXME: None of this is documented :( */
5305 data.lpISP = This->dp2->spData.lpISP;
5306 data.dwFlags = flags;
5307 data.idFrom = from;
5308 data.idTo = to;
5309 data.lpdwNumMsgs = msgs;
5310 data.lpdwNumBytes = bytes;
5312 hr = (*This->dp2->spData.lpCB->GetMessageQueue)( &data );
5314 else
5315 FIXME( "No SP for GetMessageQueue - fake some data\n" );
5317 return hr;
5320 static HRESULT dplay_cancelmsg ( IDirectPlayImpl* This, DWORD msgid, DWORD flags, DWORD minprio,
5321 DWORD maxprio )
5323 HRESULT hr = DP_OK;
5325 FIXME( "(%p)->(0x%08x,0x%08x): semi stub\n", This, msgid, flags );
5327 if ( This->dp2->spData.lpCB->Cancel )
5329 DPSP_CANCELDATA data;
5331 TRACE( "Calling SP Cancel\n" );
5333 /* FIXME: Undocumented callback */
5335 data.lpISP = This->dp2->spData.lpISP;
5336 data.dwFlags = flags;
5337 data.lprglpvSPMsgID = NULL;
5338 data.cSPMsgID = msgid;
5339 data.dwMinPriority = minprio;
5340 data.dwMaxPriority = maxprio;
5342 hr = (*This->dp2->spData.lpCB->Cancel)( &data );
5344 else
5345 FIXME( "SP doesn't implement Cancel\n" );
5347 return hr;
5350 static HRESULT WINAPI IDirectPlay4AImpl_CancelMessage( IDirectPlay4A *iface, DWORD msgid,
5351 DWORD flags )
5353 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5354 return IDirectPlayX_CancelMessage( &This->IDirectPlay4_iface, msgid, flags );
5357 static HRESULT WINAPI IDirectPlay4Impl_CancelMessage( IDirectPlay4 *iface, DWORD msgid,
5358 DWORD flags )
5360 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5362 if ( flags != 0 )
5363 return DPERR_INVALIDFLAGS;
5365 if ( msgid == 0 )
5366 flags |= DPCANCELSEND_ALL;
5368 return dplay_cancelmsg( This, msgid, flags, 0, 0 );
5371 static HRESULT WINAPI IDirectPlay4AImpl_CancelPriority( IDirectPlay4A *iface, DWORD minprio,
5372 DWORD maxprio, DWORD flags )
5374 IDirectPlayImpl *This = impl_from_IDirectPlay4A( iface );
5375 return IDirectPlayX_CancelPriority( &This->IDirectPlay4_iface, minprio, maxprio, flags );
5378 static HRESULT WINAPI IDirectPlay4Impl_CancelPriority( IDirectPlay4 *iface, DWORD minprio,
5379 DWORD maxprio, DWORD flags )
5381 IDirectPlayImpl *This = impl_from_IDirectPlay4( iface );
5383 if ( flags != 0 )
5384 return DPERR_INVALIDFLAGS;
5386 return dplay_cancelmsg( This, 0, DPCANCELSEND_PRIORITY, minprio, maxprio );
5389 static const IDirectPlay2Vtbl dp2_vt =
5391 IDirectPlay2Impl_QueryInterface,
5392 IDirectPlay2Impl_AddRef,
5393 IDirectPlay2Impl_Release,
5394 IDirectPlay2Impl_AddPlayerToGroup,
5395 IDirectPlay2Impl_Close,
5396 IDirectPlay2Impl_CreateGroup,
5397 IDirectPlay2Impl_CreatePlayer,
5398 IDirectPlay2Impl_DeletePlayerFromGroup,
5399 IDirectPlay2Impl_DestroyGroup,
5400 IDirectPlay2Impl_DestroyPlayer,
5401 IDirectPlay2Impl_EnumGroupPlayers,
5402 IDirectPlay2Impl_EnumGroups,
5403 IDirectPlay2Impl_EnumPlayers,
5404 IDirectPlay2Impl_EnumSessions,
5405 IDirectPlay2Impl_GetCaps,
5406 IDirectPlay2Impl_GetGroupData,
5407 IDirectPlay2Impl_GetGroupName,
5408 IDirectPlay2Impl_GetMessageCount,
5409 IDirectPlay2Impl_GetPlayerAddress,
5410 IDirectPlay2Impl_GetPlayerCaps,
5411 IDirectPlay2Impl_GetPlayerData,
5412 IDirectPlay2Impl_GetPlayerName,
5413 IDirectPlay2Impl_GetSessionDesc,
5414 IDirectPlay2Impl_Initialize,
5415 IDirectPlay2Impl_Open,
5416 IDirectPlay2Impl_Receive,
5417 IDirectPlay2Impl_Send,
5418 IDirectPlay2Impl_SetGroupData,
5419 IDirectPlay2Impl_SetGroupName,
5420 IDirectPlay2Impl_SetPlayerData,
5421 IDirectPlay2Impl_SetPlayerName,
5422 IDirectPlay2Impl_SetSessionDesc
5425 static const IDirectPlay2Vtbl dp2A_vt =
5427 IDirectPlay2AImpl_QueryInterface,
5428 IDirectPlay2AImpl_AddRef,
5429 IDirectPlay2AImpl_Release,
5430 IDirectPlay2AImpl_AddPlayerToGroup,
5431 IDirectPlay2AImpl_Close,
5432 IDirectPlay2AImpl_CreateGroup,
5433 IDirectPlay2AImpl_CreatePlayer,
5434 IDirectPlay2AImpl_DeletePlayerFromGroup,
5435 IDirectPlay2AImpl_DestroyGroup,
5436 IDirectPlay2AImpl_DestroyPlayer,
5437 IDirectPlay2AImpl_EnumGroupPlayers,
5438 IDirectPlay2AImpl_EnumGroups,
5439 IDirectPlay2AImpl_EnumPlayers,
5440 IDirectPlay2AImpl_EnumSessions,
5441 IDirectPlay2AImpl_GetCaps,
5442 IDirectPlay2AImpl_GetGroupData,
5443 IDirectPlay2AImpl_GetGroupName,
5444 IDirectPlay2AImpl_GetMessageCount,
5445 IDirectPlay2AImpl_GetPlayerAddress,
5446 IDirectPlay2AImpl_GetPlayerCaps,
5447 IDirectPlay2AImpl_GetPlayerData,
5448 IDirectPlay2AImpl_GetPlayerName,
5449 IDirectPlay2AImpl_GetSessionDesc,
5450 IDirectPlay2AImpl_Initialize,
5451 IDirectPlay2AImpl_Open,
5452 IDirectPlay2AImpl_Receive,
5453 IDirectPlay2AImpl_Send,
5454 IDirectPlay2AImpl_SetGroupData,
5455 IDirectPlay2AImpl_SetGroupName,
5456 IDirectPlay2AImpl_SetPlayerData,
5457 IDirectPlay2AImpl_SetPlayerName,
5458 IDirectPlay2AImpl_SetSessionDesc
5461 static const IDirectPlay3Vtbl dp3_vt =
5463 IDirectPlay3Impl_QueryInterface,
5464 IDirectPlay3Impl_AddRef,
5465 IDirectPlay3Impl_Release,
5466 IDirectPlay3Impl_AddPlayerToGroup,
5467 IDirectPlay3Impl_Close,
5468 IDirectPlay3Impl_CreateGroup,
5469 IDirectPlay3Impl_CreatePlayer,
5470 IDirectPlay3Impl_DeletePlayerFromGroup,
5471 IDirectPlay3Impl_DestroyGroup,
5472 IDirectPlay3Impl_DestroyPlayer,
5473 IDirectPlay3Impl_EnumGroupPlayers,
5474 IDirectPlay3Impl_EnumGroups,
5475 IDirectPlay3Impl_EnumPlayers,
5476 IDirectPlay3Impl_EnumSessions,
5477 IDirectPlay3Impl_GetCaps,
5478 IDirectPlay3Impl_GetGroupData,
5479 IDirectPlay3Impl_GetGroupName,
5480 IDirectPlay3Impl_GetMessageCount,
5481 IDirectPlay3Impl_GetPlayerAddress,
5482 IDirectPlay3Impl_GetPlayerCaps,
5483 IDirectPlay3Impl_GetPlayerData,
5484 IDirectPlay3Impl_GetPlayerName,
5485 IDirectPlay3Impl_GetSessionDesc,
5486 IDirectPlay3Impl_Initialize,
5487 IDirectPlay3Impl_Open,
5488 IDirectPlay3Impl_Receive,
5489 IDirectPlay3Impl_Send,
5490 IDirectPlay3Impl_SetGroupData,
5491 IDirectPlay3Impl_SetGroupName,
5492 IDirectPlay3Impl_SetPlayerData,
5493 IDirectPlay3Impl_SetPlayerName,
5494 IDirectPlay3Impl_SetSessionDesc,
5495 IDirectPlay3Impl_AddGroupToGroup,
5496 IDirectPlay3Impl_CreateGroupInGroup,
5497 IDirectPlay3Impl_DeleteGroupFromGroup,
5498 IDirectPlay3Impl_EnumConnections,
5499 IDirectPlay3Impl_EnumGroupsInGroup,
5500 IDirectPlay3Impl_GetGroupConnectionSettings,
5501 IDirectPlay3Impl_InitializeConnection,
5502 IDirectPlay3Impl_SecureOpen,
5503 IDirectPlay3Impl_SendChatMessage,
5504 IDirectPlay3Impl_SetGroupConnectionSettings,
5505 IDirectPlay3Impl_StartSession,
5506 IDirectPlay3Impl_GetGroupFlags,
5507 IDirectPlay3Impl_GetGroupParent,
5508 IDirectPlay3Impl_GetPlayerAccount,
5509 IDirectPlay3Impl_GetPlayerFlags
5512 static const IDirectPlay3Vtbl dp3A_vt =
5514 IDirectPlay3AImpl_QueryInterface,
5515 IDirectPlay3AImpl_AddRef,
5516 IDirectPlay3AImpl_Release,
5517 IDirectPlay3AImpl_AddPlayerToGroup,
5518 IDirectPlay3AImpl_Close,
5519 IDirectPlay3AImpl_CreateGroup,
5520 IDirectPlay3AImpl_CreatePlayer,
5521 IDirectPlay3AImpl_DeletePlayerFromGroup,
5522 IDirectPlay3AImpl_DestroyGroup,
5523 IDirectPlay3AImpl_DestroyPlayer,
5524 IDirectPlay3AImpl_EnumGroupPlayers,
5525 IDirectPlay3AImpl_EnumGroups,
5526 IDirectPlay3AImpl_EnumPlayers,
5527 IDirectPlay3AImpl_EnumSessions,
5528 IDirectPlay3AImpl_GetCaps,
5529 IDirectPlay3AImpl_GetGroupData,
5530 IDirectPlay3AImpl_GetGroupName,
5531 IDirectPlay3AImpl_GetMessageCount,
5532 IDirectPlay3AImpl_GetPlayerAddress,
5533 IDirectPlay3AImpl_GetPlayerCaps,
5534 IDirectPlay3AImpl_GetPlayerData,
5535 IDirectPlay3AImpl_GetPlayerName,
5536 IDirectPlay3AImpl_GetSessionDesc,
5537 IDirectPlay3AImpl_Initialize,
5538 IDirectPlay3AImpl_Open,
5539 IDirectPlay3AImpl_Receive,
5540 IDirectPlay3AImpl_Send,
5541 IDirectPlay3AImpl_SetGroupData,
5542 IDirectPlay3AImpl_SetGroupName,
5543 IDirectPlay3AImpl_SetPlayerData,
5544 IDirectPlay3AImpl_SetPlayerName,
5545 IDirectPlay3AImpl_SetSessionDesc,
5546 IDirectPlay3AImpl_AddGroupToGroup,
5547 IDirectPlay3AImpl_CreateGroupInGroup,
5548 IDirectPlay3AImpl_DeleteGroupFromGroup,
5549 IDirectPlay3AImpl_EnumConnections,
5550 IDirectPlay3AImpl_EnumGroupsInGroup,
5551 IDirectPlay3AImpl_GetGroupConnectionSettings,
5552 IDirectPlay3AImpl_InitializeConnection,
5553 IDirectPlay3AImpl_SecureOpen,
5554 IDirectPlay3AImpl_SendChatMessage,
5555 IDirectPlay3AImpl_SetGroupConnectionSettings,
5556 IDirectPlay3AImpl_StartSession,
5557 IDirectPlay3AImpl_GetGroupFlags,
5558 IDirectPlay3AImpl_GetGroupParent,
5559 IDirectPlay3AImpl_GetPlayerAccount,
5560 IDirectPlay3AImpl_GetPlayerFlags
5563 static const IDirectPlay4Vtbl dp4_vt =
5565 IDirectPlay4Impl_QueryInterface,
5566 IDirectPlay4Impl_AddRef,
5567 IDirectPlay4Impl_Release,
5568 IDirectPlay4Impl_AddPlayerToGroup,
5569 IDirectPlay4Impl_Close,
5570 IDirectPlay4Impl_CreateGroup,
5571 IDirectPlay4Impl_CreatePlayer,
5572 IDirectPlay4Impl_DeletePlayerFromGroup,
5573 IDirectPlay4Impl_DestroyGroup,
5574 IDirectPlay4Impl_DestroyPlayer,
5575 IDirectPlay4Impl_EnumGroupPlayers,
5576 IDirectPlay4Impl_EnumGroups,
5577 IDirectPlay4Impl_EnumPlayers,
5578 IDirectPlay4Impl_EnumSessions,
5579 IDirectPlay4Impl_GetCaps,
5580 IDirectPlay4Impl_GetGroupData,
5581 IDirectPlay4Impl_GetGroupName,
5582 IDirectPlay4Impl_GetMessageCount,
5583 IDirectPlay4Impl_GetPlayerAddress,
5584 IDirectPlay4Impl_GetPlayerCaps,
5585 IDirectPlay4Impl_GetPlayerData,
5586 IDirectPlay4Impl_GetPlayerName,
5587 IDirectPlay4Impl_GetSessionDesc,
5588 IDirectPlay4Impl_Initialize,
5589 IDirectPlay4Impl_Open,
5590 IDirectPlay4Impl_Receive,
5591 IDirectPlay4Impl_Send,
5592 IDirectPlay4Impl_SetGroupData,
5593 IDirectPlay4Impl_SetGroupName,
5594 IDirectPlay4Impl_SetPlayerData,
5595 IDirectPlay4Impl_SetPlayerName,
5596 IDirectPlay4Impl_SetSessionDesc,
5597 IDirectPlay4Impl_AddGroupToGroup,
5598 IDirectPlay4Impl_CreateGroupInGroup,
5599 IDirectPlay4Impl_DeleteGroupFromGroup,
5600 IDirectPlay4Impl_EnumConnections,
5601 IDirectPlay4Impl_EnumGroupsInGroup,
5602 IDirectPlay4Impl_GetGroupConnectionSettings,
5603 IDirectPlay4Impl_InitializeConnection,
5604 IDirectPlay4Impl_SecureOpen,
5605 IDirectPlay4Impl_SendChatMessage,
5606 IDirectPlay4Impl_SetGroupConnectionSettings,
5607 IDirectPlay4Impl_StartSession,
5608 IDirectPlay4Impl_GetGroupFlags,
5609 IDirectPlay4Impl_GetGroupParent,
5610 IDirectPlay4Impl_GetPlayerAccount,
5611 IDirectPlay4Impl_GetPlayerFlags,
5612 IDirectPlay4Impl_GetGroupOwner,
5613 IDirectPlay4Impl_SetGroupOwner,
5614 IDirectPlay4Impl_SendEx,
5615 IDirectPlay4Impl_GetMessageQueue,
5616 IDirectPlay4Impl_CancelMessage,
5617 IDirectPlay4Impl_CancelPriority
5620 static const IDirectPlay4Vtbl dp4A_vt =
5622 IDirectPlay4AImpl_QueryInterface,
5623 IDirectPlay4AImpl_AddRef,
5624 IDirectPlay4AImpl_Release,
5625 IDirectPlay4AImpl_AddPlayerToGroup,
5626 IDirectPlay4AImpl_Close,
5627 IDirectPlay4AImpl_CreateGroup,
5628 IDirectPlay4AImpl_CreatePlayer,
5629 IDirectPlay4AImpl_DeletePlayerFromGroup,
5630 IDirectPlay4AImpl_DestroyGroup,
5631 IDirectPlay4AImpl_DestroyPlayer,
5632 IDirectPlay4AImpl_EnumGroupPlayers,
5633 IDirectPlay4AImpl_EnumGroups,
5634 IDirectPlay4AImpl_EnumPlayers,
5635 IDirectPlay4AImpl_EnumSessions,
5636 IDirectPlay4AImpl_GetCaps,
5637 IDirectPlay4AImpl_GetGroupData,
5638 IDirectPlay4AImpl_GetGroupName,
5639 IDirectPlay4AImpl_GetMessageCount,
5640 IDirectPlay4AImpl_GetPlayerAddress,
5641 IDirectPlay4AImpl_GetPlayerCaps,
5642 IDirectPlay4AImpl_GetPlayerData,
5643 IDirectPlay4AImpl_GetPlayerName,
5644 IDirectPlay4AImpl_GetSessionDesc,
5645 IDirectPlay4AImpl_Initialize,
5646 IDirectPlay4AImpl_Open,
5647 IDirectPlay4AImpl_Receive,
5648 IDirectPlay4AImpl_Send,
5649 IDirectPlay4AImpl_SetGroupData,
5650 IDirectPlay4AImpl_SetGroupName,
5651 IDirectPlay4AImpl_SetPlayerData,
5652 IDirectPlay4AImpl_SetPlayerName,
5653 IDirectPlay4AImpl_SetSessionDesc,
5654 IDirectPlay4AImpl_AddGroupToGroup,
5655 IDirectPlay4AImpl_CreateGroupInGroup,
5656 IDirectPlay4AImpl_DeleteGroupFromGroup,
5657 IDirectPlay4AImpl_EnumConnections,
5658 IDirectPlay4AImpl_EnumGroupsInGroup,
5659 IDirectPlay4AImpl_GetGroupConnectionSettings,
5660 IDirectPlay4AImpl_InitializeConnection,
5661 IDirectPlay4AImpl_SecureOpen,
5662 IDirectPlay4AImpl_SendChatMessage,
5663 IDirectPlay4AImpl_SetGroupConnectionSettings,
5664 IDirectPlay4AImpl_StartSession,
5665 IDirectPlay4AImpl_GetGroupFlags,
5666 IDirectPlay4AImpl_GetGroupParent,
5667 IDirectPlay4AImpl_GetPlayerAccount,
5668 IDirectPlay4AImpl_GetPlayerFlags,
5669 IDirectPlay4AImpl_GetGroupOwner,
5670 IDirectPlay4AImpl_SetGroupOwner,
5671 IDirectPlay4AImpl_SendEx,
5672 IDirectPlay4AImpl_GetMessageQueue,
5673 IDirectPlay4AImpl_CancelMessage,
5674 IDirectPlay4AImpl_CancelPriority
5677 HRESULT dplay_create( REFIID riid, void **ppv )
5679 IDirectPlayImpl *obj;
5680 HRESULT hr;
5682 TRACE( "(%s, %p)\n", debugstr_guid( riid ), ppv );
5684 *ppv = NULL;
5685 obj = HeapAlloc( GetProcessHeap(), 0, sizeof( *obj ) );
5686 if ( !obj )
5687 return DPERR_OUTOFMEMORY;
5689 obj->IDirectPlay_iface.lpVtbl = &dp_vt;
5690 obj->IDirectPlay2A_iface.lpVtbl = &dp2A_vt;
5691 obj->IDirectPlay2_iface.lpVtbl = &dp2_vt;
5692 obj->IDirectPlay3A_iface.lpVtbl = &dp3A_vt;
5693 obj->IDirectPlay3_iface.lpVtbl = &dp3_vt;
5694 obj->IDirectPlay4A_iface.lpVtbl = &dp4A_vt;
5695 obj->IDirectPlay4_iface.lpVtbl = &dp4_vt;
5696 obj->numIfaces = 1;
5697 obj->ref = 0;
5698 obj->ref2A = 0;
5699 obj->ref2 = 0;
5700 obj->ref3A = 0;
5701 obj->ref3 = 0;
5702 obj->ref4A = 0;
5703 obj->ref4 = 1;
5705 InitializeCriticalSection( &obj->lock );
5706 obj->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectPlayImpl.lock");
5708 if ( DP_CreateDirectPlay2( obj ) )
5709 hr = IDirectPlayX_QueryInterface( &obj->IDirectPlay4_iface, riid, ppv );
5710 else
5711 hr = DPERR_NOMEMORY;
5712 IDirectPlayX_Release( &obj->IDirectPlay4_iface );
5714 return hr;
5718 HRESULT DP_GetSPPlayerData( IDirectPlayImpl *lpDP, DPID idPlayer, void **lplpData )
5720 lpPlayerList lpPlayer = DP_FindPlayer( lpDP, idPlayer );
5722 if( lpPlayer == NULL )
5724 return DPERR_INVALIDPLAYER;
5727 *lplpData = lpPlayer->lpPData->lpSPPlayerData;
5729 return DP_OK;
5732 HRESULT DP_SetSPPlayerData( IDirectPlayImpl *lpDP, DPID idPlayer, void *lpData )
5734 lpPlayerList lpPlayer = DP_FindPlayer( lpDP, idPlayer );
5736 if( lpPlayer == NULL )
5738 return DPERR_INVALIDPLAYER;
5741 lpPlayer->lpPData->lpSPPlayerData = lpData;
5743 return DP_OK;
5746 /***************************************************************************
5747 * DirectPlayEnumerateAW
5749 * The pointer to the structure lpContext will be filled with the
5750 * appropriate data for each service offered by the OS. These services are
5751 * not necessarily available on this particular machine but are defined
5752 * as simple service providers under the "Service Providers" registry key.
5753 * This structure is then passed to lpEnumCallback for each of the different
5754 * services.
5756 * This API is useful only for applications written using DirectX3 or
5757 * worse. It is superseded by IDirectPlay3::EnumConnections which also
5758 * gives information on the actual connections.
5760 * defn of a service provider:
5761 * A dynamic-link library used by DirectPlay to communicate over a network.
5762 * The service provider contains all the network-specific code required
5763 * to send and receive messages. Online services and network operators can
5764 * supply service providers to use specialized hardware, protocols, communications
5765 * media, and network resources.
5768 static HRESULT DirectPlayEnumerateAW(LPDPENUMDPCALLBACKA lpEnumCallbackA,
5769 LPDPENUMDPCALLBACKW lpEnumCallbackW,
5770 LPVOID lpContext)
5772 HKEY hkResult;
5773 DWORD dwIndex;
5774 FILETIME filetime;
5776 char *descriptionA = NULL;
5777 DWORD max_sizeOfDescriptionA = 0;
5778 WCHAR *descriptionW = NULL;
5779 DWORD max_sizeOfDescriptionW = 0;
5780 DWORD sizeOfSubKeyName;
5781 WCHAR subKeyName[255]; /* 255 is the maximum key size according to MSDN */
5782 LONG ret_value;
5783 static GUID *guid_cache;
5784 static int cache_count;
5786 if (!lpEnumCallbackA && !lpEnumCallbackW)
5788 return DPERR_INVALIDPARAMS;
5791 /* Need to loop over the service providers in the registry */
5792 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay\\Service Providers",
5793 0, KEY_READ, &hkResult) != ERROR_SUCCESS)
5795 /* Hmmm. Does this mean that there are no service providers? */
5796 ERR(": no service provider key in the registry - check your Wine installation !!!\n");
5797 return DPERR_GENERIC;
5800 dwIndex = 0;
5803 sizeOfSubKeyName = ARRAY_SIZE(subKeyName);
5804 ret_value = RegEnumKeyW(hkResult, dwIndex, subKeyName, sizeOfSubKeyName);
5805 dwIndex++;
5807 while (ret_value == ERROR_SUCCESS);
5808 /* The game Swing from bug 37185 expects GUID values to persist after
5809 * the end of the enumeration. */
5810 if (cache_count < dwIndex)
5812 HeapFree(GetProcessHeap(), 0, guid_cache);
5813 guid_cache = HeapAlloc(GetProcessHeap(), 0, sizeof(GUID) * dwIndex);
5814 if (!guid_cache)
5816 ERR(": failed to allocate required memory.\n");
5817 return DPERR_EXCEPTION;
5819 cache_count = dwIndex;
5821 /* Traverse all the service providers we have available */
5822 dwIndex = 0;
5823 while (1)
5825 HKEY hkServiceProvider;
5826 WCHAR guidKeyContent[(2 * 16) + 1 + 6 /* This corresponds to '{....-..-..-..-......}' */ ];
5827 DWORD sizeOfGuidKeyContent = sizeof(guidKeyContent);
5829 sizeOfSubKeyName = ARRAY_SIZE(subKeyName);
5830 ret_value = RegEnumKeyExW(hkResult, dwIndex, subKeyName, &sizeOfSubKeyName,
5831 NULL, NULL, NULL, &filetime);
5832 if (ret_value == ERROR_NO_MORE_ITEMS)
5833 break;
5834 else if (ret_value != ERROR_SUCCESS)
5836 ERR(": could not enumerate on service provider key.\n");
5837 return DPERR_EXCEPTION;
5839 TRACE(" this time through sub-key %s.\n", debugstr_w(subKeyName));
5841 /* Open the key for this service provider */
5842 if (RegOpenKeyExW(hkResult, subKeyName, 0, KEY_READ, &hkServiceProvider) != ERROR_SUCCESS)
5844 ERR(": could not open registry key for service provider %s.\n", debugstr_w(subKeyName));
5845 continue;
5848 /* Get the GUID from the registry */
5849 if (RegQueryValueExW(hkServiceProvider, L"Guid",
5850 NULL, NULL, (LPBYTE) guidKeyContent, &sizeOfGuidKeyContent) != ERROR_SUCCESS)
5852 ERR(": missing GUID registry data member for service provider %s.\n", debugstr_w(subKeyName));
5853 continue;
5855 if (sizeOfGuidKeyContent != sizeof(guidKeyContent))
5857 ERR(": invalid format for the GUID registry data member for service provider %s (%s).\n", debugstr_w(subKeyName), debugstr_w(guidKeyContent));
5858 continue;
5860 CLSIDFromString(guidKeyContent, &guid_cache[dwIndex]);
5862 /* The enumeration will return FALSE if we are not to continue.
5864 * Note: on my windows box, major / minor version is 6 / 0 for all service providers
5865 * and have no relation to any of the two dwReserved1 and dwReserved2 keys.
5866 * I think that it simply means that they are in-line with DirectX 6.0
5868 if (lpEnumCallbackA)
5870 DWORD sizeOfDescription = 0;
5872 /* Note that this is the A case of this function, so use the A variant to get the description string */
5873 if (RegQueryValueExA(hkServiceProvider, "DescriptionA",
5874 NULL, NULL, NULL, &sizeOfDescription) != ERROR_SUCCESS)
5876 ERR(": missing 'DescriptionA' registry data member for service provider %s.\n", debugstr_w(subKeyName));
5877 continue;
5879 if (sizeOfDescription > max_sizeOfDescriptionA)
5881 HeapFree(GetProcessHeap(), 0, descriptionA);
5882 max_sizeOfDescriptionA = sizeOfDescription;
5884 descriptionA = HeapAlloc(GetProcessHeap(), 0, sizeOfDescription);
5885 RegQueryValueExA(hkServiceProvider, "DescriptionA",
5886 NULL, NULL, (LPBYTE) descriptionA, &sizeOfDescription);
5888 if (!lpEnumCallbackA(&guid_cache[dwIndex], descriptionA, 6, 0, lpContext))
5889 goto end;
5891 else
5893 DWORD sizeOfDescription = 0;
5895 if (RegQueryValueExW(hkServiceProvider, L"DescriptionW",
5896 NULL, NULL, NULL, &sizeOfDescription) != ERROR_SUCCESS)
5898 ERR(": missing 'DescriptionW' registry data member for service provider %s.\n", debugstr_w(subKeyName));
5899 continue;
5901 if (sizeOfDescription > max_sizeOfDescriptionW)
5903 HeapFree(GetProcessHeap(), 0, descriptionW);
5904 max_sizeOfDescriptionW = sizeOfDescription;
5906 descriptionW = HeapAlloc(GetProcessHeap(), 0, sizeOfDescription);
5907 RegQueryValueExW(hkServiceProvider, L"DescriptionW",
5908 NULL, NULL, (LPBYTE) descriptionW, &sizeOfDescription);
5910 if (!lpEnumCallbackW(&guid_cache[dwIndex], descriptionW, 6, 0, lpContext))
5911 goto end;
5914 dwIndex++;
5917 end:
5918 HeapFree(GetProcessHeap(), 0, descriptionA);
5919 HeapFree(GetProcessHeap(), 0, descriptionW);
5921 return DP_OK;
5924 /***************************************************************************
5925 * DirectPlayEnumerate [DPLAYX.9]
5926 * DirectPlayEnumerateA [DPLAYX.2]
5928 HRESULT WINAPI DirectPlayEnumerateA(LPDPENUMDPCALLBACKA lpEnumCallback, LPVOID lpContext )
5930 TRACE("(%p,%p)\n", lpEnumCallback, lpContext);
5932 return DirectPlayEnumerateAW(lpEnumCallback, NULL, lpContext);
5935 /***************************************************************************
5936 * DirectPlayEnumerateW [DPLAYX.3]
5938 HRESULT WINAPI DirectPlayEnumerateW(LPDPENUMDPCALLBACKW lpEnumCallback, LPVOID lpContext )
5940 TRACE("(%p,%p)\n", lpEnumCallback, lpContext);
5942 return DirectPlayEnumerateAW(NULL, lpEnumCallback, lpContext);
5945 typedef struct tagCreateEnum
5947 LPVOID lpConn;
5948 LPCGUID lpGuid;
5949 } CreateEnumData, *lpCreateEnumData;
5951 /* Find and copy the matching connection for the SP guid */
5952 static BOOL CALLBACK cbDPCreateEnumConnections(
5953 LPCGUID lpguidSP,
5954 LPVOID lpConnection,
5955 DWORD dwConnectionSize,
5956 LPCDPNAME lpName,
5957 DWORD dwFlags,
5958 LPVOID lpContext)
5960 lpCreateEnumData lpData = (lpCreateEnumData)lpContext;
5962 if( IsEqualGUID( lpguidSP, lpData->lpGuid ) )
5964 TRACE( "Found SP entry with guid %s\n", debugstr_guid(lpData->lpGuid) );
5966 lpData->lpConn = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
5967 dwConnectionSize );
5968 CopyMemory( lpData->lpConn, lpConnection, dwConnectionSize );
5970 /* Found the record that we were looking for */
5971 return FALSE;
5974 /* Haven't found what were looking for yet */
5975 return TRUE;
5979 /***************************************************************************
5980 * DirectPlayCreate [DPLAYX.1]
5983 HRESULT WINAPI DirectPlayCreate
5984 ( LPGUID lpGUID, LPDIRECTPLAY *lplpDP, IUnknown *pUnk )
5986 HRESULT hr;
5987 LPDIRECTPLAY3A lpDP3A;
5988 CreateEnumData cbData;
5990 TRACE( "lpGUID=%s lplpDP=%p pUnk=%p\n", debugstr_guid(lpGUID), lplpDP, pUnk );
5992 if( pUnk != NULL )
5994 return CLASS_E_NOAGGREGATION;
5997 if( (lplpDP == NULL) || (lpGUID == NULL) )
5999 return DPERR_INVALIDPARAMS;
6002 if ( dplay_create( &IID_IDirectPlay, (void**)lplpDP ) != DP_OK )
6003 return DPERR_UNAVAILABLE;
6005 if( IsEqualGUID( &GUID_NULL, lpGUID ) )
6007 /* The GUID_NULL means don't bind a service provider. Just return the
6008 interface as is */
6009 return DP_OK;
6012 /* Bind the desired service provider since lpGUID is non NULL */
6013 TRACE( "Service Provider binding for %s\n", debugstr_guid(lpGUID) );
6015 /* We're going to use a DP3 interface */
6016 hr = IDirectPlayX_QueryInterface( *lplpDP, &IID_IDirectPlay3A,
6017 (LPVOID*)&lpDP3A );
6018 if( FAILED(hr) )
6020 ERR( "Failed to get DP3 interface: %s\n", DPLAYX_HresultToString(hr) );
6021 return hr;
6024 cbData.lpConn = NULL;
6025 cbData.lpGuid = lpGUID;
6027 /* We were given a service provider, find info about it... */
6028 hr = IDirectPlayX_EnumConnections( lpDP3A, NULL, cbDPCreateEnumConnections,
6029 &cbData, DPCONNECTION_DIRECTPLAY );
6030 if( ( FAILED(hr) ) ||
6031 ( cbData.lpConn == NULL )
6034 ERR( "Failed to get Enum for SP: %s\n", DPLAYX_HresultToString(hr) );
6035 IDirectPlayX_Release( lpDP3A );
6036 return DPERR_UNAVAILABLE;
6039 /* Initialize the service provider */
6040 hr = IDirectPlayX_InitializeConnection( lpDP3A, cbData.lpConn, 0 );
6041 if( FAILED(hr) )
6043 ERR( "Failed to Initialize SP: %s\n", DPLAYX_HresultToString(hr) );
6044 HeapFree( GetProcessHeap(), 0, cbData.lpConn );
6045 IDirectPlayX_Release( lpDP3A );
6046 return hr;
6049 /* Release our version of the interface now that we're done with it */
6050 IDirectPlayX_Release( lpDP3A );
6051 HeapFree( GetProcessHeap(), 0, cbData.lpConn );
6053 return DP_OK;