mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Allow to reconnect to proxy server
This commit is contained in:
parent
811680c4c5
commit
f3fa0f8652
@ -417,6 +417,9 @@ void CServerHandler::sendClientDisconnecting()
|
|||||||
logNetwork->info("Sent leaving signal to the server");
|
logNetwork->info("Sent leaving signal to the server");
|
||||||
}
|
}
|
||||||
sendLobbyPack(lcd);
|
sendLobbyPack(lcd);
|
||||||
|
|
||||||
|
c->close();
|
||||||
|
c.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerHandler::setCampaignState(std::shared_ptr<CampaignState> newCampaign)
|
void CServerHandler::setCampaignState(std::shared_ptr<CampaignState> newCampaign)
|
||||||
|
@ -211,21 +211,20 @@ void CVCMIServer::establishRemoteConnections()
|
|||||||
|
|
||||||
uuid = cmdLineOptions["lobby-uuid"].as<std::string>();
|
uuid = cmdLineOptions["lobby-uuid"].as<std::string>();
|
||||||
int numOfConnections = cmdLineOptions["connections"].as<ui16>();
|
int numOfConnections = cmdLineOptions["connections"].as<ui16>();
|
||||||
auto address = cmdLineOptions["lobby"].as<std::string>();
|
|
||||||
int port = cmdLineOptions["lobby-port"].as<ui16>();
|
|
||||||
logGlobal->info("Server is connecting to remote at %s:%d with uuid %s %d times", address, port, uuid, numOfConnections);
|
|
||||||
|
|
||||||
for(int i = 0; i < numOfConnections; ++i)
|
for(int i = 0; i < numOfConnections; ++i)
|
||||||
connectToRemote(address, port);
|
connectToRemote();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVCMIServer::connectToRemote(const std::string & addr, int port)
|
void CVCMIServer::connectToRemote()
|
||||||
{
|
{
|
||||||
std::shared_ptr<CConnection> c;
|
std::shared_ptr<CConnection> c;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logNetwork->info("Establishing connection...");
|
auto address = cmdLineOptions["lobby"].as<std::string>();
|
||||||
c = std::make_shared<CConnection>(addr, port, SERVER_NAME, uuid);
|
int port = cmdLineOptions["lobby-port"].as<ui16>();
|
||||||
|
|
||||||
|
logNetwork->info("Establishing connection to remote at %s:%d with uuid %s", address, port, uuid);
|
||||||
|
c = std::make_shared<CConnection>(address, port, SERVER_NAME, uuid);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
@ -235,6 +234,7 @@ void CVCMIServer::connectToRemote(const std::string & addr, int port)
|
|||||||
if(c)
|
if(c)
|
||||||
{
|
{
|
||||||
connections.insert(c);
|
connections.insert(c);
|
||||||
|
remoteConnections.insert(c);
|
||||||
c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
|
c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ public:
|
|||||||
|
|
||||||
boost::program_options::variables_map cmdLineOptions;
|
boost::program_options::variables_map cmdLineOptions;
|
||||||
std::set<std::shared_ptr<CConnection>> connections;
|
std::set<std::shared_ptr<CConnection>> connections;
|
||||||
|
std::set<std::shared_ptr<CConnection>> remoteConnections;
|
||||||
std::set<std::shared_ptr<CConnection>> hangingConnections; //keep connections of players disconnected during the game
|
std::set<std::shared_ptr<CConnection>> hangingConnections; //keep connections of players disconnected during the game
|
||||||
|
|
||||||
std::atomic<int> currentClientId;
|
std::atomic<int> currentClientId;
|
||||||
@ -78,7 +79,7 @@ public:
|
|||||||
void startGameImmidiately();
|
void startGameImmidiately();
|
||||||
|
|
||||||
void establishRemoteConnections();
|
void establishRemoteConnections();
|
||||||
void connectToRemote(const std::string & addr, int port);
|
void connectToRemote();
|
||||||
void startAsyncAccept();
|
void startAsyncAccept();
|
||||||
void connectionAccepted(const boost::system::error_code & ec);
|
void connectionAccepted(const boost::system::error_code & ec);
|
||||||
void threadHandleClient(std::shared_ptr<CConnection> c);
|
void threadHandleClient(std::shared_ptr<CConnection> c);
|
||||||
|
@ -189,6 +189,12 @@ void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyClientDisconnected(Lobb
|
|||||||
srv.addToAnnounceQueue(std::move(ph));
|
srv.addToAnnounceQueue(std::move(ph));
|
||||||
}
|
}
|
||||||
srv.updateAndPropagateLobbyState();
|
srv.updateAndPropagateLobbyState();
|
||||||
|
|
||||||
|
if(srv.getState() != EServerState::SHUTDOWN && srv.remoteConnections.count(pack.c))
|
||||||
|
{
|
||||||
|
srv.remoteConnections -= pack.c;
|
||||||
|
srv.connectToRemote();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPermissionsCheckerNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
|
void ClientPermissionsCheckerNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
|
||||||
|
Loading…
Reference in New Issue
Block a user