2018-01-19 14:42:21 +01:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <future>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QList>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QMetaType>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
|
|
|
#include "citra_qt/game_list_p.h"
|
|
|
|
#include "citra_qt/multiplayer/client_room.h"
|
|
|
|
#include "citra_qt/multiplayer/message.h"
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/announce_multiplayer_session.h"
|
2018-04-18 18:29:03 +02:00
|
|
|
#include "ui_client_room.h"
|
2018-01-19 14:42:21 +01:00
|
|
|
|
|
|
|
ClientRoomWindow::ClientRoomWindow(QWidget* parent)
|
|
|
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
|
2018-04-18 07:06:02 +02:00
|
|
|
ui(std::make_unique<Ui::ClientRoom>()) {
|
2018-01-19 14:42:21 +01:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
// setup the callbacks for network updates
|
|
|
|
if (auto member = Network::GetRoomMember().lock()) {
|
|
|
|
member->BindOnRoomInformationChanged(
|
|
|
|
[this](const Network::RoomInformation& info) { emit RoomInformationChanged(info); });
|
|
|
|
member->BindOnStateChanged(
|
|
|
|
[this](const Network::RoomMember::State& state) { emit StateChanged(state); });
|
|
|
|
|
|
|
|
connect(this, &ClientRoomWindow::RoomInformationChanged, this,
|
|
|
|
&ClientRoomWindow::OnRoomUpdate);
|
|
|
|
connect(this, &ClientRoomWindow::StateChanged, this, &::ClientRoomWindow::OnStateChange);
|
|
|
|
} else {
|
|
|
|
// TODO (jroweboy) network was not initialized?
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui->disconnect, &QPushButton::pressed, [this] { Disconnect(); });
|
|
|
|
ui->disconnect->setDefault(false);
|
|
|
|
ui->disconnect->setAutoDefault(false);
|
|
|
|
UpdateView();
|
|
|
|
}
|
|
|
|
|
2018-04-18 18:29:03 +02:00
|
|
|
ClientRoomWindow::~ClientRoomWindow() = default;
|
|
|
|
|
2018-01-19 14:42:21 +01:00
|
|
|
void ClientRoomWindow::OnRoomUpdate(const Network::RoomInformation& info) {
|
|
|
|
UpdateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
|
|
|
|
switch (state) {
|
|
|
|
case Network::RoomMember::State::Idle:
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: Idle");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::Joining:
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: Joining");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::Joined:
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: Joined");
|
2018-01-19 14:42:21 +01:00
|
|
|
ui->chat->Clear();
|
|
|
|
ui->chat->AppendStatusMessage(tr("Connected"));
|
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::LostConnection:
|
|
|
|
NetworkMessage::ShowError(NetworkMessage::LOST_CONNECTION);
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: LostConnection");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::CouldNotConnect:
|
|
|
|
NetworkMessage::ShowError(NetworkMessage::UNABLE_TO_CONNECT);
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: CouldNotConnect");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::NameCollision:
|
|
|
|
NetworkMessage::ShowError(NetworkMessage::USERNAME_IN_USE);
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: NameCollision");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::MacCollision:
|
|
|
|
NetworkMessage::ShowError(NetworkMessage::MAC_COLLISION);
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: MacCollision");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::WrongPassword:
|
|
|
|
NetworkMessage::ShowError(NetworkMessage::WRONG_PASSWORD);
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: WrongPassword");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
case Network::RoomMember::State::WrongVersion:
|
|
|
|
NetworkMessage::ShowError(NetworkMessage::WRONG_VERSION);
|
2018-04-18 07:06:02 +02:00
|
|
|
NGLOG_INFO(Network, "State: WrongVersion");
|
2018-01-19 14:42:21 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UpdateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientRoomWindow::Disconnect() {
|
|
|
|
if (!NetworkMessage::WarnDisconnect()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto member = Network::GetRoomMember().lock()) {
|
|
|
|
member->Leave();
|
|
|
|
ui->chat->AppendStatusMessage(tr("Disconnected"));
|
2018-04-05 20:07:11 +02:00
|
|
|
close();
|
|
|
|
emit Closed();
|
2018-01-19 14:42:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientRoomWindow::UpdateView() {
|
|
|
|
if (auto member = Network::GetRoomMember().lock()) {
|
|
|
|
if (member->IsConnected()) {
|
|
|
|
ui->chat->Enable();
|
|
|
|
ui->disconnect->setEnabled(true);
|
|
|
|
auto memberlist = member->GetMemberInformation();
|
|
|
|
ui->chat->SetPlayerList(memberlist);
|
|
|
|
const auto information = member->GetRoomInformation();
|
|
|
|
setWindowTitle(QString(tr("%1 (%2/%3 members) - connected"))
|
|
|
|
.arg(QString::fromStdString(information.name))
|
|
|
|
.arg(memberlist.size())
|
|
|
|
.arg(information.member_slots));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO(B3N30): can't get RoomMember*, show error and close window
|
|
|
|
close();
|
|
|
|
emit Closed();
|
|
|
|
return;
|
|
|
|
}
|