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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. Sword online Server local control window
  3. Copyright : Kingsoft 2002
  4. Author :   Wooy(Wu yue)
  5. CreateTime: 2002-12-19
  6. *****************************************************************************************/
  7. #include "KEngine.h"
  8. #include "ServerLocalControlWnd.h"
  9. #include "SwordOnLineServer.h"
  10. #include "ClientConnectListWnd.h"
  11. #include "BroadCastWnd.h"
  12. #include "../Core/src/CoreServerShell.h"
  13. KServerLocalControlWnd* KServerLocalControlWnd::m_pSelf = NULL;
  14. //--------------------------------------------------------------------------
  15. // 功能:窗口函数
  16. //--------------------------------------------------------------------------
  17. LRESULT CALLBACK KServerLocalControlWnd::WndProc(HWND hWnd, unsigned int uMsg, unsigned int uParam, int nParam)
  18. {
  19. switch(uMsg)
  20. {
  21. case WM_COMMAND:
  22. switch (LOWORD(uParam))
  23. {
  24. case ID_LAUNCH:
  25. if (m_pSelf)
  26. m_pSelf->OnLaunch();
  27. break;
  28. case ID_SHUTDOWN:
  29. if (m_pSelf && m_pSelf->m_pServer)
  30. {
  31. m_pSelf->m_pServer->ShutDown();
  32. UpdateData();
  33. }
  34. break;
  35. case ID_CLIENT_LIST:
  36. if (m_pSelf)
  37. KClientConnectListWnd::Create(
  38. m_pSelf->m_hModule, m_pSelf->m_pServer);
  39. break;
  40. case ID_SETTING:
  41. if (m_pSelf && m_pSelf->m_pServer)
  42. m_pSelf->m_pServer->OperationRequest(SSOI_RELOAD_WELCOME_MSG, 0, 0);
  43. break;
  44. case ID_BROADCAST:
  45. if (m_pSelf && m_pSelf->m_pServer)
  46. KBroadCastWnd::Create(
  47. m_pSelf->m_hModule, m_pSelf->m_pServer);
  48. break;
  49. case ID_EXIT:
  50. KClientConnectListWnd::Close();
  51. if (m_pSelf)
  52. m_pSelf->OnExit();
  53. else
  54. ::DestroyWindow(hWnd);
  55. PostQuitMessage(0);
  56. break;
  57. }
  58. break;
  59. }
  60. return 0;
  61. }
  62. void KServerLocalControlWnd::OnLaunch()
  63. {
  64. if (m_pSelf->m_pServer)
  65. {
  66. ::EnableWindow(::GetDlgItem(m_hWnd, ID_LAUNCH), false);
  67. SetDlgItemText(m_hWnd, IDC_INFO, "Launching......");
  68. if (m_pServer->Launch())
  69. {
  70. ::EnableWindow(::GetDlgItem(m_hWnd, ID_LAUNCH), false);
  71. ::EnableWindow(::GetDlgItem(m_hWnd, ID_SHUTDOWN), true);
  72. ::EnableWindow(::GetDlgItem(m_hWnd, ID_BROADCAST), true);
  73. ::EnableWindow(::GetDlgItem(m_hWnd, ID_CLIENT_LIST), true);
  74. }
  75. UpdateData();
  76. }
  77. else
  78. SetDlgItemText(m_hWnd, IDC_INFO, "Haven't conected to the server!");
  79. }
  80. void KServerLocalControlWnd::SwitchLaunchable(bool bEnable)
  81. {
  82. HWND hWnd = ::GetDlgItem(m_hWnd, ID_LAUNCH);
  83. if (hWnd)
  84. ::EnableWindow(hWnd, bEnable);
  85. hWnd = ::GetDlgItem(m_hWnd, ID_SHUTDOWN);
  86. if (hWnd)
  87. ::EnableWindow(hWnd, !bEnable);
  88. }
  89. KServerLocalControlWnd::KServerLocalControlWnd()
  90. {
  91. m_hWnd = NULL;
  92. m_hModule = NULL;
  93. m_pServer = NULL;
  94. }
  95. bool KServerLocalControlWnd::Create(HINSTANCE hModule, KSwordOnLineSever* pServer)
  96. {
  97. if (m_pSelf)
  98. return true;
  99. if (hModule == NULL)
  100. return false;
  101. m_pSelf = new KServerLocalControlWnd;
  102. if (m_pSelf)
  103. {
  104. m_pSelf->m_hWnd = ::CreateDialog(hModule,
  105. MAKEINTRESOURCE(IDD), NULL, (DLGPROC)WndProc);
  106. if (m_pSelf->m_hWnd)
  107. {
  108. m_pSelf->m_hModule = hModule;
  109. m_pSelf->m_pServer = pServer;
  110. ::ShowWindow(m_pSelf->m_hWnd, SW_SHOW);
  111. }
  112. else
  113. {
  114. delete (m_pSelf);
  115. m_pSelf = NULL;
  116. }
  117. return true;
  118. }
  119. return false;
  120. }
  121. void KServerLocalControlWnd::UpdateData()
  122. {
  123. char Status[128], Info[128];
  124. if (m_pSelf && m_pSelf->m_pServer)
  125. {
  126. m_pSelf->m_pServer->GetStatus(Status, Info);
  127. ::SetDlgItemText(m_pSelf->m_hWnd, IDC_STATUS, Status);
  128. ::SetDlgItemText(m_pSelf->m_hWnd, IDC_INFO, Info);
  129. }
  130. }
  131. void KServerLocalControlWnd::OnExit()
  132. {
  133. if (m_pSelf)
  134. {
  135. if (m_hWnd)
  136. {
  137. ::DestroyWindow(m_hWnd);
  138. m_hWnd = NULL;
  139. }
  140. m_pServer = NULL;
  141. m_hModule = NULL;
  142. delete (m_pSelf);
  143. m_pSelf = NULL;
  144. }
  145. }