RMG: update netplay to API version 17

This commit is contained in:
Rosalie Wanders
2024-12-27 22:50:50 +01:00
parent 9b5a7848d3
commit 72b3b4fb75
5 changed files with 55 additions and 40 deletions
@@ -200,8 +200,6 @@ void CreateNetplaySessionDialog::on_networkAccessManager_Finished(QNetworkReply*
this->serverComboBox->addItem(jsonServers.at(i), jsonObject.value(jsonServers.at(i)).toString());
}
// TODO: custom server support
//this->serverComboBox->addItem(QString("Custom"), QString("Custom"));
reply->deleteLater();
}
@@ -263,13 +261,15 @@ void CreateNetplaySessionDialog::accept()
jsonFeatures.insert("gfx_plugin", plugins[1]);
QJsonObject json;
QJsonObject session;
session.insert("room_name", this->sessionNameLineEdit->text());
session.insert("password", this->passwordLineEdit->text());
session.insert("MD5", romData.MD5);
session.insert("game_name", this->getGameName(romData.GoodName, romData.File));
session.insert("features", jsonFeatures);
json.insert("type", "request_create_room");
json.insert("room_name", this->sessionNameLineEdit->text());
json.insert("player_name", this->nickNameLineEdit->text());
json.insert("password", this->passwordLineEdit->text());
json.insert("MD5", romData.MD5);
json.insert("game_name", this->getGameName(romData.GoodName, romData.File));
json.insert("features", jsonFeatures);
json.insert("room", session);
NetplayCommon::AddCommonJson(json);
this->webSocket->sendTextMessage(QJsonDocument(json).toJson());
@@ -29,7 +29,7 @@ void NetplayCommon::AddCommonJson(QJsonObject& json)
json.insert("emulator", "RMG");
json.insert("auth", QString(hash.result().toHex()));
json.insert("authTime", QString(currentTime));
json.insert("netplay_version", 16);
json.insert("netplay_version", 17);
}
QList<QString> NetplayCommon::GetPluginNames(QString md5QString)
@@ -20,6 +20,7 @@
#include <QPushButton>
#include <QFileDialog>
#include <QJsonObject>
#include <QJsonArray>
#include <RMG-Core/Core.hpp>
@@ -188,24 +189,23 @@ void NetplaySessionBrowserDialog::on_webSocket_textMessageReceived(QString messa
{
if (json.value("accept").toInt() == 0)
{
this->sessionBrowserWidget->AddSessionData(json.value("room_name").toString(),
json.value("game_name").toString(),
json.value("MD5").toString(),
json.value("protected").toBool(),
json.value("port").toInt(),
json.value("features").toObject().value("cpu_emulator").toString(),
json.value("features").toObject().value("rsp_plugin").toString(),
json.value("features").toObject().value("gfx_plugin").toString());
}
else
{
QtMessageBox::Error(this, "Server Error", json.value("message").toString());
}
}
else if (type == "reply_get_rooms_done")
{
if (json.value("accept").toInt() == 0)
{
QJsonArray sessions = json.value("rooms").toArray();
QJsonObject session;
for (int i = 0; i < sessions.size(); i++)
{
session = sessions.at(i).toObject();
this->sessionBrowserWidget->AddSessionData(session.value("room_name").toString(),
session.value("game_name").toString(),
session.value("MD5").toString(),
session.value("protected").toBool(),
session.value("port").toInt(),
session.value("features").toObject().value("cpu_emulator").toString(),
session.value("features").toObject().value("rsp_plugin").toString(),
session.value("features").toObject().value("gfx_plugin").toString());
}
// we're done refreshing the sessions
this->sessionBrowserWidget->RefreshDone();
// enable refresh button when refreshing is done
QPushButton* refreshButton = this->buttonBox->button(QDialogButtonBox::RestoreDefaults);
@@ -391,11 +391,14 @@ void NetplaySessionBrowserDialog::accept()
}
QJsonObject json;
QJsonObject session;
json.insert("type", "request_join_room");
json.insert("port", sessionData.Port);
json.insert("player_name", this->nickNameLineEdit->text());
json.insert("password", password);
json.insert("MD5", QString::fromStdString(md5));
session.insert("port", sessionData.Port);
session.insert("password", password);
session.insert("MD5", QString::fromStdString(md5));
json.insert("room", session);
NetplayCommon::AddCommonJson(json);
this->webSocket->sendTextMessage(QJsonDocument(json).toJson());
@@ -22,32 +22,39 @@
using namespace UserInterface::Dialog;
using namespace Utilities;
NetplaySessionDialog::NetplaySessionDialog(QWidget *parent, QWebSocket* webSocket, QJsonObject sessionJson, QString sessionFile) : QDialog(parent)
NetplaySessionDialog::NetplaySessionDialog(QWidget *parent, QWebSocket* webSocket, QJsonObject json, QString sessionFile) : QDialog(parent)
{
this->setupUi(this);
this->webSocket = webSocket;
this->nickName = sessionJson.value("player_name").toString();
this->sessionPort = sessionJson.value("port").toInt();
this->sessionName = sessionJson.value("room_name").toString();
QJsonObject session = json.value("room").toObject();
this->nickName = json.value("player_name").toString();
this->sessionPort = session.value("port").toInt();
this->sessionName = session.value("room_name").toString();
this->sessionFile = sessionFile;
this->sessionNameLineEdit->setText(this->sessionName);
this->gameNameLineEdit->setText(sessionJson.value("game_name").toString());
this->gameNameLineEdit->setText(session.value("game_name").toString());
connect(this->webSocket, &QWebSocket::textMessageReceived, this, &NetplaySessionDialog::on_webSocket_textMessageReceived);
// reset json objects
session = {};
json = {};
// request server motd
QJsonObject json;
json.insert("type", "request_motd");
json.insert("room_name", this->sessionName);
NetplayCommon::AddCommonJson(json);
webSocket->sendTextMessage(QJsonDocument(json).toJson());
// request players
json = {};
session.insert("port", this->sessionPort);
json.insert("type", "request_players");
json.insert("port", this->sessionPort);
json.insert("room", session);
NetplayCommon::AddCommonJson(json);
webSocket->sendTextMessage(QJsonDocument(json).toJson());
@@ -72,9 +79,10 @@ void NetplaySessionDialog::on_webSocket_textMessageReceived(QString message)
{
this->listWidget->clear();
QString name;
QJsonArray names = json.value("player_names").toArray();
for (int i = 0; i < 4; i++)
{
name = json.value("player_names").toArray().at(i).toString();
name = names.at(i).toString();
if (!name.isEmpty())
{
this->listWidget->addItem(name);
@@ -117,10 +125,12 @@ void NetplaySessionDialog::on_chatLineEdit_textChanged(QString text)
void NetplaySessionDialog::on_sendPushButton_clicked(void)
{
QJsonObject json;
QJsonObject session;
session.insert("port", this->sessionPort);
json.insert("type", "request_chat_message");
json.insert("port", this->sessionPort);
json.insert("player_name", this->nickName);
json.insert("message", this->chatLineEdit->text());
json.insert("room", session);
NetplayCommon::AddCommonJson(json);
webSocket->sendTextMessage(QJsonDocument(json).toJson());
@@ -133,8 +143,10 @@ void NetplaySessionDialog::accept()
startButton->setEnabled(false);
QJsonObject json;
QJsonObject session;
session.insert("port", this->sessionPort);
json.insert("type", "request_begin_game");
json.insert("port", this->sessionPort);
json.insert("room", session);
NetplayCommon::AddCommonJson(json);
webSocket->sendTextMessage(QJsonDocument(json).toJson());
@@ -26,7 +26,7 @@ class NetplaySessionDialog : public QDialog, private Ui::NetplaySessionDialog
Q_OBJECT
public:
NetplaySessionDialog(QWidget *parent, QWebSocket* webSocket, QJsonObject sessionJson, QString sessionFile);
NetplaySessionDialog(QWidget *parent, QWebSocket* webSocket, QJsonObject json, QString sessionFile);
~NetplaySessionDialog(void);
private: