diff --git a/CMakeLists.txt b/CMakeLists.txt index 806919b..6a223f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,3 +67,5 @@ install(TARGETS ${PROJECT_NAME} install(DIRECTORY docroot/ DESTINATION /opt/ypchat/docroot ) +install(CODE "file(MAKE_DIRECTORY /opt/ypchat/logs)") +install(CODE "execute_process(COMMAND chmod 777 /opt/ypchat/logs)") diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index eca8067..a7ced9e 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -379,7 +379,7 @@ singlechat.wt CMakeProjectManager.CMakeRunConfiguration.singlechat.wt singlechat.wt - --docroot ../docroot/ --http-port=4500 --http-address=0.0.0.0 + --docroot="../docroot/;/style.css,/resources" --http-port=4500 --http-address=0.0.0.0 false true true diff --git a/src/app.cpp b/src/app.cpp index 8507567..43f1f34 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -220,7 +220,6 @@ void App::handleLogin(Wt::WLineEdit* userName, Wt::WComboBox* countryWidget, Wt: validateName(nick); validateGender(genderWidget); validateAge(ageWidget); - setUserData(nick, countryWidget, ageWidget, genderWidget); connectToServer(); startChat(); diff --git a/src/broadcast.cpp b/src/broadcast.cpp index f694830..d5f09b3 100644 --- a/src/broadcast.cpp +++ b/src/broadcast.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,26 @@ Broadcast::Broadcast(Wt::WServer *server): downloadCountries(); thread_ = std::thread(std::bind(&Broadcast::run, this)); lastTimeoutCheck_ = Wt::WDateTime::currentDateTime(); + checkAndLogStart(); +} + +void Broadcast::checkAndLogStart() { + const std::string logFilePath = "/opt/ypchat/logs/starts.log"; + std::ifstream infile(logFilePath); + if (!infile.good()) { + std::ofstream outfile(logFilePath); + outfile.close(); + } + infile.close(); + Wt::WDateTime now = Wt::WDateTime::currentDateTime(); + std::string timestamp = now.toString("yyyy-MM-dd HH:mm:ss").toUTF8(); + std::ofstream outfile(logFilePath, std::ios_base::app); + if (outfile.is_open()) { + outfile << timestamp << std::endl; + outfile.close(); + } else { + std::cerr << "Fehler beim Öffnen der Datei: " << logFilePath << std::endl; + } } Broadcast::~Broadcast() { @@ -36,6 +57,25 @@ void Broadcast::connect(Client *client, const std::function &fct) { connection->addBroadcast(userlistBroadcast); connection->addBroadcast(newUserBroadcast); } + logClientLogin(client->json()); +} + +void Broadcast::logClientLogin(const Wt::Json::Object &clientJson) { + const std::string logFilePath = "/opt/ypchat/logs/logins.log"; + std::ifstream infile(logFilePath); + if (!infile.good()) { + std::ofstream outfile(logFilePath); + outfile.close(); + } + infile.close(); + std::string clientData = Wt::Json::serialize(clientJson); + std::ofstream outfile(logFilePath, std::ios_base::app); + if (outfile.is_open()) { + outfile << clientData << std::endl; + outfile.close(); + } else { + std::cerr << "Fehler beim Öffnen der Datei: " << logFilePath << std::endl; + } } void Broadcast::disconnect(Client *client) { diff --git a/src/broadcast.h b/src/broadcast.h index c56876e..d791ac8 100644 --- a/src/broadcast.h +++ b/src/broadcast.h @@ -147,6 +147,8 @@ private: void sendBlockedMessage(std::string sessionId, std::string toUserName); void sendBlockDone(std::string sessionId, std::string toUserName); void sendUnblockDone(std::string sessionId, std::string toUserName); + void checkAndLogStart(); + void logClientLogin(const Wt::Json::Object &clientJson); }; #endif // BROADCAST_H