mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-31 22:59:54 +02:00
Finally game restart works
# Conflicts: # lib/CGameState.cpp # server/CVCMIServer.cpp
This commit is contained in:
parent
cbfa125085
commit
fea05a4320
@ -1359,7 +1359,7 @@ static void handleEvent(SDL_Event & ev)
|
||||
break;
|
||||
case EUserEvent::RESTART_GAME:
|
||||
{
|
||||
CSH->sendStartGame();
|
||||
CSH->sendRestartGame();
|
||||
}
|
||||
break;
|
||||
case EUserEvent::CAMPAIGN_START_SCENARIO:
|
||||
|
@ -502,6 +502,14 @@ void CServerHandler::sendGuiAction(ui8 action) const
|
||||
sendLobbyPack(lga);
|
||||
}
|
||||
|
||||
void CServerHandler::sendRestartGame() const
|
||||
{
|
||||
LobbyEndGame endGame;
|
||||
endGame.closeConnection = false;
|
||||
endGame.restart = true;
|
||||
sendLobbyPack(endGame);
|
||||
}
|
||||
|
||||
void CServerHandler::sendStartGame(bool allowOnlyAI) const
|
||||
{
|
||||
verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
|
||||
@ -568,6 +576,9 @@ void CServerHandler::endGameplay(bool closeConnection, bool restart)
|
||||
GH.curInt = CMainMenu::create().get();
|
||||
}
|
||||
}
|
||||
|
||||
serverConnection->enterLobbyConnectionMode();
|
||||
serverConnection->disableStackSendingByID();
|
||||
}
|
||||
|
||||
void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
virtual void sendMessage(const std::string & txt) const = 0;
|
||||
virtual void sendGuiAction(ui8 action) const = 0; // TODO: possibly get rid of it?
|
||||
virtual void sendStartGame(bool allowOnlyAI = false) const = 0;
|
||||
virtual void sendRestartGame() const = 0;
|
||||
};
|
||||
|
||||
/// structure to handle running server and connecting to it
|
||||
@ -141,6 +142,7 @@ public:
|
||||
void setTurnLength(int npos) const override;
|
||||
void sendMessage(const std::string & txt) const override;
|
||||
void sendGuiAction(ui8 action) const override;
|
||||
void sendRestartGame() const override;
|
||||
void sendStartGame(bool allowOnlyAI = false) const override;
|
||||
|
||||
void startGameplay(CGameState * gameState = nullptr);
|
||||
|
@ -93,12 +93,21 @@ void LobbyGuiAction::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * h
|
||||
}
|
||||
}
|
||||
|
||||
bool LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
|
||||
bool LobbyEndGame::applyOnLobbyHandler(CServerHandler * handler)
|
||||
{
|
||||
if(handler->state == EClientState::GAMEPLAY)
|
||||
{
|
||||
handler->endGameplay(false, true);
|
||||
handler->endGameplay(closeConnection, restart);
|
||||
}
|
||||
|
||||
if(restart)
|
||||
handler->sendStartGame();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
|
||||
{
|
||||
handler->state = EClientState::STARTING;
|
||||
if(handler->si->mode != StartInfo::LOAD_GAME)
|
||||
{
|
||||
|
@ -138,6 +138,22 @@ struct LobbyGuiAction : public CLobbyPackToPropagate
|
||||
}
|
||||
};
|
||||
|
||||
struct LobbyEndGame : public CLobbyPackToPropagate
|
||||
{
|
||||
bool closeConnection = false, restart = false;
|
||||
|
||||
bool checkClientPermissions(CVCMIServer * srv) const;
|
||||
bool applyOnServer(CVCMIServer * srv);
|
||||
void applyOnServerAfterAnnounce(CVCMIServer * srv);
|
||||
bool applyOnLobbyHandler(CServerHandler * handler);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & closeConnection;
|
||||
h & restart;
|
||||
}
|
||||
};
|
||||
|
||||
struct LobbyStartGame : public CLobbyPackToPropagate
|
||||
{
|
||||
// Set by server
|
||||
|
@ -372,6 +372,7 @@ void registerTypesLobbyPacks(Serializer &s)
|
||||
s.template registerType<CLobbyPackToPropagate, LobbyChatMessage>();
|
||||
// Only host client send
|
||||
s.template registerType<CLobbyPackToPropagate, LobbyGuiAction>();
|
||||
s.template registerType<CLobbyPackToPropagate, LobbyEndGame>();
|
||||
s.template registerType<CLobbyPackToPropagate, LobbyStartGame>();
|
||||
s.template registerType<CLobbyPackToPropagate, LobbyChangeHost>();
|
||||
// Only server send
|
||||
|
@ -220,7 +220,7 @@ void CVCMIServer::threadAnnounceLobby()
|
||||
}
|
||||
}
|
||||
|
||||
bool CVCMIServer::prepareToStartGame()
|
||||
void CVCMIServer::prepareToRestart()
|
||||
{
|
||||
if(state == EServerState::GAMEPLAY)
|
||||
{
|
||||
@ -237,7 +237,12 @@ bool CVCMIServer::prepareToStartGame()
|
||||
c->enterLobbyConnectionMode();
|
||||
c->disableStackSendingByID();
|
||||
}
|
||||
boost::unique_lock<boost::recursive_mutex> queueLock(mx);
|
||||
gh = nullptr;
|
||||
}
|
||||
|
||||
bool CVCMIServer::prepareToStartGame()
|
||||
{
|
||||
gh = std::make_shared<CGameHandler>(this);
|
||||
switch(si->mode)
|
||||
{
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
~CVCMIServer();
|
||||
void run();
|
||||
bool prepareToStartGame();
|
||||
void prepareToRestart();
|
||||
void startGameImmidiately();
|
||||
|
||||
void startAsyncAccept();
|
||||
|
@ -161,6 +161,27 @@ bool LobbyGuiAction::checkClientPermissions(CVCMIServer * srv) const
|
||||
return srv->isClientHost(c->connectionID);
|
||||
}
|
||||
|
||||
bool LobbyEndGame::checkClientPermissions(CVCMIServer * srv) const
|
||||
{
|
||||
return srv->isClientHost(c->connectionID);
|
||||
}
|
||||
|
||||
bool LobbyEndGame::applyOnServer(CVCMIServer * srv)
|
||||
{
|
||||
srv->prepareToRestart();
|
||||
return true;
|
||||
}
|
||||
|
||||
void LobbyEndGame::applyOnServerAfterAnnounce(CVCMIServer * srv)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> stateLock(srv->stateMutex);
|
||||
for(auto & c : srv->connections)
|
||||
{
|
||||
c->enterLobbyConnectionMode();
|
||||
c->disableStackSendingByID();
|
||||
}
|
||||
}
|
||||
|
||||
bool LobbyStartGame::checkClientPermissions(CVCMIServer * srv) const
|
||||
{
|
||||
return srv->isClientHost(c->connectionID);
|
||||
|
Loading…
x
Reference in New Issue
Block a user