diff --git a/src/chatlog.cpp b/src/chatlog.cpp index b36be63a..ab460501 100644 --- a/src/chatlog.cpp +++ b/src/chatlog.cpp @@ -8,23 +8,37 @@ #include "common.h" #include "init.hpp" +#include +#include + namespace chatlog { CatVar enabled(CV_SWITCH, "chat_log", "0", "Chat log", "Log chat to file"); -CatVar message_template(CV_STRING, "chat_log_template", "[U:1:%u] %n: %m", "Log template", "%u - SteamID\n%n - name\n%m - message"); +CatVar message_template(CV_STRING, "chat_log_template", "[%t] [U:1:%u] %n: %m", "Log template", "%u - SteamID\n%n - name\n%m - message\n%t - time"); CatVar dont_log_spam(CV_SWITCH, "chat_log_nospam", "1", "No Spam", "Don't log your messages if spam is active"); class RAIILog { public: RAIILog() { - stream.open("cathook/chat.log", std::ios::out | std::ios::app); + open(); } ~RAIILog() { stream.close(); } + void open() { + logging::Info("Trying to open log file"); + uid_t uid = geteuid(); + struct passwd *pw = getpwuid(uid); + std::string uname = ""; + if (pw) { + uname = std::string(pw->pw_name); + } + stream.open("cathook/chat-" + uname + ".log", std::ios::out | std::ios::app); + } void log(const std::string& msg) { if (stream.bad()) { logging::Info("[ERROR] RAIILog stream is bad!"); + open(); return; } stream << msg << "\n"; @@ -54,7 +68,14 @@ void LogMessage(int eid, std::string message) { for (auto& x : message) { if (x < 32) x = '*'; } + time_t current_time; + struct tm * time_info; + char timeString[9]; + time(¤t_time); + time_info = localtime(¤t_time); + strftime(timeString, sizeof(timeString), "%H:%M:%S", time_info); std::string msg(message_template.GetString()); + ReplaceString(msg, "%t", std::string(timeString)); ReplaceString(msg, "%u", std::to_string(info.friendsID)); ReplaceString(msg, "%n", name); ReplaceString(msg, "%m", message); diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index 14e8d235..9ba6db3c 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -29,8 +29,9 @@ CatCommand debug_startsearch("debug_startsearch", "DEBUG StartSearch", []() { logging::Info("%d", g_TFGCClientSystem->RequestSelectWizardStep(4)); }); CatCommand debug_casual("debug_casual", "DEBUG Casual", []() { - logging::Info("%d", g_TFGCClientSystem->RequestSelectWizardStep(6)); + g_IEngine->ExecuteClientCmd("OpenMatchmakingLobby casual"); g_TFGCClientSystem->LoadSearchCriteria(); + //logging::Info("%d", g_TFGCClientSystem->RequestSelectWizardStep(6)); }); CatCommand debug_readytosearch("debug_gcstate", "DEBUG GCState", []() { @@ -60,7 +61,7 @@ void UpdateSearch() { } else if (g_TFGCClientSystem->GetState() == 5) { g_IEngine->ExecuteClientCmd("OpenMatchmakingLobby casual"); g_TFGCClientSystem->LoadSearchCriteria(); - logging::Info("%d", g_TFGCClientSystem->RequestSelectWizardStep(6)); + //logging::Info("%d", g_TFGCClientSystem->RequestSelectWizardStep(6)); } last_check = std::chrono::system_clock::now(); diff --git a/src/logging.cpp b/src/logging.cpp index b875bdfe..de101f70 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -29,8 +29,14 @@ void logging::Info(const char* fmt, ...) { vsprintf(buffer, fmt, list); va_end(list); size_t length = strlen(buffer); - char* result = new char[length + 9]; - sprintf(result, "[CAT] %s\n", buffer); + char* result = new char[length + 24]; + time_t current_time; + struct tm * time_info = nullptr; + char timeString[10]; + time(¤t_time); + time_info = localtime(¤t_time); + strftime(timeString, sizeof(timeString), "%H:%M:%S", time_info); + sprintf(result, "%% [%s] %s\n", timeString, buffer); fprintf(logging::handle, "%s", result); fflush(logging::handle); #ifndef TEXTMODE