diff --git a/simple64-gui/netplay/createroom.cpp b/simple64-gui/netplay/createroom.cpp index 1d2647a..377225a 100644 --- a/simple64-gui/netplay/createroom.cpp +++ b/simple64-gui/netplay/createroom.cpp @@ -175,9 +175,10 @@ void CreateRoom::createRoom() json.insert("game_name", QString(rom_settings.goodname)); json.insert("client_sha", QStringLiteral(GUI_VERSION)); json.insert("netplay_version", NETPLAY_VER); - json.insert("emulator", "simple64"); + addAuthData(webSocket, &json); - sendNetplayMessage(webSocket, json); + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); } void CreateRoom::processTextMessage(QString message) diff --git a/simple64-gui/netplay/joinroom.cpp b/simple64-gui/netplay/joinroom.cpp index 6939a32..3345114 100644 --- a/simple64-gui/netplay/joinroom.cpp +++ b/simple64-gui/netplay/joinroom.cpp @@ -178,7 +178,8 @@ void JoinRoom::joinGame() json.insert("MD5", QString(rom_settings.MD5)); json.insert("port", room_port); - sendNetplayMessage(webSocket, json); + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); } else { @@ -257,8 +258,10 @@ void JoinRoom::onConnected() QJsonObject json; json.insert("type", "request_get_rooms"); json.insert("netplay_version", NETPLAY_VER); - json.insert("emulator", "simple64"); - sendNetplayMessage(webSocket, json); + addAuthData(webSocket, &json); + + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); } void JoinRoom::processTextMessage(QString message) diff --git a/simple64-gui/netplay/netplay_common.cpp b/simple64-gui/netplay/netplay_common.cpp index f58f4b6..14ccc62 100644 --- a/simple64-gui/netplay/netplay_common.cpp +++ b/simple64-gui/netplay/netplay_common.cpp @@ -1,7 +1,6 @@ #include "netplay_common.h" -#include -void sendNetplayMessage(QWebSocket* webSocket, QJsonObject json) +void addAuthData(QWebSocket* webSocket, QJsonObject* json) { QCryptographicHash hash = QCryptographicHash(QCryptographicHash::Sha256); QByteArray currentTime = QByteArray::number(QDateTime::currentMSecsSinceEpoch()); @@ -10,9 +9,7 @@ void sendNetplayMessage(QWebSocket* webSocket, QJsonObject json) // this auth code is emulator specific, and is only checked when the server is running with the --enable-auth option hash.addData(QStringLiteral(NETPLAY_AUTH_CODE).toUtf8()); - json.insert("auth", QString(hash.result().toHex())); - json.insert("authTime", QString(currentTime)); - - QJsonDocument json_doc(json); - webSocket->sendTextMessage(json_doc.toJson()); + json->insert("auth", QString(hash.result().toHex())); + json->insert("authTime", QString(currentTime)); + json->insert("emulator", "simple64"); } diff --git a/simple64-gui/netplay/netplay_common.h b/simple64-gui/netplay/netplay_common.h index 294eab2..ea983de 100644 --- a/simple64-gui/netplay/netplay_common.h +++ b/simple64-gui/netplay/netplay_common.h @@ -4,6 +4,6 @@ #include #include -void sendNetplayMessage(QWebSocket* webSocket, QJsonObject json); +void addAuthData(QWebSocket* webSocket, QJsonObject* json); #endif diff --git a/simple64-gui/netplay/waitroom.cpp b/simple64-gui/netplay/waitroom.cpp index 99b567b..2de63d7 100644 --- a/simple64-gui/netplay/waitroom.cpp +++ b/simple64-gui/netplay/waitroom.cpp @@ -1,7 +1,6 @@ #include "waitroom.h" #include "../mainwindow.h" #include "../interface/core_commands.h" -#include "netplay_common.h" #include #include #include @@ -88,7 +87,8 @@ WaitRoom::WaitRoom(QString filename, QJsonObject room, QWebSocket *socket, QWidg QJsonObject json; json.insert("type", "request_players"); json.insert("port", room_port); - sendNetplayMessage(webSocket, json); + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &WaitRoom::sendPing); @@ -113,7 +113,8 @@ void WaitRoom::sendPing() QJsonObject json; json.insert("type", "request_motd"); json.insert("room_name", room_name); - sendNetplayMessage(webSocket, json); + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); } webSocket->ping(); } @@ -131,7 +132,8 @@ void WaitRoom::startGame() QJsonObject json; json.insert("type", "request_begin_game"); json.insert("port", room_port); - sendNetplayMessage(webSocket, json); + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); } else { @@ -150,7 +152,8 @@ void WaitRoom::sendChat() json.insert("port", room_port); json.insert("player_name", player_name); json.insert("message", chatEdit->text()); - sendNetplayMessage(webSocket, json); + QJsonDocument json_doc(json); + webSocket->sendTextMessage(json_doc.toJson()); chatEdit->clear(); } }