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

模拟服务器

开发平台:

C/C++

  1. // RelayCenter.cpp: implementation of the CRelayCenter class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "RelayCenter.h"
  6. #include "S3Relay.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CRelayCenter::CRelayCenter()
  11. {
  12. }
  13. CRelayCenter::~CRelayCenter()
  14. {
  15. }
  16. void CRelayCenter::OnBuildup()
  17. {
  18. AUTOLOCKWRITE(m_lockIpMap);
  19. }
  20. void CRelayCenter::OnClearup()
  21. {
  22. AUTOLOCKWRITE(m_lockIpMap);
  23. m_mapIp2Client.clear();
  24. }
  25. void CRelayCenter::OnServerEventCreate(CNetClient* pClient)
  26. {
  27. AUTOLOCKWRITE(m_lockIpMap);
  28. m_mapIp2Client[pClient->GetSvrIP()] = (CRelayClient*)pClient;
  29. }
  30. void CRelayCenter::OnServerEventClose(CNetClient* pClient)
  31. {
  32. AUTOLOCKWRITE(m_lockIpMap);
  33. m_mapIp2Client.erase(pClient->GetSvrIP());
  34. }
  35. BOOL CRelayCenter::FindRelayClientByIP(DWORD IP, CNetClientDup* pClntDup)
  36. {
  37. AUTOLOCKREAD(m_lockIpMap);
  38. IP2CLIENTMAP::iterator it = m_mapIp2Client.find(IP);
  39. if (it == m_mapIp2Client.end())
  40. return FALSE;
  41. CRelayClient* pRelayClnt = (*it).second;
  42. if (!pRelayClnt)
  43. return FALSE;
  44. if (pClntDup != NULL)
  45. *pClntDup = *pRelayClnt;
  46. return TRUE;
  47. }
  48. BOOL CRelayCenter::TraceInfo()
  49. {
  50. AUTOLOCKREAD(m_lockIpMap);
  51. std::_tstring info("message: [RelayCenter] ");
  52. char buffer[_MAX_PATH];
  53. sprintf(buffer, "<total: %d> : ", m_mapIp2Client.size());
  54. info.append(buffer);
  55. size_t idx = 0;
  56. for (IP2CLIENTMAP::iterator it = m_mapIp2Client.begin(); it != m_mapIp2Client.end(); it++)
  57. {
  58. if (it != m_mapIp2Client.begin())
  59. info.append(", ");
  60. sprintf(buffer, "%08X", (*it).first);
  61. info.append(buffer);
  62. }
  63. rTRACE(info.c_str());
  64. return TRUE;
  65. }