mainProc.cpp 5.4 KB

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