data.h 16 KB

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