cMultiplayer.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:4k
源码类别:

游戏

开发平台:

Visual C++

  1. // CMAIN LIB - APPLICATION AND DIRECT WRAPPER
  2. //
  3. // Written by Mauricio Teichmann Ritter
  4. //
  5. // Copyright (C) 2002, Brazil. All rights reserved.
  6. // 
  7. //
  8. // cMultiplayer.h: interface for the cMultiplayer class.
  9. //
  10. //////////////////////////////////////////////////////////////////////
  11. #if !defined(AFX_CMULTIPLAYER_H__1AA8D187_1064_40A7_A709_B2684653429F__INCLUDED_)
  12. #define AFX_CMULTIPLAYER_H__1AA8D187_1064_40A7_A709_B2684653429F__INCLUDED_
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif // _MSC_VER > 1000
  16. #include "stdafx.h"
  17. #include "cApplication.h"
  18. #include "cMessageHandler.h"
  19. #include <dplay8.h>
  20. #include <vector>
  21. #include <list>
  22. using namespace std;
  23. #define PLAYERTYPE_HOST 1
  24. #define PLAYERTYPE_PEER 2
  25. extern const GUID g_guidApp;
  26. struct PLAYER_MESSAGE
  27. {
  28. int m_iType;
  29. BYTE* pReceiveData;
  30. };
  31. struct PLAYER_INFO
  32. {
  33. DPNID  dpnidPlayer;
  34. };
  35. struct HOST_NODE
  36. {
  37.     DPN_APPLICATION_DESC*   pAppDesc;
  38.     IDirectPlay8Address*    pHostAddress;
  39.     WCHAR*                  pwszSessionName;
  40.     HOST_NODE*             pNext;
  41. };
  42. typedef vector<PLAYER_INFO*> PLAYERINFO_VECTOR;
  43. typedef list<PLAYER_MESSAGE*> PLAYER_MESSAGES;
  44. typedef list<PLAYER_MESSAGE*>::iterator PLAYERMESSAGE_ELEMENT;
  45. class cMultiplayer  : public cMessageHandler
  46. {
  47. private:
  48. cMessageHandler* m_pHandler;
  49. DWORD m_dwTcpPort;
  50. int m_iModemDevice;
  51. IDirectPlay8Peer    *m_pDP;
  52. IDirectPlay8Address *m_pDeviceAddress;
  53. DPN_SERVICE_PROVIDER_INFO*  m_pdnSPInfo;
  54. DPN_SERVICE_PROVIDER_INFO*  m_pdnDeviceInfo;
  55. char m_sFlowControl[10];
  56. char m_sParity[10];
  57. char m_sStopBits[10];
  58. DWORD m_dwNumSP;
  59. DWORD m_dwNumDevices;
  60. int m_iSPIndex;
  61. int m_iSerialDevice;
  62. HOST_NODE* m_pHostList;
  63. int  m_iNumHosts;
  64. BOOL m_bCanConnect;
  65. int m_iPlayerType;
  66. DPNID m_dpnidHost;
  67. DPNID m_dpnidSelf;
  68. PLAYER_MESSAGES m_lstMessages;
  69. CRITICAL_SECTION    m_csMessages;
  70. PLAYERINFO_VECTOR  m_lstPlayers;
  71. public:
  72. void SetHandler(cMessageHandler *pHandler);
  73. void ReleaseMessage();
  74. int GetMyId();
  75. void FindHost();
  76. int GetHost();
  77. void RemoveMessage(PLAYER_MESSAGE* pMessage);
  78. PLAYER_MESSAGE* GetMessage(int iIndex);
  79. int GetNumMessages();
  80. void SendTo(DPNID dpnidTarget, int iType, LPBYTE lpBuffer, DWORD dwSize, DWORD dwFlags = DPNSEND_SYNC | DPNSEND_NOLOOPBACK);
  81. PLAYER_INFO* GetPlayerInfo(int iIndex);
  82. int GetNumConnected();
  83. BOOL IsHosting();
  84. void Connect(int iHost);
  85. BOOL GetCanConnect();
  86. void SetCanConnect(BOOL bValue);
  87. void GetSessionName(int iIndex, char* sValue, int iSize);
  88. int GetNumSessions();
  89. BOOL EnumSessions();
  90. BOOL Host(char* sSessionName);
  91. void AdvanceSPOption(int iOption);
  92. void GetSPOption(int iOption, char* szBuffer, DWORD dwBufferSize);
  93. char* GetSPOptionName(int iOption);
  94. int GetSPOptionType(int iOption);
  95. int GetSPIndex();
  96. void NextSP();
  97. int GetNumSPOptions();
  98. GUID* GetSPGuid(int iIndex);
  99. char* GetSPName(int iIndex);
  100. long GetNumSPs();
  101. void Destroy();
  102. void EnumServiceProviders();
  103. static HRESULT WINAPI cMultiplayer::StaticDirectPlayMessageHandler(
  104. PVOID pvUserContext,
  105. DWORD dwMessageId,
  106. PVOID pMsgBuffer );
  107. HRESULT WINAPI cMultiplayer::DirectPlayMessageHandler(
  108. PVOID pvUserContext,
  109. DWORD dwMessageId,
  110. PVOID pMsgBuffer );
  111. BOOL Initialize();
  112. cMultiplayer();
  113. virtual ~cMultiplayer();
  114. DWORD GetRegDWValue(char* lpszValue);
  115. char* GetRegStringValue(char* lpszValue, char* szBuffer, DWORD dwBufLen);
  116. void SetRegDWValue(char* lpszValueName, DWORD dwValue);
  117. void SetRegStringValue(char* lpszValueName, char* lpszValue);
  118. protected:
  119. DWORD m_dwBaudRate;
  120. void EnumDevices();
  121. };
  122. #endif // !defined(AFX_CMULTIPLAYER_H__1AA8D187_1064_40A7_A709_B2684653429F__INCLUDED_)