Пример #1
0
/*
 * DPlayClose
 *
 * Wrapper for DirectPlay Close API
 */
HRESULT DPlayClose(void)
{
	HRESULT hr=E_FAIL;

	if (glpDP) 
		hr = IDirectPlayX_Close(glpDP);
	
	return hr;
}
Пример #2
0
// ////////////////////////////////////////////////////////////////////////
// Create a new DPLAY game
HRESULT HostSession(LPDIRECTPLAY4A lpDirectPlay4A, LPSTR lpszSessionName, LPSTR lpszPlayerName,LPNETPLAY lpNetPlay,
					DWORD one, DWORD two, DWORD three, DWORD four, UDWORD mplayers)
{
	DPID				dpidPlayer;
	DPNAME				dpName;
	DPSESSIONDESC2		sessionDesc;
	HRESULT				hr;

	ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC2));					// host a new session
	sessionDesc.dwSize = sizeof(DPSESSIONDESC2);
   
    sessionDesc.guidApplication = GAME_GUID;
    sessionDesc.dwMaxPlayers = mplayers;
	sessionDesc.lpszSessionNameA = lpszSessionName;
#ifdef USE_DIRECTPLAY_PROTOCOL
	sessionDesc.dwFlags = DPSESSION_MIGRATEHOST | DPSESSION_KEEPALIVE | DPSESSION_DIRECTPLAYPROTOCOL ;
#else
	sessionDesc.dwFlags = DPSESSION_MIGRATEHOST | DPSESSION_KEEPALIVE;
#endif
	sessionDesc.dwUser1 = one;											// set the user flags
	sessionDesc.dwUser2 = two;
	sessionDesc.dwUser3 = three;
	sessionDesc.dwUser4 = four;

	hr = IDirectPlayX_Open(glpDP,&sessionDesc, DPOPEN_CREATE);
	if FAILED(hr)
	{
		goto OPEN_FAILURE;
	}
	ZeroMemory(&dpName, sizeof(DPNAME));								// fill out name structure
	dpName.dwSize = sizeof(DPNAME);
	dpName.lpszShortNameA = lpszPlayerName;
	dpName.lpszLongNameA = NULL;

	hr = IDirectPlayX_CreatePlayer(glpDP,&dpidPlayer, &dpName, lpNetPlay->hPlayerEvent, NULL, 0, 0);		
							
	if FAILED(hr)
	{
		goto CREATEPLAYER_FAILURE;
	}
	lpNetPlay->lpDirectPlay4A	= lpDirectPlay4A;							// return connection info
	lpNetPlay->dpidPlayer		= dpidPlayer;
	lpNetPlay->bHost			= TRUE;
	lpNetPlay->bSpectator		= FALSE;
	return (DP_OK);

CREATEPLAYER_FAILURE:
OPEN_FAILURE:
	IDirectPlayX_Close(glpDP);
	return (hr);
}
Пример #3
0
//====================================================================================================
//	DPlayRelease
//====================================================================================================
HRESULT DPlayRelease(void)
{
    HRESULT hr = DP_OK;

	if (g_lpDP)
	{
		IDirectPlayX_Close(g_lpDP );

		hr = IDirectPlayX_Release(g_lpDP);
		g_lpDP = NULL;
	}
	
	CoUninitialize();

    return hr;
}
Пример #4
0
// ////////////////////////////////////////////////////////////////////////
// Enter a DPLAY game 
HRESULT JoinSession(LPDIRECTPLAY4A lpDirectPlay4A,
					LPGUID lpguidSessionInstance, LPSTR lpszPlayerName,
					LPNETPLAY	lpNetPlay)
{
	DPID				dpidPlayer;
	DPNAME				dpName;
	DPSESSIONDESC2		sessionDesc;
	HRESULT				hr;

	ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC2));					// join existing session
	sessionDesc.dwSize = sizeof(DPSESSIONDESC2);
    sessionDesc.guidInstance = *lpguidSessionInstance;

	hr = IDirectPlayX_Open(glpDP,&sessionDesc, DPOPEN_JOIN);
	
	if FAILED(hr)
		goto OPEN_FAILURE;

	ZeroMemory(&dpName, sizeof(DPNAME));								// fill out name structure
	dpName.dwSize = sizeof(DPNAME);
	dpName.lpszShortNameA = lpszPlayerName;
	dpName.lpszLongNameA = NULL;

	hr = IDirectPlayX_CreatePlayer(glpDP,&dpidPlayer, &dpName, lpNetPlay->hPlayerEvent, NULL, 0, 0);			
							
	if FAILED(hr)
		goto CREATEPLAYER_FAILURE;
	
	lpNetPlay->lpDirectPlay4A = lpDirectPlay4A;							// return connection info
	lpNetPlay->dpidPlayer = dpidPlayer;
	lpNetPlay->bHost = FALSE;
	lpNetPlay->bSpectator = FALSE;

	return (DP_OK);

CREATEPLAYER_FAILURE:
OPEN_FAILURE:
	IDirectPlayX_Close(glpDP);
	return (hr);
}