data.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. }
  212. bool datavalue()
  213. {
  214. if (authcode.empty() || authkey.empty() || account.empty())
  215. {
  216. return false;
  217. }
  218. return true;
  219. }
  220. };
  221. struct kickuser
  222. {
  223. std::string authcode{}; //代理对外账号
  224. std::string authkey{}; //代理对外密码
  225. std::string acc{}; //代理名下玩家账号
  226. public:
  227. std::string getfieldvalue(std::int32_t index)
  228. {
  229. const char* value[] = { "authcode", "authkey", "acc" };
  230. return value[index];
  231. }
  232. void getdata()
  233. {
  234. authcode = authcode.substr(0, LEN_AUTHCODE);
  235. authkey = authkey.substr(0, LEN_AUTHKEY);
  236. acc = acc.substr(0, LEN_ACCOUNTS);
  237. }
  238. bool datavalue()
  239. {
  240. if (authcode.empty() || authkey.empty() || acc.empty())
  241. {
  242. return false;
  243. }
  244. return true;
  245. }
  246. };
  247. struct prohibituser
  248. {
  249. std::string authcode{};
  250. std::string authkey{};
  251. std::string account{}; //玩家账号
  252. std::int32_t state{2}; //-1是封号,0是解封
  253. public:
  254. std::string getfieldvalue(std::int32_t index)
  255. {
  256. const char* value[] = { "authcode", "authkey", "account", "state" };
  257. return value[index];
  258. }
  259. void getdata()
  260. {
  261. authcode = authcode.substr(0, LEN_AUTHCODE);
  262. authkey = authkey.substr(0, LEN_AUTHKEY);
  263. account = account.substr(0, LEN_ACCOUNTS);
  264. }
  265. bool datavalue()
  266. {
  267. if (authcode.empty() || authkey.empty() || account.empty() || (state != -1 && state != 0))
  268. {
  269. return false;
  270. }
  271. return true;
  272. }
  273. };
  274. struct adminprohibituser
  275. {
  276. std::string authcode{};
  277. std::string authkey{};
  278. std::int32_t state{2}; //-1是封号,0是解封
  279. public:
  280. std::string getfieldvalue(std::int32_t index)
  281. {
  282. const char* value[] = { "authcode", "authkey", "state" };
  283. return value[index];
  284. }
  285. void getdata()
  286. {
  287. authcode = authcode.substr(0, LEN_AUTHCODE);
  288. authkey = authkey.substr(0, LEN_AUTHKEY);
  289. }
  290. bool datavalue()
  291. {
  292. if (authcode.empty() || authkey.empty() || (state != -1 && state != 0))
  293. {
  294. return false;
  295. }
  296. return true;
  297. }
  298. };
  299. struct sellbuyscoreinfo
  300. {
  301. std::string authcode{};
  302. std::string authkey{};
  303. std::int64_t ipagenum{0};
  304. std::int64_t begintime{0};
  305. std::int64_t endtime{0};
  306. std::int64_t iuserid{};
  307. std::int64_t iagentid{};
  308. public:
  309. std::string getfieldvalue(std::int32_t index)
  310. {
  311. const char* value[] = { "authcode", "authkey", "pagenum", "begintime", "endtime", "userid", "agentid"};
  312. return value[index];
  313. }
  314. void getdata()
  315. {
  316. authcode = authcode.substr(0, LEN_AUTHCODE);
  317. authkey = authkey.substr(0, LEN_AUTHKEY);
  318. }
  319. bool datavalue()
  320. {
  321. if (authcode.empty() || authkey.empty() || ipagenum < 0 || begintime <= 0 || endtime <= 0 || endtime < begintime || iuserid < 0 || iagentid < 0)
  322. {
  323. return false;
  324. }
  325. return true;
  326. }
  327. };
  328. struct playinfo
  329. {
  330. std::string authcode{};
  331. std::string authkey{};
  332. std::int64_t iuserid{}; //玩家账号
  333. std::int32_t igametype{};
  334. std::int32_t ipagesize{ 10 };
  335. std::int32_t ipagenum{0};
  336. std::int64_t begintime{0};
  337. std::int64_t endtime{0};
  338. public:
  339. std::string getfieldvalue(std::int32_t index)
  340. {
  341. const char* value[] = { "authcode", "authkey", "userid", "gametype", "pagesize", "pagenum", "begintime", "endtime"};
  342. return value[index];
  343. }
  344. void getdata()
  345. {
  346. authcode = authcode.substr(0, LEN_AUTHCODE);
  347. authkey = authkey.substr(0, LEN_AUTHKEY);
  348. }
  349. bool datavalue()
  350. {
  351. if (authcode.empty() || authkey.empty() || iuserid < 0 || igametype < 0 || ipagesize > 50 || ipagenum < 0 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  352. {
  353. return false;
  354. }
  355. return true;
  356. }
  357. };
  358. struct getaccount
  359. {
  360. std::string authcode{};
  361. std::string authkey{};
  362. std::string account{}; //玩家账号
  363. public:
  364. std::string getfieldvalue(std::int32_t index)
  365. {
  366. const char* value[] = { "authcode", "authkey", "account" };
  367. return value[index];
  368. }
  369. void getdata()
  370. {
  371. authcode = authcode.substr(0, LEN_AUTHCODE);
  372. authkey = authkey.substr(0, LEN_AUTHKEY);
  373. account = account.substr(0, LEN_ACCOUNTS);
  374. }
  375. bool datavalue()
  376. {
  377. if (authcode.empty() || authkey.empty() || account.empty())
  378. {
  379. return false;
  380. }
  381. return true;
  382. }
  383. };
  384. struct playscoreinfo
  385. {
  386. std::string authcode{};
  387. std::string authkey{};
  388. std::string account{}; //玩家账号
  389. std::int64_t begintime{0};
  390. std::int64_t endtime{0};
  391. public:
  392. std::string getfieldvalue(std::int32_t index)
  393. {
  394. const char* value[] = { "authcode", "authkey", "account", "begintime", "endtime"};
  395. return value[index];
  396. }
  397. void getdata()
  398. {
  399. authcode = authcode.substr(0, LEN_AUTHCODE);
  400. authkey = authkey.substr(0, LEN_AUTHKEY);
  401. }
  402. bool datavalue()
  403. {
  404. if (authcode.empty() || authkey.empty() || account.length() < 6 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  405. {
  406. return false;
  407. }
  408. return true;
  409. }
  410. };
  411. struct updateingot
  412. {
  413. std::string authcode;
  414. std::string authkey;
  415. std::string account; //玩家账号
  416. std::int64_t score; //添加奖励码个数,负数表明vip赠送出去
  417. public:
  418. std::string getfieldvalue(std::int32_t index)
  419. {
  420. const char* value[] = { "authcode", "authkey", "account", "score" };
  421. return value[index];
  422. }
  423. void getdata()
  424. {
  425. authcode = authcode.substr(0, LEN_AUTHCODE);
  426. authkey = authkey.substr(0, LEN_AUTHKEY);
  427. account = account.substr(0, LEN_ACCOUNTS);
  428. }
  429. bool datavalue()
  430. {
  431. if (authcode.empty() || authkey.empty() || account.length() < 6)
  432. {
  433. return false;
  434. }
  435. return true;
  436. }
  437. };
  438. struct backingot
  439. {
  440. std::string authcode{};
  441. std::string authkey{};
  442. std::string account{}; //玩家账号
  443. std::int64_t score{0}; //回退奖励码个数,负数表明vip赠送出去
  444. public:
  445. std::string getfieldvalue(std::int32_t index)
  446. {
  447. const char* value[] = { "authcode", "authkey", "account", "score" };
  448. return value[index];
  449. }
  450. void getdata()
  451. {
  452. authcode = authcode.substr(0, LEN_AUTHCODE);
  453. authkey = authkey.substr(0, LEN_AUTHKEY);
  454. account = account.substr(0, LEN_ACCOUNTS);
  455. }
  456. bool datavalue()
  457. {
  458. if (authcode.empty() || authkey.empty() || account.length() < 6)
  459. {
  460. return false;
  461. }
  462. return true;
  463. }
  464. };
  465. struct activemsg
  466. {
  467. __int64 activecode; //激活码
  468. char activekey[LEN_AUTHKEY];
  469. };
  470. //game msg data
  471. struct CMD_CS_C_RegisterWeb
  472. {
  473. TCHAR szServerAddr[32]; //服务地址
  474. };
  475. struct CMD_CS_C_UpdateScoreEx
  476. {
  477. DWORD dwUserID; //用户标识
  478. LONGLONG addscore;
  479. WORD wgameserverid;
  480. DWORD dwGameContextID;
  481. DWORD dwLoginContextID;
  482. };
  483. struct adminlogin
  484. {
  485. char authcode[LEN_AUTHCODE];
  486. char authkey[LEN_AUTHKEY];
  487. char account[LEN_ACCOUNTS]; //玩家账号
  488. char pwd[LEN_PASSWORD]; //玩家密码
  489. char pwd2[LEN_PASSWORD]; //商家二级密码
  490. char ip[LEN_IP]; //登录IP地址
  491. };
  492. struct userinfo
  493. {
  494. std::string authcode{};
  495. std::string authkey{};
  496. std::string account{}; //玩家账号
  497. std::string pwd{}; //玩家密码
  498. public:
  499. std::string getfieldvalue(std::int32_t index)
  500. {
  501. const char* value[] = { "authcode", "authkey", "account", "pwdnew" };
  502. return value[index];
  503. }
  504. void getdata()
  505. {
  506. authcode = authcode.substr(0, LEN_AUTHCODE);
  507. authkey = authkey.substr(0, LEN_AUTHKEY);
  508. account = account.substr(0, LEN_ACCOUNTS);
  509. pwd = pwd.substr(0, LEN_PASSWORD);
  510. }
  511. bool datavalue()
  512. {
  513. if (authcode.empty() || authkey.empty() || account.empty() || pwd.length() < 6)
  514. {
  515. return false;
  516. }
  517. return true;
  518. }
  519. };
  520. struct allplayscoreinfo
  521. {
  522. std::string authcode{};
  523. std::string authkey{};
  524. std::int32_t ipagenum{0};
  525. std::int64_t begintime{0};
  526. std::int64_t endtime{0};
  527. public:
  528. std::string getfieldvalue(std::int32_t index)
  529. {
  530. const char* value[] = { "authcode", "authkey", "pagenum", "begintime", "endtime" };
  531. return value[index];
  532. }
  533. void getdata()
  534. {
  535. authcode = authcode.substr(0, LEN_AUTHCODE);
  536. authkey = authkey.substr(0, LEN_AUTHKEY);
  537. }
  538. bool datavalue()
  539. {
  540. if (authcode.empty() || authkey.empty() || ipagenum < 0 || begintime <= 0 || endtime <= 0 || endtime < begintime)
  541. {
  542. return false;
  543. }
  544. return true;
  545. }
  546. };
  547. struct gameuserlog
  548. {
  549. __int64 dbquestid;
  550. std::string account;
  551. std::string servername;
  552. __int32 serverid;
  553. std::string betscore;
  554. std::string winscore;
  555. std::string userscore;
  556. std::string gamelog;
  557. __int64 inserttime;
  558. };
  559. struct taggameuserlog {
  560. __int32 ret;
  561. std::string info;
  562. __int64 allrecordnum;
  563. __int64 recordnum;
  564. __int64 curpagenum;
  565. __int64 allpagenum;
  566. std::vector<gameuserlog> userlog{};
  567. };
  568. //踢出玩家
  569. struct CMD_CS_C_DelOnlineUser
  570. {
  571. DWORD dwUserID;
  572. WORD wserverid;
  573. DWORD dwGameContextID;
  574. };
  575. #pragma pack()