exposed noob

This commit is contained in:
nullifiedcat 2017-07-29 13:06:33 +03:00
parent f578811e25
commit 3fccca1012
3 changed files with 34 additions and 6 deletions

View File

@ -8,23 +8,37 @@
#include "common.h"
#include "init.hpp"
#include <pwd.h>
#include <unistd.h>
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(&current_time);
time_info = localtime(&current_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);

View File

@ -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();

View File

@ -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(&current_time);
time_info = localtime(&current_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