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

模拟服务器

开发平台:

C/C++

  1. /********************************************************************
  2. created: 2003/04/08
  3. file base: GamePlayer
  4. file ext: h
  5. author: liupeng
  6. purpose:
  7. *********************************************************************/
  8. #ifndef __INCLUDE_GAMEPLAYER_H__
  9. #define __INCLUDE_GAMEPLAYER_H__
  10. #include "IPlayer.h"
  11. #pragma warning(disable : 4786)  // identifier was truncated to '255' characters 
  12.                                  // in the debug information
  13. #include "CriticalSection.h"
  14. #include "tstring.h"
  15. #include "Buffer.h"
  16. #include "IClient.h"
  17. #include "RainbowInterface.h"
  18. #include "IServer.h"
  19. #include "HeavenInterface.h"
  20. #include "S3DBInterface.h"
  21. #include "KRoleStreamArtery.h"
  22. #include <vector>
  23. #include <map>
  24. using namespace std;
  25. typedef vector< void* > stdVector;
  26. typedef map< LONG, const void * > stdMap;
  27. /*
  28.  * class CGamePlayer
  29.  */
  30. class CGamePlayer : public IPlayer
  31. {
  32. public:
  33. explicit CGamePlayer( IServer *pPlayerSender, IClient *pRoleDBSender, LONG nIdentityID = -1 );
  34. virtual ~CGamePlayer();
  35. /*
  36.  * Task option
  37.  */
  38. enum
  39. {
  40. /*
  41.  * Task command
  42.  */
  43. enumLogin = 0,
  44. enumLogOut,
  45. enumExchangeRegin,
  46. /*
  47.  * Task status
  48.  */
  49. enumComplete,
  50. enumRepeat,
  51. enumNone
  52. };
  53. virtual bool DispatchTask( LONG lnTaskID );
  54. virtual bool IsWorking() { return false; }
  55. virtual int Run();
  56. virtual bool AppendData( const void *pData );
  57. virtual bool Create( const char * const pName, const char * const pPassword );
  58. virtual bool Destroy( const char * const pPassword );
  59. static bool SetupGlobalAllocator( size_t bufferSize, size_t maxFreeBuffers );
  60. private:
  61. /*
  62.  * Event option
  63.  */
  64. enum
  65. {
  66. enumQuitEvent = 0, // the first value must be set zero
  67. enumWorkEvent,
  68. enumEventTotal // must put it on last, be used to total counts of variable
  69. };
  70. static LONG m_slnIdentityCounts;
  71. LONG m_lnIdentityID;
  72. bool ( CGamePlayer::* EventProcessor[enumEventTotal] )();
  73. void InitEventProcessor();
  74. /*
  75.  * Task system
  76.  */
  77. class CTask
  78. {
  79. public:
  80. explicit CTask( CGamePlayer *pReceiver, UINT nTaskID, UINT nNextTaskID = enumComplete );
  81. ~CTask();
  82. typedef bool ( CGamePlayer::* Action )();
  83. size_t AddCmd( Action pFun, UINT nFaildValue = enumNone );
  84. UINT Execute();
  85. void Reset() { m_indexCmd = 0; }
  86. protected:
  87. CTask();
  88. OnlineGameLib::Win32::CCriticalSection m_cs;
  89. private:
  90. CGamePlayer *m_pReceiver;
  91. stdVector m_stdCommand;
  92. size_t m_indexCmd;
  93. UINT m_nTaskProgID;
  94. UINT m_nNextTaskID;
  95. };
  96. CTask m_theLoginTask;
  97. CTask m_theLogoutTask;
  98. CTask m_theExchangeReginTask;
  99. void SetCurrentTask( UINT nID ) { m_nCurrentTaskID = nID; /*::InterlockedExchange( &m_nCurrentTaskID, nID );*/ }
  100. UINT GetCurrentTask() { return m_nCurrentTaskID; /*::InterlockedExchange( &m_nCurrentTaskID, m_nCurrentTaskID );*/ }
  101. UINT m_nCurrentTaskID;
  102. void InitTaskProcessor();
  103. /*
  104.  * Information
  105.  */
  106. OnlineGameLib::Win32::_tstring m_sAccountName;
  107. OnlineGameLib::Win32::_tstring m_sPassword;
  108. OnlineGameLib::Win32::_tstring m_sBlockBuffer; // temporal variable
  109. static OnlineGameLib::Win32::CBuffer::Allocator m_theGlobalAllocator;
  110. enum
  111. {
  112. enumRoleListCount = 3
  113. };
  114. S3DBI_RoleBaseInfo m_theRoleDBList[enumRoleListCount];
  115. struct tagRoleInfomation
  116. {
  117. int nIndexInList;
  118. TRoleData theRoleData;
  119. };
  120. tagRoleInfomation m_theRoleInfomation;
  121. /*
  122.  * Network
  123.  */
  124. /*
  125.  * The role dabase
  126.  */
  127. IClient *m_pRoleDBSender;
  128. IServer *m_pPlayerServer;
  129. KRoleStreamVein m_theRoleStreamVein;
  130. class CDataQueue
  131. {
  132. private:
  133. stdMap m_theData;
  134. OnlineGameLib::Win32::CCriticalSection m_csQueue;
  135. public:
  136. ~CDataQueue();
  137. void Empty();
  138. size_t Push( LONG lnID, const void * pData );
  139. const void *Top( LONG lnID );
  140. size_t Pop( LONG lnID );
  141. };
  142. CDataQueue m_theDataQueue;
  143. protected:
  144. /*
  145.  * Event function
  146.  */
  147. bool Quit();
  148. bool Work();
  149. /*
  150.  * Helper function
  151.  */
  152. bool TaskCompleted();
  153. /*
  154.  * Task function
  155.  */
  156. bool QueryAccPwd();
  157. bool VerifyAccount();
  158. bool QueryRoleList();
  159. bool GetRoleListInfo();
  160. bool QueryRoleInfo();
  161. bool ProcessRoleInfo();
  162. };
  163. #endif // __INCLUDE_GAMEPLAYER_H__