DirectPlay.h
资源名称:DXGuide.zip [点击查看]
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:6k
源码类别:
DirextX编程
开发平台:
Visual C++
- // Copyright (C) 1998-1999 DXGuide. All Rights Reserved.
- // File: DirectPlay.h
- #ifndef _DIRECTPLAY__H
- #define _DIRECTPLAY__H
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- #define IDIRECTPLAY2_OR_GREATER
- #include <dplay.h>
- #include <dplobby.h>
- #include <afxtempl.h>
- #include "DPConnectionObject.h"
- #include "DPSessionInfoObject.h"
- #include "DPPlayerInfoObject.h"
- class CDirectPlay
- {
- public:
- CDirectPlay(void);
- virtual ~CDirectPlay();
- protected:
- bool CreateDirectPlayInterface(void);
- bool CreateDirectPlayLobbyInterface(void);
- public:
- void SetMaxPlayers(DWORD dwMaxPlayers);
- void SetClientServerMode(bool bClientServerMode);
- bool SetupConnection(DWORD dwMaxPlayers = 0);
- bool ConnectUsingLobby(void);
- virtual bool ConnectUsingSettings(void);
- virtual bool HandleSystemMessage(void);
- virtual bool HandleApplicationMessage(DPID idFrom, DPID idTo);
- bool GetInfo(REFGUID guidApp);
- bool Create(int nProviderIndex, bool bHost, LPCTSTR lpszAddress = NULL, int nModemIndex = -1);
- bool Create(REFGUID guidServiceProvider, bool bHost, LPCTSTR lpszAddress = NULL, LPCTSTR lpszModem = NULL);
- bool InitializeConnection(LPVOID lpConnection);
- bool CreateSession(LPCTSTR lpszSessionName,
- bool bSecure = false,
- LPCTSTR lpszSecurityProvider = NULL);
- bool EnumSessions(DWORD dwTimeout = 0, DWORD dwFlags = DPENUMSESSIONS_AVAILABLE);
- bool JoinSession(int nSession,
- LPCTSTR lpszUserName = NULL,
- LPCTSTR lpszPassword = NULL,
- LPCTSTR lpszDomain = NULL);
- protected:
- #ifdef UNICODE
- LPDIRECTPLAY3 m_lpDirectPlay;
- LPDIRECTPLAYLOBBY2 m_lpDirectPlayLobby;
- #else
- LPDIRECTPLAY3A m_lpDirectPlay;
- LPDIRECTPLAYLOBBY2A m_lpDirectPlayLobby;
- #endif // UNICODE
- HANDLE m_hPlayerEvent; // player event to use
- HANDLE m_hReceiveThread; // handle of receive thread
- HANDLE m_hKillReceiveEvent; // event used to kill receive thread
- DPID m_dpidPlayer; // ID of player created
- bool m_bHost; // true if we are hosting the session
- bool m_bClientServerMode;
- bool m_bSecure; // true if session is secure
- bool m_bSessionLost; // did we get disconnected ?
- GUID m_guidApp;
- DWORD m_dwMaxPlayers;
- bool m_bReliable;
- LPVOID m_pReceiveBuffer;
- DWORD m_dwReceiveBufferSize;
- LPDPSESSIONDESC2 m_lpDPSessionDesc;
- public:
- CStringArray m_strModemNameArray;
- CTypedPtrArray<CObArray, CDPConnectionObject*> m_dpConnectionArray;
- CTypedPtrArray<CObArray, CDPSessionInfoObject*> m_dpSessionArray;
- CTypedPtrArray<CObArray, CDPPlayerInfoObject*> m_dpPlayerArray;
- DPCOMPORTADDRESS m_dpComPortAddress;
- static BOOL FAR PASCAL EnumModemAddress(
- REFGUID guidDataType, DWORD dwDataSize,
- LPCVOID lpData, LPVOID lpContext);
- static BOOL FAR PASCAL EnumConnectionsCallback(
- LPCGUID lpguidSP,
- LPVOID lpConnection,
- DWORD dwConnectionSize,
- LPCDPNAME lpName,
- DWORD dwFlags,
- LPVOID lpContext);
- static BOOL FAR PASCAL EnumSessionsCallback2(
- LPCDPSESSIONDESC2 lpThisSD,
- LPDWORD lpdwTimeOut,
- DWORD dwFlags,
- LPVOID lpContext);
- static bool FAR PASCAL EnumPlayersCallback2(
- DPID dpId,
- DWORD dwPlayerType,
- LPCDPNAME lpName,
- DWORD dwFlags,
- LPVOID lpContext);
- void AddConnection(LPCGUID lpguidSP, LPCDPNAME lpName,
- LPVOID lpConnection, DWORD dwConnectionSize);
- void AddSession(const DPSESSIONDESC2* pDPSessionDesc);
- void AddPlayer(DPID dpId, DWORD dwPlayerType,
- LPCDPNAME lpName, DWORD dwFlags);
- LPVOID GetServiceProviderConnection(REFGUID guidServiceProvider);
- static DWORD WINAPI ReceiveThread(LPVOID lpThreadParameter);
- public:
- //Group management
- HRESULT AddPlayerToGroup(DPID idGroup, DPID idPlayer);
- HRESULT CreateGroup(LPDPID lpidGroup,
- LPDPNAME lpGroupName, LPVOID lpData,
- DWORD dwDataSize, DWORD dwFlags);
- HRESULT DeletePlayerFromGroup(DPID idGroup, DPID idPlayer);
- HRESULT DestroyGroup(DPID idGroup);
- HRESULT EnumGroupPlayers(DPID idGroup, LPGUID lpguidInstance,
- LPDPENUMPLAYERSCALLBACK2 lpEnumPlayersCallback2,
- LPVOID lpContext, DWORD dwFlags);
- HRESULT EnumGroups(LPGUID lpguidInstance,
- LPDPENUMPLAYERSCALLBACK2 lpEnumPlayersCallback2,
- LPVOID lpContext, DWORD dwFlags);
- // Message management
- void SetReliable(bool bReliable);
- DWORD GetMessageCount(DPID idPlayer);
- HRESULT Receive(LPDPID lpidFrom, LPDPID lpidTo,
- DWORD dwFlags);
- HRESULT Send(DPID idFrom, DPID idTo, DWORD dwFlags,
- LPVOID lpData, DWORD dwDataSize);
- // Player management
- public:
- HRESULT CDirectPlay::CreatePlayer(LPCTSTR lpszPlayerName);
- protected:
- HRESULT CreatePlayer(LPDPID lpidPlayer,
- LPDPNAME lpPlayerName, HANDLE hEvent,
- LPVOID lpData, DWORD dwDataSize, DWORD dwFlags);
- public:
- HRESULT DestroyPlayer(DPID idPlayer);
- HRESULT EnumPlayers(LPGUID lpguidInstance,
- LPDPENUMPLAYERSCALLBACK2 lpEnumPlayersCallback2,
- LPVOID lpContext, DWORD dwFlags);
- HRESULT GetPlayerData(DPID dpId, LPVOID lpData,
- LPDWORD lpdwDataSize, DWORD dwFlags);
- HRESULT SetPlayerData(DPID dpid, LPVOID lpData,
- DWORD dwSize, DWORD dwFlags);
- HRESULT GetPlayerCaps(DPID idPlayer,
- LPDPCAPS lpPlayerCaps, DWORD dwFlags);
- DWORD GetPlayerFlags(DPID idPlayer);
- HRESULT GetPlayerName(DPID idPlayer,
- LPVOID lpData, LPDWORD lpdwDataSize);
- bool GetPlayerName(DPID idPlayer, CString& strPlayerName);
- bool GetPlayerAccountID(DPID idPlayer,
- CString& strPlayerAccountID);
- HRESULT SetPlayerName(DPID idPlayer,
- LPDPNAME lpPlayerName, DWORD dwFlags);
- // Session management
- HRESULT Close(void);
- HRESULT EnumSessions(LPDPSESSIONDESC2 lpsd,
- DWORD dwTimeout,
- LPDPENUMSESSIONSCALLBACK2 lpEnumSessionsCallback2,
- LPVOID lpContext, DWORD dwFlags);
- HRESULT GetCaps(LPDPCAPS lpDPCaps, DWORD dwFlags);
- bool GetSessionDesc(void);
- protected:
- bool Open(LPDPSESSIONDESC2 lpsd, DWORD dwFlags);
- bool SecureOpen(LPCDPSESSIONDESC2 lpsd,
- DWORD dwFlags, LPCDPSECURITYDESC lpSecurity,
- LPCDPCREDENTIALS lpCredentials);
- };
- #include "DirectPlay.inl"
- #endif // _DIRECTPLAY__H