data.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. #pragma once
  2. #include <deque>
  3. #include <vector>
  4. #include <random>
  5. #include <fstream>
  6. #include <iostream>
  7. #include <boost/asio.hpp>
  8. #include <boost/thread.hpp>
  9. #include <boost/pfr.hpp>
  10. #include <boost/any.hpp>
  11. #include <boost/property_tree/ptree.hpp>
  12. #include <boost/property_tree/ini_parser.hpp>
  13. #include "bsoncxx/builder/stream/document.hpp"
  14. #include "mongocxx/instance.hpp"
  15. #include "mongocxx/uri.hpp"
  16. #include "mongocxx/client.hpp"
  17. #include <mongocxx/exception/exception.hpp>
  18. #include "bsoncxx/json.hpp"
  19. #include "rapidjson/document.h"
  20. #include "rapidjson/writer.h"
  21. #include "rapidjson/stringbuffer.h"
  22. #include <boost/filesystem.hpp>
  23. #include <unordered_set>
  24. #include <unordered_map>
  25. #include "funclib.hpp"
  26. #include "resource.h"
  27. #include <string>
  28. #include <sstream>
  29. #include <iostream>
  30. #pragma pack(1)
  31. //data define
  32. #define MSG_NUM 20
  33. #define HTTPLEN 30000
  34. #define HTTPSENDLEN 300000
  35. #define RECLEN 5000
  36. #define LEN_ACCOUNTS 32
  37. #define LEN_PASSWORD 33
  38. #define LEN_SEAT_PHONE 33 //固定电话或移动电话
  39. #define LEN_INFO 128
  40. #define LEN_IP 16 //IP长度
  41. #define LEN_ACTION 100 //操作行动
  42. #define LEN_ACTIONINFO 200 //操作描述
  43. #define LEN_AUTHCODE 32 //授权码
  44. #define LEN_AUTHKEY 32 //授权密码
  45. //msg define
  46. #define HTTPMIN 0 //http最小id
  47. #define HTTPREGUSER 1 //注册玩家账号
  48. #define HTTPUPDATEUSERSCORE 2 //更新玩家分数
  49. #define HTTPADMINKICKUSER 5 //管理员把玩家踢出房价
  50. #define HTTPADMINPROHIBITUSER 7 //管理员禁止管理员所属玩家
  51. #define HTTPGETUSERACCOUNT 8 //获取用户账号信息
  52. #define HTTPMODIFYUSERPWD 16 //修改玩家登录密码
  53. #define HTTPADMINPROHIBITMYUSER 20 //管理员禁止直属玩家
  54. #define HTTPLOOKUPCZ 21 //查询充值信息
  55. #define HTTPLOOKUPPLAYGAME 22 //查询游戏信息
  56. #define HTTPLOOKUPUSERPLAYSCORE 23 //查询玩家总下注和总赢回
  57. #define HTTPLACTIVEMSG 25 //程序激活消息
  58. #define HTTPLUPDATEUSERINGOT 26 //添加奖励码
  59. #define HTTPLBACKINGOT 27 //回退奖励码
  60. #define HTTPLOOKUPALLUSERPLAYSCORE 28 //查询所有玩家总下注和总赢回
  61. #define HTTPMAX 29 //http最大id
  62. //game msg define
  63. #define MDM_CS_REGISTER 1
  64. #define MDM_CS_SERVICE_INFO 2
  65. #define SUB_CS_C_SERVER_UPDATESCORE 4
  66. #define SUB_CS_C_REGISTER_WEB 103
  67. static std::string g_chars(
  68. "abcdefghijklmnopqrstuvwxyz"
  69. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  70. "1234567890");
  71. //msg data
  72. typedef struct tagMsgBuffer
  73. {
  74. __int32 itype;
  75. __int32 idatasize;
  76. void *pdata;
  77. }MsgBuffer;
  78. typedef struct tagwritedata
  79. {
  80. __int64 sendallsize; //发送总长度
  81. __int64 completesize; //发送完成长度
  82. }writedata;
  83. typedef struct tag_socketmsg
  84. {
  85. int isize;
  86. void *pbuffer;
  87. tag_socketmsg()
  88. {
  89. isize = 0;
  90. pbuffer = nullptr;
  91. }
  92. }socketmsg;
  93. struct staticdata
  94. {
  95. bool m_bcreaditagent{ false };
  96. bool m_bsubmeter{ false };
  97. bool bTest{ false };
  98. std::string m_strgamelist{};
  99. std::string m_strsubgame{};
  100. std::map<std::string, std::string> m_mapregiongame{};
  101. std::string m_gameiconurl{};
  102. std::string m_strlogurl{};
  103. std::string m_strgameurl{};
  104. std::string m_strreturnurl{};
  105. std::vector<std::int32_t> m_veckindid{};
  106. std::unordered_map<std::int32_t, std::string> m_maparead;
  107. };
  108. enum EErrorCode
  109. {
  110. Err_ParamError = 1008, // 参数错误
  111. Err_No_Player = 1009, // 未找到玩家
  112. Err_No_Agent = 1010, // 未找到代理
  113. Err_No_IPWhite = 1011, // IP不在白名单
  114. Err_No_APIPermission = 1012, // 没有api权限
  115. Err_OnUpdate_DynamicPass = 1013, // 玩家动态密码更新出错
  116. Err_APIType_NotTrans = 1014, // 代理不是转账钱包
  117. Err_OutOfState_Agent = 1015, // 代理不是启用状态
  118. Err_Agent_LackInfo = 1016, // 代理信息不完整
  119. Err_Player_LackInfo = 1017, // 玩家信息不完整
  120. Err_Create_PlayerAccount = 1018, // 玩家账号生成失败
  121. Err_Create_PlayerIndex = 1019, // 玩家账号数据库索引生成失败
  122. Err_Create_UserIdDuplication = 1020, // 玩家id重复
  123. Err_Create_AlreadHasLoseWin = 1021, // 用户输赢表存在
  124. Err_Create_UserAccDuplication = 1022, // 玩家账号重复
  125. Err_Create_InsertUserInfo = 1023, // 数据库插入玩家信息失败
  126. Err_Create_InsertLoseWin = 1024, // 数据库插入输赢表失败
  127. Err_Token_Expiration = 1025, // Token已过期
  128. Err_PrizeLog_NotFound = 1026, // 游戏日志未找到
  129. Err_PrizeLog_AgentErr = 1027, // 游戏日志代理不正确
  130. Err_PrizeLog_NoQuestId = 1028, // 游戏日志没有桌号ID
  131. Err_PrizeLog_NoGID = 1029, // 游戏日志没有GID
  132. Err_ExeChangeRate_NotFound = 1030, // 汇率表未找到
  133. Err_NoSitInfo = 1031, // 站点信息未找到
  134. Err_NoGrandPrizePool = 1032, // 未找到血池信息
  135. Err_UpdateScore_OrderDuplication = 1033, // 玩家上下分订单重复
  136. Err_No_UrlPullGame = 1034, // 拉起游戏的url未配置
  137. Err_UpdateScore_OuOfLimit = 1035, // 更新玩家分数-分数超限制
  138. Err_Player_InGame = 1036, // 玩家正在游戏中
  139. Err_Trade_Forbid = 1037, // 禁止交易
  140. Err_Trade_UserScoreLack = 1038, // 玩家交易分数不足
  141. Err_QueryTime_TooLong = 1039, // 查询时间范围过大
  142. Err_Player_LoginElse = 1040, // 玩家其它地方登录
  143. Err_Player_TokenExpired = 1041, // 玩家Token过期
  144. Err_Player_NotOnline = 1042, // 玩家不在线
  145. Err_InnerError = 1043, // 内部错误
  146. Err_KeyNotExist = 1044, // code或key不存在
  147. Err_CreateUserNumberError = 1045, // 创建玩家的数量过大
  148. Err_UserScoreLessZero = 1046, // 玩家分数小于0
  149. Err_AgentScoreNotEnough = 1047, // 代理分数不足
  150. Err_ThreeAdminLackInfo = 1048, // 第三方平台信息不完整
  151. Err_AgentUpdateScoreFailed = 1049, // 商家更新分数失败
  152. Err_UserUpdateScoreFailed = 1050, // 玩家分数更新失败
  153. Err_UpdateScoreTrickyError = 1051, // 更新分数票据错误
  154. Err_UserIdNotMatchSpreadId = 1052, // 玩家id与代理id不匹配
  155. Err_LoseWinTableNotFound = 1053, // 玩家输赢表未找到
  156. Err_AgengtHasNoPlayer = 1054, // 代理下没有玩家
  157. Err_ScoreParamError = 1055, // 分数参数错误,小于0
  158. Err_OverQueryTimeLimit = 1056, // 查询时间超时
  159. };
  160. struct reguser
  161. {
  162. std::string authcode{};
  163. std::string authkey{};
  164. std::int64_t score{0}; //获取分数
  165. std::string name{}; //玩家姓名
  166. std::string phone{}; //玩家电话
  167. std::string info{}; //玩家备注
  168. public:
  169. std::string getfieldvalue(std::int32_t index)
  170. {
  171. const char* value[] = { "authcode", "authkey", "score", "name", "phone", "info"};
  172. return value[index];
  173. }
  174. void getdata()
  175. {
  176. authcode = authcode.substr(0, LEN_AUTHCODE);
  177. authkey = authkey.substr(0, LEN_AUTHKEY);
  178. name = name.substr(0, LEN_ACCOUNTS);
  179. phone = phone.substr(0, LEN_SEAT_PHONE);
  180. info = info.substr(0, LEN_INFO);
  181. if (score < 0)
  182. {
  183. score = 0;
  184. }
  185. }
  186. bool datavalue()
  187. {
  188. if (authcode.empty() || authkey.empty())
  189. {
  190. return false;
  191. }
  192. return true;
  193. }
  194. };
  195. struct userscore
  196. {
  197. std::string authcode{};
  198. std::string authkey{};
  199. std::string account{}; //玩家账号
  200. std::int64_t score{0}; //玩家分数
  201. public:
  202. std::string getfieldvalue(std::int32_t index)
  203. {
  204. const char* value[] = { "authcode", "authkey", "account", "score"};
  205. return value[index];
  206. }
  207. void getdata()
  208. {
  209. authcode = authcode.substr(0, LEN_AUTHCODE);
  210. authkey = authkey.substr(0, LEN_AUTHKEY);
  211. account = account.substr(0, LEN_ACCOUNTS);
  212. }
  213. bool datavalue()
  214. {
  215. if (authcode.empty() || authkey.empty() || account.empty())
  216. {
  217. return false;
  218. }
  219. return true;
  220. }
  221. };
  222. struct kickuser
  223. {
  224. std::string authcode{}; //代理对外账号
  225. std::string authkey{}; //代理对外密码
  226. std::string acc{}; //代理名下玩家账号
  227. public:
  228. std::string getfieldvalue(std::int32_t index)
  229. {
  230. const char* value[] = { "authcode", "authkey", "acc" };
  231. return value[index];
  232. }
  233. void getdata()
  234. {
  235. authcode = authcode.substr(0, LEN_AUTHCODE);
  236. authkey = authkey.substr(0, LEN_AUTHKEY);
  237. acc = acc.substr(0, LEN_ACCOUNTS);
  238. }
  239. bool datavalue()
  240. {
  241. if (authcode.empty() || authkey.empty() || acc.empty())
  242. {
  243. return false;
  244. }
  245. return true;
  246. }
  247. };
  248. struct prohibituser
  249. {
  250. std::string authcode{};
  251. std::string authkey{};
  252. std::string account{}; //玩家账号
  253. std::int32_t state{2}; //-1是封号,0是解封
  254. public:
  255. std::string getfieldvalue(std::int32_t index)
  256. {
  257. const char* value[] = { "authcode", "authkey", "account", "state" };
  258. return value[index];
  259. }
  260. void getdata()
  261. {
  262. authcode = authcode.substr(0, LEN_AUTHCODE);
  263. authkey = authkey.substr(0, LEN_AUTHKEY);
  264. account = account.substr(0, LEN_ACCOUNTS);
  265. }
  266. bool datavalue()
  267. {
  268. if (authcode.empty() || authkey.empty() || account.empty() || (state != -1 && state != 0))
  269. {
  270. return false;
  271. }
  272. return true;
  273. }
  274. };
  275. struct adminprohibituser
  276. {
  277. std::string authcode{};
  278. std::string authkey{};
  279. std::int32_t state{2}; //-1是封号,0是解封
  280. public:
  281. std::string getfieldvalue(std::int32_t index)
  282. {
  283. const char* value[] = { "authcode", "authkey", "state" };
  284. return value[index];
  285. }
  286. void getdata()
  287. {
  288. authcode = authcode.substr(0, LEN_AUTHCODE);
  289. authkey = authkey.substr(0, LEN_AUTHKEY);
  290. }
  291. bool datavalue()
  292. {
  293. if (authcode.empty() || authkey.empty() || (state != -1 && state != 0))
  294. {
  295. return false;
  296. }
  297. return true;
  298. }
  299. };
  300. struct sellbuyscoreinfo
  301. {
  302. std::string authcode{};
  303. std::string authkey{};
  304. std::int64_t ipagenum{0};
  305. std::int64_t begintime{0};
  306. std::int64_t endtime{0};
  307. public:
  308. std::string getfieldvalue(std::int32_t index)
  309. {
  310. const char* value[] = { "authcode", "authkey", "pagenum", "begintime", "endtime" };
  311. return value[index];
  312. }
  313. void getdata()
  314. {
  315. authcode = authcode.substr(0, LEN_AUTHCODE);
  316. authkey = authkey.substr(0, LEN_AUTHKEY);
  317. }
  318. bool datavalue()
  319. {
  320. if (authcode.empty() || authkey.empty() || ipagenum < 0 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  321. {
  322. return false;
  323. }
  324. return true;
  325. }
  326. };
  327. struct playinfo
  328. {
  329. std::string authcode{};
  330. std::string authkey{};
  331. std::string account{}; //玩家账号
  332. std::int64_t ipagenum{0};
  333. std::int64_t begintime{0};
  334. std::int64_t endtime{0};
  335. public:
  336. std::string getfieldvalue(std::int32_t index)
  337. {
  338. const char* value[] = { "authcode", "authkey", "account", "pagenum", "begintime", "endtime"};
  339. return value[index];
  340. }
  341. void getdata()
  342. {
  343. authcode = authcode.substr(0, LEN_AUTHCODE);
  344. authkey = authkey.substr(0, LEN_AUTHKEY);
  345. account = account.substr(0, LEN_ACCOUNTS);
  346. }
  347. bool datavalue()
  348. {
  349. if (authcode.empty() || authkey.empty() || account.length() < 6 || ipagenum < 0 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  350. {
  351. return false;
  352. }
  353. return true;
  354. }
  355. };
  356. struct getaccount
  357. {
  358. std::string authcode{};
  359. std::string authkey{};
  360. std::string account{}; //玩家账号
  361. public:
  362. std::string getfieldvalue(std::int32_t index)
  363. {
  364. const char* value[] = { "authcode", "authkey", "account" };
  365. return value[index];
  366. }
  367. void getdata()
  368. {
  369. authcode = authcode.substr(0, LEN_AUTHCODE);
  370. authkey = authkey.substr(0, LEN_AUTHKEY);
  371. account = account.substr(0, LEN_ACCOUNTS);
  372. }
  373. bool datavalue()
  374. {
  375. if (authcode.empty() || authkey.empty() || account.empty())
  376. {
  377. return false;
  378. }
  379. return true;
  380. }
  381. };
  382. struct playscoreinfo
  383. {
  384. std::string authcode{};
  385. std::string authkey{};
  386. std::string account{}; //玩家账号
  387. std::int64_t begintime{0};
  388. std::int64_t endtime{0};
  389. public:
  390. std::string getfieldvalue(std::int32_t index)
  391. {
  392. const char* value[] = { "authcode", "authkey", "account", "begintime", "endtime"};
  393. return value[index];
  394. }
  395. void getdata()
  396. {
  397. authcode = authcode.substr(0, LEN_AUTHCODE);
  398. authkey = authkey.substr(0, LEN_AUTHKEY);
  399. }
  400. bool datavalue()
  401. {
  402. if (authcode.empty() || authkey.empty() || account.length() < 6 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  403. {
  404. return false;
  405. }
  406. return true;
  407. }
  408. };
  409. struct updateingot
  410. {
  411. std::string authcode;
  412. std::string authkey;
  413. std::string account; //玩家账号
  414. std::int64_t score; //添加奖励码个数,负数表明vip赠送出去
  415. public:
  416. std::string getfieldvalue(std::int32_t index)
  417. {
  418. const char* value[] = { "authcode", "authkey", "account", "score" };
  419. return value[index];
  420. }
  421. void getdata()
  422. {
  423. authcode = authcode.substr(0, LEN_AUTHCODE);
  424. authkey = authkey.substr(0, LEN_AUTHKEY);
  425. account = account.substr(0, LEN_ACCOUNTS);
  426. }
  427. bool datavalue()
  428. {
  429. if (authcode.empty() || authkey.empty() || account.length() < 6)
  430. {
  431. return false;
  432. }
  433. return true;
  434. }
  435. };
  436. struct backingot
  437. {
  438. std::string authcode{};
  439. std::string authkey{};
  440. std::string account{}; //玩家账号
  441. std::int64_t score{0}; //回退奖励码个数,负数表明vip赠送出去
  442. public:
  443. std::string getfieldvalue(std::int32_t index)
  444. {
  445. const char* value[] = { "authcode", "authkey", "account", "score" };
  446. return value[index];
  447. }
  448. void getdata()
  449. {
  450. authcode = authcode.substr(0, LEN_AUTHCODE);
  451. authkey = authkey.substr(0, LEN_AUTHKEY);
  452. account = account.substr(0, LEN_ACCOUNTS);
  453. }
  454. bool datavalue()
  455. {
  456. if (authcode.empty() || authkey.empty() || account.length() < 6)
  457. {
  458. return false;
  459. }
  460. return true;
  461. }
  462. };
  463. struct activemsg
  464. {
  465. __int64 activecode; //激活码
  466. char activekey[LEN_AUTHKEY];
  467. };
  468. //game msg data
  469. struct CMD_CS_C_RegisterWeb
  470. {
  471. TCHAR szServerAddr[32]; //服务地址
  472. };
  473. struct CMD_CS_C_UpdateScoreEx
  474. {
  475. DWORD dwUserID; //用户标识
  476. LONGLONG addscore;
  477. WORD wgameserverid;
  478. DWORD dwGameContextID;
  479. DWORD dwLoginContextID;
  480. };
  481. struct adminlogin
  482. {
  483. char authcode[LEN_AUTHCODE];
  484. char authkey[LEN_AUTHKEY];
  485. char account[LEN_ACCOUNTS]; //玩家账号
  486. char pwd[LEN_PASSWORD]; //玩家密码
  487. char pwd2[LEN_PASSWORD]; //商家二级密码
  488. char ip[LEN_IP]; //登录IP地址
  489. };
  490. struct userinfo
  491. {
  492. std::string authcode{};
  493. std::string authkey{};
  494. std::string account{}; //玩家账号
  495. std::string pwd{}; //玩家密码
  496. public:
  497. std::string getfieldvalue(std::int32_t index)
  498. {
  499. const char* value[] = { "authcode", "authkey", "account", "pwdnew" };
  500. return value[index];
  501. }
  502. void getdata()
  503. {
  504. authcode = authcode.substr(0, LEN_AUTHCODE);
  505. authkey = authkey.substr(0, LEN_AUTHKEY);
  506. account = account.substr(0, LEN_ACCOUNTS);
  507. pwd = pwd.substr(0, LEN_PASSWORD);
  508. }
  509. bool datavalue()
  510. {
  511. if (authcode.empty() || authkey.empty() || account.empty() || pwd.length() < 6)
  512. {
  513. return false;
  514. }
  515. return true;
  516. }
  517. };
  518. struct allplayscoreinfo
  519. {
  520. std::string authcode{};
  521. std::string authkey{};
  522. std::int32_t ipagenum{0};
  523. std::int64_t begintime{0};
  524. std::int64_t endtime{0};
  525. public:
  526. std::string getfieldvalue(std::int32_t index)
  527. {
  528. const char* value[] = { "authcode", "authkey", "pagenum", "begintime", "endtime" };
  529. return value[index];
  530. }
  531. void getdata()
  532. {
  533. authcode = authcode.substr(0, LEN_AUTHCODE);
  534. authkey = authkey.substr(0, LEN_AUTHKEY);
  535. }
  536. bool datavalue()
  537. {
  538. if (authcode.empty() || authkey.empty() || ipagenum < 0 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  539. {
  540. return false;
  541. }
  542. return true;
  543. }
  544. };
  545. struct gameuserlog
  546. {
  547. __int64 dbquestid;
  548. std::string account;
  549. std::string servername;
  550. __int32 serverid;
  551. std::string betscore;
  552. std::string winscore;
  553. std::string userscore;
  554. std::string gamelog;
  555. __int64 inserttime;
  556. };
  557. struct taggameuserlog {
  558. __int32 ret;
  559. std::string info;
  560. __int64 allrecordnum;
  561. __int64 recordnum;
  562. __int64 curpagenum;
  563. __int64 allpagenum;
  564. std::vector<gameuserlog> userlog{};
  565. };
  566. //踢出玩家
  567. struct CMD_CS_C_DelOnlineUser
  568. {
  569. DWORD dwUserID;
  570. WORD wserverid;
  571. DWORD dwGameContextID;
  572. };
  573. #pragma pack()