PlayerManager.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:4k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /********************************************************************
  2. created: 2003/05/06
  3. file base: PlayerManager
  4. file ext: h
  5. author: liupeng
  6. purpose:
  7. *********************************************************************/
  8. #ifndef __INCLUDE_PLAYERMANAGER_H__
  9. #define __INCLUDE_PLAYERMANAGER_H__
  10. #include "IPlayer.h"
  11. #include "GamePlayer.h"
  12. #include "IGServer.h"
  13. #include "IClient.h"
  14. #include "RainbowInterface.h"
  15. #include "IServer.h"
  16. #include "HeavenInterface.h"
  17. #include "Library.h"
  18. #include "Event.h"
  19. #include "Network.h"
  20. #pragma warning(disable : 4786)  // identifier was truncated to '255' characters 
  21.                                  // in the debug information
  22. #include <map>
  23. #include <list>
  24. /*
  25.  * CPlayerManager class
  26.  */
  27. class CPlayerManager
  28. {
  29. public:
  30. explicit CPlayerManager( unsigned long lnMaxPlayerCount, CNetwork &theNetworkConfig );
  31. virtual ~CPlayerManager();
  32. bool Create();
  33. void Destroy();
  34. /*
  35.  * Callback function for network
  36.  */
  37. static void __stdcall AccountEventNotify( LPVOID lpParam, 
  38. const unsigned long &ulnEventType );
  39. static void __stdcall DBRoleEventNotify( LPVOID lpParam, 
  40. const unsigned long &ulnEventType );
  41. static void __stdcall PlayerEventNotify( LPVOID lpParam,
  42. const unsigned long &ulnID,
  43. const unsigned long &ulnEventType );
  44. static void __stdcall GameSvrEventNotify( LPVOID lpParam,
  45. const unsigned long &ulnID,
  46. const unsigned long &ulnEventType );
  47. protected:
  48. /*
  49.  * Network
  50.  */
  51. bool StartupNetwork();
  52. void CleanNetwork();
  53. typedef HRESULT ( __stdcall * pfnCreateServerInterface )( REFIID riid, void **ppv );
  54. typedef HRESULT ( __stdcall * pfnCreateClientInterface )( REFIID riid, void **ppv );
  55. static OnlineGameLib::Win32::CLibrary m_theHeavenLib;
  56. static OnlineGameLib::Win32::CLibrary m_theRainbowLib;
  57. IClient *m_pAccSvrClient;
  58. IClient *m_pDBRoleClient;
  59. IServer *m_pGameSvrServer;
  60. IServer *m_pPlayerServer;
  61. /*
  62.  * Helper function
  63.  */
  64. void _PlayerEventNotify( const unsigned long &ulnID,
  65. const unsigned long &ulnEventType );
  66. void _GameServerEventNotify( const unsigned long &ulnID,
  67. const unsigned long &ulnEventType );
  68. /*
  69.  * Listen and accept data from network
  70.  */
  71. HANDLE m_hWorkingThread;
  72. HANDLE m_hHelperThread;
  73. static DWORD WINAPI WorkingThreadFunction( void *pV );
  74. int Working();
  75. static DWORD WINAPI HelperThreadFunction( void *pV );
  76. int Helper();
  77. bool AnalyzePlayerRequire( size_t index, const void *pData, size_t datalength );
  78. private:
  79. OnlineGameLib::Win32::CEvent m_hQuitEvent;
  80. OnlineGameLib::Win32::CEvent m_hStartupWoringThreadEvent;
  81. OnlineGameLib::Win32::CEvent m_hStartupHelperThreadEvent;
  82. CNetwork &m_theNetworkConfig;
  83. /*
  84.  * Player information
  85.  */
  86. const unsigned long m_lnMaxPlayerCount;
  87. OnlineGameLib::Win32::CCriticalSection m_csPlayerAction;
  88. OnlineGameLib::Win32::CCriticalSection m_csUsedClientList;
  89. typedef std::map< size_t, IPlayer * > PLAYER_MAP;
  90. PLAYER_MAP m_thePlayers;
  91. typedef std::list< size_t > LIST;
  92. LIST m_usedClientNode;
  93. /*
  94.  * Game server information
  95.  */
  96. OnlineGameLib::Win32::CCriticalSection m_csGameSvrAction;
  97. typedef std::map< size_t, IGServer * > GAMESVR_MAP;
  98. GAMESVR_MAP m_theGameServers;
  99. /*
  100.  * Loader balance information
  101.  */
  102. /*
  103.  * ID of map convert to ID of game server
  104.  */
  105. OnlineGameLib::Win32::CCriticalSection m_csMI2GSAction;
  106. typedef std::map< size_t, size_t > MAPID_MAPTO_GAMESVR;
  107. MAPID_MAPTO_GAMESVR m_theMapIDMapToGameSvr;
  108. /*
  109.  * ID of player convert to ID of game server
  110.  */
  111. OnlineGameLib::Win32::CCriticalSection m_csPI2GSAction;
  112. typedef std::map< size_t, size_t > PLAYERID_MAPTO_GAMESVR;
  113. PLAYERID_MAPTO_GAMESVR m_thePlayerIDMapToGameSvr;
  114. };
  115. #endif // __INCLUDE_PLAYERMANAGER_H__