1
0
Fork 0

Merge pull request #4987 from vvanelslande/room-logging

network/room (server): add message/join/leave/kick/ban/unban/game name logging
This commit is contained in:
Pengfei Zhu 2019-11-11 20:29:33 +08:00 committed by GitHub
commit 060119d333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 1 deletions

View File

@ -19,8 +19,12 @@
#include <shellapi.h>
#endif
#include "common/common_paths.h"
#include "common/common_types.h"
#include "common/detached_tasks.h"
#include "common/file_util.h"
#include "common/logging/backend.h"
#include "common/logging/log.h"
#include "common/scm_rev.h"
#include "common/string_util.h"
#include "core/announce_multiplayer_session.h"
@ -54,6 +58,7 @@ static void PrintHelp(const char* argv0) {
"--token The token used for announce\n"
"--web-api-url Citra Web API url\n"
"--ban-list-file The file for storing the room ban list\n"
"--log-file The file for storing the room log\n"
"--enable-citra-mods Allow Citra Community Moderators to moderate on your room\n"
"-h, --help Display this help and exit\n"
"-v, --version Output version information and exit\n";
@ -147,6 +152,18 @@ static void SaveBanList(const Network::Room::BanList& ban_list, const std::strin
file.flush();
}
static void InitializeLogging(const std::string& log_file) {
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
FileUtil::CreateFullPath(log_dir);
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + log_file));
#ifdef _WIN32
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
#endif
}
/// Application entry point
int main(int argc, char** argv) {
Common::DetachedTasks detached_tasks;
@ -164,6 +181,7 @@ int main(int argc, char** argv) {
std::string token;
std::string web_api_url;
std::string ban_list_file;
std::string log_file = "citra-room.log";
u64 preferred_game_id = 0;
u32 port = Network::DefaultRoomPort;
u32 max_members = 16;
@ -181,6 +199,7 @@ int main(int argc, char** argv) {
{"token", required_argument, 0, 't'},
{"web-api-url", required_argument, 0, 'a'},
{"ban-list-file", required_argument, 0, 'b'},
{"log-file", required_argument, 0, 'l'},
{"enable-citra-mods", no_argument, 0, 'e'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
@ -188,7 +207,7 @@ int main(int argc, char** argv) {
};
while (optind < argc) {
int arg = getopt_long(argc, argv, "n:d:p:m:w:g:u:t:a:i:hv", long_options, &option_index);
int arg = getopt_long(argc, argv, "n:d:p:m:w:g:u:t:a:i:l:hv", long_options, &option_index);
if (arg != -1) {
switch (static_cast<char>(arg)) {
case 'n':
@ -224,6 +243,9 @@ int main(int argc, char** argv) {
case 'b':
ban_list_file.assign(optarg);
break;
case 'l':
log_file.assign(optarg);
break;
case 'e':
enable_citra_mods = true;
break;
@ -293,6 +315,8 @@ int main(int argc, char** argv) {
std::cout << "Can not enable Citra Moderators for private rooms\n\n";
}
InitializeLogging(log_file);
// Load the ban list
Network::Room::BanList ban_list;
if (!ban_list_file.empty()) {

View File

@ -778,6 +778,27 @@ void Room::RoomImpl::SendStatusMessage(StatusMessageTypes type, const std::strin
}
}
enet_host_flush(server);
const std::string display_name =
username.empty() ? nickname : fmt::format("{} ({})", nickname, username);
switch (type) {
case IdMemberJoin:
LOG_INFO(Network, "{} has joined.", display_name);
break;
case IdMemberLeave:
LOG_INFO(Network, "{} has left.", display_name);
break;
case IdMemberKicked:
LOG_INFO(Network, "{} has been kicked.", display_name);
break;
case IdMemberBanned:
LOG_INFO(Network, "{} has been banned.", display_name);
break;
case IdAddressUnbanned:
LOG_INFO(Network, "{} has been unbanned.", display_name);
break;
}
}
void Room::RoomImpl::BroadcastRoomInformation() {
@ -911,6 +932,13 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) {
}
enet_host_flush(server);
if (sending_member->user_data.username.empty()) {
LOG_INFO(Network, "{}: {}", sending_member->nickname, message);
} else {
LOG_INFO(Network, "{} ({}): {}", sending_member->nickname,
sending_member->user_data.username, message);
}
}
void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) {
@ -930,6 +958,17 @@ void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) {
});
if (member != members.end()) {
member->game_info = game_info;
const std::string display_name =
member->user_data.username.empty()
? member->nickname
: fmt::format("{} ({})", member->nickname, member->user_data.username);
if (game_info.name.empty()) {
LOG_INFO(Network, "{} is not playing", display_name);
} else {
LOG_INFO(Network, "{} is playing {}", display_name, game_info.name);
}
}
}
BroadcastRoomInformation();