DirectPlay.h
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:6k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // Copyright (C) 1998-1999 DXGuide.  All Rights Reserved.
  2. // File: DirectPlay.h
  3. #ifndef _DIRECTPLAY__H
  4. #define _DIRECTPLAY__H
  5. #if _MSC_VER >= 1000
  6. #pragma once
  7. #endif // _MSC_VER >= 1000
  8. #define IDIRECTPLAY2_OR_GREATER
  9. #include <dplay.h>
  10. #include <dplobby.h>
  11. #include <afxtempl.h>
  12. #include "DPConnectionObject.h"
  13. #include "DPSessionInfoObject.h"
  14. #include "DPPlayerInfoObject.h"
  15. class CDirectPlay
  16. {
  17. public:
  18. CDirectPlay(void);
  19. virtual ~CDirectPlay();
  20. protected:
  21. bool CreateDirectPlayInterface(void);
  22. bool CreateDirectPlayLobbyInterface(void);
  23. public:
  24. void SetMaxPlayers(DWORD  dwMaxPlayers);
  25. void SetClientServerMode(bool  bClientServerMode);
  26. bool SetupConnection(DWORD  dwMaxPlayers = 0);
  27. bool ConnectUsingLobby(void);
  28. virtual bool ConnectUsingSettings(void);
  29. virtual bool HandleSystemMessage(void);
  30. virtual bool HandleApplicationMessage(DPID  idFrom, DPID  idTo);
  31. bool GetInfo(REFGUID  guidApp);
  32. bool Create(int  nProviderIndex, bool  bHost, LPCTSTR  lpszAddress = NULL, int  nModemIndex = -1);
  33. bool Create(REFGUID  guidServiceProvider, bool  bHost, LPCTSTR  lpszAddress = NULL, LPCTSTR  lpszModem = NULL);
  34. bool InitializeConnection(LPVOID  lpConnection);
  35. bool CreateSession(LPCTSTR  lpszSessionName,
  36. bool  bSecure = false,
  37. LPCTSTR  lpszSecurityProvider = NULL);
  38. bool EnumSessions(DWORD  dwTimeout = 0, DWORD  dwFlags = DPENUMSESSIONS_AVAILABLE);
  39. bool JoinSession(int  nSession,
  40. LPCTSTR  lpszUserName = NULL,
  41. LPCTSTR  lpszPassword = NULL,
  42. LPCTSTR  lpszDomain = NULL);
  43. protected:
  44. #ifdef UNICODE
  45. LPDIRECTPLAY3 m_lpDirectPlay;
  46. LPDIRECTPLAYLOBBY2 m_lpDirectPlayLobby;
  47. #else
  48. LPDIRECTPLAY3A m_lpDirectPlay;
  49. LPDIRECTPLAYLOBBY2A m_lpDirectPlayLobby;
  50. #endif // UNICODE
  51. HANDLE m_hPlayerEvent; // player event to use
  52. HANDLE m_hReceiveThread; // handle of receive thread
  53. HANDLE m_hKillReceiveEvent; // event used to kill receive thread
  54. DPID m_dpidPlayer; // ID of player created
  55. bool m_bHost; // true if we are hosting the session
  56. bool m_bClientServerMode;
  57. bool m_bSecure; // true if session is secure
  58. bool m_bSessionLost; // did we get disconnected ?
  59. GUID m_guidApp;
  60. DWORD m_dwMaxPlayers;
  61. bool m_bReliable;
  62. LPVOID m_pReceiveBuffer;
  63. DWORD m_dwReceiveBufferSize;
  64. LPDPSESSIONDESC2 m_lpDPSessionDesc;
  65. public:
  66. CStringArray m_strModemNameArray;
  67. CTypedPtrArray<CObArray, CDPConnectionObject*> m_dpConnectionArray;
  68. CTypedPtrArray<CObArray, CDPSessionInfoObject*> m_dpSessionArray;
  69. CTypedPtrArray<CObArray, CDPPlayerInfoObject*> m_dpPlayerArray;
  70. DPCOMPORTADDRESS m_dpComPortAddress;
  71. static BOOL FAR PASCAL EnumModemAddress(
  72. REFGUID  guidDataType, DWORD  dwDataSize,
  73. LPCVOID  lpData, LPVOID  lpContext);
  74. static BOOL FAR PASCAL EnumConnectionsCallback(
  75. LPCGUID  lpguidSP,
  76. LPVOID  lpConnection,
  77. DWORD  dwConnectionSize,
  78. LPCDPNAME  lpName,
  79. DWORD  dwFlags,
  80. LPVOID  lpContext);
  81. static BOOL FAR PASCAL EnumSessionsCallback2(
  82. LPCDPSESSIONDESC2  lpThisSD,
  83. LPDWORD  lpdwTimeOut,
  84. DWORD  dwFlags,
  85. LPVOID  lpContext);
  86. static bool FAR PASCAL EnumPlayersCallback2(
  87. DPID  dpId,
  88. DWORD  dwPlayerType,
  89. LPCDPNAME  lpName,
  90. DWORD  dwFlags,
  91. LPVOID  lpContext);
  92. void AddConnection(LPCGUID  lpguidSP, LPCDPNAME  lpName,
  93. LPVOID  lpConnection, DWORD  dwConnectionSize);
  94. void AddSession(const DPSESSIONDESC2*  pDPSessionDesc);
  95. void AddPlayer(DPID  dpId, DWORD  dwPlayerType,
  96. LPCDPNAME  lpName, DWORD  dwFlags);
  97. LPVOID GetServiceProviderConnection(REFGUID  guidServiceProvider);
  98. static DWORD WINAPI ReceiveThread(LPVOID  lpThreadParameter);
  99. public:
  100. //Group management
  101. HRESULT AddPlayerToGroup(DPID  idGroup, DPID  idPlayer);
  102. HRESULT CreateGroup(LPDPID  lpidGroup,
  103. LPDPNAME  lpGroupName, LPVOID  lpData,
  104. DWORD  dwDataSize, DWORD  dwFlags);
  105. HRESULT DeletePlayerFromGroup(DPID  idGroup, DPID  idPlayer);
  106. HRESULT DestroyGroup(DPID  idGroup);
  107. HRESULT EnumGroupPlayers(DPID  idGroup, LPGUID  lpguidInstance,
  108. LPDPENUMPLAYERSCALLBACK2  lpEnumPlayersCallback2,
  109. LPVOID  lpContext, DWORD  dwFlags);
  110. HRESULT EnumGroups(LPGUID  lpguidInstance,
  111. LPDPENUMPLAYERSCALLBACK2  lpEnumPlayersCallback2,
  112. LPVOID  lpContext, DWORD  dwFlags);
  113. // Message management
  114. void SetReliable(bool  bReliable);
  115. DWORD GetMessageCount(DPID  idPlayer);
  116. HRESULT Receive(LPDPID  lpidFrom, LPDPID  lpidTo,
  117. DWORD  dwFlags);
  118. HRESULT Send(DPID  idFrom, DPID  idTo, DWORD  dwFlags,
  119. LPVOID  lpData, DWORD  dwDataSize);
  120. // Player management
  121. public:
  122. HRESULT CDirectPlay::CreatePlayer(LPCTSTR  lpszPlayerName);
  123. protected:
  124. HRESULT CreatePlayer(LPDPID  lpidPlayer,
  125. LPDPNAME  lpPlayerName, HANDLE  hEvent,
  126. LPVOID  lpData, DWORD  dwDataSize, DWORD  dwFlags);
  127. public:
  128. HRESULT DestroyPlayer(DPID  idPlayer);
  129. HRESULT EnumPlayers(LPGUID  lpguidInstance,
  130. LPDPENUMPLAYERSCALLBACK2  lpEnumPlayersCallback2,
  131. LPVOID  lpContext, DWORD  dwFlags);
  132. HRESULT GetPlayerData(DPID  dpId, LPVOID lpData,
  133. LPDWORD lpdwDataSize, DWORD dwFlags);
  134. HRESULT SetPlayerData(DPID  dpid, LPVOID  lpData,
  135. DWORD  dwSize, DWORD  dwFlags);
  136. HRESULT GetPlayerCaps(DPID  idPlayer,
  137. LPDPCAPS lpPlayerCaps, DWORD  dwFlags);
  138. DWORD GetPlayerFlags(DPID  idPlayer);
  139. HRESULT GetPlayerName(DPID  idPlayer,
  140. LPVOID  lpData, LPDWORD  lpdwDataSize);
  141. bool GetPlayerName(DPID  idPlayer, CString&  strPlayerName);
  142. bool GetPlayerAccountID(DPID  idPlayer,
  143. CString&  strPlayerAccountID);
  144. HRESULT SetPlayerName(DPID  idPlayer,
  145. LPDPNAME  lpPlayerName, DWORD  dwFlags);
  146. // Session management
  147. HRESULT Close(void);
  148. HRESULT EnumSessions(LPDPSESSIONDESC2  lpsd,
  149. DWORD  dwTimeout,
  150. LPDPENUMSESSIONSCALLBACK2  lpEnumSessionsCallback2,
  151. LPVOID  lpContext, DWORD  dwFlags);
  152. HRESULT GetCaps(LPDPCAPS  lpDPCaps, DWORD  dwFlags);
  153. bool GetSessionDesc(void);
  154. protected:
  155. bool Open(LPDPSESSIONDESC2  lpsd, DWORD  dwFlags);
  156. bool SecureOpen(LPCDPSESSIONDESC2  lpsd,
  157. DWORD  dwFlags, LPCDPSECURITYDESC  lpSecurity,
  158. LPCDPCREDENTIALS  lpCredentials);
  159. };
  160. #include "DirectPlay.inl"
  161. #endif // _DIRECTPLAY__H