// MonitoringTool.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "MonitoringTool.h" #include "MonitoringToolSetup.h" #include "GlobalFunc.h" #include "ChatServerEventhandler.h" #include "ChattingPage.h" #include #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #endif // CMonitoringToolApp BEGIN_MESSAGE_MAP(CMonitoringToolApp, CWinApp) ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() // CMonitoringToolApp construction CMonitoringToolApp::CMonitoringToolApp() : m_DefaultiniFileName(_T("./RylMonitoringToolSetup.ini")) , m_bIsAuthorized(false) , m_lpEventHandlerMgr(0) , m_lpManageServerEventHandler(0) , m_lpBufferFactory(0) { // TODO: add construction code here, // Place all significant initialization in InitInstance } // The one and only CMonitoringToolApp object CMonitoringToolApp theApp; // CMonitoringToolApp initialization BOOL CMonitoringToolApp::InitInstance() { m_lpEventHandlerMgr = new ClientNet::CClientEventHandlerMgr; if(!m_lpEventHandlerMgr) { return FALSE; } m_lpBufferFactory = new CPoolBufferFactory; if(!m_lpBufferFactory) { return FALSE; } InitCommonControls(); CWinApp::InitInstance(); AfxEnableControlContainer(); SetRegistryKey(_T("Local AppWizard-Generated Applications")); InitServerNameMap(); InitServerIndexMap(); CMonitoringToolDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } return FALSE; } int CMonitoringToolApp::ExitInstance() { delete m_lpEventHandlerMgr; m_lpEventHandlerMgr = 0; delete m_lpBufferFactory; m_lpBufferFactory = 0; return CWinApp::ExitInstance(); } /// \brief ¼­¹ö±×·ì¸í ¸Ê ÃʱâÈ­ void CMonitoringToolApp::InitServerNameMap() { m_ServerNameMap.clear(); CMonitoringToolSetup Setup = CMonitoringToolSetup::GetInstance(); const int MAX_BUFFER = 256; const char* szSection = _T("SERVER_GROUP_INFO"); char szKey[MAX_BUFFER]; unsigned int nServerGroup; for(unsigned int nIndex = 0; nIndex < Setup.GetInt(szSection, _T("SERVER_GROUP_NUM")); ++nIndex) { _snprintf(szKey, MAX_BUFFER, _T("SERVER_GROUP_INDEX_%02d"), nIndex); nServerGroup = Setup.GetInt(szSection, szKey, 0xFFFFFFFF); if(nServerGroup != 0xFFFFFFFF) { _snprintf(szKey, MAX_BUFFER, _T("SERVER_GROUP_NAME_%02d"), nIndex); m_ServerNameMap.insert(ServerNameMap::value_type(nServerGroup, Setup.GetString(szSection, szKey))); } } } /// \brief ¼­¹ö±×·ì¸í ¾ò±â /// \param nServerGroup ¼­¹ö±×·ì À妽º /// \return ¼­¹ö±×·ì¸í const char* CMonitoringToolApp::GetServerName(unsigned int nServerGroup) { ServerNameMap::iterator find = m_ServerNameMap.find(nServerGroup); if(find != m_ServerNameMap.end()) { return find->second.c_str(); } return _T("Tool"); } /// \brief ¼­¹ö±×·ì À妽º ¸Ê ÃʱâÈ­ void CMonitoringToolApp::InitServerIndexMap() { m_ServerIndexMap.clear(); CMonitoringToolSetup Setup = CMonitoringToolSetup::GetInstance(); const int MAX_BUFFER = 256; const char* szSection = _T("SERVER_GROUP_INFO"); char szKey[MAX_BUFFER]; unsigned int nServerGroup; for(unsigned int nIndex = 0; nIndex < Setup.GetInt(szSection, _T("SERVER_GROUP_NUM")); ++nIndex) { _snprintf(szKey, MAX_BUFFER, _T("SERVER_GROUP_INDEX_%02d"), nIndex); nServerGroup = Setup.GetInt(szSection, szKey, 0xFFFFFFFF); if(nServerGroup != 0xFFFFFFFF) { _snprintf(szKey, MAX_BUFFER, _T("SERVER_GROUP_NAME_%02d"), nIndex); m_ServerIndexMap.insert(ServerIndexMap::value_type(Setup.GetString(szSection, szKey), nServerGroup)); } } } /// \brief ¼­¹ö±×·ì À妽º ¾ò±â /// \param strServerName ¼­¹ö±×·ì¸í /// \return ¼­¹ö ±×·ì À妽º unsigned int CMonitoringToolApp::GetServerIndex(CString strServerName) { ServerIndexMap::iterator find = m_ServerIndexMap.find(strServerName); if(find != m_ServerIndexMap.end()) { return find->second; } return 100; } void CMonitoringToolApp::RegisterManagerHandler(ClientNet::CManagerServerEventHandler* lpHandler) { m_lpManageServerEventHandler = lpHandler; } void CMonitoringToolApp::RemoveManagerHandler(ClientNet::CManagerServerEventHandler* lpHandler) { if(m_lpManageServerEventHandler == lpHandler) { m_lpManageServerEventHandler = 0; } } /// \brief äÆÃ¼­¹ö ¿¬°á ¼¼¼Ç µî·Ï /// \param nServerGroup äÆÃ¼­¹öÀÇ ±×·ì À妽º /// \param lpHandler äÆÃ¼­¹ö ¿¬°á ¼¼¼Ç Æ÷ÀÎÅÍ void CMonitoringToolApp::RegisterChatHandler(unsigned int nServerGroup, ClientNet::CChatServerEventHandler* lpHandler) { ChatServerHandlerMap::iterator pos = m_ChatHandlerMap.find(nServerGroup); ChatServerHandlerMap::iterator end = m_ChatHandlerMap.end(); if (pos != end && lpHandler != pos->second) { // ÀÌ¹Ì Á¸ÀçÇÑ´Ù. pos->second = lpHandler; } else { m_ChatHandlerMap.insert(ChatServerHandlerMap::value_type(nServerGroup, lpHandler)); } } void CMonitoringToolApp::RemoveChatHandler(unsigned int nServerGroup, ClientNet::CChatServerEventHandler* lpHandler) { ChatServerHandlerMap::iterator pos = m_ChatHandlerMap.find(nServerGroup); ChatServerHandlerMap::iterator end = m_ChatHandlerMap.end(); if (pos != end) { m_ChatHandlerMap.erase(pos); } } ClientNet::CChatServerEventHandler* CMonitoringToolApp::GetChatServerHandler(unsigned int nServerGroup) { ChatServerHandlerMap::iterator pos = m_ChatHandlerMap.find(nServerGroup); if (pos != m_ChatHandlerMap.end()) { return pos->second; } return 0; } bool CMonitoringToolApp::RegisterWindow(unsigned int nIDD, CWnd* lpWindow) { return m_WindowMap.insert(WindowMap::value_type(nIDD, lpWindow)).second; } bool CMonitoringToolApp::RemoveWindow(unsigned int nIDD) { return 0 != m_WindowMap.erase(nIDD); } CWnd* CMonitoringToolApp::GetRegisteredWindow(unsigned int nIDD) { WindowMap::iterator find = m_WindowMap.find(nIDD); if(find != m_WindowMap.end()) { return find->second; } return 0; } /// \brief °á°úâ¿¡ ¸Þ¼¼Áö Ãâ·Â /// \param szResult Ãâ·ÂÇÒ ¸Þ¼¼Áö void CMonitoringToolApp::ReportResult(const char* szResult) { CMonitoringToolDlg* lpDlg = static_cast(theApp.GetRegisteredWindow(IDD_MONITORINGTOOLDLG)); if (NULL != lpDlg) { lpDlg->ReportWorkResult(szResult); } }