Hookup new clients to logger, test logger construction and log writing to buffer

This commit is contained in:
Salanto 2021-08-25 02:33:19 +02:00
parent eda0a2f690
commit 16fd57e591
5 changed files with 42 additions and 4 deletions

View File

@ -90,7 +90,7 @@ public slots:
/**
* @brief Logs any connection attempt to the server, wether sucessful or not.
*/
void logConnectionAttempt(const QString &f_ip_address, const QString &f_ipid, const QString &f_hdid);
void logConnectionAttempt(const QString &f_ip_address, const QString &f_ipid);
private:

View File

@ -278,7 +278,20 @@ class Server : public QObject {
*/
void banWebhookRequest(const QString& f_ipid, const QString& f_moderator, const QString& f_duration, const QString& f_reason, const int& f_banID);
/**
* @brief Signal connected to universal logger. Logs a client connection attempt.
* @param f_ip_address The IP Address of the incoming connection.
* @param f_ipid The IPID of the incoming connection.
* @param f_hdid The HDID of the incoming connection.
*/
void logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid);
private:
/**
* @brief Connects new AOClient to the logger.
**/
void hookupLogger(AOClient* client);
/**
* @brief The proxy used for WebSocket connections.
*

View File

@ -99,6 +99,9 @@ void Logger::flush()
break;
case DataTypes::LogType::FULL:
l_logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd")));
break;
case DataTypes::LogType::SQL:
break;
}

View File

@ -131,11 +131,11 @@ void ULogger::logModcall(const QString &f_charName, const QString &f_ipid, const
}
}
void ULogger::logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid, const QString& f_hdid)
void ULogger::logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][CONNECT][%2][%3][%4]\n")
.arg(l_time, f_ip_address, f_ipid, f_hdid);
QString l_logEntry = QStringLiteral("[%1][CONNECT][%2][%3]\n")
.arg(l_time, f_ip_address, f_ipid);
updateAreaBuffer("SERVER",l_logEntry);
}

View File

@ -70,6 +70,8 @@ void Server::start()
}
logger = new ULogger(this);
connect(this, &Server::logConnectionAttempt,
logger, &ULogger::logConnectionAttempt);
proxy = new WSProxy(port, ws_port, this);
if(ws_port != -1)
@ -171,6 +173,8 @@ void Server::clientConnected()
// tsuserver4. It should disable fantacrypt
// completely in any client 2.4.3 or newer
client->sendPacket(decryptor);
hookupLogger(client);
emit logConnectionAttempt(client->remote_ip.toString(), client->getIpid());
#ifdef NET_DEBUG
qDebug() << client->remote_ip.toString() << "connected";
#endif
@ -308,6 +312,24 @@ void Server::handleDiscordIntegration()
return;
}
void Server::hookupLogger(AOClient* client)
{
connect(client, &AOClient::logIC,
logger, &ULogger::logIC);
connect(client, &AOClient::logOOC,
logger, &ULogger::logOOC);
connect(client, &AOClient::logLogin,
logger, &ULogger::logLogin);
connect(client, &AOClient::logCMD,
logger, &ULogger::logCMD);
connect(client, &AOClient::logBan,
logger, &ULogger::logBan);
connect(client, &AOClient::logKick,
logger, &ULogger::logKick);
connect(client, &AOClient::logModcall,
logger, &ULogger::logModcall);
}
Server::~Server()
{
for (AOClient* client : qAsConst(clients)) {