Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Name: 
// Desc: create local player
//-----------------------------------------------------------------------------
BOOL Network_CreatePlayer(const char* pszPlayerName)
{
	DPNAME dpname;
	HRESULT hRet;

	if (g_pDPlay == NULL)
		return FALSE;

	strcpy(g_cDesc.szPlayerName, pszPlayerName);
	g_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

	memset(&dpname, 0, sizeof(DPNAME));
	dpname.dwSize = sizeof(DPNAME);
	dpname.lpszShortNameA = g_cDesc.szPlayerName;

	hRet = g_pDPlay->CreatePlayer(&g_LocalPlayerID, &dpname, g_hEvent, NULL, 0, 0);
	if (FAILED(hRet))
		return FALSE;

	return TRUE;
}