void HumanClientApp::KillServer() { DebugLogger() << "HumanClientApp::KillServer()"; m_server_process.Kill(); m_networking.SetPlayerID(Networking::INVALID_PLAYER_ID); m_networking.SetHostPlayerID(Networking::INVALID_PLAYER_ID); SetEmpireID(ALL_EMPIRES); }
void HumanClientApp::EndGame(bool suppress_FSM_reset) { DebugLogger() << "HumanClientApp::EndGame"; m_game_started = false; if (m_networking.Connected()) { DebugLogger() << "HumanClientApp::EndGame Sending server shutdown message."; m_networking.SendMessage(ShutdownServerMessage(m_networking.PlayerID())); boost::this_thread::sleep(boost::posix_time::seconds(1)); m_networking.DisconnectFromServer(); if (!m_networking.Connected()) DebugLogger() << "HumanClientApp::EndGame Disconnected from server."; else ErrorLogger() << "HumanClientApp::EndGame Unexpectedly still connected to server...?"; } if (!m_server_process.Empty()) { DebugLogger() << "HumanClientApp::EndGame Terminated server process."; m_server_process.RequestTermination(); } m_networking.SetPlayerID(Networking::INVALID_PLAYER_ID); m_networking.SetHostPlayerID(Networking::INVALID_PLAYER_ID); SetEmpireID(ALL_EMPIRES); m_ui->GetMapWnd()->Sanitize(); m_universe.Clear(); m_empires.Clear(); m_orders.Reset(); GetCombatLogManager().Clear(); if (!suppress_FSM_reset) m_fsm->process_event(ResetToIntroMenu()); }
bool CPythonNetworkStream::SendSelectEmpirePacket(DWORD dwEmpireID) { TPacketCGEmpire kPacketEmpire; kPacketEmpire.bHeader=HEADER_CG_EMPIRE; kPacketEmpire.bEmpire=dwEmpireID; if (!Send(sizeof(kPacketEmpire), &kPacketEmpire)) { Tracen("SendSelectEmpirePacket - Error"); return false; } SetEmpireID(dwEmpireID); return SendSequence(); }
void HumanClientApp::LoadSinglePlayerGame(std::string filename/* = ""*/) { DebugLogger() << "HumanClientApp::LoadSinglePlayerGame"; if (!filename.empty()) { if (!exists(FilenameToPath(filename))) { std::string msg = "HumanClientApp::LoadSinglePlayerGame() given a nonexistent file \"" + filename + "\" to load; aborting."; DebugLogger() << msg; std::cerr << msg << '\n'; abort(); } } else { try { SaveFileDialog sfd(SP_SAVE_FILE_EXTENSION, true); sfd.Run(); if (!sfd.Result().empty()) filename = sfd.Result(); } catch (const std::exception& e) { ClientUI::MessageBox(e.what(), true); } } if (filename.empty()) { DebugLogger() << "HumanClientApp::LoadSinglePlayerGame has empty filename. Aborting load."; return; } // end any currently-playing game before loading new one if (m_game_started) { EndGame(); // delay to make sure old game is fully cleaned up before attempting to start a new one boost::this_thread::sleep(boost::posix_time::seconds(3)); } else { DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() not already in a game, so don't need to end it"; } if (!GetOptionsDB().Get<bool>("force-external-server")) { DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Starting server"; StartServer(); DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Server started"; } else { DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() assuming external server will be available"; } DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Connecting to server"; unsigned int start_time = Ticks(); while (!m_networking.ConnectToLocalHostServer()) { if (SERVER_CONNECT_TIMEOUT < Ticks() - start_time) { ErrorLogger() << "HumanClientApp::LoadSinglePlayerGame() server connecting timed out"; ClientUI::MessageBox(UserString("ERR_CONNECT_TIMED_OUT"), true); KillServer(); return; } } DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Connected to server"; m_connected = true; m_networking.SetPlayerID(Networking::INVALID_PLAYER_ID); m_networking.SetHostPlayerID(Networking::INVALID_PLAYER_ID); SetEmpireID(ALL_EMPIRES); SinglePlayerSetupData setup_data; // leving GalaxySetupData information default / blank : not used when loading a game setup_data.m_new_game = false; setup_data.m_filename = filename; // leving setup_data.m_players empty : not specified when loading a game, as server will generate from save file m_networking.SendMessage(HostSPGameMessage(setup_data)); m_fsm->process_event(HostSPGameRequested()); }
void HumanClientApp::FreeServer() { m_server_process.Free(); m_networking.SetPlayerID(Networking::INVALID_PLAYER_ID); m_networking.SetHostPlayerID(Networking::INVALID_PLAYER_ID); SetEmpireID(ALL_EMPIRES); }