DBConnect.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:4k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // DBClient.cpp: implementation of the CDBClient class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Global.h"
  6. #include "DBConnect.h"
  7. #include "S3Relay.h"
  8. #include "DealRelay.h"
  9. #include "crtdbg.h"
  10. #include "../../../Headers/KGmProtocol.h"
  11. #include "../../Sword3PaySys/S3AccServer/AccountLoginDef.h"
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CDBCenter::CDBCenter()
  16. {
  17. }
  18. CDBCenter::~CDBCenter()
  19. {
  20. }
  21. BOOL CDBCenter::TraceInfo()
  22. {
  23. std::_tstring info("message: [DBRoleCenter] ");
  24. char buffer[_MAX_PATH];
  25. BOOL ready = g_DBClient.IsReady();
  26. sprintf(buffer, "<total: %d> : ", ready ? 1 : 0);
  27. info.append(buffer);
  28. if (ready)
  29. {
  30. sprintf(buffer, "%08X", g_DBClient.GetSvrIP());
  31. info.append(buffer);
  32. }
  33. rTRACE(info.c_str());
  34. return TRUE;
  35. }
  36. //////////////////////////////////////////////////////////////////////
  37. // Construction/Destruction
  38. //////////////////////////////////////////////////////////////////////
  39. CDBClient::CDBClient(CDBCenter* pRootCenter, BOOL bAutoFree)
  40. : CNetClient(pRootCenter, bAutoFree)
  41. {
  42. }
  43. CDBClient::~CDBClient()
  44. {
  45. }
  46. void CDBClient::OnServerEventCreate()
  47. {
  48. gOnOneClientCreate(oneclient_db);
  49. rTRACE("DBRole client create: %s", _ip2a(GetSvrIP()));
  50. }
  51. void CDBClient::OnServerEventClose()
  52. {
  53. rTRACE("DBRole client close: %s", _ip2a(GetSvrIP()));
  54. gOnOneClientClose(oneclient_db);
  55. }
  56. void CDBClient::RecvPackage(const void* pData, size_t size)
  57. {
  58. if (size <= 0)
  59. return;
  60. switch (*((BYTE*)pData))
  61. {
  62. case s2c_roleserver_getrolelist_result:
  63. {
  64. TProcessData* pProtocol = (TProcessData*)pData;
  65. int nSize = pProtocol->pDataBuffer[0];
  66. if (nSize > 0 && nSize <= MAX_PLAYER_PER_ACCOUNT)
  67. {
  68. int nRelaySize = sizeof(RELAY_ASKWAY_DATA) +
  69.  sizeof(GM_GET_ROLE_LIST_SYNC) +
  70.  sizeof(RoleBaseInfo) * MAX_PLAYER_PER_ACCOUNT;
  71. RELAY_ASKWAY_DATA* pAskWayData = (RELAY_ASKWAY_DATA*)_alloca(nRelaySize);
  72. pAskWayData->ProtocolFamily = pf_relay;
  73. pAskWayData->ProtocolID = relay_c2c_askwaydata;
  74. pAskWayData->nFromIP = 0;
  75. pAskWayData->nFromRelayID = 0;
  76. pAskWayData->seekRelayCount = 0;
  77. pAskWayData->seekMethod = rm_gm;
  78. pAskWayData->wMethodDataLength = 0;
  79. pAskWayData->routeDateLength = nRelaySize - sizeof(RELAY_ASKWAY_DATA);
  80. GM_GET_ROLE_LIST_SYNC* pGMData = (GM_GET_ROLE_LIST_SYNC*)(pAskWayData + 1);
  81. pGMData->AccountName[0] = 0;
  82. pGMData->wRoleCount = nSize;
  83. pGMData->ProtocolFamily = pf_gamemaster;
  84. pGMData->ProtocolType = gm_s2c_getrolelist;
  85. memcpy((pGMData + 1), &pProtocol->pDataBuffer[1], sizeof(RoleBaseInfo) * MAX_PLAYER_PER_ACCOUNT);
  86. g_RootClient.SendPackage(pAskWayData, nRelaySize);
  87. }
  88. else
  89. _ASSERT(0);
  90. }
  91. break;
  92. case s2c_extend:
  93. if (size > 1)
  94. {
  95. int nRelaySize = sizeof(RELAY_ASKWAY_DATA) + size - 1;
  96. RELAY_ASKWAY_DATA* pAskWayData = (RELAY_ASKWAY_DATA*)_alloca(nRelaySize);
  97. pAskWayData->ProtocolFamily = pf_relay;
  98. pAskWayData->ProtocolID = relay_c2c_askwaydata;
  99. pAskWayData->nFromIP = 0;
  100. pAskWayData->nFromRelayID = 0;
  101. pAskWayData->seekRelayCount = 0;
  102. pAskWayData->seekMethod = rm_gm;
  103. pAskWayData->wMethodDataLength = 0;
  104. pAskWayData->routeDateLength = size - 1;
  105. memcpy(pAskWayData + 1, ((char*)pData) + 1, size - 1);
  106. g_RootClient.SendPackage(pAskWayData, nRelaySize);
  107. }
  108. break;
  109. default:
  110. _ASSERT(0);
  111. break;
  112. };
  113. }