From cd69bc8f9d1609f69ddba2aca010e6031ff62c2d Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 1 Jan 2015 15:48:53 +0100 Subject: [PATCH] Add configuration options to enable database logging --- common/server.cpp | 2 +- common/server_database_interface.h | 2 +- servatrice/servatrice.ini.example | 20 ++++++++++++++++++- .../src/servatrice_database_interface.cpp | 14 +++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/common/server.cpp b/common/server.cpp index 432c008ed..4b65739bf 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -346,7 +346,7 @@ void Server::externalRoomSay(int roomId, const QString &userName, const QString } room->say(userName, message, false); - getDatabaseInterface()->logMessage(0, userName, "ISL", message, Server_DatabaseInterface::MessageTargetRoom, room->getId(), room->getName()); + getDatabaseInterface()->logMessage(0, userName, "ISL", message, Server_DatabaseInterface::MessageTargetIslRoom, room->getId(), room->getName()); } void Server::externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo) diff --git a/common/server_database_interface.h b/common/server_database_interface.h index 690d09f8c..f3ffed6df 100644 --- a/common/server_database_interface.h +++ b/common/server_database_interface.h @@ -36,7 +36,7 @@ public: virtual bool getRequireRegistration() { return false; } - enum LogMessage_TargetType { MessageTargetRoom, MessageTargetGame, MessageTargetChat }; + enum LogMessage_TargetType { MessageTargetRoom, MessageTargetGame, MessageTargetChat, MessageTargetIslRoom }; virtual void logMessage(const int senderId, const QString &senderName, const QString &senderIp, const QString &logMessage, LogMessage_TargetType targetType, const int targetId, const QString &targetName) { }; }; diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index b3e431a12..c44547450 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -79,7 +79,7 @@ password=foobar [rooms] -; A servtrice server can expose to the users different "rooms" to chat and create games. Rooms can be defined +; A servatrice server can expose to the users different "rooms" to chat and create games. Rooms can be defined ; with two different methods: ; config: rooms are defined in this configuration (see the following example) ; sql: rooms are defined in the "rooms" table of the database @@ -144,6 +144,24 @@ max_message_count_per_interval=10 max_games_per_user=5 +[logging] + +; Servatrice can log user messages to the database table cockatrice_log. +; These messages can come from different sources; each source can be enabled separately. + +; Log user messages inside chat rooms +log_user_msg_room=false + +; Log user messages inside games +log_user_msg_game=false + +; Log user messages in private chats +log_user_msg_chat=false + +; Log user messages coming from other servers in the network +log_user_msg_isl=false + + ; EXPERIMENTAL - NOT WORKING YET ; The following settings are relative to the server network functionality, that is not yet complete. ; Avoid enabling it unless you are willing to test it and help its development. diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index 38ea25b0b..7ee12cd7a 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -546,15 +546,29 @@ void Servatrice_DatabaseInterface::logMessage(const int senderId, const QString switch(targetType) { case MessageTargetRoom: + if(!settingsCache->value("logging/log_user_msg_room", 0).toBool()) + return; targetTypeString = "room"; break; case MessageTargetGame: + if(!settingsCache->value("logging/log_user_msg_game", 0).toBool()) + return; targetTypeString = "game"; break; case MessageTargetChat: + if(!settingsCache->value("logging/log_user_msg_chat", 0).toBool()) + return; targetTypeString = "chat"; break; + case MessageTargetIslRoom: + if(!settingsCache->value("logging/log_user_msg_isl", 0).toBool()) + return; + targetTypeString = "room"; + break; + default: + return; } + query.prepare("insert into " + server->getDbPrefix() + "_log (log_time, sender_id, sender_name, sender_ip, log_message, target_type, target_id, target_name) values (now(), :sender_id, :sender_name, :sender_ip, :log_message, :target_type, :target_id, :target_name)"); query.bindValue(":sender_id", senderId); query.bindValue(":sender_name", senderName);