Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
10 KiB

  1. // Direct Play object class implementation
  2. #ifndef _DP_SPIMP_H
  3. #define _DP_SPIMP_H
  4. #include "..\dplay\dplayi.h"
  5. // Begin: declaration of main implementation class for IDirectPlay
  6. #define MAX_MSG (512 + sizeof(DPHDR))
  7. #define MAX_PLAYERS 16
  8. #define MAXIMUM_PLAYER_ID 256
  9. typedef struct
  10. {
  11. DPID pid;
  12. char chNickName[DPSHORTNAMELEN];
  13. char chFullName[DPLONGNAMELEN ];
  14. HANDLE hEvent;
  15. BOOL bPlayer;
  16. BOOL bValid;
  17. BOOL bLocal;
  18. DPID aGroup[MAX_PLAYERS];
  19. } PLAYER_RECORD;
  20. class CImpIDP_SP : public IDirectPlaySP {
  21. public:
  22. // IUnknown methods
  23. // IDirectPlay methods
  24. virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, LPVOID *ppvObj );
  25. virtual ULONG STDMETHODCALLTYPE AddRef( void);
  26. virtual ULONG STDMETHODCALLTYPE Release( void );
  27. virtual HRESULT STDMETHODCALLTYPE AddPlayerToGroup(
  28. DPID dwDPIDGroup,
  29. DPID dwDPIDPlayer);
  30. virtual HRESULT STDMETHODCALLTYPE Close(DWORD);
  31. virtual HRESULT STDMETHODCALLTYPE CreatePlayer(
  32. LPDPID pPlayerID,
  33. LPSTR pNickName,
  34. LPSTR pFullName,
  35. LPHANDLE lpReceiveEvent,
  36. BOOL bPlayer);
  37. virtual HRESULT STDMETHODCALLTYPE DeletePlayerFromGroup(
  38. DPID DPid,
  39. DPID dwDPIDPlayer);
  40. virtual HRESULT STDMETHODCALLTYPE DestroyPlayer( DPID pPlayerID, BOOL );
  41. virtual HRESULT STDMETHODCALLTYPE EnumGroupPlayers(
  42. DPID dwGroupPid,
  43. LPDPENUMPLAYERSCALLBACK EnumCallback,
  44. LPVOID pContext,
  45. DWORD dwFlags);
  46. virtual HRESULT STDMETHODCALLTYPE EnumPlayers(
  47. DWORD dwSessionID,
  48. LPDPENUMPLAYERSCALLBACK EnumCallback,
  49. LPVOID pContext,
  50. DWORD dwFlags);
  51. virtual HRESULT STDMETHODCALLTYPE EnumSessions(
  52. LPDPSESSIONDESC,
  53. DWORD dwTimeout,
  54. LPDPENUMSESSIONSCALLBACK EnumCallback,
  55. LPVOID,
  56. DWORD);
  57. virtual HRESULT STDMETHODCALLTYPE GetCaps(LPDPCAPS lpDPCaps);
  58. virtual HRESULT STDMETHODCALLTYPE GetMessageCount(DPID pidPlayer, LPDWORD lpdwCount);
  59. virtual HRESULT STDMETHODCALLTYPE GetPlayerCaps(
  60. DPID dwDPId,
  61. LPDPCAPS lpDPCaps);
  62. virtual HRESULT STDMETHODCALLTYPE GetPlayerName(DPID dpID,
  63. LPSTR lpFriendlyName, // buffer to hold name
  64. LPDWORD pdwFriendlyNameLength, // length of name buffer
  65. LPSTR lpFormalName,
  66. LPDWORD pdwFormalNameLength
  67. );
  68. virtual HRESULT STDMETHODCALLTYPE Initialize(LPGUID);
  69. virtual HRESULT STDMETHODCALLTYPE Open(
  70. LPDPSESSIONDESC lpSDesc, HANDLE hEvent);
  71. virtual HRESULT STDMETHODCALLTYPE Receive(
  72. LPDPID from,
  73. LPDPID to,
  74. DWORD dwReceiveFlags,
  75. LPVOID,
  76. LPDWORD);
  77. virtual HRESULT STDMETHODCALLTYPE SaveSession(LPVOID lpv, LPDWORD lpdw);
  78. virtual HRESULT STDMETHODCALLTYPE SetPrevPlayer(LPSTR lpName, LPVOID lpv, DWORD dw);
  79. virtual HRESULT STDMETHODCALLTYPE SetPrevSession(LPSTR lpName, LPVOID lpv, DWORD dw);
  80. virtual HRESULT STDMETHODCALLTYPE EnableNewPlayers(BOOL bEnable);
  81. virtual HRESULT STDMETHODCALLTYPE Send(
  82. DPID from,
  83. DPID to,
  84. DWORD dwFlags,
  85. LPVOID lpvMsg,
  86. DWORD dwLength);
  87. virtual HRESULT STDMETHODCALLTYPE SetPlayerName(
  88. DPID from,
  89. LPSTR lpFriendlyName,
  90. LPSTR lpFormalName,
  91. BOOL bPlayer);
  92. static CImpIDP_SP* NewCImpIDP_SP();
  93. VOID HandleConnect();
  94. VOID HandleMessage(LPVOID lpv, DWORD dwSize);
  95. VOID PulseBlock() {PulseEvent(m_hBlockingEvent);}
  96. VOID SetBlock() {SetEvent(m_hBlockingEvent);}
  97. VOID SendDesc(LPDPSESSIONDESC);
  98. VOID SendPing();
  99. VOID PostHangup();
  100. VOID ISend(LONG, LONG, DWORD, LPVOID, DWORD);
  101. VOID LocalMsg(LONG, LPVOID, DWORD);
  102. VOID RemoteMsg(LONG, LPVOID, DWORD);
  103. LONG FindInvalidIndex();
  104. VOID ConnectPlayers();
  105. VOID DeleteRemotePlayers();
  106. VOID ResetSessionDesc() {memset(&m_dpDesc, 0x00, sizeof(DPSESSIONDESC));}
  107. volatile BOOL m_bConnected;
  108. BOOL m_bPlayer0; // If I created the call, I am player
  109. // zero.
  110. volatile DWORD m_dwPendingWrites;
  111. void *operator new( size_t size );
  112. void operator delete( void *ptr );
  113. protected:
  114. void Lock();
  115. void Unlock();
  116. private:
  117. LONG GetPlayerIndex(DPID);
  118. BOOL SetSession(DWORD dw);
  119. CImpIDP_SP(void);
  120. ~CImpIDP_SP(void);
  121. DWORD m_dwPingSent;
  122. HANDLE m_hBlockingEvent;
  123. DWORD m_dwNextPlayer;
  124. BOOL m_bEnablePlayerAdd;
  125. PLAYER_RECORD m_aPlayer[MAX_PLAYERS];
  126. char m_lpDisplay[128];
  127. char m_lpDialable[128];
  128. DWORD m_dwID;
  129. LONG m_iPlayerIndex;
  130. DPSESSIONDESC m_dpDesc;
  131. int m_refCount;
  132. CRITICAL_SECTION m_critSection;
  133. DPCAPS m_dpcaps;
  134. HANDLE m_hNewPlayerEvent;
  135. HANDLE m_hTapiThread;
  136. DWORD m_dwTapiThreadID;
  137. char **m_ppSessionArray;
  138. DWORD m_dwSessionPrev;
  139. DWORD m_dwSessionAlloc;
  140. };
  141. BOOL SetIDP_SP( CImpIDP_SP *pSP);
  142. // End : declaration of main implementation class for IDirectPlay
  143. /****************************************************************************
  144. *
  145. * DIRECTPLAY MESSAGES
  146. *
  147. * Errors are represented by negative values and cannot be combined.
  148. *
  149. ****************************************************************************/
  150. // #define DPSYS_ENUM 0x6172 // '4b797261' == 'Kyra' Born 10/21/94
  151. // #define DPSYS_KYRA 0x6172794b
  152. // #define DPSYS_HALL 0x6c6c6148
  153. #define SPSYS_SYS 0x07
  154. #define SPSYS_USER 0x0b
  155. #define SPSYS_HIGH 0x0d
  156. #define SPSYS_CONNECT 0x0f
  157. // #define SYS_MSG 0x8000
  158. typedef struct
  159. {
  160. union
  161. {
  162. DWORD dwConnect1;
  163. struct
  164. {
  165. UINT to : 8;
  166. UINT from : 8;
  167. UINT usCount : 10;
  168. UINT usCookie : 6;
  169. };
  170. };
  171. } DPHDR;
  172. #if 0
  173. typedef struct
  174. {
  175. union
  176. {
  177. DWORD dwConnect1;
  178. struct
  179. {
  180. USHORT usCookie;
  181. BYTE to;
  182. BYTE from;
  183. };
  184. };
  185. union
  186. {
  187. DWORD dwConnect2;
  188. struct
  189. {
  190. USHORT usCount;
  191. BYTE bHdrCRC;
  192. BYTE bMsgCRC;
  193. };
  194. };
  195. } DPHDR;
  196. #endif
  197. typedef struct
  198. {
  199. DPHDR dpHdr;
  200. char chMsgCompose[1000];
  201. } MSG_BUILDER;
  202. #define SP_ENUM_COOKIE 0x794b
  203. typedef struct
  204. {
  205. DPHDR dpHdr;
  206. USHORT usVerMajor;
  207. USHORT usVerMinor;
  208. DWORD dwConnect1;
  209. DWORD dwConnect2;
  210. } SPMSG_CONNECT;
  211. typedef struct
  212. {
  213. DPHDR dpHdr;
  214. DPMSG_GENERIC sMsg;
  215. } SPMSG_GENERIC;
  216. typedef struct
  217. {
  218. DPHDR dpHdr;
  219. DWORD dwType;
  220. BYTE Group;
  221. BYTE bytePlayers[16];
  222. } SPMSG_SETGROUPPLAYERS16;
  223. #define SIZE_GENERIC (sizeof(SPMSG_GENERIC) - sizeof(DPHDR))
  224. typedef struct
  225. {
  226. DPHDR dpHdr;
  227. DWORD dwType;
  228. DPSESSIONDESC dpSessionDesc;
  229. } SPMSG_ENUM;
  230. #define DPSYS_ENUM_REPLY 0x0002
  231. typedef struct
  232. {
  233. DPHDR dpHdr;
  234. DWORD dwType;
  235. DWORD usPort;
  236. } SPMSG_ENUM_REPLY;
  237. typedef struct
  238. {
  239. DWORD dwType;
  240. DPID dpId;
  241. } DPMSG_GETPLAYER;
  242. typedef struct
  243. {
  244. DPHDR dpHdr;
  245. DPMSG_GETPLAYER sMsg;
  246. } SPMSG_GETPLAYER;
  247. #define SIZE_GETPLAYER (sizeof(SPMSG_GETPLAYER) - sizeof(DPHDR))
  248. typedef struct
  249. {
  250. DPHDR dpHdr;
  251. DPMSG_ADDPLAYER sMsg;
  252. } SPMSG_ADDPLAYER;
  253. #define SIZE_ADDPLAYER (sizeof(SPMSG_ADDPLAYER) - sizeof(DPHDR))
  254. typedef struct
  255. {
  256. DPHDR dpHdr;
  257. DPMSG_GROUPADD sMsg;
  258. } SPMSG_GROUPADD;
  259. typedef struct
  260. {
  261. DPHDR dpHdr;
  262. DWORD dwType;
  263. DWORD dwTicks;
  264. } SPMSG_PING;
  265. #define SIZE_PING (sizeof(SPMSG_PING) - sizeof(DPHDR))
  266. typedef struct
  267. {
  268. DPHDR dpHdr;
  269. DWORD dwType;
  270. GUID guid;
  271. } SPMSG_INVITE;
  272. typedef struct
  273. {
  274. DPHDR dpHdr;
  275. DWORD dwType;
  276. DPCAPS dpCaps;
  277. } SPMSG_GETPLAYERCAPS;
  278. #define SIZE_GETPLAYERCAPS (sizeof(SPMSG_GETPLAYERCAPS) - sizeof(DPHDR))
  279. typedef struct
  280. {
  281. DPHDR dpHdr;
  282. DWORD dwType;
  283. DPSESSIONDESC dpDesc;
  284. } SPMSG_SENDDESC;
  285. #define SIZE_SENDDESC (sizeof(SPMSG_SENDDESC) - sizeof(DPHDR))
  286. typedef struct
  287. {
  288. DWORD dwType;
  289. BOOL bEnable;
  290. } DPMSG_ENABLEPLAYER;
  291. typedef struct
  292. {
  293. DPHDR dpHdr;
  294. DPMSG_ENABLEPLAYER sMsg;
  295. } SPMSG_ENABLEPLAYER;
  296. extern BOOL AddMessage(LPVOID lpvMsg, DWORD dwSize, DPID pidTo, DPID pidFrom, BOOL bHigh);
  297. extern HRESULT GetQMessage(LPVOID lpvMsg, LPDWORD pdwSize, DPID *ppidTo, DPID *ppidFrom,
  298. DWORD dwFlags, BOOL bPeek);
  299. extern VOID FlushQueue(DPID pid);
  300. extern DWORD GetPlayerCount(DPID spid);
  301. #define DPSYS_JOHN 0x6e686f4a
  302. // Enumeration Messages
  303. //
  304. // Thread Messages
  305. //
  306. #define PWM_BASE 0x00007000
  307. #define PWM_COMMWRITE PWM_BASE +1
  308. #define PWM_SETIDP PWM_BASE +2
  309. #define PWM_HANGUP PWM_BASE +3
  310. #define PWM_CLOSE PWM_BASE +4
  311. #endif
  312.