Esempio n. 1
0
//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
BOOL FAR PASCAL DPConnect_EnumSessionsCallback(LPCDPSESSIONDESC2 pdpsd, DWORD* pdwTimeout,
												DWORD dwFlags, VOID* pvContext)
{
	HRESULT hRet;

	if (dwFlags & DPESC_TIMEDOUT)
		return FALSE;

	if (strcmp(pdpsd->lpszSessionNameA, g_cDesc.szSessionName) == 0) {
		DPSESSIONDESC2 dpsd;
		memset(&dpsd, 0, sizeof(dpsd));
		dpsd.dwSize = sizeof(dpsd);
		dpsd.guidInstance = pdpsd->guidInstance;
		dpsd.guidApplication = PXAPP_GUID;

		hRet = g_pDPlay->Open(&dpsd, DPOPEN_JOIN);
		if (FAILED(hRet))
			return FALSE;

		*(BOOL*) pvContext = TRUE;
		return FALSE; //for stop enumerations
	}

	return TRUE;
}
Esempio n. 2
0
HRESULT bld_create_player(
        LPDIRECTPLAY4A dp_interface, const char *game_name,
        const char *player_name, PLAYER_INFO *player_info
) {
        DPID dpid;/* the dpid of the player created given by directplay */
        DPNAME name;
        HRESULT hr;
        DPSESSIONDESC2 session_desc;

        if (dp_interface == NULL)
                return DPERR_INVALIDOBJECT;

        ZeroMemory(&session_desc, sizeof(DPSESSIONDESC2));
        session_desc.dwSize = sizeof(DPSESSIONDESC2);
        session_desc.dwFlags = (DPSESSION_KEEPALIVE | DPSESSION_MIGRATEHOST);
        session_desc.guidApplication = AppGUID;
        session_desc.dwMaxPlayers = gbl_max_players;
        session_desc.lpszSessionNameA = (char *)game_name;

        hr = dp_interface->Open(&session_desc, DPOPEN_CREATE);
        if (FAILED(hr))
                goto close;

        ZeroMemory(&name,sizeof(DPNAME));
        name.dwSize = sizeof(DPNAME);
        name.lpszShortNameA = (char *)player_name;
        name.lpszLongNameA = NULL;

        dp_interface->CreatePlayer(
                &dpid, &name, player_info->event, NULL, 0, DPPLAYER_SERVERPLAYER
        );
        if (FAILED(hr))
                goto close;

        player_info->dp_interface = dp_interface;
        player_info->dpid = dpid;
        player_info->is_server = 1;

        return DP_OK;
close:
        dp_interface->Close();

        return hr;
}
Esempio n. 3
0
HRESULT bld_create_client_player(
        LPDIRECTPLAY4A dp_interface, LPGUID sessionGuid,
        const char *player_name, PLAYER_INFO *player_info)
{
        DPID dpid;/* the dpid of the player created given by directplay */
        DPNAME name;
        HRESULT hr;
        DPSESSIONDESC2 session_desc;

        if (dp_interface == NULL)
                return DPERR_INVALIDOBJECT;

        ZeroMemory(&session_desc, sizeof(DPSESSIONDESC2));
        session_desc.dwSize = sizeof(DPSESSIONDESC2);
        session_desc.guidInstance = *sessionGuid;

        player_info->dp_interface = dp_interface;

        hr = dp_interface->Open(&session_desc, DPOPEN_JOIN);
        if (FAILED(hr))
                goto close;

        ZeroMemory(&name,sizeof(DPNAME));
        name.dwSize = sizeof(DPNAME);
        name.lpszShortNameA = (char *)player_name;
        name.lpszLongNameA = NULL;

        dp_interface->CreatePlayer(
                &dpid, &name, player_info->event, NULL, 0, 0
        );
        if (FAILED(hr))
                goto close;

        player_info->dpid = dpid;
        player_info->is_server = 0;

        return DP_OK;

close:
        dp_interface->Close();

        return hr;
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
BOOL Network_CreateSession(const char* pszSessionName, int nMaxPlayers)
{
	DPSESSIONDESC2 dpsd;
	HRESULT hRet;

	if (!nm_InitConnection(NULL))
		return FALSE;

	strcpy(g_cDesc.szSessionName, pszSessionName);
	g_cDesc.bIsServer = TRUE;

	memset(&dpsd, 0, sizeof(dpsd));
	dpsd.dwSize = sizeof(dpsd);
	dpsd.lpszSessionNameA = g_cDesc.szSessionName;
	dpsd.guidApplication = PXAPP_GUID;
	dpsd.dwMaxPlayers = nMaxPlayers;
	dpsd.dwFlags = DPSESSION_KEEPALIVE;

	hRet = g_pDPlay->Open(&dpsd, DPOPEN_CREATE);
	if (FAILED(hRet))
		return FALSE;

	return TRUE;
}