Skip to content

Commit

Permalink
Refactor lobby connection method
Browse files Browse the repository at this point in the history
  • Loading branch information
palindromiq committed Feb 21, 2022
1 parent 2715426 commit 3c28df8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
5 changes: 5 additions & 0 deletions discordmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ void DiscordManager::sendMessageToLobby(QString msg)
}
}

long long DiscordManager::getLobbyId() const
{
return lobbyId_;
}



bool DiscordManager::running() const
Expand Down
2 changes: 2 additions & 0 deletions discordmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class DiscordManager : public QObject

bool running() const;

long long getLobbyId() const;

public slots:
void start();
void stop();
Expand Down
47 changes: 27 additions & 20 deletions yatewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ void Yate::YATEWindow::initDiscord()
#endif
}

void YATEWindow::establishLobbyConnection(QString lobbyId)
{
if (!lobbyId.size()) {
qDebug() << "Returned empty Lobby Id";
return;
}
qDebug() << "Connecting to Lobby ID" << lobbyId;
auto split = lobbyId.split(":");
if (split.size() != 2) {
QMessageBox::critical(this, "Error", "Invalid code format.");
return;
}
if (split[0] == QString::number(discord_->getLobbyId())) {
QMessageBox::critical(this, "Error", "Cannot to connect to self-lobby.");
return;
}
if(discord_->connectTo(lobbyId)) {
qDebug() << "Passed initial connection to Lobby";
showClientLiveFeedback(false);
} else {
qCritical() << "Failed at initial connection to Lobby";
QMessageBox::critical(this, "Error", "Failed to establish connection to lobby, double check the input value.");
}
}


void YATEWindow::dragEnterEvent(QDragEnterEvent *e)
{
Expand Down Expand Up @@ -472,14 +497,7 @@ void YATEWindow::onUserConnected(QString name)
return;
}

qDebug() << "Connecting to Lobby ID" << lobbyId;
if(discord_->connectTo(lobbyId)) {
qDebug() << "Passed initial connection to Lobby";
showClientLiveFeedback(false);
} else {
qCritical() << "Failed at initial connection to Lobby";
QMessageBox::critical(this, "Error", "Failed to establish connection to lobby, double check the input value.");
}
establishLobbyConnection(lobbyId);
#else
QMessageBox::critical(this, "Discord Features Required", "Discord features are needed but not supported by this version.");
return;
Expand Down Expand Up @@ -578,18 +596,7 @@ void YATEWindow::on_btnLiveFeedbackVS_clicked()
return;
}
QString lobbyId = QInputDialog::getText(this, "Host Lobby ID", "Enter the host's Lobby ID").trimmed();
if (!lobbyId.size()) {
qDebug() << "Returned empty Lobby Id";
return;
}
qDebug() << "Connecting to Lobby ID" << lobbyId;
if(discord_->connectTo(lobbyId)) {
qDebug() << "Passed initial connection to Lobby";
showClientLiveFeedback(false);
} else {
qCritical() << "Failed at initial connection to Lobby";
QMessageBox::critical(this, "Error", "Failed to establish connection to lobby, double check the input value.");
}
establishLobbyConnection(lobbyId);
#else
QMessageBox::critical(this, "Discord Features Required", "Discord features are needed but not supported by this version.");
return;
Expand Down
1 change: 1 addition & 0 deletions yatewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public slots:
QAtomicInt isLiveFeedbackRunning_;
QString codeURI_;
void initDiscord();
void establishLobbyConnection(QString lobbyId);
};
}
#endif // YATEWINDOW_H

0 comments on commit 3c28df8

Please sign in to comment.