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

游戏

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. // File: NetConnect.h
  3. //
  4. // Desc:
  5. //
  6. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef NETCONNECT_H
  9. #define NETCONNECT_H
  10. #include <windows.h>
  11. #include <dplay8.h>
  12. #include <dpaddr.h>
  13. #include <tchar.h>
  14. //-----------------------------------------------------------------------------
  15. // Defines, structures, and error codes
  16. //-----------------------------------------------------------------------------
  17. #define DISPLAY_REFRESH_RATE        250
  18. #define TIMERID_DISPLAY_HOSTS       1
  19. #define TIMERID_CONNECT_COMPLETE    2
  20. #define MAX_PLAYER_NAME             14
  21. #define NCW_S_FORWARD      ( (HRESULT) 0x01000001 ) // Dialog success, so go forward
  22. #define NCW_S_BACKUP       ( (HRESULT) 0x01000002 ) // Dialog canceled, show previous dialog
  23. #define NCW_S_QUIT         ( (HRESULT) 0x01000003 ) // Dialog quit, close app
  24. #define NCW_S_LOBBYCONNECT ( (HRESULT) 0x01000004 ) // Dialog connected from lobby, connect success
  25. enum SigningType { SIGN_NONE, SIGN_FAST, SIGN_FULL };
  26. class CNetConnectWizard
  27. {
  28. public:
  29. CNetConnectWizard( HINSTANCE hInst, HWND hWndParent, LPCTSTR strAppName, GUID* pGuidApp );
  30. virtual ~CNetConnectWizard();
  31.     HRESULT WINAPI MessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  32.     HRESULT WINAPI LobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  33.     HRESULT Init( IDirectPlay8Peer* pDP, IDirectPlay8LobbiedApplication* pLobbiedApp );
  34.     VOID    Shutdown();
  35.     HRESULT DoConnectWizard( BOOL bBackTrack );
  36.     HRESULT ConnectUsingLobbySettings();
  37.     void   SetMaxPlayers( DWORD dwMaxPlayers )                  { m_dwMaxPlayers = dwMaxPlayers; }
  38.     void   SetPlayerName( LPCTSTR strPlayerName )               { _tcsncpy( m_strLocalPlayerName, strPlayerName, MAX_PLAYER_NAME-1 ); m_strLocalPlayerName[ MAX_PLAYER_NAME-1 ] = 0; }
  39.     void   SetSessionName( LPCTSTR strSessionName )             { _tcsncpy( m_strSessionName, strSessionName, MAX_PATH-1 ); m_strSessionName[ MAX_PATH-1 ] = 0; }
  40.     void   SetPreferredProvider( LPCTSTR strPreferredProvider ) { _tcsncpy( m_strPreferredProvider, strPreferredProvider, MAX_PATH-1 ); m_strPreferredProvider[ MAX_PATH-1 ] = 0; }
  41.     void   SetDefaultPort( DWORD dwDefaultPort )                { m_dwPort = dwDefaultPort; }
  42.     TCHAR* GetPlayerName()                                      { return m_strLocalPlayerName; }
  43.     TCHAR* GetSessionName()                                     { return m_strSessionName; }
  44.     TCHAR* GetPreferredProvider()                               { return m_strPreferredProvider; }
  45.     BOOL   IsHostPlayer()                                       { return m_bHostPlayer; }
  46.     BOOL   IsMigrateHost()                                      { return m_bMigrateHost; }
  47.     BOOL   HaveConnectionSettingsFromLobby()                    { return m_bHaveConnectionSettingsFromLobby; }
  48.     static BOOL SPRequiresPort( GUID* pSP )                     { return (*pSP != CLSID_DP8SP_MODEM && *pSP != CLSID_DP8SP_SERIAL && *pSP != CLSID_DP8SP_BLUETOOTH); } 
  49. protected:
  50.     struct DPHostEnumInfo
  51.     {
  52.         DWORD                 dwRef;
  53.         DPN_APPLICATION_DESC* pAppDesc;
  54.         IDirectPlay8Address* pHostAddr;
  55.         IDirectPlay8Address* pDeviceAddr;
  56. TCHAR                szSession[MAX_PATH];
  57.         DWORD                dwLastPollTime;
  58.         BOOL                 bValid;
  59.         DPHostEnumInfo*      pNext;
  60.     };
  61.     static INT_PTR CALLBACK StaticConnectionsDlgProc( HWND, UINT, WPARAM, LPARAM );
  62.     static INT_PTR CALLBACK StaticSessionsDlgProc( HWND, UINT, WPARAM, LPARAM );
  63.     static INT_PTR CALLBACK StaticCreateSessionDlgProc( HWND, UINT, WPARAM, LPARAM );
  64.     static INT_PTR CALLBACK StaticLobbyWaitDlgProc( HWND, UINT, WPARAM, LPARAM );
  65.     static INT_PTR CALLBACK StaticAddressDlgProc( HWND, UINT, WPARAM, LPARAM );
  66.     INT_PTR CALLBACK ConnectionsDlgProc( HWND, UINT, WPARAM, LPARAM );
  67.     INT_PTR CALLBACK SessionsDlgProc( HWND, UINT, WPARAM, LPARAM );
  68.     INT_PTR CALLBACK CreateSessionDlgProc( HWND, UINT, WPARAM, LPARAM );
  69.     INT_PTR CALLBACK LobbyWaitDlgProc( HWND, UINT, WPARAM, LPARAM );
  70.     INT_PTR CALLBACK AddressDlgProc( HWND, UINT, WPARAM, LPARAM );
  71.     HRESULT ConnectionsDlgFillListBox( HWND hDlg );
  72.     HRESULT ConnectionsDlgOnOK( HWND hDlg );
  73.     VOID    ConnectionsDlgCleanup( HWND hDlg );
  74.     VOID    SessionsDlgInitListbox( HWND hDlg );
  75.     HRESULT SessionsDlgEnumHosts( HWND hDlg );
  76.     VOID    SessionsDlgStopEnumHosts( HWND hDlg );
  77.     VOID    SessionsDlgFinalizeEnumHosts( HWND hDlg );
  78.     HRESULT SessionsDlgNoteEnumResponse( PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponse );
  79.     VOID    SessionsDlgExpireOldHostEnums();
  80.     HRESULT SessionsDlgDisplayEnumList( HWND hDlg );
  81.     HRESULT SessionsDlgJoinGame( HWND hDlg );
  82.     HRESULT SessionsDlgCreateGame( HWND hDlg );
  83.     VOID    SessionsDlgEnumListCleanup();
  84.     IDirectPlay8Peer*       m_pDP;
  85.     IDirectPlay8LobbiedApplication* m_pLobbiedApp;
  86.     CRITICAL_SECTION        m_csHostEnum;
  87.     GUID                    m_guidApp;
  88.     HRESULT                 m_hrDialog;
  89.     HWND                    m_hDlg;
  90.     HINSTANCE               m_hInst;
  91.     HWND                    m_hWndParent;
  92.     DWORD                   m_dwMaxPlayers;
  93.     DWORD                   m_dwPort;
  94.     TCHAR                   m_strAppName[MAX_PATH];
  95.     TCHAR                   m_strPreferredProvider[MAX_PATH];
  96.     TCHAR                   m_strSessionName[MAX_PATH];
  97.     TCHAR                   m_strLocalPlayerName[MAX_PLAYER_NAME];
  98.     TCHAR                   m_strHostname[MAX_PATH];
  99.     BOOL                    m_bSearchingForSessions;
  100.     BOOL                    m_bMigrateHost;
  101.     BOOL                    m_bUseDPNSVR;
  102.     SigningType             m_eSigningType;
  103.     DPHostEnumInfo          m_DPHostEnumHead;
  104.     BOOL                    m_bEnumListChanged;
  105.     DPNHANDLE               m_hEnumAsyncOp;
  106.     BOOL                    m_bHostPlayer;
  107.     DWORD                   m_dwEnumHostExpireInterval;
  108.     BOOL                    m_bConnecting;
  109.     DPNHANDLE               m_hConnectAsyncOp;
  110.     HANDLE                  m_hConnectCompleteEvent;
  111.     HANDLE                  m_hLobbyConnectionEvent;
  112.     HRESULT                 m_hrConnectComplete;
  113.     BOOL                    m_bHaveConnectionSettingsFromLobby;
  114.     DPNHANDLE             m_hLobbyClient;
  115.     GUID                    m_guidSP;
  116. };
  117. #endif // NETCONNECT_H