o&c.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "Win32.h"
  2. #include "ID.h"
  3. #include "Function.h"
  4. #include "SharedValue.h"
  5. static void AutoClose(DWORD time, LPCWSTR title)
  6. {
  7. Sleep(time*1000);
  8. HWND box = FindWindow(NULL, title);
  9. if (box)
  10. {
  11. SendMessage(box, WM_CLOSE, 0, 0);
  12. }
  13. }
  14. //Open&Stop
  15. PROCESS_INFORMATION pi;
  16. HWND hBDS;
  17. static void CloseHandleA()
  18. {
  19. CloseHandle(BDSr_key);
  20. CloseHandle(UIw_key);
  21. CloseHandle(UIr_log);
  22. CloseHandle(BDSw_log);
  23. CloseHandle(pi.hProcess);
  24. CloseHandle(pi.hThread);
  25. BDSr_key = UIw_key = UIr_log = BDSw_log = NULL;
  26. pi.hProcess = pi.hThread = NULL;
  27. }
  28. static void CloseHandleS()
  29. {
  30. CloseHandle(BDSr_key);
  31. CloseHandle(BDSw_log);
  32. }
  33. InitHA(BDSr_key); InitHA(UIw_key); InitHA(BDSw_log); InitHA(UIr_log);
  34. void StartBDS()
  35. {
  36. SECURITY_ATTRIBUTES sa = { sizeof(sa),NULL , TRUE };
  37. if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
  38. Err(_T("Failed to create pipe_key"));
  39. if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
  40. Err(_T("Failed to create pipe_log"));
  41. STARTUPINFO si = { sizeof(si) };
  42. si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  43. si.hStdInput = BDSr_key;
  44. si.hStdOutput = BDSw_log;
  45. //si.wShowWindow = SW_SHOWMINIMIZED;
  46. if (CreateProcess(
  47. L"bedrock_server.exe",
  48. NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
  49. {
  50. CloseHandleS();
  51. }
  52. else {
  53. Err(_T("Failed to send command to BDS!"));
  54. CloseHandleA();
  55. }
  56. }
  57. void StopBDS()
  58. {
  59. if (pi.hProcess)
  60. {
  61. SendCommand_WhenStop(C("stop"));
  62. }
  63. }
  64. void ForceStopBDS()
  65. {
  66. if(pi.hProcess)
  67. {
  68. TerminateProcess(pi.hProcess, 0);
  69. CloseHandleA();
  70. MessageBox(hWnd,
  71. _T("Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷"), TITLE,
  72. MB_OK);
  73. }
  74. }