mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Do not accept connections into ongoing game
This commit is contained in:
@@ -16,7 +16,6 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
NetworkServer::NetworkServer(INetworkServerListener & listener)
|
||||
:listener(listener)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetworkServer::start(uint16_t port)
|
||||
@@ -63,6 +62,12 @@ void NetworkServer::sendPacket(const std::shared_ptr<NetworkConnection> & connec
|
||||
connection->sendPacket(message);
|
||||
}
|
||||
|
||||
void NetworkServer::closeConnection(const std::shared_ptr<NetworkConnection> & connection)
|
||||
{
|
||||
assert(connections.count(connection));
|
||||
connections.erase(connection);
|
||||
}
|
||||
|
||||
void NetworkServer::onDisconnected(const std::shared_ptr<NetworkConnection> & connection)
|
||||
{
|
||||
assert(connections.count(connection));
|
||||
|
@@ -33,6 +33,7 @@ public:
|
||||
explicit NetworkServer(INetworkServerListener & listener);
|
||||
|
||||
void sendPacket(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message);
|
||||
void closeConnection(const std::shared_ptr<NetworkConnection> &);
|
||||
|
||||
void start(uint16_t port);
|
||||
void run(std::chrono::milliseconds duration);
|
||||
|
@@ -178,22 +178,22 @@ void CVCMIServer::onNewConnection(const std::shared_ptr<NetworkConnection> & con
|
||||
|
||||
if(state == EServerState::LOBBY)
|
||||
{
|
||||
activeConnections.push_back(std::make_shared<CConnection>(connection));//, SERVER_NAME, uuid);)
|
||||
activeConnections.push_back(std::make_shared<CConnection>(connection));
|
||||
activeConnections.back()->enterLobbyConnectionMode();
|
||||
}
|
||||
// TODO: else: deny connection
|
||||
// TODO: else: try to reconnect / send state to reconnected client
|
||||
else
|
||||
{
|
||||
networkServer->closeConnection(connection);
|
||||
}
|
||||
}
|
||||
|
||||
void CVCMIServer::onPacketReceived(const std::shared_ptr<NetworkConnection> & connection, const std::vector<uint8_t> & message)
|
||||
{
|
||||
std::shared_ptr<CConnection> c = findConnection(connection);
|
||||
CPack * pack = c->retrievePack(message);
|
||||
auto pack = c->retrievePack(message);
|
||||
pack->c = c;
|
||||
CVCMIServerPackVisitor visitor(*this, this->gh);
|
||||
pack->visit(visitor);
|
||||
|
||||
//FIXME: delete pack?
|
||||
}
|
||||
|
||||
void CVCMIServer::onConnectionFailed(const std::string & errorMessage)
|
||||
|
Reference in New Issue
Block a user