2000-07-10 15:19:28 +02:00
|
|
|
/* DirectPlay & DirectPlayLobby messaging implementation
|
|
|
|
*
|
2001-04-12 23:10:54 +02:00
|
|
|
* Copyright 2000,2001 - Peter Hunnisett
|
2000-07-10 15:19:28 +02:00
|
|
|
*
|
|
|
|
* <presently under construction - contact hunnise@nortelnetworks.com>
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-07-10 15:19:28 +02:00
|
|
|
*/
|
|
|
|
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2000-07-10 15:19:28 +02:00
|
|
|
#include "winbase.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-07-10 15:19:28 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2000-08-30 01:55:06 +02:00
|
|
|
#include "winerror.h"
|
2000-08-25 23:58:05 +02:00
|
|
|
|
2000-07-10 15:19:28 +02:00
|
|
|
#include "dplayx_messages.h"
|
2000-08-30 01:55:06 +02:00
|
|
|
#include "dplay_global.h"
|
|
|
|
#include "dplayx_global.h"
|
2001-04-12 23:10:54 +02:00
|
|
|
#include "name_server.h"
|
2000-07-10 15:19:28 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dplay);
|
2000-07-10 15:19:28 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
typedef struct tagMSGTHREADINFO
|
|
|
|
{
|
|
|
|
HANDLE hStart;
|
2002-06-01 01:06:46 +02:00
|
|
|
HANDLE hDeath;
|
2000-08-25 23:58:05 +02:00
|
|
|
HANDLE hSettingRead;
|
2002-06-01 01:06:46 +02:00
|
|
|
HANDLE hNotifyEvent;
|
2000-08-25 23:58:05 +02:00
|
|
|
} MSGTHREADINFO, *LPMSGTHREADINFO;
|
|
|
|
|
|
|
|
static DWORD CALLBACK DPL_MSG_ThreadMain( LPVOID lpContext );
|
2002-06-01 01:06:46 +02:00
|
|
|
static LPVOID DP_MSG_ExpectReply( IDirectPlay2AImpl* This, LPDPSP_SENDDATA data,
|
2000-10-19 22:20:58 +02:00
|
|
|
DWORD dwWaitTime, WORD wReplyCommandId,
|
|
|
|
LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize );
|
|
|
|
|
2000-07-10 15:19:28 +02:00
|
|
|
|
|
|
|
/* Create the message reception thread to allow the application to receive
|
|
|
|
* asynchronous message reception
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD CreateLobbyMessageReceptionThread( HANDLE hNotifyEvent, HANDLE hStart,
|
2000-08-25 23:58:05 +02:00
|
|
|
HANDLE hDeath, HANDLE hConnRead )
|
2000-07-10 15:19:28 +02:00
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
DWORD dwMsgThreadId;
|
|
|
|
LPMSGTHREADINFO lpThreadInfo;
|
2000-07-10 15:19:28 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
lpThreadInfo = HeapAlloc( GetProcessHeap(), 0, sizeof( *lpThreadInfo ) );
|
|
|
|
if( lpThreadInfo == NULL )
|
2000-07-10 15:19:28 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* The notify event may or may not exist. Depends if async comm or not */
|
|
|
|
if( hNotifyEvent &&
|
2002-06-01 01:06:46 +02:00
|
|
|
!DuplicateHandle( GetCurrentProcess(), hNotifyEvent,
|
|
|
|
GetCurrentProcess(), &lpThreadInfo->hNotifyEvent,
|
2000-08-25 23:58:05 +02:00
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS ) )
|
|
|
|
{
|
|
|
|
ERR( "Unable to duplicate event handle\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These 3 handles don't need to be duplicated because we don't keep a
|
|
|
|
* reference to them where they're created. They're created specifically
|
2002-06-01 01:06:46 +02:00
|
|
|
* for the message thread
|
2000-08-25 23:58:05 +02:00
|
|
|
*/
|
|
|
|
lpThreadInfo->hStart = hStart;
|
|
|
|
lpThreadInfo->hDeath = hDeath;
|
|
|
|
lpThreadInfo->hSettingRead = hConnRead;
|
|
|
|
|
|
|
|
if( !CreateThread( NULL, /* Security attribs */
|
2002-06-01 01:06:46 +02:00
|
|
|
0, /* Stack */
|
2000-08-25 23:58:05 +02:00
|
|
|
DPL_MSG_ThreadMain, /* Msg reception function */
|
|
|
|
lpThreadInfo, /* Msg reception func parameter */
|
|
|
|
0, /* Flags */
|
|
|
|
&dwMsgThreadId /* Updated with thread id */
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ERR( "Unable to create msg thread\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Should I be closing the handle to the thread or does that
|
|
|
|
terminate the thread? */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-10 15:19:28 +02:00
|
|
|
return dwMsgThreadId;
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpThreadInfo );
|
|
|
|
|
|
|
|
return 0;
|
2000-07-10 15:19:28 +02:00
|
|
|
}
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
static DWORD CALLBACK DPL_MSG_ThreadMain( LPVOID lpContext )
|
2000-07-10 15:19:28 +02:00
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
LPMSGTHREADINFO lpThreadInfo = (LPMSGTHREADINFO)lpContext;
|
|
|
|
DWORD dwWaitResult;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
TRACE( "Msg thread created. Waiting on app startup\n" );
|
|
|
|
|
|
|
|
/* Wait to ensure that the lobby application is started w/ 1 min timeout */
|
|
|
|
dwWaitResult = WaitForSingleObject( lpThreadInfo->hStart, 10000 /* 10 sec */ );
|
|
|
|
if( dwWaitResult == WAIT_TIMEOUT )
|
|
|
|
{
|
|
|
|
FIXME( "Should signal app/wait creation failure (0x%08lx)\n", dwWaitResult );
|
|
|
|
goto end_of_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close this handle as it's not needed anymore */
|
|
|
|
CloseHandle( lpThreadInfo->hStart );
|
|
|
|
lpThreadInfo->hStart = 0;
|
|
|
|
|
|
|
|
/* Wait until the lobby knows what it is */
|
|
|
|
dwWaitResult = WaitForSingleObject( lpThreadInfo->hSettingRead, INFINITE );
|
|
|
|
if( dwWaitResult == WAIT_TIMEOUT )
|
|
|
|
{
|
|
|
|
ERR( "App Read connection setting timeout fail (0x%08lx)\n", dwWaitResult );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close this handle as it's not needed anymore */
|
|
|
|
CloseHandle( lpThreadInfo->hSettingRead );
|
|
|
|
lpThreadInfo->hSettingRead = 0;
|
|
|
|
|
|
|
|
TRACE( "App created && intialized starting main message reception loop\n" );
|
2000-07-10 15:19:28 +02:00
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
MSG lobbyMsg;
|
2001-01-02 23:16:14 +01:00
|
|
|
GetMessageW( &lobbyMsg, 0, 0, 0 );
|
2000-07-10 15:19:28 +02:00
|
|
|
}
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
end_of_thread:
|
|
|
|
TRACE( "Msg thread exiting!\n" );
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpThreadInfo );
|
|
|
|
|
|
|
|
return 0;
|
2000-07-10 15:19:28 +02:00
|
|
|
}
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* DP messageing stuff */
|
|
|
|
static HANDLE DP_MSG_BuildAndLinkReplyStruct( IDirectPlay2Impl* This,
|
2002-06-01 01:06:46 +02:00
|
|
|
LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList,
|
2000-10-19 22:20:58 +02:00
|
|
|
WORD wReplyCommandId );
|
|
|
|
static LPVOID DP_MSG_CleanReplyStruct( LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList,
|
|
|
|
LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize );
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
HANDLE DP_MSG_BuildAndLinkReplyStruct( IDirectPlay2Impl* This,
|
|
|
|
LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList, WORD wReplyCommandId )
|
|
|
|
{
|
|
|
|
lpReplyStructList->replyExpected.hReceipt = CreateEventA( NULL, FALSE, FALSE, NULL );
|
|
|
|
lpReplyStructList->replyExpected.wExpectedReply = wReplyCommandId;
|
|
|
|
lpReplyStructList->replyExpected.lpReplyMsg = NULL;
|
|
|
|
lpReplyStructList->replyExpected.dwMsgBodySize = 0;
|
|
|
|
|
|
|
|
/* Insert into the message queue while locked */
|
|
|
|
EnterCriticalSection( &This->unk->DP_lock );
|
|
|
|
DPQ_INSERT( This->dp2->replysExpected, lpReplyStructList, replysExpected );
|
|
|
|
LeaveCriticalSection( &This->unk->DP_lock );
|
|
|
|
|
|
|
|
return lpReplyStructList->replyExpected.hReceipt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
LPVOID DP_MSG_CleanReplyStruct( LPDP_MSG_REPLY_STRUCT_LIST lpReplyStructList,
|
|
|
|
LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize )
|
|
|
|
{
|
|
|
|
CloseHandle( lpReplyStructList->replyExpected.hReceipt );
|
|
|
|
|
|
|
|
*lplpReplyMsg = lpReplyStructList->replyExpected.lpReplyMsg;
|
|
|
|
*lpdwMsgBodySize = lpReplyStructList->replyExpected.dwMsgBodySize;
|
|
|
|
|
|
|
|
return lpReplyStructList->replyExpected.lpReplyMsg;
|
|
|
|
}
|
2000-08-30 01:55:06 +02:00
|
|
|
|
|
|
|
HRESULT DP_MSG_SendRequestPlayerId( IDirectPlay2AImpl* This, DWORD dwFlags,
|
|
|
|
LPDPID lpdpidAllocatedId )
|
|
|
|
{
|
|
|
|
LPVOID lpMsg;
|
|
|
|
LPDPMSG_REQUESTNEWPLAYERID lpMsgBody;
|
|
|
|
DWORD dwMsgSize;
|
|
|
|
HRESULT hr = DP_OK;
|
|
|
|
|
|
|
|
dwMsgSize = This->dp2->spData.dwSPHeaderSize + sizeof( *lpMsgBody );
|
|
|
|
|
|
|
|
lpMsg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwMsgSize );
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
lpMsgBody = (LPDPMSG_REQUESTNEWPLAYERID)( (BYTE*)lpMsg +
|
2000-08-30 01:55:06 +02:00
|
|
|
This->dp2->spData.dwSPHeaderSize );
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Compose dplay message envelope */
|
2000-08-30 01:55:06 +02:00
|
|
|
lpMsgBody->envelope.dwMagic = DPMSGMAGIC_DPLAYMSG;
|
|
|
|
lpMsgBody->envelope.wCommandId = DPMSGCMD_REQUESTNEWPLAYERID;
|
|
|
|
lpMsgBody->envelope.wVersion = DPMSGVER_DP6;
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Compose the body of the message */
|
2000-08-30 01:55:06 +02:00
|
|
|
lpMsgBody->dwFlags = dwFlags;
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Send the message */
|
|
|
|
{
|
2000-08-30 01:55:06 +02:00
|
|
|
DPSP_SENDDATA data;
|
|
|
|
|
|
|
|
data.dwFlags = DPSEND_GUARANTEED;
|
|
|
|
data.idPlayerTo = 0; /* Name server */
|
|
|
|
data.idPlayerFrom = 0; /* Sending from DP */
|
|
|
|
data.lpMessage = lpMsg;
|
|
|
|
data.dwMessageSize = dwMsgSize;
|
|
|
|
data.bSystemMessage = TRUE; /* Allow reply to be sent */
|
|
|
|
data.lpISP = This->dp2->spData.lpISP;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE( "Asking for player id w/ dwFlags 0x%08lx\n",
|
2000-10-19 22:20:58 +02:00
|
|
|
lpMsgBody->dwFlags );
|
2000-09-27 01:11:48 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
DP_MSG_ExpectReply( This, &data, DPMSG_DEFAULT_WAIT_TIME, DPMSGCMD_NEWPLAYERIDREPLY,
|
2000-10-19 22:20:58 +02:00
|
|
|
&lpMsg, &dwMsgSize );
|
2000-08-30 01:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to examine the data and extract the new player id */
|
2000-09-27 01:11:48 +02:00
|
|
|
if( !FAILED(hr) )
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
LPCDPMSG_NEWPLAYERIDREPLY lpcReply;
|
2000-09-27 01:11:48 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
lpcReply = (LPCDPMSG_NEWPLAYERIDREPLY)lpMsg;
|
2000-09-27 01:11:48 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
*lpdpidAllocatedId = lpcReply->dpidNewPlayerId;
|
2000-09-27 01:11:48 +02:00
|
|
|
|
|
|
|
TRACE( "Received reply for id = 0x%08lx\n", lpcReply->dpidNewPlayerId );
|
|
|
|
|
|
|
|
/* FIXME: I think that the rest of the message has something to do
|
|
|
|
* with remote data for the player that perhaps I need to setup.
|
2000-10-19 22:20:58 +02:00
|
|
|
* However, with the information that is passed, all that it could
|
2002-06-01 01:06:46 +02:00
|
|
|
* be used for is a standardized intialization value, which I'm
|
2000-10-19 22:20:58 +02:00
|
|
|
* guessing we can do without. Unless the message content is the same
|
|
|
|
* for several different messages?
|
2000-09-27 01:11:48 +02:00
|
|
|
*/
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, lpMsg );
|
2000-10-19 22:20:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DP_MSG_ForwardPlayerCreation( IDirectPlay2AImpl* This, DPID dpidServer )
|
|
|
|
{
|
|
|
|
LPVOID lpMsg;
|
|
|
|
LPDPMSG_FORWARDADDPLAYER lpMsgBody;
|
|
|
|
DWORD dwMsgSize;
|
|
|
|
HRESULT hr = DP_OK;
|
|
|
|
|
|
|
|
dwMsgSize = This->dp2->spData.dwSPHeaderSize + sizeof( *lpMsgBody );
|
|
|
|
|
|
|
|
lpMsg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwMsgSize );
|
|
|
|
|
|
|
|
lpMsgBody = (LPDPMSG_FORWARDADDPLAYER)( (BYTE*)lpMsg +
|
|
|
|
This->dp2->spData.dwSPHeaderSize );
|
|
|
|
|
|
|
|
/* Compose dplay message envelope */
|
|
|
|
lpMsgBody->envelope.dwMagic = DPMSGMAGIC_DPLAYMSG;
|
|
|
|
lpMsgBody->envelope.wCommandId = DPMSGCMD_FORWARDADDPLAYER;
|
|
|
|
lpMsgBody->envelope.wVersion = DPMSGVER_DP6;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
LPBYTE lpPData;
|
|
|
|
DWORD dwDataSize;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* SP Player remote data needs to be propagated at some point - is this the point? */
|
2001-04-12 23:10:54 +02:00
|
|
|
IDirectPlaySP_GetSPPlayerData( This->dp2->spData.lpISP, 0, (LPVOID*)&lpPData, &dwDataSize, DPSET_REMOTE );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
ERR( "Player Data size is 0x%08lx\n"
|
|
|
|
"[%02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x]\n"
|
2002-06-01 01:06:46 +02:00
|
|
|
"[%02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x]\n",
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
dwDataSize,
|
|
|
|
lpPData[0], lpPData[1], lpPData[2], lpPData[3], lpPData[4],
|
|
|
|
lpPData[5], lpPData[6], lpPData[7], lpPData[8], lpPData[9],
|
|
|
|
lpPData[10], lpPData[11], lpPData[12], lpPData[13], lpPData[14],
|
|
|
|
lpPData[15], lpPData[16], lpPData[17], lpPData[18], lpPData[19],
|
|
|
|
lpPData[20], lpPData[21], lpPData[22], lpPData[23], lpPData[24],
|
|
|
|
lpPData[25], lpPData[26], lpPData[27], lpPData[28], lpPData[29],
|
2002-06-01 01:06:46 +02:00
|
|
|
lpPData[30], lpPData[31]
|
2000-10-19 22:20:58 +02:00
|
|
|
);
|
|
|
|
DebugBreak();
|
|
|
|
}
|
2000-09-27 01:11:48 +02:00
|
|
|
#endif
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Compose body of message */
|
|
|
|
lpMsgBody->dpidAppServer = dpidServer;
|
|
|
|
lpMsgBody->unknown2[0] = 0x0;
|
|
|
|
lpMsgBody->unknown2[1] = 0x1c;
|
|
|
|
lpMsgBody->unknown2[2] = 0x6c;
|
|
|
|
lpMsgBody->unknown2[3] = 0x50;
|
|
|
|
lpMsgBody->unknown2[4] = 0x9;
|
|
|
|
|
|
|
|
lpMsgBody->dpidAppServer2 = dpidServer;
|
|
|
|
lpMsgBody->unknown3[0] = 0x0;
|
|
|
|
lpMsgBody->unknown3[0] = 0x0;
|
|
|
|
lpMsgBody->unknown3[0] = 0x20;
|
|
|
|
lpMsgBody->unknown3[0] = 0x0;
|
|
|
|
lpMsgBody->unknown3[0] = 0x0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
lpMsgBody->dpidAppServer3 = dpidServer;
|
2002-06-01 01:06:46 +02:00
|
|
|
lpMsgBody->unknown4[0] = 0x30;
|
2000-10-19 22:20:58 +02:00
|
|
|
lpMsgBody->unknown4[1] = 0xb;
|
|
|
|
lpMsgBody->unknown4[2] = 0x0;
|
2001-04-12 23:10:54 +02:00
|
|
|
|
|
|
|
lpMsgBody->unknown4[3] = NS_GetNsMagic( This->dp2->lpNameServerData ) -
|
|
|
|
0x02000000;
|
|
|
|
TRACE( "Setting first magic to 0x%08lx\n", lpMsgBody->unknown4[3] );
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
lpMsgBody->unknown4[4] = 0x0;
|
|
|
|
lpMsgBody->unknown4[5] = 0x0;
|
|
|
|
lpMsgBody->unknown4[6] = 0x0;
|
2001-04-12 23:10:54 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
lpMsgBody->unknown4[7] = NS_GetOtherMagic( This->dp2->lpNameServerData )
|
|
|
|
#else
|
|
|
|
lpMsgBody->unknown4[7] = NS_GetNsMagic( This->dp2->lpNameServerData );
|
|
|
|
#endif
|
|
|
|
TRACE( "Setting second magic to 0x%08lx\n", lpMsgBody->unknown4[7] );
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
lpMsgBody->unknown4[8] = 0x0;
|
|
|
|
lpMsgBody->unknown4[9] = 0x0;
|
|
|
|
lpMsgBody->unknown4[10] = 0x0;
|
|
|
|
lpMsgBody->unknown4[11] = 0x0;
|
|
|
|
lpMsgBody->unknown4[12] = 0x0;
|
|
|
|
|
|
|
|
lpMsgBody->unknown5[0] = 0x0;
|
|
|
|
lpMsgBody->unknown5[1] = 0x0;
|
|
|
|
|
|
|
|
/* Send the message */
|
|
|
|
{
|
|
|
|
DPSP_SENDDATA data;
|
|
|
|
|
|
|
|
data.dwFlags = DPSEND_GUARANTEED;
|
|
|
|
data.idPlayerTo = 0; /* Name server */
|
|
|
|
data.idPlayerFrom = dpidServer; /* Sending from session server */
|
|
|
|
data.lpMessage = lpMsg;
|
|
|
|
data.dwMessageSize = dwMsgSize;
|
|
|
|
data.bSystemMessage = TRUE; /* Allow reply to be sent */
|
|
|
|
data.lpISP = This->dp2->spData.lpISP;
|
|
|
|
|
2001-04-12 23:10:54 +02:00
|
|
|
TRACE( "Sending forward player request with 0x%08lx\n", dpidServer );
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
lpMsg = DP_MSG_ExpectReply( This, &data,
|
|
|
|
DPMSG_WAIT_60_SECS,
|
2000-10-19 22:20:58 +02:00
|
|
|
DPMSGCMD_GETNAMETABLEREPLY,
|
|
|
|
&lpMsg, &dwMsgSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to examine the data and extract the new player id */
|
|
|
|
if( lpMsg != NULL )
|
|
|
|
{
|
|
|
|
FIXME( "Name Table reply received: stub\n" );
|
2000-09-27 01:11:48 +02:00
|
|
|
}
|
2000-08-30 01:55:06 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Queue up a structure indicating that we want a reply of type wReplyCommandId. DPlay does
|
|
|
|
* not seem to offer any way of uniquely differentiating between replies of the same type
|
|
|
|
* relative to the request sent. There is an implicit assumption that there will be no
|
|
|
|
* ordering issues on sends and receives from the opposite machine. No wonder MS is not
|
|
|
|
* a networking company.
|
|
|
|
*/
|
|
|
|
static
|
2002-06-01 01:06:46 +02:00
|
|
|
LPVOID DP_MSG_ExpectReply( IDirectPlay2AImpl* This, LPDPSP_SENDDATA lpData,
|
2000-10-19 22:20:58 +02:00
|
|
|
DWORD dwWaitTime, WORD wReplyCommandId,
|
|
|
|
LPVOID* lplpReplyMsg, LPDWORD lpdwMsgBodySize )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hMsgReceipt;
|
|
|
|
DP_MSG_REPLY_STRUCT_LIST replyStructList;
|
|
|
|
DWORD dwWaitReturn;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Setup for receipt */
|
2002-06-01 01:06:46 +02:00
|
|
|
hMsgReceipt = DP_MSG_BuildAndLinkReplyStruct( This, &replyStructList,
|
2000-10-19 22:20:58 +02:00
|
|
|
wReplyCommandId );
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE( "Sending msg and expecting cmd %u in reply within %lu ticks\n",
|
2000-10-19 22:20:58 +02:00
|
|
|
wReplyCommandId, dwWaitTime );
|
|
|
|
hr = (*This->dp2->spData.lpCB->Send)( lpData );
|
|
|
|
|
|
|
|
if( FAILED(hr) )
|
|
|
|
{
|
2001-04-12 23:10:54 +02:00
|
|
|
ERR( "Send failed: %s\n", DPLAYX_HresultToString( hr ) );
|
2000-10-19 22:20:58 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-12 23:10:54 +02:00
|
|
|
/* The reply message will trigger the hMsgReceipt event effectively switching
|
|
|
|
* control back to this thread. See DP_MSG_ReplyReceived.
|
|
|
|
*/
|
2000-10-19 22:20:58 +02:00
|
|
|
dwWaitReturn = WaitForSingleObject( hMsgReceipt, dwWaitTime );
|
|
|
|
if( dwWaitReturn != WAIT_OBJECT_0 )
|
|
|
|
{
|
|
|
|
ERR( "Wait failed 0x%08lx\n", dwWaitReturn );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean Up */
|
|
|
|
return DP_MSG_CleanReplyStruct( &replyStructList, lplpReplyMsg, lpdwMsgBodySize );
|
|
|
|
}
|
2000-08-30 01:55:06 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
/* Determine if there is a matching request for this incomming message and then copy
|
|
|
|
* all important data. It is quite silly to have to copy the message, but the documents
|
|
|
|
* indicate that a copy is taken. Silly really.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
void DP_MSG_ReplyReceived( IDirectPlay2AImpl* This, WORD wCommandId,
|
2000-10-19 22:20:58 +02:00
|
|
|
LPCVOID lpcMsgBody, DWORD dwMsgBodySize )
|
2000-08-30 01:55:06 +02:00
|
|
|
{
|
2000-10-19 22:20:58 +02:00
|
|
|
LPDP_MSG_REPLY_STRUCT_LIST lpReplyList;
|
2000-08-30 01:55:06 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
#if 0
|
|
|
|
if( wCommandId == DPMSGCMD_FORWARDADDPLAYER )
|
|
|
|
{
|
|
|
|
DebugBreak();
|
|
|
|
}
|
|
|
|
#endif
|
2000-08-30 01:55:06 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Find, and immediately remove (to avoid double triggering), the appropriate entry. Call locked to
|
2000-10-19 22:20:58 +02:00
|
|
|
* avoid problems.
|
|
|
|
*/
|
|
|
|
EnterCriticalSection( &This->unk->DP_lock );
|
|
|
|
DPQ_REMOVE_ENTRY( This->dp2->replysExpected, replysExpected, replyExpected.wExpectedReply,\
|
|
|
|
==, wCommandId, lpReplyList );
|
2002-06-01 01:06:46 +02:00
|
|
|
LeaveCriticalSection( &This->unk->DP_lock );
|
2000-08-30 01:55:06 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
if( lpReplyList != NULL )
|
2000-08-30 01:55:06 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
lpReplyList->replyExpected.dwMsgBodySize = dwMsgBodySize;
|
2000-10-19 22:20:58 +02:00
|
|
|
lpReplyList->replyExpected.lpReplyMsg = HeapAlloc( GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
dwMsgBodySize );
|
2002-06-01 01:06:46 +02:00
|
|
|
CopyMemory( lpReplyList->replyExpected.lpReplyMsg,
|
2000-10-19 22:20:58 +02:00
|
|
|
lpcMsgBody, dwMsgBodySize );
|
|
|
|
|
|
|
|
/* Signal the thread which sent the message that it has a reply */
|
|
|
|
SetEvent( lpReplyList->replyExpected.hReceipt );
|
2000-08-30 01:55:06 +02:00
|
|
|
}
|
2000-10-19 22:20:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR( "No receipt event set - only expecting in reply mode\n" );
|
|
|
|
DebugBreak();
|
|
|
|
}
|
2001-04-12 23:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DP_MSG_ToSelf( IDirectPlay2AImpl* This, DPID dpidSelf )
|
|
|
|
{
|
|
|
|
LPVOID lpMsg;
|
|
|
|
LPDPMSG_SENDENVELOPE lpMsgBody;
|
|
|
|
DWORD dwMsgSize;
|
|
|
|
|
|
|
|
dwMsgSize = This->dp2->spData.dwSPHeaderSize + sizeof( *lpMsgBody );
|
|
|
|
|
|
|
|
lpMsg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwMsgSize );
|
|
|
|
|
|
|
|
lpMsgBody = (LPDPMSG_SENDENVELOPE)( (BYTE*)lpMsg +
|
|
|
|
This->dp2->spData.dwSPHeaderSize );
|
|
|
|
|
|
|
|
/* Compose dplay message envelope */
|
|
|
|
lpMsgBody->dwMagic = DPMSGMAGIC_DPLAYMSG;
|
|
|
|
lpMsgBody->wCommandId = DPMSGCMD_JUSTENVELOPE;
|
|
|
|
lpMsgBody->wVersion = DPMSGVER_DP6;
|
|
|
|
|
|
|
|
/* Send the message to ourselves */
|
|
|
|
{
|
|
|
|
DPSP_SENDDATA data;
|
|
|
|
|
|
|
|
data.dwFlags = 0;
|
|
|
|
data.idPlayerTo = dpidSelf; /* Sending to session server */
|
|
|
|
data.idPlayerFrom = 0; /* Sending from session server */
|
|
|
|
data.lpMessage = lpMsg;
|
|
|
|
data.dwMessageSize = dwMsgSize;
|
|
|
|
data.bSystemMessage = TRUE; /* Allow reply to be sent */
|
|
|
|
data.lpISP = This->dp2->spData.lpISP;
|
|
|
|
|
|
|
|
lpMsg = DP_MSG_ExpectReply( This, &data,
|
|
|
|
DPMSG_WAIT_5_SECS,
|
|
|
|
DPMSGCMD_JUSTENVELOPE,
|
|
|
|
&lpMsg, &dwMsgSize );
|
|
|
|
}
|
2000-10-19 22:20:58 +02:00
|
|
|
}
|
2000-08-30 01:55:06 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
void DP_MSG_ErrorReceived( IDirectPlay2AImpl* This, WORD wCommandId,
|
|
|
|
LPCVOID lpMsgBody, DWORD dwMsgBodySize )
|
|
|
|
{
|
|
|
|
LPCDPMSG_FORWARDADDPLAYERNACK lpcErrorMsg;
|
2000-08-30 01:55:06 +02:00
|
|
|
|
2000-10-19 22:20:58 +02:00
|
|
|
lpcErrorMsg = (LPCDPMSG_FORWARDADDPLAYERNACK)lpMsgBody;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
ERR( "Received error message %u. Error is %s\n",
|
2000-10-19 22:20:58 +02:00
|
|
|
wCommandId, DPLAYX_HresultToString( lpcErrorMsg->errorCode) );
|
|
|
|
DebugBreak();
|
2000-08-30 01:55:06 +02:00
|
|
|
}
|
2000-10-19 22:20:58 +02:00
|
|
|
|