诸暨麻将添加redis
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

958 řádky
33 KiB

  1. #include "StdAfx.h"
  2. #include "ServiceUnits.h"
  3. #include "DataBaseEngineSink.h"
  4. #include "LogonServer.h"
  5. #include "LogonServerDlg.h"
  6. #include "AttemperEngineSink.h"
  7. #include <unordered_map>
  8. #include <strsafe.h>
  9. #include "BaiDuMap.h"
  10. extern CLogonServerApp theApp;
  11. //////////////////////////////////////////////////////////////////////////////////
  12. CMap<DWORD, DWORD, LONGLONG, LONGLONG> CDataBaseEngineSink::m_MapUserIDJuli;
  13. //构造函数
  14. CDataBaseEngineSink::CDataBaseEngineSink()
  15. {
  16. //组件变量
  17. m_pInitParameter = NULL;
  18. m_pIDataBaseEngineEvent = NULL;
  19. return;
  20. }
  21. //析构函数
  22. CDataBaseEngineSink::~CDataBaseEngineSink()
  23. {
  24. }
  25. //接口查询
  26. VOID * CDataBaseEngineSink::QueryInterface(REFGUID Guid, DWORD dwQueryVer)
  27. {
  28. QUERYINTERFACE(IDataBaseEngineSink, Guid, dwQueryVer);
  29. QUERYINTERFACE_IUNKNOWNEX(IDataBaseEngineSink, Guid, dwQueryVer);
  30. return NULL;
  31. }
  32. //启动事件
  33. bool CDataBaseEngineSink::OnDataBaseEngineStart(IUnknownEx * pIUnknownEx)
  34. {
  35. //创建对象
  36. if ((m_AccountsDBModule.GetInterface() == NULL) && (m_AccountsDBModule.CreateInstance() == false))
  37. {
  38. ASSERT(FALSE);
  39. return false;
  40. }
  41. //创建对象
  42. if ((m_TreasureDBModule.GetInterface() == NULL) && (m_TreasureDBModule.CreateInstance() == false))
  43. {
  44. ASSERT(FALSE);
  45. return false;
  46. }
  47. //创建对象
  48. if ((m_PlatformDBModule.GetInterface() == NULL) && (m_PlatformDBModule.CreateInstance() == false))
  49. {
  50. ASSERT(FALSE);
  51. return false;
  52. }
  53. try
  54. {
  55. //连接信息
  56. tagDataBaseParameter * pAccountsDBParameter = &m_pInitParameter->m_AccountsDBParameter;
  57. tagDataBaseParameter * pTreasureDBParameter = &m_pInitParameter->m_TreasureDBParameter;
  58. tagDataBaseParameter * pPlatformDBParameter = &m_pInitParameter->m_PlatformDBParameter;
  59. //设置连接
  60. m_AccountsDBModule->SetConnectionInfo(pAccountsDBParameter->szDataBaseAddr, pAccountsDBParameter->wDataBasePort,
  61. pAccountsDBParameter->szDataBaseName, pAccountsDBParameter->szDataBaseUser, pAccountsDBParameter->szDataBasePass);
  62. m_TreasureDBModule->SetConnectionInfo(pTreasureDBParameter->szDataBaseAddr, pTreasureDBParameter->wDataBasePort,
  63. pTreasureDBParameter->szDataBaseName, pTreasureDBParameter->szDataBaseUser, pTreasureDBParameter->szDataBasePass);
  64. m_PlatformDBModule->SetConnectionInfo(pPlatformDBParameter->szDataBaseAddr, pPlatformDBParameter->wDataBasePort,
  65. pPlatformDBParameter->szDataBaseName, pPlatformDBParameter->szDataBaseUser, pPlatformDBParameter->szDataBasePass);
  66. //发起连接
  67. m_AccountsDBModule->OpenConnection();
  68. m_AccountsDBAide.SetDataBase(m_AccountsDBModule.GetInterface());
  69. //发起连接
  70. m_TreasureDBModule->OpenConnection();
  71. m_TreasureDBAide.SetDataBase(m_TreasureDBModule.GetInterface());
  72. //发起连接
  73. m_PlatformDBModule->OpenConnection();
  74. m_PlatformDBAide.SetDataBase(m_PlatformDBModule.GetInterface());
  75. return true;
  76. }
  77. catch (IDataBaseException * pIException)
  78. {
  79. //错误信息
  80. LPCTSTR pszDescribe = pIException->GetExceptionDescribe();
  81. CTraceService::TraceString(pszDescribe, TraceLevel_Exception);
  82. return false;
  83. }
  84. return true;
  85. }
  86. //停止事件
  87. bool CDataBaseEngineSink::OnDataBaseEngineConclude(IUnknownEx * pIUnknownEx)
  88. {
  89. //设置对象
  90. m_AccountsDBAide.SetDataBase(NULL);
  91. m_TreasureDBAide.SetDataBase(NULL);
  92. m_PlatformDBAide.SetDataBase(NULL);
  93. //关闭连接
  94. if (m_AccountsDBModule.GetInterface() != NULL)
  95. {
  96. m_AccountsDBModule->CloseConnection();
  97. m_AccountsDBModule.CloseInstance();
  98. }
  99. //关闭连接
  100. if (m_TreasureDBModule.GetInterface() != NULL)
  101. {
  102. m_TreasureDBModule->CloseConnection();
  103. m_TreasureDBModule.CloseInstance();
  104. }
  105. //关闭连接
  106. if (m_PlatformDBModule.GetInterface() != NULL)
  107. {
  108. m_PlatformDBModule->CloseConnection();
  109. m_PlatformDBModule.CloseInstance();
  110. }
  111. //组件变量
  112. m_pInitParameter = NULL;
  113. m_pIDataBaseEngineEvent = NULL;
  114. return true;
  115. }
  116. //时间事件
  117. bool CDataBaseEngineSink::OnDataBaseEngineTimer(DWORD dwTimerID, WPARAM dwBindParameter)
  118. {
  119. return false;
  120. }
  121. //控制事件
  122. bool CDataBaseEngineSink::OnDataBaseEngineControl(WORD wControlID, VOID * pData, WORD wDataSize)
  123. {
  124. return false;
  125. }
  126. //请求事件
  127. bool CDataBaseEngineSink::OnDataBaseEngineRequest(WORD wRequestID, DWORD dwContextID, VOID * pData, WORD wDataSize)
  128. {
  129. switch (wRequestID)
  130. {
  131. //case DBR_GP_LOAD_PLATFORM_PARAMETER: //平台参数
  132. //{
  133. // return OnRequestPlatformParameter(dwContextID, pData, wDataSize);
  134. //}
  135. case DBR_GP_ONLINE_SERVICE:
  136. {
  137. //更新通道状态
  138. return OnRequestOnLineService(dwContextID, pData, wDataSize);
  139. }
  140. case DBR_GP_CLEARJULI: //清空距离
  141. {
  142. return OnRequestClearJuLi(dwContextID, pData, wDataSize);
  143. }
  144. case DBR_GP_CLEARJULIADD: //距离添加
  145. {
  146. return OnRequestAddJuLi(dwContextID, pData, wDataSize);
  147. }
  148. case DBR_GP_ONLINE_COUNT_INFO: //在线信息
  149. {
  150. return OnRequestOnLineCountInfo(dwContextID, pData, wDataSize);
  151. }
  152. case DBR_MB_LOGON_ACCOUNTS: //帐号登录,手机登录
  153. {
  154. return OnMobileLogonAccounts(dwContextID, pData, wDataSize);
  155. }
  156. case DBR_MB_LOGON_OTHERPLATFORM: //微信登录
  157. {
  158. return OnMobileLogonOtherPlatform(dwContextID, pData, wDataSize);
  159. }
  160. case DBR_MB_IPHONEYANZM: //获取验证码
  161. {
  162. return OnMobileLogonYanZhengMa(dwContextID, pData, wDataSize);
  163. }
  164. case DBR_MB_IPHONEMIMA: //落地密码
  165. {
  166. return OnMobileLogonVerfCodeToMiMa(dwContextID, pData, wDataSize);
  167. }
  168. case DBR_MB_HANDLE_IPHONEMIMA: //处理手机验证码出错
  169. {
  170. return OnMobileLogonHandleVerfCodeFail(dwContextID, pData, wDataSize);
  171. }
  172. }
  173. return false;
  174. }
  175. //帐号登录、手机登录
  176. bool CDataBaseEngineSink::OnMobileLogonAccounts(DWORD dwContextID, VOID * pData, WORD wDataSize)
  177. {
  178. CTraceService::TraceString(TEXT("CDataBaseEngineSink::OnMobileLogonAccounts"), TraceLevel_Debug);
  179. try
  180. {
  181. //效验参数
  182. ASSERT(wDataSize == sizeof(DBR_MB_LogonAccounts));
  183. if (wDataSize != sizeof(DBR_MB_LogonAccounts)) return false;
  184. //请求处理
  185. DBR_MB_LogonAccounts * pLogonAccounts = (DBR_MB_LogonAccounts *)pData;
  186. //账号名不能为空
  187. if (pLogonAccounts->szAccounts[0] == 0)
  188. {
  189. OnLogonDisposeResult(dwContextID, DB_ERROR, TEXT("账号名不能为空!"), 0, true);
  190. return false;
  191. }
  192. //执行判断
  193. tagBindParameter * pBindParameter = (tagBindParameter *)pLogonAccounts->pBindParameter;
  194. if (pBindParameter->dwSocketID != dwContextID) return true;
  195. //构造参数
  196. m_AccountsDBAide.ResetParameter();
  197. m_AccountsDBAide.AddParameter(TEXT("@LogonType"), pLogonAccounts->LogonType);
  198. m_AccountsDBAide.AddParameter(TEXT("@cbDeviceType"), pLogonAccounts->cbDeviceType);//设备类型
  199. m_AccountsDBAide.AddParameter(TEXT("@strAccounts"), pLogonAccounts->szAccounts);
  200. m_AccountsDBAide.AddParameter(TEXT("@strPassword"), pLogonAccounts->szPassword);
  201. m_AccountsDBAide.AddParameter(TEXT("@strMobilePhone"), pLogonAccounts->szMobilePhone);
  202. m_AccountsDBAide.AddParameter(TEXT("@strIPhonePassword"), pLogonAccounts->szIPhonePassword);
  203. m_AccountsDBAide.AddParameter(TEXT("@strMachineID"), pLogonAccounts->szMachineID);
  204. //输出参数
  205. TCHAR szDescribeString[128] = TEXT("");
  206. m_AccountsDBAide.AddParameterOutput(TEXT("@strErrorDescribe"), szDescribeString, sizeof(szDescribeString), adParamOutput);
  207. //执行查询
  208. LONG lResultCode = m_AccountsDBAide.ExecuteProcess(TEXT("GSP_MB_EfficacyAccounts"), true);
  209. //结果处理
  210. CDBVarValue DBVarValue;
  211. m_AccountsDBModule->GetParameter(TEXT("@strErrorDescribe"), DBVarValue);
  212. OnLogonDisposeResult(dwContextID, lResultCode, CW2CT(DBVarValue.bstrVal), 0, true);
  213. return true;
  214. }
  215. catch (IDataBaseException * pIException)
  216. {
  217. //错误信息
  218. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  219. //错误处理
  220. OnLogonDisposeResult(dwContextID, DB_ERROR, TEXT("由于数据库操作异常,请您稍后重试或选择另一服务器登录!"), 0, true);
  221. return false;
  222. }
  223. return true;
  224. }
  225. //获取验证码
  226. bool CDataBaseEngineSink::OnMobileLogonYanZhengMa(DWORD dwContextID, VOID * pData, WORD wDataSize)
  227. {
  228. CTraceService::TraceString(TEXT("CDataBaseEngineSink::OnMobileLogonYanZhengM"), TraceLevel_Debug);
  229. try
  230. {
  231. //效验参数
  232. ASSERT(wDataSize == sizeof(DBR_MB_LogonCheckVerifCode));
  233. if (wDataSize != sizeof(DBR_MB_LogonCheckVerifCode)) return false;
  234. //请求处理
  235. DBR_MB_LogonCheckVerifCode * pLogonAccounts = (DBR_MB_LogonCheckVerifCode *)pData;
  236. //构造参数
  237. m_AccountsDBAide.ResetParameter();
  238. m_AccountsDBAide.AddParameter(TEXT("@strMobilePhone"), pLogonAccounts->PhoneNum);
  239. //输出参数
  240. TCHAR szDescribeString[128] = TEXT("");
  241. m_AccountsDBAide.AddParameterOutput(TEXT("@strErrorDescribe"), szDescribeString, sizeof(szDescribeString), adParamOutput);
  242. //执行查询
  243. LONG lResultCode = m_AccountsDBAide.ExecuteProcess(TEXT("GSP_MB_LogonYanZhengMa"), true);
  244. CMD_MB_LogonCheckVerifCode strLogonReslut = { 0 };
  245. strLogonReslut.bResult = lResultCode;
  246. //获取信息
  247. lstrcpyn(strLogonReslut.PhoneNum, pLogonAccounts->PhoneNum, sizeof(pLogonAccounts->PhoneNum));
  248. //结果处理
  249. if (strLogonReslut.bResult != 0)
  250. {
  251. CDBVarValue DBVarValue;
  252. m_AccountsDBModule->GetParameter(TEXT("@strErrorDescribe"), DBVarValue);
  253. _sntprintf(strLogonReslut.strErrorDescribe, 127, TEXT("%s"), static_cast<LPCWSTR>(DBVarValue.bstrVal));
  254. }
  255. m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBR_MB_IPHONEYANZM, dwContextID, &strLogonReslut, sizeof(CMD_MB_LogonCheckVerifCode));
  256. return true;
  257. }
  258. catch (IDataBaseException * pIException)
  259. {
  260. //错误信息
  261. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  262. return false;
  263. }
  264. return true;
  265. }
  266. //落地密码
  267. bool CDataBaseEngineSink::OnMobileLogonVerfCodeToMiMa(DWORD dwContextID, VOID * pData, WORD wDataSize)
  268. {
  269. try
  270. {
  271. //效验参数
  272. ASSERT(wDataSize == sizeof(DBR_MB_VerifCodeToMiMa));
  273. if (wDataSize != sizeof(DBR_MB_VerifCodeToMiMa)) return false;
  274. //请求处理
  275. DBR_MB_VerifCodeToMiMa * pLogonAccountsMiMa = (DBR_MB_VerifCodeToMiMa *)pData;
  276. //构造参数
  277. m_AccountsDBAide.ResetParameter();
  278. m_AccountsDBAide.AddParameter(TEXT("@strMobilePhone"), pLogonAccountsMiMa->PhoneNum);
  279. m_AccountsDBAide.AddParameter(TEXT("@strPassWord"), pLogonAccountsMiMa->VerifCode);
  280. //输出参数
  281. TCHAR szDescribeString[128] = TEXT("");
  282. m_AccountsDBAide.AddParameterOutput(TEXT("@strErrorDescribe"), szDescribeString, sizeof(szDescribeString), adParamOutput);
  283. //执行查询
  284. LONG lResultCode = m_AccountsDBAide.ExecuteProcess(TEXT("GSP_MB_LogonMiMa"), true);
  285. if (lResultCode != 0)
  286. {
  287. TCHAR szString[512] = TEXT("");
  288. _sntprintf(szString, CountArray(szString), TEXT("密码落地失败"));
  289. CTraceService::TraceString(szString, TraceLevel_Warning);
  290. }
  291. return true;
  292. }
  293. catch (IDataBaseException * pIException)
  294. {
  295. //错误信息
  296. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  297. return false;
  298. }
  299. return true;
  300. }
  301. //
  302. bool CDataBaseEngineSink::OnMobileLogonHandleVerfCodeFail(DWORD dwContextID, VOID * pData, WORD wDataSize)
  303. {
  304. try
  305. {
  306. //效验参数
  307. ASSERT(wDataSize == sizeof(DBR_MB_VerifCodeToMiMa));
  308. if (wDataSize != sizeof(DBR_MB_VerifCodeToMiMa)) return false;
  309. //请求处理
  310. DBR_MB_VerifCodeToMiMa * pLogonAccountsMiMa = (DBR_MB_VerifCodeToMiMa *)pData;
  311. //构造参数
  312. m_AccountsDBAide.ResetParameter();
  313. m_AccountsDBAide.AddParameter(TEXT("@strMobilePhone"), pLogonAccountsMiMa->PhoneNum);
  314. //输出参数
  315. TCHAR szDescribeString[128] = TEXT("");
  316. m_AccountsDBAide.AddParameterOutput(TEXT("@strErrorDescribe"), szDescribeString, sizeof(szDescribeString), adParamOutput);
  317. //执行查询
  318. LONG lResultCode = m_AccountsDBAide.ExecuteProcess(TEXT("GSP_GR_DELETE_PHONEACCOUNT"), true);
  319. if (lResultCode != 0)
  320. {
  321. TCHAR szString[512] = TEXT("");
  322. _sntprintf(szString, CountArray(szString), TEXT("处理清除绑定手机号失败"));
  323. CTraceService::TraceString(szString, TraceLevel_Warning);
  324. }
  325. return true;
  326. }
  327. catch (IDataBaseException * pIException)
  328. {
  329. //错误信息
  330. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  331. return false;
  332. }
  333. return true;
  334. }
  335. //其他登录
  336. bool CDataBaseEngineSink::OnMobileLogonOtherPlatform(DWORD dwContextID, VOID * pData, WORD wDataSize)
  337. {
  338. CTraceService::TraceString(TEXT("CDataBaseEngineSink::OnMobileLogonOtherPlatform"), TraceLevel_Debug);
  339. try
  340. {
  341. //效验参数
  342. ASSERT(wDataSize == sizeof(DBR_MB_LogonOtherPlatform));
  343. if (wDataSize != sizeof(DBR_MB_LogonOtherPlatform))
  344. {
  345. //构造提示
  346. TCHAR szString[512] = TEXT("");
  347. _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败 [DBR_MB_LogonOtherPlatform验证失败]"));
  348. //提示消息
  349. CTraceService::TraceString(szString, TraceLevel_Normal);
  350. return true;
  351. }
  352. //请求处理
  353. DBR_MB_LogonOtherPlatform * pLogonOtherPlatform = (DBR_MB_LogonOtherPlatform *)pData;
  354. //账号名不能为空
  355. //if (pLogonOtherPlatform->szNickName[0] == 0 )
  356. //{
  357. // OnLogonDisposeResult(dwContextID, DB_ERROR, TEXT("账号名不能为空!"), 0, true);
  358. // return false;
  359. //}
  360. //转化地址
  361. TCHAR szClientAddr[16] = TEXT("");
  362. BYTE * pClientAddr = (BYTE *)&pLogonOtherPlatform->dwClientAddr;
  363. _sntprintf(szClientAddr, CountArray(szClientAddr), TEXT("%d.%d.%d.%d"), pClientAddr[0], pClientAddr[1], pClientAddr[2], pClientAddr[3]);
  364. //执行判断
  365. tagBindParameter * pBindParameter = (tagBindParameter *)pLogonOtherPlatform->pBindParameter;
  366. if (pBindParameter->dwSocketID != dwContextID)
  367. {
  368. //构造提示
  369. TCHAR szString[512] = TEXT("");
  370. _sntprintf(szString, CountArray(szString), TEXT("客户端[%s][%s]登录失败 [上次绑定SOCKET不是当前链接]"), pLogonOtherPlatform->szUserUin, szClientAddr);
  371. //提示消息
  372. CTraceService::TraceString(szString, TraceLevel_Normal);
  373. return true;
  374. }
  375. //参数过滤
  376. if (pLogonOtherPlatform->cbGender != 1
  377. && pLogonOtherPlatform->cbGender != 2
  378. && pLogonOtherPlatform->cbGender != 255)
  379. {
  380. pLogonOtherPlatform->cbGender = 2;
  381. }
  382. if (pLogonOtherPlatform->cbGender != 255)
  383. {
  384. //不为自动登录
  385. CString csName = pLogonOtherPlatform->szNickName;
  386. int Num = rand() % 10000;
  387. if (csName == _T(""))
  388. {
  389. csName.Format(_T("神秘大侠%d"), Num);
  390. }
  391. _sntprintf(pLogonOtherPlatform->szNickName, CountArray(szClientAddr), TEXT("%s"), csName);
  392. CString csHeadUrl = pLogonOtherPlatform->szHeadUrl;
  393. }
  394. TCHAR szBuffer[128] = { 0 };
  395. ZeroMemory(szBuffer, 128 * sizeof(TCHAR));
  396. int iRet = BASE64_Encode((const BYTE*) pLogonOtherPlatform->szNickName, 32, szBuffer);
  397. if (iRet < 0)
  398. {
  399. ZeroMemory(szBuffer, 128 * sizeof(TCHAR));
  400. _sntprintf(szBuffer, 128, TEXT("%s"), TEXT("麻将高手"));
  401. }
  402. CString csTest;
  403. BaiDuMap aa;
  404. //选点为重庆
  405. double dX1 = 106.554865;
  406. double dY1 = 29.557174;
  407. LONGLONG llx2 = pLogonOtherPlatform->x;
  408. LONGLONG lly2 = pLogonOtherPlatform->y;
  409. double dX2 = (double)llx2 / (double)1000000;
  410. double dY2 = (double)lly2 / (double)1000000;
  411. LONGLONG llRet = 0;
  412. if (dX2 != 0.0f && dY2 != 0.0f)
  413. {
  414. double dRet = aa.GetShortDistance(dX1, dY1, dX2, dY2);
  415. llRet = dRet * 1000000;
  416. csTest.Format(L"%lld", llRet);
  417. }
  418. else
  419. {
  420. llRet = 0;
  421. csTest = L"0";
  422. }
  423. CString Temp;
  424. Temp.Format(L"x:%lld,y:%lld 距离:%lld,是否在模拟器中:%d,是否4G:%d,当前电量:%d", llx2, lly2, llRet, pLogonOtherPlatform->isSimulator, pLogonOtherPlatform->networkType, pLogonOtherPlatform->dianliang);
  425. //提示消息
  426. CTraceService::TraceString(Temp, TraceLevel_Info);
  427. //计算距离
  428. //构造参数
  429. m_AccountsDBAide.ResetParameter();
  430. m_AccountsDBAide.AddParameter(TEXT("@cbPlatformID"), pLogonOtherPlatform->cbPlatformID);
  431. m_AccountsDBAide.AddParameter(TEXT("@cbDeviceType"), pLogonOtherPlatform->isSimulator);
  432. m_AccountsDBAide.AddParameter(TEXT("@strUserUin"), pLogonOtherPlatform->szUserUin);
  433. m_AccountsDBAide.AddParameter(TEXT("@strNickName"), szBuffer);
  434. m_AccountsDBAide.AddParameter(TEXT("@strCompellation"), pLogonOtherPlatform->szCompellation);
  435. m_AccountsDBAide.AddParameter(TEXT("@cbGender"), pLogonOtherPlatform->cbGender);
  436. m_AccountsDBAide.AddParameter(TEXT("@strClientIP"), szClientAddr);
  437. m_AccountsDBAide.AddParameter(TEXT("@strMachineID"), pLogonOtherPlatform->szMachineID);
  438. m_AccountsDBAide.AddParameter(TEXT("@strMobilePhone"), csTest.GetBuffer(0));
  439. m_AccountsDBAide.AddParameter(TEXT("@strHeadUrl"), pLogonOtherPlatform->szHeadUrl);
  440. csTest.ReleaseBuffer();
  441. //输出参数
  442. TCHAR szDescribeString[128] = TEXT("");
  443. m_AccountsDBAide.AddParameterOutput(TEXT("@strErrorDescribe"), szDescribeString, sizeof(szDescribeString), adParamOutput);
  444. DWORD dStart = GetTickCount();
  445. //执行查询
  446. LONG lResultCode = m_AccountsDBAide.ExecuteProcess(TEXT("GSP_MB_EfficacyOtherPlatform"), true);
  447. //结果处理
  448. CDBVarValue DBVarValue;
  449. m_AccountsDBModule->GetParameter(TEXT("@strErrorDescribe"), DBVarValue);
  450. OnLogonDisposeResult(dwContextID, lResultCode, CW2CT(DBVarValue.bstrVal), 0, true, llRet, pLogonOtherPlatform->isSimulator, pLogonOtherPlatform->networkType, pLogonOtherPlatform->dianliang);
  451. csTest.Format(L"数据时长:%ld毫秒", GetTickCount() - dStart);
  452. //提示消息
  453. CTraceService::TraceString(csTest, TraceLevel_Normal);
  454. return true;
  455. }
  456. catch (IDataBaseException * pIException)
  457. {
  458. //错误信息
  459. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  460. //错误处理
  461. OnLogonDisposeResult(dwContextID, DB_ERROR, TEXT("由于数据库操作异常,请您稍后重试或选择另一服务器登录!"), 0, true);
  462. return true;
  463. }
  464. return true;
  465. }
  466. //游客登录
  467. bool CDataBaseEngineSink::OnMobileLogonVisitor(DWORD dwContextID, VOID * pData, WORD wDataSize)
  468. {
  469. CTraceService::TraceString(TEXT("CDataBaseEngineSink::OnMobileLogonVisitor"), TraceLevel_Debug);
  470. try
  471. {
  472. //效验参数
  473. ASSERT(wDataSize == sizeof(DBR_MB_LogonVisitor));
  474. if (wDataSize != sizeof(DBR_MB_LogonVisitor)) return false;
  475. //请求处理
  476. DBR_MB_LogonVisitor * pVisitorLogon = (DBR_MB_LogonVisitor *)pData;
  477. //执行判断
  478. tagBindParameter * pBindParameter = (tagBindParameter *)pVisitorLogon->pBindParameter;
  479. if (pBindParameter->dwSocketID != dwContextID) return true;
  480. //转化地址
  481. TCHAR szClientAddr[16] = TEXT("");
  482. BYTE * pClientAddr = (BYTE *)&pVisitorLogon->dwClientAddr;
  483. _sntprintf(szClientAddr, CountArray(szClientAddr), TEXT("%d.%d.%d.%d"), pClientAddr[0], pClientAddr[1], pClientAddr[2], pClientAddr[3]);
  484. //构造参数
  485. m_AccountsDBAide.ResetParameter();
  486. m_AccountsDBAide.AddParameter(TEXT("@cbLogonMode"), pVisitorLogon->cbPlatformID);
  487. m_AccountsDBAide.AddParameter(TEXT("@strClientIP"), szClientAddr);
  488. m_AccountsDBAide.AddParameter(TEXT("@strMachineID"), pVisitorLogon->szMachineID);
  489. m_AccountsDBAide.AddParameter(TEXT("@strMobilePhone"), pVisitorLogon->szMobilePhone);
  490. //输出参数
  491. TCHAR szDescribeString[128] = TEXT("");
  492. m_AccountsDBAide.AddParameterOutput(TEXT("@strErrorDescribe"), szDescribeString, sizeof(szDescribeString), adParamOutput);
  493. //执行查询
  494. LONG lResultCode = m_AccountsDBAide.ExecuteProcess(TEXT("GSP_MB_EfficacyLogonVisitor"), true);
  495. //结果处理
  496. CDBVarValue DBVarValue;
  497. m_AccountsDBModule->GetParameter(TEXT("@strErrorDescribe"), DBVarValue);
  498. OnLogonDisposeResult(dwContextID, lResultCode, CW2CT(DBVarValue.bstrVal), 0, true);
  499. return true;
  500. }
  501. catch (IDataBaseException * pIException)
  502. {
  503. //错误信息
  504. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  505. //错误处理
  506. OnLogonDisposeResult(dwContextID, DB_ERROR, TEXT("由于数据库操作异常,请您稍后重试或选择另一服务器登录!"), 0, true);
  507. return false;
  508. }
  509. return true;
  510. }
  511. //加载列表
  512. bool CDataBaseEngineSink::OnRequestLoadGameList(DWORD dwContextID, VOID * pData, WORD wDataSize)
  513. {
  514. try
  515. {
  516. DBO_GP_GameListResult GameListResult;
  517. ZeroMemory(&GameListResult, sizeof(GameListResult));
  518. //设置变量
  519. GameListResult.cbSuccess = TRUE;
  520. //发送消息
  521. m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBO_GP_GAME_LIST_RESULT, dwContextID, &GameListResult, sizeof(GameListResult));
  522. return true;
  523. }
  524. catch (IDataBaseException * pIException)
  525. {
  526. //输出错误
  527. LPCTSTR pszDescribe = pIException->GetExceptionDescribe();
  528. CTraceService::TraceString(pszDescribe, TraceLevel_Exception);
  529. //变量定义
  530. DBO_GP_GameListResult GameListResult;
  531. ZeroMemory(&GameListResult, sizeof(GameListResult));
  532. //设置变量
  533. GameListResult.cbSuccess = FALSE;
  534. //发送消息
  535. m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBO_GP_GAME_LIST_RESULT, dwContextID, &GameListResult, sizeof(GameListResult));
  536. return false;
  537. }
  538. return true;
  539. }
  540. // 距离清除
  541. bool CDataBaseEngineSink::OnRequestClearJuLi(DWORD dwContextID, VOID * pData, WORD wDataSize)
  542. {
  543. CString str; //获取系统时间   
  544. CTime tm; tm = CTime::GetCurrentTime();
  545. if (tm.GetHour() == 4
  546. && (tm.GetMinute() == 0
  547. || tm.GetMinute() == 1))
  548. {
  549. //清除
  550. m_MapUserIDJuli.RemoveAll();
  551. }
  552. return TRUE;
  553. }
  554. // 距离添加
  555. bool CDataBaseEngineSink::OnRequestAddJuLi(DWORD dwContextID, VOID * pData, WORD wDataSize)
  556. {
  557. ASSERT(wDataSize == sizeof(CMD_CS_C_JULI));
  558. if (wDataSize != sizeof(CMD_CS_C_JULI)) return false;
  559. //变量定义
  560. CMD_CS_C_JULI * pServerUserInfo = (CMD_CS_C_JULI *)pData;
  561. m_MapUserIDJuli[pServerUserInfo->dUserID] = pServerUserInfo->llJuLi;
  562. return TRUE;
  563. }
  564. // 更新服务器通道状态
  565. bool CDataBaseEngineSink::OnRequestOnLineService(DWORD dwContextID, VOID * pData, WORD wDataSize)
  566. {
  567. IPLIST* pIPLIST = (IPLIST*)pData;
  568. CLogonServerDlg *pCLogonServerDlg = (CLogonServerDlg *)theApp.m_pMainWnd;
  569. CServerListManager *pCServerListManager = &(pCLogonServerDlg->m_ServiceUnits.m_AttemperEngineSink.m_ServerListManager);
  570. CList<LianLu> ListLL;
  571. for (int i = 0; i < 64; i++)
  572. {
  573. std::wstring strTemp = pIPLIST->ST_LIST[i];
  574. if (strTemp == _T("")) continue;
  575. try
  576. {
  577. //构造参数
  578. m_PlatformDBAide.ResetParameter();
  579. m_PlatformDBAide.AddParameter(TEXT("@strIP"), strTemp.c_str());
  580. m_PlatformDBAide.AddParameter(TEXT("@strErrorDescribe"), _T(""));
  581. //执行查询
  582. LONG lResultCode = m_PlatformDBAide.ExecuteProcess(TEXT("GSP_MB_IP"), true);
  583. //写入记录
  584. if (lResultCode == DB_SUCCESS)
  585. {
  586. ListLL.RemoveAll();
  587. //节点
  588. while (m_PlatformDBModule->IsRecordsetEnd() == false)
  589. {
  590. INT ZhuangTai = m_PlatformDBAide.GetValue_INT(TEXT("ZhuangTai"));
  591. TCHAR szIP[32];
  592. ZeroMemory(szIP, sizeof(TCHAR) * 32);
  593. m_PlatformDBAide.GetValue_String(TEXT("MoreIp"), szIP, 32);
  594. SYSTEMTIME SystemTimeConclude;
  595. m_PlatformDBAide.GetValue_SystemTime(TEXT("LastAddTime"), SystemTimeConclude);
  596. //pGameServerItem->SetLLStat(szIP, ZhuangTai, SystemTimeConclude);
  597. LianLu myTemp;
  598. ZeroMemory(&myTemp, sizeof(LianLu));
  599. myTemp.iIsOk = ZhuangTai;
  600. myTemp.SystemTimeConclude = SystemTimeConclude;
  601. StringCchCat(myTemp.szIP, 32, szIP);
  602. ListLL.AddTail(myTemp);
  603. //移动记录
  604. m_PlatformDBModule->MoveToNext();
  605. }
  606. LianLuGroup Buffer;
  607. ZeroMemory(&Buffer, sizeof(LianLuGroup));
  608. StringCchCat(Buffer.szAdminIP, 32, strTemp.c_str());
  609. POSITION Pos = ListLL.GetHeadPosition();
  610. int j = 0;
  611. while (Pos)
  612. {
  613. LianLu wRet = ListLL.GetNext(Pos);
  614. Buffer.Data[j] = wRet;
  615. j++;
  616. if (j > (MAX_TONGDAO -1)) break;
  617. }
  618. ListLL.RemoveAll();
  619. //通知网络线程更新数据
  620. (pCLogonServerDlg->m_ServiceUnits.m_AttemperEngineSink.m_pITCPNetworkEngine)->OnTBDataEvent(218, 0, &Buffer, sizeof(LianLuGroup));
  621. }
  622. else
  623. {
  624. TCHAR szString[512] = TEXT("");
  625. _sntprintf(szString, CountArray(szString), TEXT("通道更新存储过程执行失败"));
  626. //提示消息
  627. CTraceService::TraceString(szString, TraceLevel_Warning);
  628. }
  629. }
  630. catch (IDataBaseException * pIException)
  631. {
  632. //输出错误
  633. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  634. }
  635. }
  636. return TRUE;
  637. }
  638. //在线信息
  639. bool CDataBaseEngineSink::OnRequestOnLineCountInfo(DWORD dwContextID, VOID * pData, WORD wDataSize)
  640. {
  641. try
  642. {
  643. //变量定义
  644. DBR_GP_OnLineCountInfo * pOnLineCountInfo = (DBR_GP_OnLineCountInfo *)pData;
  645. WORD wHeadSize = (sizeof(DBR_GP_OnLineCountInfo)-sizeof(pOnLineCountInfo->OnLineCountKind));
  646. //效验数据
  647. ASSERT((wDataSize >= wHeadSize) && (wDataSize == (wHeadSize + pOnLineCountInfo->wKindCount*sizeof(tagOnLineInfoKindEx))));
  648. if ((wDataSize < wHeadSize) || (wDataSize != (wHeadSize + pOnLineCountInfo->wKindCount*sizeof(tagOnLineInfoKindEx)))) return false;
  649. //机器标识
  650. TCHAR szMachineID[LEN_MACHINE_ID];
  651. CWHService::GetMachineID(szMachineID);
  652. //构造信息
  653. TCHAR szOnLineCountKind[2048] = TEXT("");
  654. for (WORD i = 0; i < pOnLineCountInfo->wKindCount; i++)
  655. {
  656. INT nLength = lstrlen(szOnLineCountKind);
  657. _sntprintf(&szOnLineCountKind[nLength], CountArray(szOnLineCountKind) - nLength, TEXT("%d:%ld;"), pOnLineCountInfo->OnLineCountKind[i].wKindID, pOnLineCountInfo->OnLineCountKind[i].dwOnLineCount);
  658. }
  659. //机器信息
  660. TCHAR szAndroidCountKind[2048] = TEXT("");
  661. for (WORD j = 0; j < pOnLineCountInfo->wKindCount; j++)
  662. {
  663. INT nLength = lstrlen(szAndroidCountKind);
  664. _sntprintf(&szAndroidCountKind[nLength], CountArray(szAndroidCountKind) - nLength, TEXT("%d:%ld;"), pOnLineCountInfo->OnLineCountKind[j].wKindID, pOnLineCountInfo->OnLineCountKind[j].wTableCount);
  665. }
  666. //构造参数
  667. m_PlatformDBAide.ResetParameter();
  668. m_PlatformDBAide.AddParameter(TEXT("@strMachineID"), szMachineID);
  669. m_PlatformDBAide.AddParameter(TEXT("@strMachineServer"), m_pInitParameter->m_szServerName);
  670. m_PlatformDBAide.AddParameter(TEXT("@dwOnLineCountSum"), pOnLineCountInfo->dwOnLineCountSum);
  671. m_PlatformDBAide.AddParameter(TEXT("@dwAndroidCountSum"), pOnLineCountInfo->dwAndroidCountSum);
  672. m_PlatformDBAide.AddParameter(TEXT("@strOnLineCountKind"), szOnLineCountKind);
  673. m_PlatformDBAide.AddParameter(TEXT("@strAndroidCountKind"), szAndroidCountKind);
  674. //执行命令
  675. m_PlatformDBAide.ExecuteProcess(TEXT("GSP_GP_OnLineCountInfo"), false);
  676. CLogonServerDlg::SetJiQi(CString(szMachineID));
  677. CLogonServerDlg::SetShangBao(pOnLineCountInfo->dwOnLineCountSum);
  678. return true;
  679. }
  680. catch (IDataBaseException * pIException)
  681. {
  682. //输出错误
  683. CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  684. return false;
  685. }
  686. return true;
  687. }
  688. ////平台配置 兑换比率
  689. //bool CDataBaseEngineSink::OnRequestPlatformParameter(DWORD dwContextID, VOID * pData, WORD wDataSize)
  690. //{
  691. // try
  692. // {
  693. // //构造参数
  694. // m_PlatformDBAide.ResetParameter();
  695. //
  696. // //执行命令
  697. // LONG lResultCode = m_PlatformDBAide.ExecuteProcess(TEXT("GSP_GR_LoadPlatformParameter"), true);
  698. //
  699. // //构造结构
  700. // DBO_GP_PlatformParameter PlatformParameter;
  701. // ZeroMemory(&PlatformParameter, sizeof(PlatformParameter));
  702. //
  703. // //执行成功
  704. // if (lResultCode == DB_SUCCESS)
  705. // {
  706. // //记录判断
  707. // if (m_PlatformDBModule->IsRecordsetEnd() == false)
  708. // {
  709. // //读取数据
  710. // PlatformParameter.wExchangeRate = m_PlatformDBAide.GetValue_WORD(TEXT("ExchangeRate"));
  711. // }
  712. // }
  713. //
  714. // //发送数据
  715. // m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBO_GP_PLATFORM_PARAMETER, dwContextID, &PlatformParameter, sizeof(PlatformParameter));
  716. //
  717. // return true;
  718. // }
  719. // catch (IDataBaseException * pIException)
  720. // {
  721. // //输出错误
  722. // CTraceService::TraceString(pIException->GetExceptionDescribe(), TraceLevel_Exception);
  723. //
  724. // return false;
  725. // }
  726. //
  727. // return true;
  728. //}
  729. //
  730. //登录成功
  731. VOID CDataBaseEngineSink::OnLogonDisposeResult(DWORD dwContextID, DWORD dwErrorCode, LPCTSTR pszErrorString, DWORD dwCheckUserRight, bool bMobileClient, LONGLONG llJuLi, byte isSimulator, byte networkType, byte dianliang)
  732. {
  733. if (dwErrorCode == DB_SUCCESS)
  734. {
  735. //变量定义
  736. DBO_MB_LogonSuccess LogonSuccess;
  737. ZeroMemory(&LogonSuccess, sizeof(LogonSuccess));
  738. //属性资料
  739. LogonSuccess.wFaceID = m_AccountsDBAide.GetValue_WORD(TEXT("FaceID"));
  740. LogonSuccess.cbGender = m_AccountsDBAide.GetValue_BYTE(TEXT("Gender"));
  741. LogonSuccess.dwCustomID = m_AccountsDBAide.GetValue_DWORD(TEXT("CustomID"));
  742. LogonSuccess.dwUserID = m_AccountsDBAide.GetValue_DWORD(TEXT("UserID"));
  743. LogonSuccess.dwGameID = m_AccountsDBAide.GetValue_DWORD(TEXT("GameID"));
  744. LogonSuccess.dwExperience = m_AccountsDBAide.GetValue_DWORD(TEXT("Experience"));
  745. LogonSuccess.dwLoveLiness = m_AccountsDBAide.GetValue_DWORD(TEXT("LoveLiness"));
  746. LogonSuccess.dwXinYong = m_AccountsDBAide.GetValue_DWORD(TEXT("xinyong"));
  747. TCHAR szBuffer[128] = { 0 };
  748. ZeroMemory(szBuffer, 128 * sizeof(TCHAR));
  749. m_AccountsDBAide.GetValue_String(TEXT("NickName"), szBuffer, CountArray(szBuffer));
  750. TCHAR szOutBuffer[128] = { 0 };
  751. ZeroMemory(szOutBuffer, 128 * sizeof(TCHAR));
  752. //解码
  753. int iRet = BASE64_Decode(szBuffer, 128, (BYTE*) szOutBuffer);
  754. if (iRet == -1)
  755. {
  756. szBuffer[32] = 0x0;
  757. _sntprintf(LogonSuccess.szNickName, 32, TEXT("%s"), szBuffer);
  758. }
  759. else
  760. {
  761. szOutBuffer[32] = 0x0;
  762. _sntprintf(LogonSuccess.szNickName, 32, TEXT("%s"), szOutBuffer);
  763. }
  764. //2019-9-18pm lyh add
  765. TCHAR szUnionID[33] = { 0 };
  766. memset(szUnionID, 0, 32 * sizeof(TCHAR));
  767. m_AccountsDBAide.GetValue_String(TEXT("UserUin"), szUnionID, CountArray(szUnionID));
  768. szUnionID[32] = 0x0;
  769. CString csUin(szUnionID);
  770. CString csUinTemp = csUin.Right(6);
  771. int nUserIDTemp = _ttoi(csUinTemp.GetBuffer());
  772. if (nUserIDTemp == LogonSuccess.dwUserID)
  773. {
  774. szBuffer[32] = 0x0;
  775. _sntprintf(LogonSuccess.szNickName, 32, TEXT("%s"), szBuffer);
  776. }
  777. m_AccountsDBAide.GetValue_String(TEXT("DynamicPass"), LogonSuccess.szDynamicPass, CountArray(LogonSuccess.szDynamicPass));
  778. LogonSuccess.BingDing = m_AccountsDBAide.GetValue_DWORD(TEXT("BingID"));
  779. //用户成绩
  780. LogonSuccess.lUserScore = m_AccountsDBAide.GetValue_LONGLONG(TEXT("Score"));
  781. LogonSuccess.lUserIngot = m_AccountsDBAide.GetValue_LONGLONG(TEXT("Ingot"));
  782. LogonSuccess.lUserInsure = m_AccountsDBAide.GetValue_LONGLONG(TEXT("Insure"));
  783. LogonSuccess.dUserBeans = m_AccountsDBAide.GetValue_DWORD(TEXT("Beans"));
  784. LogonSuccess.llJuLi = llJuLi;
  785. //扩展信息
  786. LogonSuccess.cbInsureEnabled = m_AccountsDBAide.GetValue_BYTE(TEXT("InsureEnabled"));
  787. m_AccountsDBAide.GetValue_String(TEXT("HeadUrl"), LogonSuccess.szHeadUrl, CountArray(LogonSuccess.szHeadUrl));
  788. //获取信息
  789. lstrcpyn(LogonSuccess.szDescribeString, pszErrorString, CountArray(LogonSuccess.szDescribeString));
  790. //发送结果
  791. WORD wDataSize = CountStringBuffer(LogonSuccess.szDescribeString);
  792. WORD wHeadSize = sizeof(LogonSuccess)-sizeof(LogonSuccess.szDescribeString);
  793. m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBO_MB_LOGON_SUCCESS, dwContextID, &LogonSuccess, wHeadSize + wDataSize);
  794. }
  795. else
  796. {
  797. //变量定义
  798. DBO_MB_LogonFailure LogonFailure;
  799. ZeroMemory(&LogonFailure, sizeof(LogonFailure));
  800. //构造数据
  801. LogonFailure.lResultCode = dwErrorCode;
  802. lstrcpyn(LogonFailure.szDescribeString, pszErrorString, CountArray(LogonFailure.szDescribeString));
  803. //发送结果
  804. WORD wDataSize = CountStringBuffer(LogonFailure.szDescribeString);
  805. WORD wHeadSize = sizeof(LogonFailure)-sizeof(LogonFailure.szDescribeString);
  806. m_pIDataBaseEngineEvent->OnEventDataBaseResult(DBO_MB_LOGON_FAILURE, dwContextID, &LogonFailure, wHeadSize + wDataSize);
  807. }
  808. return;
  809. }
  810. //////////////////////////////////////////////////////////////////////////////////