mainProc.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "Win32.h"
  2. #include "ID.h"
  3. #include "Function.h"
  4. #include "SharedValue.h"
  5. InitHW(hTime); InitHW(hWeather); InitHW(hLog); InitHW(hPlayer); InitHW(hConfig);
  6. LRESULT CALLBACK TimeProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  7. LRESULT CALLBACK WeatherProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  8. LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  9. LRESULT CALLBACK PlayerProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  10. LRESULT CALLBACK ConfProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
  11. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  12. {
  13. PAINTSTRUCT ps;
  14. HDC hdc;
  15. TCHAR greeting[] = _T("by xksyu2021\nYou must obey / 您必须遵守 Minecraft EULA.");
  16. switch (message)
  17. {
  18. case WM_CREATE:
  19. {
  20. ClearLog();
  21. //StartBDS();
  22. HINSTANCE HI_Log = NULL;
  23. hLog = CreateLogWindow(
  24. _T("日志"),
  25. 1000, 690,
  26. LogProc, _T("log"), HI_Log);
  27. Log(GetDlgItem(hLog, ID_LOG));
  28. break;
  29. }
  30. case WM_PAINT:
  31. hdc = BeginPaint(hWnd, &ps);
  32. TextOut(hdc,
  33. 5, 5,
  34. greeting, _tcslen(greeting));
  35. EndPaint(hWnd, &ps);
  36. break;
  37. case WM_COMMAND:
  38. {
  39. WORD wmId = LOWORD(wParam);
  40. switch (wmId)
  41. {
  42. case ID_START:
  43. ClearLog();
  44. StartBDS();
  45. break;
  46. case ID_STOP:
  47. StopBDS();
  48. break;
  49. case ID_STOP_FORCE:
  50. if (MessageBox(hWnd,
  51. L"强制关闭服务器是非常危险的操作!\n是否仍要继续?", TITLE,
  52. MB_OKCANCEL | MB_APPLMODAL | MB_ICONWARNING)
  53. == 1)
  54. {
  55. ForceStopBDS();
  56. }
  57. break;
  58. case ID_DUWP:
  59. ShellExecute(
  60. NULL, L"runas",
  61. L"C:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
  62. L"-NoProfile -ExecutionPolicy Bypass -Command \"Get-ChildItem -Path Registry::'HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Mappings\\' -name | ForEach-Object {CheckNetIsolation.exe LoopbackExempt -a -p=$_}\"" ,
  63. NULL, SW_SHOWNORMAL
  64. );
  65. break;
  66. case ID_CMD_OK:
  67. {
  68. if (GetWindowTextLength(GetDlgItem(hWnd, ID_CMD_KEY)) > 0)
  69. {
  70. char Command[1024] = { 0 };
  71. GetWindowTextA(GetDlgItem(hWnd, ID_CMD_KEY), Command, 1024);
  72. std::string temp(Command);
  73. temp += "\n";
  74. SendCommand(temp.c_str());
  75. }
  76. break;
  77. }
  78. case ID_CMD_CLEAR:
  79. SetWindowText(GetDlgItem(hWnd, ID_CMD_KEY), _T(" "));
  80. break;
  81. case ID_FC_Weather:
  82. if (!hWeather)
  83. {
  84. HINSTANCE HI_FC_weather = NULL;
  85. hWeather = CreateChildWindow(hWnd,
  86. _T("天气控制"),
  87. 400, 370,
  88. WeatherProc, _T("fc_wea"), HI_FC_weather);
  89. }
  90. break;
  91. case ID_FC_Time:
  92. if (!hTime)
  93. {
  94. HINSTANCE HI_FC_time = NULL;
  95. hTime = CreateChildWindow(hWnd,
  96. _T("时间控制"),
  97. 400, 415,
  98. TimeProc, _T("fc_time"), HI_FC_time);
  99. }
  100. break;
  101. case ID_FS_WT:
  102. if (SendCommand_NoErr(C("time query daytime")) == FALSE ||
  103. SendCommand_NoErr(C("weather query")) == FALSE)
  104. {
  105. Err(_T("发送命令失败\n可能是因为服务器已被关闭"));
  106. }
  107. break;
  108. case ID_FC_PLAYER:
  109. if (!hPlayer)
  110. {
  111. HINSTANCE HI_FC_player = NULL;
  112. hPlayer = CreateChildWindow(hWnd,
  113. _T("玩家面板"),
  114. 380, 390,
  115. PlayerProc, _T("fc_player"), HI_FC_player);
  116. }
  117. break;
  118. case ID_FS_LIST:
  119. SendCommand(C("list"));
  120. break;
  121. case ID_FILE_Config:
  122. if (!hConfig)
  123. {
  124. HINSTANCE HI_FI_config = NULL;
  125. hConfig = CreateChildWindow(hWnd,
  126. _T("配置文件编辑"),
  127. 570, 1200,
  128. ConfProc, _T("fc_player"), HI_FI_config);
  129. }
  130. break;
  131. }
  132. break;
  133. }
  134. case WM_CLOSE:
  135. if (MessageBox(hWnd,
  136. L"您正在关闭主程序!\n若服务端正在运行,将被一并正常关闭。\n若有正在执行的任务,将被强行停止。", TITLE,
  137. MB_OKCANCEL | MB_ICONWARNING)
  138. == 1)
  139. {
  140. StopBDS();
  141. PostQuitMessage(0);
  142. }
  143. break;
  144. case WM_DESTROY:
  145. PostQuitMessage(0);
  146. break;
  147. default:
  148. return DefWindowProc(hWnd, message, wParam, lParam);
  149. break;
  150. }
  151. return 0;
  152. }