mainProc.cpp 5.7 KB

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