诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

125 regels
3.6 KiB

  1. #ifndef DISTRIBUTE_MANAGER_HEAD_FILE
  2. #define DISTRIBUTE_MANAGER_HEAD_FILE
  3. #pragma once
  4. #include "Stdafx.h"
  5. //////////////////////////////////////////////////////////////////////////////////
  6. //分组数据
  7. struct tagDistributeInfo
  8. {
  9. WORD wDistribute; //分配等级
  10. WORD wLastTableID; //上局桌号
  11. IServerUserItem * pIServerUserItem; //用户接口
  12. VOID * pPertainNode; //所属结点
  13. };
  14. //分组结点
  15. struct tagDistributeNode
  16. {
  17. tagDistributeNode * pPrepDistributeNode; //前一结点
  18. tagDistributeNode * pNextDistributeNode; //下一结点
  19. tagDistributeInfo DistributeInfo; //分组信息
  20. };
  21. //////////////////////////////////////////////////////////////////////////////////
  22. typedef CWHArray<tagDistributeInfo> CDistributeInfoArray; //分组数组
  23. //////////////////////////////////////////////////////////////////////////////////
  24. //结点池
  25. class CDistributeNodePool
  26. {
  27. //管理变量
  28. public:
  29. static const int BLOCK_SIZE;
  30. static tagDistributeNode * m_pHeadOfFreeList;
  31. //函数定义
  32. public:
  33. //构造函数
  34. CDistributeNodePool();
  35. //析构函数
  36. ~CDistributeNodePool();
  37. //功能函数
  38. public:
  39. //分配结点
  40. tagDistributeNode * AllocNode();
  41. //释放结点
  42. VOID FreeNode(void * pNode);
  43. };
  44. //////////////////////////////////////////////////////////////////////////////////
  45. //分组管理
  46. class CDistributeManager
  47. {
  48. //数目变量
  49. protected:
  50. WORD m_wNodeCount; //结点数目
  51. WORD m_wRealCount; //玩家数目
  52. WORD m_wAndroidCount; //机器数目
  53. //管理变量
  54. protected:
  55. CDistributeNodePool m_DistributeNodePool; //结点池
  56. tagDistributeNode * m_pHeadNode; //头部结点
  57. //分组变量
  58. protected:
  59. BYTE m_cbDistributeRule; //分组规则
  60. //函数定义
  61. public:
  62. //构造函数
  63. CDistributeManager();
  64. //析构函数
  65. virtual ~CDistributeManager();
  66. //内联函数
  67. public:
  68. //结点数目
  69. inline WORD GetCount() { return m_wNodeCount; }
  70. //真人数目
  71. inline WORD GetRealCount() { return m_wRealCount; }
  72. //机器数目
  73. inline WORD GetAndroidCount() { return m_wAndroidCount; }
  74. //设置规则
  75. inline VOID SetDistributeRule(BYTE cbDistributeRule) { m_cbDistributeRule = cbDistributeRule; }
  76. //内部函数
  77. protected:
  78. //查找结点
  79. tagDistributeNode* SearchNode(const IServerUserItem * const pIServerUserItem);
  80. //功能函数
  81. public:
  82. //移除结点
  83. VOID RemoveAll();
  84. //移除结点
  85. VOID RemoveDistributeNode(tagDistributeNode * pDistributeNode);
  86. //移除结点
  87. VOID RemoveDistributeNode(const IServerUserItem * pIServerUserItem);
  88. //插入结点
  89. BOOL InsertDistributeNode(const tagDistributeInfo & DistributeInfo);
  90. //执行分组
  91. WORD PerformDistribute(CDistributeInfoArray & DistributeInfoArray, WORD wNeedCount);
  92. //过滤函数
  93. protected:
  94. //IP同址
  95. inline BOOL FilterRuleExitsIPAddr(const CDistributeInfoArray & DistributeInfoArray, DWORD dwClientAddr);
  96. //上局同桌
  97. inline BOOL FilterRuleExitsSameTable(const CDistributeInfoArray & DistributeInfoArray, WORD wLastTableID);
  98. //机器过滤
  99. inline BOOL FilterRuleIsAllAndroid(const CDistributeInfoArray & DistributeInfoArray, IServerUserItem * const pIServerUserItem);
  100. };
  101. //////////////////////////////////////////////////////////////////////////////////
  102. #endif