From deb398d190459b1fcdb238c12b9a7a9b9df6b344 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Sat, 24 Nov 2018 16:22:49 +0800 Subject: [PATCH] citra_qt: Save ban list for room hosting --- src/citra_qt/configuration/config.cpp | 28 ++++++++++++++++++++++++++ src/citra_qt/multiplayer/host_room.cpp | 9 +++++++-- src/citra_qt/multiplayer/host_room.ui | 14 +++++++++++++ src/citra_qt/multiplayer/state.cpp | 5 +++++ src/citra_qt/ui_settings.h | 3 +++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 5a69a2d305..dcbe181221 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -330,6 +330,21 @@ void Config::ReadValues() { UISettings::values.max_player = ReadSetting("max_player", 8).toUInt(); UISettings::values.game_id = ReadSetting("game_id", 0).toULongLong(); UISettings::values.room_description = ReadSetting("room_description", "").toString(); + // Read ban list back + size = qt_config->beginReadArray("username_ban_list"); + UISettings::values.ban_list.first.resize(size); + for (int i = 0; i < size; ++i) { + qt_config->setArrayIndex(i); + UISettings::values.ban_list.first[i] = ReadSetting("username").toString().toStdString(); + } + qt_config->endArray(); + size = qt_config->beginReadArray("ip_ban_list"); + UISettings::values.ban_list.second.resize(size); + for (int i = 0; i < size; ++i) { + qt_config->setArrayIndex(i); + UISettings::values.ban_list.second[i] = ReadSetting("ip").toString().toStdString(); + } + qt_config->endArray(); qt_config->endGroup(); qt_config->endGroup(); @@ -535,6 +550,19 @@ void Config::SaveValues() { WriteSetting("max_player", UISettings::values.max_player, 8); WriteSetting("game_id", UISettings::values.game_id, 0); WriteSetting("room_description", UISettings::values.room_description, ""); + // Write ban list + qt_config->beginWriteArray("username_ban_list"); + for (std::size_t i = 0; i < UISettings::values.ban_list.first.size(); ++i) { + qt_config->setArrayIndex(i); + WriteSetting("username", QString::fromStdString(UISettings::values.ban_list.first[i])); + } + qt_config->endArray(); + qt_config->beginWriteArray("ip_ban_list"); + for (std::size_t i = 0; i < UISettings::values.ban_list.second.size(); ++i) { + qt_config->setArrayIndex(i); + WriteSetting("ip", QString::fromStdString(UISettings::values.ban_list.second[i])); + } + qt_config->endArray(); qt_config->endGroup(); qt_config->endGroup(); diff --git a/src/citra_qt/multiplayer/host_room.cpp b/src/citra_qt/multiplayer/host_room.cpp index 27ab37f463..d5f093e48a 100644 --- a/src/citra_qt/multiplayer/host_room.cpp +++ b/src/citra_qt/multiplayer/host_room.cpp @@ -127,11 +127,16 @@ void HostRoomWindow::Host() { auto port = ui->port->isModified() ? ui->port->text().toInt() : Network::DefaultRoomPort; auto password = ui->password->text().toStdString(); const bool is_public = ui->host_type->currentIndex() == 0; + Network::Room::BanList ban_list{}; + if (ui->load_ban_list->isChecked()) { + ban_list = UISettings::values.ban_list; + } if (auto room = Network::GetRoom().lock()) { bool created = room->Create(ui->room_name->text().toStdString(), ui->room_description->toPlainText().toStdString(), "", port, - password, ui->max_player->value(), game_name.toStdString(), - game_id, CreateVerifyBackend(is_public)); + password, ui->max_player->value(), + Settings::values.citra_username, game_name.toStdString(), + game_id, CreateVerifyBackend(is_public), ban_list); if (!created) { NetworkMessage::ShowError(NetworkMessage::COULD_NOT_CREATE_ROOM); LOG_ERROR(Network, "Could not create room!"); diff --git a/src/citra_qt/multiplayer/host_room.ui b/src/citra_qt/multiplayer/host_room.ui index 5084ef7f42..d54cf49c65 100644 --- a/src/citra_qt/multiplayer/host_room.ui +++ b/src/citra_qt/multiplayer/host_room.ui @@ -145,6 +145,20 @@ + + + + + + Load Previous Ban List + + + true + + + + + diff --git a/src/citra_qt/multiplayer/state.cpp b/src/citra_qt/multiplayer/state.cpp index 996af55b33..2970c06918 100644 --- a/src/citra_qt/multiplayer/state.cpp +++ b/src/citra_qt/multiplayer/state.cpp @@ -13,6 +13,7 @@ #include "citra_qt/multiplayer/lobby.h" #include "citra_qt/multiplayer/message.h" #include "citra_qt/multiplayer/state.h" +#include "citra_qt/ui_settings.h" #include "citra_qt/util/clickable_label.h" #include "common/announce_multiplayer_room.h" #include "common/logging/log.h" @@ -213,6 +214,10 @@ bool MultiplayerState::OnCloseRoom() { if (room->GetState() != Network::Room::State::Open) { return true; } + // Save ban list + if (auto room = Network::GetRoom().lock()) { + UISettings::values.ban_list = std::move(room->GetBanList()); + } room->Destroy(); announce_multiplayer_session->Stop(); LOG_DEBUG(Frontend, "Closed the room (as a server)"); diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h index b26d693644..d623b14dae 100644 --- a/src/citra_qt/ui_settings.h +++ b/src/citra_qt/ui_settings.h @@ -5,6 +5,8 @@ #pragma once #include +#include +#include #include #include #include @@ -110,6 +112,7 @@ struct Values { uint host_type; qulonglong game_id; QString room_description; + std::pair, std::vector> ban_list; // logging bool show_console;