network/room: add message/join/leave/kick/ban/unban/game name logging
This commit is contained in:
parent
35690e3ac7
commit
db1b0a1964
2 changed files with 64 additions and 1 deletions
|
@ -18,8 +18,12 @@
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "common/common_paths.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/detached_tasks.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/scm_rev.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#include "core/announce_multiplayer_session.h"
|
#include "core/announce_multiplayer_session.h"
|
||||||
|
@ -53,6 +57,7 @@ static void PrintHelp(const char* argv0) {
|
||||||
"--token The token used for announce\n"
|
"--token The token used for announce\n"
|
||||||
"--web-api-url Citra Web API url\n"
|
"--web-api-url Citra Web API url\n"
|
||||||
"--ban-list-file The file for storing the room ban list\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"
|
"--enable-citra-mods Allow Citra Community Moderators to moderate on your room\n"
|
||||||
"-h, --help Display this help and exit\n"
|
"-h, --help Display this help and exit\n"
|
||||||
"-v, --version Output version information and exit\n";
|
"-v, --version Output version information and exit\n";
|
||||||
|
@ -128,6 +133,18 @@ static void SaveBanList(const Network::Room::BanList& ban_list, const std::strin
|
||||||
file.flush();
|
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
|
/// Application entry point
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
Common::DetachedTasks detached_tasks;
|
Common::DetachedTasks detached_tasks;
|
||||||
|
@ -145,6 +162,7 @@ int main(int argc, char** argv) {
|
||||||
std::string token;
|
std::string token;
|
||||||
std::string web_api_url;
|
std::string web_api_url;
|
||||||
std::string ban_list_file;
|
std::string ban_list_file;
|
||||||
|
std::string log_file = "citra-room.log";
|
||||||
u64 preferred_game_id = 0;
|
u64 preferred_game_id = 0;
|
||||||
u32 port = Network::DefaultRoomPort;
|
u32 port = Network::DefaultRoomPort;
|
||||||
u32 max_members = 16;
|
u32 max_members = 16;
|
||||||
|
@ -162,6 +180,7 @@ int main(int argc, char** argv) {
|
||||||
{"token", required_argument, 0, 't'},
|
{"token", required_argument, 0, 't'},
|
||||||
{"web-api-url", required_argument, 0, 'a'},
|
{"web-api-url", required_argument, 0, 'a'},
|
||||||
{"ban-list-file", required_argument, 0, 'b'},
|
{"ban-list-file", required_argument, 0, 'b'},
|
||||||
|
{"log-file", required_argument, 0, 'l'},
|
||||||
{"enable-citra-mods", no_argument, 0, 'e'},
|
{"enable-citra-mods", no_argument, 0, 'e'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
|
@ -169,7 +188,7 @@ int main(int argc, char** argv) {
|
||||||
};
|
};
|
||||||
|
|
||||||
while (optind < argc) {
|
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) {
|
if (arg != -1) {
|
||||||
switch (static_cast<char>(arg)) {
|
switch (static_cast<char>(arg)) {
|
||||||
case 'n':
|
case 'n':
|
||||||
|
@ -205,6 +224,9 @@ int main(int argc, char** argv) {
|
||||||
case 'b':
|
case 'b':
|
||||||
ban_list_file.assign(optarg);
|
ban_list_file.assign(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
log_file.assign(optarg);
|
||||||
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
enable_citra_mods = true;
|
enable_citra_mods = true;
|
||||||
break;
|
break;
|
||||||
|
@ -271,6 +293,8 @@ int main(int argc, char** argv) {
|
||||||
std::cout << "Can not enable Citra Moderators for private rooms\n\n";
|
std::cout << "Can not enable Citra Moderators for private rooms\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InitializeLogging(log_file);
|
||||||
|
|
||||||
// Load the ban list
|
// Load the ban list
|
||||||
Network::Room::BanList ban_list;
|
Network::Room::BanList ban_list;
|
||||||
if (!ban_list_file.empty()) {
|
if (!ban_list_file.empty()) {
|
||||||
|
|
|
@ -778,6 +778,27 @@ void Room::RoomImpl::SendStatusMessage(StatusMessageTypes type, const std::strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enet_host_flush(server);
|
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() {
|
void Room::RoomImpl::BroadcastRoomInformation() {
|
||||||
|
@ -911,6 +932,13 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
enet_host_flush(server);
|
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) {
|
void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) {
|
||||||
|
@ -930,6 +958,17 @@ void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) {
|
||||||
});
|
});
|
||||||
if (member != members.end()) {
|
if (member != members.end()) {
|
||||||
member->game_info = game_info;
|
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();
|
BroadcastRoomInformation();
|
||||||
|
|
Loading…
Reference in a new issue