Esempio n. 1
0
//==================================================================================================
//	NetPlayCreateSession
//==================================================================================================
BOOL NetPlayCreateSession(LPSTR SessionName, DWORD MaxPlayers)
{
	HRESULT	Hr;

	assert(g_lpDP);
	assert(lpConnectionBuffer);

	Hr = IDirectPlayX_InitializeConnection(g_lpDP, lpConnectionBuffer, 0);

	if (Hr != DP_OK)
	{
		DoDPError(Hr);
		return FALSE;
	}

	Hr = DPlayCreateSession(SessionName, MaxPlayers);

	if (Hr != DP_OK)
	{
		DoDPError(Hr);
		return FALSE;
	}

	return TRUE;
}
/*
 * DPlayCreate
 *
 * Wrapper for DirectPlay Create API.
 * Retrieves a DirectPlay4/DirectPlay4A interface based on the UNICODE flag
 * 
 */
HRESULT DPlayCreate(LPVOID lpCon)
{
	HRESULT hr=E_FAIL;

	// release if already exists
	if (glpDP) IDirectPlayX_Release(glpDP);
	glpDP=NULL;


	// create a DirectPlay4(A) interface
	hr = CoCreateInstance(&CLSID_DirectPlay, NULL, CLSCTX_INPROC_SERVER,
#ifdef UNICODE
						  &IID_IDirectPlay4, (LPVOID *) &glpDP);
#else
						  &IID_IDirectPlay4A, (LPVOID *) &glpDP);
#endif
	if (FAILED(hr))
		return (hr);

#if 1
	// initialize w/address
	if (lpCon)
	{
		hr = IDirectPlayX_InitializeConnection(glpDP, lpCon, 0);
		if (FAILED(hr))
			goto FAILURE;
	}
	return hr;

FAILURE:
	IDirectPlayX_Release(glpDP);
	glpDP = NULL;
#endif

	return hr;
}
Esempio n. 3
0
//====================================================================================================
//	 NetPlayEnumSession
//====================================================================================================
BOOL NetPlayEnumSession(LPSTR IPAdress, SESSION_DESC **SessionList, DWORD *SessionNum)
{	
	HRESULT		hr;

#if 1
	char					tempBuf[1024];
	DWORD					tempLng = 1024;
	LPDIRECTPLAYLOBBY2A		lpDPL = NULL;

	// Free the old connection buffer
	if(lpConnectionBuffer ) 
	{
		free( lpConnectionBuffer );
		lpConnectionBuffer = NULL;
	}

	hr = CoCreateInstance(	&CLSID_DirectPlayLobby, NULL, CLSCTX_INPROC_SERVER,
							&IID_IDirectPlayLobby3A, (LPVOID *) &lpDPL );

	if (hr != DP_OK)
	{
		DoDPError(hr);
		return( FALSE );
	}

 	hr = IDirectPlayLobby_CreateAddress(lpDPL, &DPSPGUID_TCPIP, &DPAID_INet, (LPVOID)IPAdress, strlen(IPAdress), tempBuf, &tempLng);

	if (hr != DP_OK)
	{
		DoDPError(hr);
		return( FALSE );
	}

	if (lpDPL)
	{
		hr = IDirectPlayLobby_Release(lpDPL);
		
		if (hr != DP_OK)
		{
			DoDPError(hr);
			return( FALSE );
		}
		lpDPL = NULL;
	}

	hr = IDirectPlayX_InitializeConnection( g_lpDP, tempBuf, 0);
#else
	hr = IDirectPlayX_InitializeConnection( g_lpDP, lpConnectionBuffer, 0);
#endif

	if (hr != DP_OK)
	{
		DoDPError(hr);
		return( FALSE );
	}
	
	GlobalSession = NULL;
	gSessionCnt = 0;

	hr = DPlayEnumSessions(0, EnumSession, NULL, 0);
	
	*SessionList = GlobalSession;
	*SessionNum = gSessionCnt;
	
	return( TRUE );

}