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

模拟服务器

开发平台:

C/C++

  1. /********************************************************************
  2. created: 2003/06/05
  3. file base: ClientNode
  4. file ext: h
  5. author: liupeng
  6. purpose:
  7. *********************************************************************/
  8. #ifndef __INCLUDE_CLIENTNODE_H__
  9. #define __INCLUDE_CLIENTNODE_H__
  10. #include "IServer.h"
  11. #include "HeavenInterface.h"
  12. #include "Buffer.h"
  13. #include "CriticalSection.h"
  14. #include "Event.h"
  15. #include "kprotocoldef.h"
  16. #define _NAME_LENGTH 64
  17. #include <list>
  18. using namespace std;
  19. class CClientNode
  20. {
  21. public:
  22. explicit CClientNode( IServer *pServer, size_t id );
  23. virtual ~CClientNode();
  24. static bool Start( IServer *pServer );
  25. static void End();
  26. static CClientNode *AddNode( IServer *pServer, size_t id );
  27. static void DelNode( size_t id );
  28. void AppendData( const void *pData, size_t datalength );
  29. void Process();
  30. protected:
  31. static unsigned int __stdcall ThreadFunction( void *pV );
  32. static HANDLE m_hThread;
  33. static OnlineGameLib::Win32::CEvent m_hQuitEvent;
  34. static OnlineGameLib::Win32::CCriticalSection m_csCL;
  35. typedef map< size_t, CClientNode * > stdMap;
  36. static stdMap m_theClientMap;
  37. void LargePackProcess( const void *pData, size_t dataLength );
  38. void SmallPackProcess( const void *pData, size_t dataLength );
  39. private:
  40. size_t m_nIndentity;
  41. OnlineGameLib::Win32::CPackager m_theRecv;
  42. OnlineGameLib::Win32::CPackager m_theSend;
  43. OnlineGameLib::Win32::CBuffer::Allocator m_theAllocator;
  44. IServer *m_pServer;
  45. typedef void ( CClientNode::*ProcessArray[c2s_end] )( const void *pData, size_t dataLength );
  46. ProcessArray m_theProcessArray;
  47. void _QueryRoleList( const void *pData, size_t dataLength );
  48. void _CreateRole( const void *pData, size_t dataLength );
  49. void _SaveRoleInfo( const void *pData, size_t dataLength );
  50. void _DelRole( const void *pData, size_t dataLength );
  51. void _GetRoleInfo( const void *pData, size_t dataLength );
  52. /*
  53.  * class CDataQueue
  54.  */
  55. class CDataQueue
  56. {
  57. public:
  58. explicit CDataQueue( size_t bufferSize = 1024 * 64, size_t maxFreeBuffers = 160 );
  59. ~CDataQueue();
  60. /*
  61.  * Function
  62.  */
  63. bool AddData( const BYTE *pData, size_t datalength );
  64. OnlineGameLib::Win32::CBuffer *Get();
  65. private:
  66. /*
  67.  * Data
  68.  */
  69. OnlineGameLib::Win32::CCriticalSection m_csQueue;
  70. typedef list< OnlineGameLib::Win32::CBuffer * > stdDataList;
  71. stdDataList m_theData;
  72. OnlineGameLib::Win32::CBuffer::Allocator m_theDQAllocator;
  73. };
  74. CDataQueue m_theDataQueue;
  75. };
  76. #endif // __INCLUDE_CLIENTNODE_H__