JIJOOOOOOOOOOO
This commit is contained in:
parent
0a0bd116d5
commit
16388f3760
@ -18,7 +18,6 @@ Server::Server(int p_ws_port, int p_wss_port, QObject *parent) :
|
|||||||
m_secure_port(p_wss_port),
|
m_secure_port(p_wss_port),
|
||||||
m_player_count(0)
|
m_player_count(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
|
||||||
db_manager = new DBManager;
|
db_manager = new DBManager;
|
||||||
@ -34,6 +33,10 @@ Server::Server(int p_ws_port, int p_wss_port, QObject *parent) :
|
|||||||
connect(this, &Server::logConnectionAttempt, logger, &ULogger::logConnectionAttempt);
|
connect(this, &Server::logConnectionAttempt, logger, &ULogger::logConnectionAttempt);
|
||||||
|
|
||||||
AOPacket::registerPackets();
|
AOPacket::registerPackets();
|
||||||
|
|
||||||
|
// Initialize both servers
|
||||||
|
server = new QWebSocketServer(QStringLiteral("Akashi"), QWebSocketServer::NonSecureMode, this);
|
||||||
|
secure_server = new QWebSocketServer(QStringLiteral("Akashi"), QWebSocketServer::SecureMode, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::start()
|
void Server::start()
|
||||||
@ -47,8 +50,10 @@ void Server::start()
|
|||||||
bind_addr = QHostAddress(bind_ip);
|
bind_addr = QHostAddress(bind_ip);
|
||||||
if (bind_addr.protocol() != QAbstractSocket::IPv4Protocol && bind_addr.protocol() != QAbstractSocket::IPv6Protocol && bind_addr != QHostAddress::Any) {
|
if (bind_addr.protocol() != QAbstractSocket::IPv4Protocol && bind_addr.protocol() != QAbstractSocket::IPv6Protocol && bind_addr != QHostAddress::Any) {
|
||||||
qDebug() << bind_ip << "is an invalid IP address to listen on! Server not starting, check your config.";
|
qDebug() << bind_ip << "is an invalid IP address to listen on! Server not starting, check your config.";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure SSL for secure server
|
||||||
QSettings settings("config/ssl.ini", QSettings::IniFormat);
|
QSettings settings("config/ssl.ini", QSettings::IniFormat);
|
||||||
|
|
||||||
QString privateKeyPath = settings.value("SSL/privateKey").toString();
|
QString privateKeyPath = settings.value("SSL/privateKey").toString();
|
||||||
@ -60,42 +65,50 @@ void Server::start()
|
|||||||
QFile keyFile(privateKeyPath);
|
QFile keyFile(privateKeyPath);
|
||||||
if (!keyFile.open(QIODevice::ReadOnly)) {
|
if (!keyFile.open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "Unable to open private key file.";
|
qWarning() << "Unable to open private key file.";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
QSslKey privateKey(&keyFile, QSsl::Rsa);
|
else {
|
||||||
keyFile.close();
|
QSslKey privateKey(&keyFile, QSsl::Rsa);
|
||||||
|
keyFile.close();
|
||||||
|
|
||||||
QFile certFile(certificatePath);
|
QFile certFile(certificatePath);
|
||||||
if (!certFile.open(QIODevice::ReadOnly)) {
|
if (!certFile.open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "Unable to open certificate file.";
|
qWarning() << "Unable to open certificate file.";
|
||||||
return;
|
}
|
||||||
|
else {
|
||||||
|
QSslCertificate certificate(&certFile);
|
||||||
|
certFile.close();
|
||||||
|
|
||||||
|
QFile caFile(caCertificatePath);
|
||||||
|
if (caFile.open(QIODevice::ReadOnly)) {
|
||||||
|
QSslCertificate caCertificate(&caFile);
|
||||||
|
sslConfig.addCaCertificate(caCertificate);
|
||||||
|
caFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
sslConfig.setPrivateKey(privateKey);
|
||||||
|
sslConfig.setLocalCertificate(certificate);
|
||||||
|
secure_server->setSslConfiguration(sslConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSslCertificate certificate(&certFile);
|
// Start non-secure server
|
||||||
certFile.close();
|
|
||||||
|
|
||||||
|
|
||||||
QFile caFile(caCertificatePath);
|
|
||||||
if (caFile.open(QIODevice::ReadOnly)) {
|
|
||||||
QSslCertificate caCertificate(&caFile);
|
|
||||||
sslConfig.addCaCertificate(caCertificate);
|
|
||||||
caFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
sslConfig.setPrivateKey(privateKey);
|
|
||||||
sslConfig.setLocalCertificate(certificate);
|
|
||||||
|
|
||||||
server = new QWebSocketServer(QStringLiteral("Akashi"), QWebSocketServer::SecureMode, this);
|
|
||||||
server->setSslConfiguration(sslConfig);
|
|
||||||
|
|
||||||
|
|
||||||
if (!server->listen(bind_addr, m_port)) {
|
if (!server->listen(bind_addr, m_port)) {
|
||||||
qDebug() << "Server error:" << server->errorString();
|
qDebug() << "Non-secure server error:" << server->errorString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connect(server, &QWebSocketServer::newConnection,
|
connect(server, &QWebSocketServer::newConnection,
|
||||||
this, &Server::clientConnected);
|
this, &Server::clientConnected);
|
||||||
qInfo() << "Server listening on" << server->serverPort();
|
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);
|
||||||
|
qInfo() << "Secure server listening on" << secure_server->serverPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct modern advertiser if enabled in config
|
// Construct modern advertiser if enabled in config
|
||||||
@ -108,7 +121,6 @@ void Server::start()
|
|||||||
m_backgrounds = ConfigManager::backgrounds();
|
m_backgrounds = ConfigManager::backgrounds();
|
||||||
|
|
||||||
// Build our music manager.
|
// Build our music manager.
|
||||||
|
|
||||||
MusicList l_musiclist = ConfigManager::musiclist();
|
MusicList l_musiclist = ConfigManager::musiclist();
|
||||||
music_manager = new MusicManager(ConfigManager::cdnList(), l_musiclist, ConfigManager::ordered_songs(), this);
|
music_manager = new MusicManager(ConfigManager::cdnList(), l_musiclist, ConfigManager::ordered_songs(), this);
|
||||||
connect(music_manager, &MusicManager::sendFMPacket, this, &Server::unicast);
|
connect(music_manager, &MusicManager::sendFMPacket, this, &Server::unicast);
|
||||||
|
@ -408,6 +408,7 @@ class Server : public QObject
|
|||||||
* @brief Listens for incoming websocket connections.
|
* @brief Listens for incoming websocket connections.
|
||||||
*/
|
*/
|
||||||
QWebSocketServer *server;
|
QWebSocketServer *server;
|
||||||
|
QWebSocketServer *secure_server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Handles HTTP server advertising.
|
* @brief Handles HTTP server advertising.
|
||||||
|
Loading…
Reference in New Issue
Block a user