@@ -319,7 +319,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
319319 if (sel == -1 )
320320 break ;
321321 mainGame->bot_mode = true ;
322- #ifdef _WIN32
323322 if (!NetServer::StartServer (mainGame->gameConf .serverport )) {
324323 soundManager.PlaySoundEffect (SOUND_INFO );
325324 mainGame->env ->addMessageBox (L" " , dataManager.GetSysString (1402 ));
@@ -331,12 +330,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
331330 mainGame->env ->addMessageBox (L" " , dataManager.GetSysString (1402 ));
332331 break ;
333332 }
334- STARTUPINFOW si;
335- PROCESS_INFORMATION pi;
336- ZeroMemory (&si, sizeof (si));
337- si.cb = sizeof (si);
338- ZeroMemory (&pi, sizeof (pi));
339- wchar_t cmd[MAX_PATH ];
333+ std::vector<std::wstring> processArgs;
340334 wchar_t arg1[512 ];
341335 if (mainGame->botInfo [sel].select_deckfile ) {
342336 wchar_t botdeck[256 ];
@@ -345,51 +339,21 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
345339 }
346340 else
347341 myswprintf (arg1, L" %ls" , mainGame->botInfo [sel].command );
342+ processArgs.push_back (arg1);
348343 int flag = 0 ;
349344 flag += (mainGame->chkBotHand ->isChecked () ? 0x1 : 0 );
350- myswprintf (cmd, L" Bot.exe \" %ls\" %d %d" , arg1, flag, mainGame->gameConf .serverport );
351- if (!CreateProcessW (nullptr , cmd, nullptr , nullptr , FALSE , 0 , nullptr , nullptr , &si, &pi))
352- {
345+ processArgs.push_back (std::to_wstring (flag));
346+ processArgs.push_back (std::to_wstring (mainGame->gameConf .serverport ));
347+ #ifdef _WIN32
348+ std::wstring executableName = L" Bot.exe" ;
349+ #else
350+ std::wstring executableName = L" ./bot" ;
351+ #endif
352+ if (!Game::SpawnAsync (executableName, processArgs)) {
353+ DuelClient::StopClient ();
353354 NetServer::StopServer ();
354355 break ;
355356 }
356- CloseHandle (pi.hThread );
357- CloseHandle (pi.hProcess );
358- #else
359- if (fork () == 0 ) {
360- usleep (100000 );
361- wchar_t warg1[512 ];
362- if (mainGame->botInfo [sel].select_deckfile ) {
363- wchar_t botdeck[256 ];
364- DeckManager::GetDeckFile (botdeck, mainGame->cbBotDeckCategory ->getSelected (), mainGame->cbBotDeckCategory ->getText (), mainGame->cbBotDeck ->getText ());
365- myswprintf (warg1, L" %ls DeckFile='%ls'" , mainGame->botInfo [sel].command , botdeck);
366- }
367- else
368- myswprintf (warg1, L" %ls" , mainGame->botInfo [sel].command );
369- char arg1[512 ];
370- BufferIO::EncodeUTF8 (warg1, arg1);
371- int flag = 0 ;
372- flag += (mainGame->chkBotHand ->isChecked () ? 0x1 : 0 );
373- char arg2[8 ];
374- mysnprintf (arg2, " %d" , flag);
375- char arg3[8 ];
376- mysnprintf (arg3, " %d" , mainGame->gameConf .serverport );
377- execl (" ./bot" , " bot" , arg1, arg2, arg3, nullptr );
378- std::exit (0 );
379- } else {
380- if (!NetServer::StartServer (mainGame->gameConf .serverport )) {
381- soundManager.PlaySoundEffect (SOUND_INFO );
382- mainGame->env ->addMessageBox (L" " , dataManager.GetSysString (1402 ));
383- break ;
384- }
385- if (!DuelClient::StartClient (0x7f000001 , mainGame->gameConf .serverport )) {
386- NetServer::StopServer ();
387- soundManager.PlaySoundEffect (SOUND_INFO );
388- mainGame->env ->addMessageBox (L" " , dataManager.GetSysString (1402 ));
389- break ;
390- }
391- }
392- #endif
393357 mainGame->btnStartBot ->setEnabled (false );
394358 mainGame->btnBotCancel ->setEnabled (false );
395359 break ;
0 commit comments