mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-06 23:26:26 +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;
|
break;
|
||||||
case EUserEvent::RESTART_GAME:
|
case EUserEvent::RESTART_GAME:
|
||||||
{
|
{
|
||||||
CSH->sendStartGame();
|
CSH->sendRestartGame();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EUserEvent::CAMPAIGN_START_SCENARIO:
|
case EUserEvent::CAMPAIGN_START_SCENARIO:
|
||||||
|
@ -502,6 +502,14 @@ void CServerHandler::sendGuiAction(ui8 action) const
|
|||||||
sendLobbyPack(lga);
|
sendLobbyPack(lga);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CServerHandler::sendRestartGame() const
|
||||||
|
{
|
||||||
|
LobbyEndGame endGame;
|
||||||
|
endGame.closeConnection = false;
|
||||||
|
endGame.restart = true;
|
||||||
|
sendLobbyPack(endGame);
|
||||||
|
}
|
||||||
|
|
||||||
void CServerHandler::sendStartGame(bool allowOnlyAI) const
|
void CServerHandler::sendStartGame(bool allowOnlyAI) const
|
||||||
{
|
{
|
||||||
verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
|
verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
|
||||||
@ -568,6 +576,9 @@ void CServerHandler::endGameplay(bool closeConnection, bool restart)
|
|||||||
GH.curInt = CMainMenu::create().get();
|
GH.curInt = CMainMenu::create().get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serverConnection->enterLobbyConnectionMode();
|
||||||
|
serverConnection->disableStackSendingByID();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
|
void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
|
||||||
|
@ -70,6 +70,7 @@ public:
|
|||||||
virtual void sendMessage(const std::string & txt) const = 0;
|
virtual void sendMessage(const std::string & txt) const = 0;
|
||||||
virtual void sendGuiAction(ui8 action) const = 0; // TODO: possibly get rid of it?
|
virtual void sendGuiAction(ui8 action) const = 0; // TODO: possibly get rid of it?
|
||||||
virtual void sendStartGame(bool allowOnlyAI = false) const = 0;
|
virtual void sendStartGame(bool allowOnlyAI = false) const = 0;
|
||||||
|
virtual void sendRestartGame() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// structure to handle running server and connecting to it
|
/// structure to handle running server and connecting to it
|
||||||
@ -141,6 +142,7 @@ public:
|
|||||||
void setTurnLength(int npos) const override;
|
void setTurnLength(int npos) const override;
|
||||||
void sendMessage(const std::string & txt) const override;
|
void sendMessage(const std::string & txt) const override;
|
||||||
void sendGuiAction(ui8 action) const override;
|
void sendGuiAction(ui8 action) const override;
|
||||||
|
void sendRestartGame() const override;
|
||||||
void sendStartGame(bool allowOnlyAI = false) const override;
|
void sendStartGame(bool allowOnlyAI = false) const override;
|
||||||
|
|
||||||
void startGameplay(CGameState * gameState = nullptr);
|
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)
|
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;
|
handler->state = EClientState::STARTING;
|
||||||
if(handler->si->mode != StartInfo::LOAD_GAME)
|
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
|
struct LobbyStartGame : public CLobbyPackToPropagate
|
||||||
{
|
{
|
||||||
// Set by server
|
// Set by server
|
||||||
|
@ -372,6 +372,7 @@ void registerTypesLobbyPacks(Serializer &s)
|
|||||||
s.template registerType<CLobbyPackToPropagate, LobbyChatMessage>();
|
s.template registerType<CLobbyPackToPropagate, LobbyChatMessage>();
|
||||||
// Only host client send
|
// Only host client send
|
||||||
s.template registerType<CLobbyPackToPropagate, LobbyGuiAction>();
|
s.template registerType<CLobbyPackToPropagate, LobbyGuiAction>();
|
||||||
|
s.template registerType<CLobbyPackToPropagate, LobbyEndGame>();
|
||||||
s.template registerType<CLobbyPackToPropagate, LobbyStartGame>();
|
s.template registerType<CLobbyPackToPropagate, LobbyStartGame>();
|
||||||
s.template registerType<CLobbyPackToPropagate, LobbyChangeHost>();
|
s.template registerType<CLobbyPackToPropagate, LobbyChangeHost>();
|
||||||
// Only server send
|
// Only server send
|
||||||
|
@ -220,7 +220,7 @@ void CVCMIServer::threadAnnounceLobby()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVCMIServer::prepareToStartGame()
|
void CVCMIServer::prepareToRestart()
|
||||||
{
|
{
|
||||||
if(state == EServerState::GAMEPLAY)
|
if(state == EServerState::GAMEPLAY)
|
||||||
{
|
{
|
||||||
@ -237,7 +237,12 @@ bool CVCMIServer::prepareToStartGame()
|
|||||||
c->enterLobbyConnectionMode();
|
c->enterLobbyConnectionMode();
|
||||||
c->disableStackSendingByID();
|
c->disableStackSendingByID();
|
||||||
}
|
}
|
||||||
|
boost::unique_lock<boost::recursive_mutex> queueLock(mx);
|
||||||
|
gh = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CVCMIServer::prepareToStartGame()
|
||||||
|
{
|
||||||
gh = std::make_shared<CGameHandler>(this);
|
gh = std::make_shared<CGameHandler>(this);
|
||||||
switch(si->mode)
|
switch(si->mode)
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
~CVCMIServer();
|
~CVCMIServer();
|
||||||
void run();
|
void run();
|
||||||
bool prepareToStartGame();
|
bool prepareToStartGame();
|
||||||
|
void prepareToRestart();
|
||||||
void startGameImmidiately();
|
void startGameImmidiately();
|
||||||
|
|
||||||
void startAsyncAccept();
|
void startAsyncAccept();
|
||||||
|
@ -161,6 +161,27 @@ bool LobbyGuiAction::checkClientPermissions(CVCMIServer * srv) const
|
|||||||
return srv->isClientHost(c->connectionID);
|
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
|
bool LobbyStartGame::checkClientPermissions(CVCMIServer * srv) const
|
||||||
{
|
{
|
||||||
return srv->isClientHost(c->connectionID);
|
return srv->isClientHost(c->connectionID);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user