mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Multiplayer: gracefully handle player loss unless it's a host
We don't want server to shutdown after just one of players lost the game.
This commit is contained in:
parent
c66c66c5ae
commit
db5a52a0f8
@ -391,7 +391,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
else
|
||||
{
|
||||
serv = con;
|
||||
networkMode = (con->connectionID == 1) ? HOST : GUEST;
|
||||
networkMode = con->isHost() ? HOST : GUEST;
|
||||
}
|
||||
|
||||
CConnection &c = *serv;
|
||||
@ -693,7 +693,7 @@ void CClient::stopConnection()
|
||||
{
|
||||
terminate = true;
|
||||
|
||||
if (serv) //request closing connection
|
||||
if (serv && serv->isHost()) //request closing connection
|
||||
{
|
||||
logNetwork->infoStream() << "Connection has been requested to be closed.";
|
||||
boost::unique_lock<boost::mutex>(*serv->wmx);
|
||||
@ -1075,6 +1075,7 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const
|
||||
ret = new CConnection( host.size() ? host : settings["server"]["server"].String(),
|
||||
realPort,
|
||||
NAME);
|
||||
ret->connectionID = 1; // TODO: Refactoring for the server so IDs set outside of CConnection
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -201,6 +201,11 @@ bool CConnection::isOpen() const
|
||||
return socket && connected;
|
||||
}
|
||||
|
||||
bool CConnection::isHost() const
|
||||
{
|
||||
return connectionID == 1;
|
||||
}
|
||||
|
||||
void CConnection::reportState(CLogger * out)
|
||||
{
|
||||
out->debugStream() << "CConnection";
|
||||
|
@ -74,6 +74,7 @@ public:
|
||||
|
||||
void close();
|
||||
bool isOpen() const;
|
||||
bool isHost() const;
|
||||
template<class T>
|
||||
CConnection &operator&(const T&);
|
||||
virtual ~CConnection(void);
|
||||
|
@ -1097,7 +1097,7 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
||||
{
|
||||
assert(!c.connected); //make sure that connection has been marked as broken
|
||||
logGlobal->error(e.what());
|
||||
end2 = true;
|
||||
conns -= &c;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@ -2631,6 +2631,9 @@ void CGameHandler::sendToAllClients(CPackForClient * info)
|
||||
logNetwork->trace("Sending to all clients a package of type %s", typeid(*info).name());
|
||||
for (auto & elem : conns)
|
||||
{
|
||||
if(!elem->isOpen())
|
||||
continue;
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(*(elem)->wmx);
|
||||
*elem << info;
|
||||
}
|
||||
@ -2703,6 +2706,7 @@ void CGameHandler::close()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
end2 = true;
|
||||
|
||||
//for (CConnection *cc : conns)
|
||||
// if (cc && cc->socket && cc->socket->is_open())
|
||||
|
Loading…
Reference in New Issue
Block a user