From 13ec2abbf6758a2817c4ad1524b01c8e9a583056 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Sat, 15 Dec 2018 22:47:07 +0800 Subject: [PATCH] network: Make citra mods optional and disabled by default To avoid extra legal responsibility, this should actually only be used on our self-hosted rooms. --- src/dedicated_room/citra-room.cpp | 13 ++++++++++++- src/network/room.cpp | 15 ++++++++++----- src/network/room.h | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/dedicated_room/citra-room.cpp b/src/dedicated_room/citra-room.cpp index 8e2938006..8a8c2ae0f 100644 --- a/src/dedicated_room/citra-room.cpp +++ b/src/dedicated_room/citra-room.cpp @@ -54,6 +54,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" + "--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"; } @@ -148,6 +149,7 @@ int main(int argc, char** argv) { u64 preferred_game_id = 0; u32 port = Network::DefaultRoomPort; u32 max_members = 16; + bool enable_citra_mods = false; static struct option long_options[] = { {"room-name", required_argument, 0, 'n'}, @@ -161,6 +163,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'}, + {"enable-citra-mods", no_argument, 0, 'e'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {0, 0, 0, 0}, @@ -203,6 +206,9 @@ int main(int argc, char** argv) { case 'b': ban_list_file.assign(optarg); break; + case 'e': + enable_citra_mods = true; + break; case 'h': PrintHelp(argv[0]); return 0; @@ -261,6 +267,10 @@ int main(int argc, char** argv) { Settings::values.citra_username = username; Settings::values.citra_token = token; } + if (!announce && enable_citra_mods) { + enable_citra_mods = false; + std::cout << "Can not enable Citra Moderators for private rooms\n\n"; + } // Load the ban list Network::Room::BanList ban_list; @@ -284,7 +294,8 @@ int main(int argc, char** argv) { Network::Init(); if (std::shared_ptr room = Network::GetRoom().lock()) { if (!room->Create(room_name, room_description, "", port, password, max_members, username, - preferred_game, preferred_game_id, std::move(verify_backend), ban_list)) { + preferred_game, preferred_game_id, std::move(verify_backend), ban_list, + enable_citra_mods)) { std::cout << "Failed to create room: \n\n"; return -1; } diff --git a/src/network/room.cpp b/src/network/room.cpp index 5386977e5..6014b4360 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp @@ -589,8 +589,6 @@ bool Room::RoomImpl::IsValidConsoleId(const std::string& console_id_hash) const } bool Room::RoomImpl::HasModPermission(const ENetPeer* client) const { - if (room_information.host_username.empty()) - return false; // This room does not support moderation std::lock_guard lock(member_mutex); const auto sending_member = std::find_if(members.begin(), members.end(), @@ -598,10 +596,16 @@ bool Room::RoomImpl::HasModPermission(const ENetPeer* client) const { if (sending_member == members.end()) { return false; } - if (sending_member->user_data.moderator) // Community moderator + if (room_information.enable_citra_mods && + sending_member->user_data.moderator) { // Community moderator + return true; - if (sending_member->user_data.username == room_information.host_username) // Room host + } + if (!room_information.host_username.empty() && + sending_member->user_data.username == room_information.host_username) { // Room host + return true; + } return false; } @@ -963,7 +967,7 @@ bool Room::Create(const std::string& name, const std::string& description, const u32 max_connections, const std::string& host_username, const std::string& preferred_game, u64 preferred_game_id, std::unique_ptr verify_backend, - const Room::BanList& ban_list) { + const Room::BanList& ban_list, bool enable_citra_mods) { ENetAddress address; address.host = ENET_HOST_ANY; if (!server_address.empty()) { @@ -986,6 +990,7 @@ bool Room::Create(const std::string& name, const std::string& description, room_impl->room_information.preferred_game = preferred_game; room_impl->room_information.preferred_game_id = preferred_game_id; room_impl->room_information.host_username = host_username; + room_impl->room_information.enable_citra_mods = enable_citra_mods; room_impl->password = password; room_impl->verify_backend = std::move(verify_backend); room_impl->username_ban_list = ban_list.first; diff --git a/src/network/room.h b/src/network/room.h index 5781631d7..a67984837 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -32,6 +32,7 @@ struct RoomInformation { std::string preferred_game; ///< Game to advertise that you want to play u64 preferred_game_id; ///< Title ID for the advertised game std::string host_username; ///< Forum username of the host + bool enable_citra_mods; ///< Allow Citra Moderators to moderate on this room }; struct GameInfo { @@ -147,7 +148,7 @@ public: const std::string& host_username = "", const std::string& preferred_game = "", u64 preferred_game_id = 0, std::unique_ptr verify_backend = nullptr, - const BanList& ban_list = {}); + const BanList& ban_list = {}, bool enable_citra_mods = false); /** * Sets the verification GUID of the room.