diff --git a/src/citra_qt/multiplayer/lobby.cpp b/src/citra_qt/multiplayer/lobby.cpp index c40c00375..c1d48d9c6 100644 --- a/src/citra_qt/multiplayer/lobby.cpp +++ b/src/citra_qt/multiplayer/lobby.cpp @@ -21,13 +21,24 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, std::shared_ptr session) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), - ui(std::make_unique()), announce_multiplayer_session(session), game_list(list) { + ui(std::make_unique()), announce_multiplayer_session(session) { ui->setupUi(this); // setup the watcher for background connections watcher = new QFutureWatcher; model = new QStandardItemModel(ui->room_list); + + // Create a proxy to the game list to get the list of games owned + game_list = new QStandardItemModel; + + for (int i = 0; i < list->rowCount(); i++) { + auto parent = list->item(i, 0); + for (int j = 0; j < parent->rowCount(); j++) { + game_list->appendRow(parent->child(j)->clone()); + } + } + proxy = new LobbyFilterProxyModel(this, game_list); proxy->setSourceModel(model); proxy->setDynamicSortFilter(true); @@ -114,20 +125,21 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { return; } + QModelIndex connection_index = proxy->index(index.row(), Column::HOST); + const std::string nickname = ui->nickname->text().toStdString(); + const std::string ip = + proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString(); + int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt(); + // attempt to connect in a different thread - QFuture f = QtConcurrent::run([&, password] { + QFuture f = QtConcurrent::run([nickname, ip, port, password] { if (auto room_member = Network::GetRoomMember().lock()) { - QModelIndex connection_index = proxy->index(index.row(), Column::HOST); - const std::string nickname = ui->nickname->text().toStdString(); - const std::string ip = - proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString(); - int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt(); room_member->Join(nickname, ip.c_str(), port, 0, Network::NoPreferredMac, password); } }); watcher->setFuture(f); - // and disable widgets and display a connecting while we wait - QModelIndex connection_index = proxy->index(index.row(), Column::HOST); + + // TODO(jroweboy): disable widgets and display a connecting while we wait // Save settings UISettings::values.nickname = ui->nickname->text(); diff --git a/src/citra_qt/multiplayer/validation.h b/src/citra_qt/multiplayer/validation.h index 4e8f6b9e9..158ac52cb 100644 --- a/src/citra_qt/multiplayer/validation.h +++ b/src/citra_qt/multiplayer/validation.h @@ -28,12 +28,12 @@ public: } private: - /// room name can be alphanumeric and " " "_" "." and "-" - QRegExp room_name_regex = QRegExp("^[a-zA-Z0-9._- ]+$"); + /// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20 + QRegExp room_name_regex = QRegExp("^[a-zA-Z0-9._- ]{4,20}$"); QRegExpValidator room_name; - /// nickname can be alphanumeric and " " "_" "." and "-" - QRegExp nickname_regex = QRegExp("^[a-zA-Z0-9._- ]+$"); + /// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20 + QRegExp nickname_regex = QRegExp("^[a-zA-Z0-9._- ]{4,20}$"); QRegExpValidator nickname; /// ipv4 address only