This commit is contained in:
simio 2025-06-22 03:52:52 -03:00
parent af37e7e01d
commit 3cfe9461cc
2 changed files with 16 additions and 11 deletions

View File

@ -94,20 +94,20 @@ void Server::start()
// Start non-secure server
if (!server->listen(bind_addr, m_port)) {
qDebug() << "Non-secure server error:" << server->errorString();
}
else {
connect(server, &QWebSocketServer::newConnection,
this, &Server::clientConnected);
} else {
connect(server, &QWebSocketServer::newConnection, this, [this]() {
this->clientConnected(server);
});
qInfo() << "Non-secure server listening on" << server->serverPort();
}
// Start secure server
if (!secure_server->listen(bind_addr, m_secure_port)) {
qDebug() << "Secure server error:" << secure_server->errorString();
}
else {
connect(secure_server, &QWebSocketServer::newConnection,
this, &Server::clientConnected);
} else {
connect(secure_server, &QWebSocketServer::newConnection, this, [this]() {
this->clientConnected(secure_server);
});
qInfo() << "Secure server listening on" << secure_server->serverPort();
}
@ -192,9 +192,14 @@ QVector<AOClient *> Server::getClients()
return m_clients;
}
void Server::clientConnected()
void Server::clientConnected(QWebSocketServer* whichServer)
{
QWebSocket *socket = server->nextPendingConnection();
QWebSocket *socket = whichServer->nextPendingConnection();
if (!socket) {
qWarning() << "Failed to get pending connection from" << whichServer->serverName();
return;
}
NetworkSocket *l_socket = new NetworkSocket(socket, socket);
// Too many players. Reject connection!

View File

@ -345,7 +345,7 @@ class Server : public QObject
* @details The function creates an AOClient to represent the user, assigns a user ID to them, and
* checks if the client is banned.
*/
void clientConnected();
void clientConnected(QWebSocketServer *whichServer);
/**
* @brief Marks a userID as free and ads it back to the available client id queue.