-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot_define.h
284 lines (200 loc) · 6.44 KB
/
robot_define.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#pragma once
#define SERVICE_NAME _T("robottool")
#define DISPLAY_NAME _T("robottoolxxx")
//#define STRICT_ASSERT // 开启严格调试模式, 错误时打印调用栈 并assert
#define CURRENT_DELAY // 限流延时标签
const std::string LocalIPStr = std::string("127.0.0.1");
// Invalid Param
const int InvalidPort = 0;
const int RobotAgentGroupID = 1;
const int InvalidUserID = 0;
const int InvalidGameID = 0;
const int InvalidRoomID = 0;
const int InvalidTableNO = 0;
const int InvalidChairNO = 0;
const int InvalidTokenID = 0;
const int InvalidRequestID = 0;
const int InvalidCount = -1;
const int InvalidThreadID = 0;
const int InvallidPort = 0;
// Time Interval
const int MS_PER_SECOND = 1000; // ms
const int TimerInterval = 1 * MS_PER_SECOND; // 定时器时间间隔 1s
const int GamePulseInterval = 30; // 心跳时间间隔 30s
const int HallPulseInterval = 30; // 心跳时间间隔 30s
const int RobotPulseInterval = 60; // 心跳时间间隔 60s
const int RequestTimeOut = 4 * MS_PER_SECOND; //请求回应超时时间 4s
const int HttpTimeOut = 5 * MS_PER_SECOND; // HTTP 超时 5s
const int MainInterval = 10 * MS_PER_SECOND; // 主循环时间间隔 10s
const int DepositInterval = 1 * MS_PER_SECOND; // 补银时间间隔 1s
// 补银还银
const int64_t GainAmount = 200000;
const int64_t BackAmount = 200000;
const int64_t MaxAmount = 200000000; // 后台同事确认正式最大补银。后台可配置
const float DepoistFactor = 0.7f; // rummy 补银业务参数
// 心跳超时计数
const int MaxPluseTimeOutCount = 5;
// 限流延时参数
const int CurrentDealy = 50; // ms
// 运行统计开关
const int ProcessInfoClose = 0;
const int ProcessInfoOpen = 1;
// 业务类型定义
using UserID = int32_t;
using GameID = int32_t;
using RoomID = int32_t;
using TableNO = int32_t;
using ChairNO = int32_t;
using TokenID = int32_t;
using RequestID = uint32_t;
using ThreadID = uint32_t;
using NeedCount = uint32_t;
using TimeStamp = time_t;
using EventKey = uint32_t;
enum class EventType {
kBeg = 0,
kSend,
kRecv,
kErr,
kEnd,
};
enum RobotErrorCode {
kCreateHallConnFailed = 10086,
kCreateGameConnFailed,
kConnectionTimeOut,
kOperationFailed,
kRespIDZero,
};
enum RobotExceptionCode {
kExceptionUserNotOnChair = 20086,
kExceptionNoRobotDeposit,
kExceptionNoMoreRobot,
kExceptionGameDataNotInited,
kExceptionRobotNotInGame,
kExceptionNotRobotType,
kExceptionRobotInGame,
};
enum class DepositType {
kDefault,
kGain, //补银
kBack, //还银
};
enum class HallLogonStatusType {
kNotLogon,
kLogon,
};
//配置类 只读
class RobotSetting {
public:
UserID userid;
std::string password;
std::string nickname;
std::string headurl;
};
struct RoomSetiing {
RoomID roomid;
int wait_time;
int count_per_table;
};
struct HallRoomData {
ROOM room;
};
struct NeedUser {
UserID userid;
TableNO tableno;
RoomID roomid;
};
struct DepositData {
DepositType type;
int64_t amount;
};
typedef struct _tagQUERY_USER_GAMEINFO {
int nUserID;
int nGameID;
DWORD dwQueryFlags;
UWL_ADDR stIPAddr;
char szHardID[MAX_HARDID_LEN];
INT64 nGiftDeposit;
int nReserved[4];
}QUERY_USER_GAMEINFO, *LPQUERY_USER_GAMEINFO;
typedef struct _tagUSER_GAMEINFO_MB {
int nUserID; // 用户ID
int nGameID; // 游戏ID
INT64 nDeposit; // 银子
int nPlayerLevel; // 级别
int nScore; // 积分
int nExperience; // 经验(分钟,已废弃)
int nBreakOff; // 断线
int nWin; // 赢
int nLoss; // 输
int nStandOff; // 和
int nBout; // 回合
int nTimeCost; // 花时(秒)
int nSalaryTime;
INT64 nSalaryDeposit;
INT64 nTotalSalary;
DWORD dwFlags; // 一些状态标记
int nReserved[7];
}USER_GAMEINFO_MB, *LPUSER_GAMEINFO_MB;//注意这个结构跟pc端的那个不同
using CDefSocketClientPtr = std::shared_ptr <CDefSocketClient>;
using RoomSettingMap = std::unordered_map<RoomID, RoomSetiing>;
using RobotSettingMap = std::unordered_map<UserID, RobotSetting>;
using HallLogonMap = std::unordered_map<UserID, HallLogonStatusType>;
using HallRoomDataMap = std::unordered_map<RoomID, HallRoomData>;
using UserDepositMap = std::unordered_map<UserID, int64_t>;
using DepositMap = std::unordered_map<UserID, DepositData>;
using RoomNeedCountMap = std::unordered_map<RoomID, NeedCount>;
using RoomNeedUserMap = std::unordered_map<RoomID, NeedUser>;
using SendMsgCountMap = std::unordered_map<RequestID, uint64_t>;
using RecvNtfCountMap = std::unordered_map<RequestID, uint64_t>;
using ErrorCountMap = std::unordered_map<uint32_t, uint64_t>;
using RobotUserIDMap = std::unordered_map<UserID, UserID>;
using RobotDepositMap = std::unordered_map<UserID, int64_t>;
class User;
using UserMap = std::hash_map<UserID, std::shared_ptr<User>>;
using UserFilterMap = std::hash_map<UserID, UserID>;
// 单例模板类
template< typename T >
class ISingletion {
public:
ISingletion(const ISingletion&) = delete;
ISingletion& operator = (const ISingletion&) = delete;
ISingletion(ISingletion&& t) = delete;
ISingletion& operator = (ISingletion&& t) = delete;
virtual ~ISingletion() {}
static T& Instance() {
static T s_xInstance;
return s_xInstance;
}
protected:
ISingletion() {}
};
#define SINGLETION_CONSTRUCTOR(_class_name_) \
friend ISingletion < _class_name_ >; \
_class_name_(){}; \
virtual ~_class_name_(){}; \
// 线程对象
class YQThread {
public:
YQThread() {}
explicit YQThread(std::thread&& thrd) { Initial(std::move(thrd)); }
~YQThread() { Release(); }
public:
void Initial(std::thread&& thrd) {
m_thrd.swap(thrd);
m_hThrd = static_cast<HANDLE>(m_thrd.native_handle());
m_nThrd = GetThreadId(m_hThrd);
}
void Release() {
if (m_nThrd == 0) return;
PostThreadMessage(m_nThrd, WM_QUIT, 0, 0);
WaitForSingleObject(m_hThrd, WAITTIME_EXIT);
m_thrd.detach(); //::CloseHandle(m_hThrd);
m_nThrd = 0; m_hThrd = nullptr;
}
ThreadID GetThreadID() const { return m_nThrd; }
protected:
std::thread m_thrd;
ThreadID m_nThrd{0};
HANDLE m_hThrd{nullptr};
};