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

模拟服务器

开发平台:

C/C++

  1. /********************************************************************
  2. created: 2003/05/15
  3. file base: Player
  4. file ext: h
  5. author: liupeng
  6. purpose:
  7. *********************************************************************/
  8. #ifndef __INCLUDE_PLAYER_H__
  9. #define __INCLUDE_PLAYER_H__
  10. // There comes a fucking request that to use zclient instead of RainBow
  11. // as the network-lib came.
  12. // This macro is the switch.
  13. #include "tstring.h"
  14. #include "Thread.h"
  15. #include "Event.h"
  16. #include "Buffer.h"
  17. #include "Library.h"
  18. #if defined _USE_RAINBOW
  19. #include "IClient.h"
  20. #include "RainbowInterface.h"
  21. #else
  22. #include "....LINUXIClient.h"
  23. #endif
  24. #include "CriticalSection.h"
  25. // move from .cpp to here.
  26. #include "KProtocol.h"
  27. // flying add the math lib
  28. #include "math.h"
  29. // GM Command list
  30. #define MAX_GM_COUNT 256
  31. #define MAX_GM_SIZE 128
  32. enum NPCCMD
  33. {
  34. do_none, // 什么也不干
  35. do_stand, // 站立
  36. do_walk, // 行走
  37. do_run, // 跑动
  38. do_jump, // 跳跃
  39. do_skill, // 发技能的命令
  40. do_magic, // 施法
  41. do_attack, // 攻击
  42. do_sit, // 打坐
  43. do_hurt, // 受伤
  44. do_death, // 死亡
  45. do_defense, // 格挡
  46. do_idle, // 喘气
  47. do_specialskill,// 技能控制动作
  48. do_special1, // 特殊1
  49. do_special2, // 特殊2
  50. do_special3, // 特殊3
  51. do_special4, // 特殊4
  52. do_runattack,
  53. do_manyattack,
  54. do_jumpattack,
  55. do_revive,
  56. };
  57. typedef struct 
  58. {
  59. int nCamp; //阵营
  60. } PLAYER_INFO;
  61. typedef struct
  62. {
  63. NPCCMD CmdKind; // 命令C
  64. int Param_X; // 参数X
  65. int Param_Y; // 参数Y
  66. int Param_Z; // 参数Y
  67. } NPC_COMMAND;
  68. #define LOCAL_REVIVE_TYPE 1
  69. class IPlayer
  70. {
  71. public:
  72. virtual bool ConnectToGateway() = 0;
  73. // flying add the interfaces
  74. virtual int SetPos(int nX, int nY) = 0;
  75. virtual int SetAttack() = 0;
  76. virtual int SetSilence(int nSilence) = 0;
  77. virtual int SetChatTimer(int nTimer) = 0;
  78. virtual ~IPlayer(){};
  79. };
  80. typedef struct _ITEMS
  81. {
  82. } ITEMS;
  83. class CPlayer : public IPlayer, protected OnlineGameLib::Win32::CThread
  84. {
  85. public:
  86. explicit CPlayer( const char *pSrvIP, unsigned short nPort, const char *pAccName );
  87. virtual ~CPlayer();
  88. virtual bool ConnectToGateway();
  89. using CThread::Start;
  90. protected:
  91. void Free();
  92. void LoginGateway();
  93. void ProcessGateway();
  94. void ProcessGatewayMsg();
  95. void ProcessGatewayLoop();
  96. void ProcessGameSvr();
  97. void ProcessGameSvrMsg();
  98. void ProcessGameSvrLoop();
  99. bool ConnectToGameSvr( const char *pIPAddr, unsigned short nPort, GUID &guid );
  100. void ShutdownGateway();
  101. void ShutdownGameSvr();
  102. bool OnAccountLoginNotify(const char* pMsg);
  103. bool OnPlayerLoginNotify(const char* pMsg);
  104. int  OnGetRoleList(const char* pMsg);
  105.     //bool OnAccountLogoutNotify(const char* pMsg);
  106. void SyncEnd();
  107. void SpeakWord( const char *pText, size_t size /*0*/ );
  108. void CastSkill();
  109. void SendGMCommand();
  110. void QueryDefaultChannel(char* szName, int nSize);
  111. void WalkTo();
  112. virtual int Run();
  113. #if defined _USE_RAINBOW
  114. static void __stdcall ClientEventNotify( LPVOID lpParam, const unsigned long &ulnEventType );
  115. #else
  116. static void ClientEventNotify( LPVOID lpParam, const unsigned long &ulnEventType );
  117. #endif
  118. void _ClientEventNotify( const unsigned long &ulnEventType );
  119. #if defined _USE_RAINBOW
  120. static void __stdcall GameServerToClientEventNotify( LPVOID lpParam, const unsigned long &ulnEventType );
  121. #else
  122. static void GameServerToClientEventNotify( LPVOID lpParam, const unsigned long &ulnEventType );
  123. #endif
  124. void _GameServerToClientEventNotify( const unsigned long &ulnEventType );
  125. typedef HRESULT ( __stdcall * pfnCreateClientInterface )( REFIID riid, void **ppv );
  126. #if defined _USE_RAINBOW
  127. static OnlineGameLib::Win32::CLibrary s_theRainbowLib;
  128. #endif
  129. // 控制线程的退出的事件
  130. OnlineGameLib::Win32::CEvent m_hQuit;
  131. private:
  132. IClient *m_pClientToGateWay;
  133. IClient *m_pClientToGameSvr;
  134. const OnlineGameLib::Win32::_tstring m_sGatewayIP;
  135. const unsigned short m_nGatewayPort;
  136. const OnlineGameLib::Win32::_tstring m_sAccName; // 帐号的名字,密码的名字,和角色的名字是一致的
  137. const LONG m_nStatus;
  138. // 机器人所跟随的Player ID
  139. static DWORD m_dwTargetID;
  140. // 机器人自己的ID
  141. DWORD m_dwID;
  142. // flying add this
  143. // 当前战斗NPC ID
  144. DWORD m_dwNpcID;
  145. POINT m_ptCurPos;
  146. POINT m_ptTagPos;
  147. // GM指令
  148. unsigned char   szGMCommand[128];
  149.     unsigned        m_RandValue;
  150.     unsigned        m_uGameServerLoopCount;
  151.     unsigned char  *m_pbyRoleMsg;
  152.     int             m_nShutDownGatewayFlag;
  153. // flying add this member, the range that robot can move.
  154. unsigned int m_nMoveRange;
  155. // Target Player's coordinate
  156. POINT m_ptTarget;
  157. int m_nCurChannel;
  158. int m_nGMChannelID;
  159. int DoSetPos();
  160. //int GetPlayerInfo();
  161. // While the command line option include "SetPos", use this member.
  162. POINT m_ptBirth;
  163. // flag
  164. int m_nFlgSetPos;
  165. int m_nFlgSetAttack;
  166. int m_nFlgAI;
  167. int m_nFlgSilence;
  168. int m_nFlgChatTimer;
  169. int m_nFlgGMDone;
  170. int m_nDoing;
  171. int m_nTeamLeader;
  172. int m_nChatTimer;
  173. // 移动坐标偏移
  174. POINT m_ptOffset;
  175. // 从core那边搬过来一点东西,实现类似的功能
  176. PLAYER_INFO m_player;
  177. int ProcessNpcSync(NPC_NORMAL_SYNC* pPS);
  178. int ProcessPlayerSync(NPC_PLAYER_TYPE_NORMAL_SYNC* pPS);
  179. int ProcessSwitchGameServer(void* lpBuffer);
  180. // 发送Ping命令
  181. void SendPing(DWORD dTime);
  182. // 处理扩展协议
  183. int ProcessExtProtocol(char* pMsg);
  184. // 装备表
  185. ITEMS m_OldItems;
  186. ITEMS m_NewItons;
  187. public:
  188. enum
  189. {
  190. enumSleep = 0x10, // 还未启动网络
  191. enumStartup, // 启动网络
  192. enumConnectToGateway, // 开始连接网关
  193. enumConnectToGatewaySucess, // 连接网关成功
  194. enumGetRoleList, // 从网关得到角色列表
  195. enumConnectToGameSvr, // 从网关得到加入游戏服务器的通告
  196. enumPlayGame, // 初始同步结束,开始游戏
  197.         enumExitGame                        // 退出游戏
  198. };
  199. void SetStatus( LONG nStatus ) { ::InterlockedExchange( const_cast< LONG * >( &m_nStatus ), nStatus ); }
  200. LONG GetStatus() { return ::InterlockedExchange( const_cast< LONG * >( &m_nStatus ), m_nStatus ); }
  201.     int GetAccountName(OnlineGameLib::Win32::_tstring &sRetAccountName)
  202.     {
  203.         sRetAccountName = m_sAccName;
  204.         return true;
  205.     }
  206. // flying add this interface to accept GM command
  207. int SetPos(int nX, int nY);
  208. int SetAttack();
  209. int SetSilence(int nSilence);
  210. int SetChatTimer(int nTimer);
  211. private:
  212. int KSG_StringToMD5String(char szDestMD5String[64], const char cszSrcString[]);
  213. };
  214. using OnlineGameLib::Win32::CCriticalSection;
  215. extern CCriticalSection g_csPlayerList;
  216. #endif // __INCLUDE_PLAYER_H__