- 更新拓展包时增加更多的提示信息
- 增加版本检测系统,同时修改了安装AES密钥的时机
- 修复了偶发性的因进房导致的闪退(或许吧)
This commit is contained in:
notify 2023-05-19 07:45:36 +08:00 committed by GitHub
parent ce2cae0aa5
commit 0d709d6a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 9 deletions

View File

@ -45,6 +45,18 @@
</message> </message>
</context> </context>
<context>
<name>PackMan</name>
<message>
<source>Syncing packages, please do not close the application.</source>
<translation></translation>
</message>
<message>
<source>[%1/%2] upgrading package '%3'</source>
<translation>[%1/%2] '%3'</translation>
</message>
</context>
<context> <context>
<name>Init</name> <name>Init</name>
<message> <message>
@ -135,6 +147,18 @@
<source>username or password error</source> <source>username or password error</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>INVALID SETUP STRING</source>
<translation></translation>
</message>
<message>
<source>server is still on version %1</source>
<translation>使(%1)使</translation>
</message>
<message>
<source>server is using version %1, please update</source>
<translation>使%1</translation>
</message>
</context> </context>
<context> <context>

View File

@ -35,12 +35,19 @@ callbacks["NetworkDelayTest"] = function(jsonData) {
} }
config.cipherText = cipherText; config.cipherText = cipherText;
Backend.replyDelayTest(config.screenName, cipherText); Backend.replyDelayTest(config.screenName, cipherText);
Backend.installAESKey();
} }
callbacks["ErrorMsg"] = function(jsonData) { callbacks["ErrorMsg"] = function(jsonData) {
console.log("ERROR: " + jsonData); let log;
toast.show(qsTr(jsonData), 5000); try {
let a = JSON.parse(jsonData);
log = qsTr(a[0]).arg(a[1]);
} catch (e) {
log = qsTr(jsonData);
}
console.log("ERROR: " + log);
toast.show(log, 5000);
mainWindow.busy = false; mainWindow.busy = false;
if (sheduled_download !== "") { if (sheduled_download !== "") {
mainWindow.busy = true; mainWindow.busy = true;
@ -139,3 +146,6 @@ callbacks["ServerMessage"] = function(jsonData) {
let current = mainStack.currentItem; // lobby or room let current = mainStack.currentItem; // lobby or room
current.sendDanmaku('<font color="gold"><b>[Server] </b></font>' + jsonData); current.sendDanmaku('<font color="gold"><b>[Server] </b></font>' + jsonData);
} }
callbacks["ShowToast"] = (j) => toast.show(j);
callbacks["InstallKey"] = (j) => Backend.installAESKey();

View File

@ -32,18 +32,27 @@ QString PackMan::getPackSummary() {
} }
void PackMan::loadSummary(const QString &jsonData, bool useThread) { void PackMan::loadSummary(const QString &jsonData, bool useThread) {
auto f = [=]() { static const auto f = [=]() {
// First, disable all packages // First, disable all packages
foreach (auto e, SelectFromDatabase(db, "SELECT name FROM packages;")) { foreach (auto e, SelectFromDatabase(db, "SELECT name FROM packages;")) {
disablePack(e.toObject()["name"].toString()); disablePack(e.toObject()["name"].toString());
} }
#ifndef FK_SERVER_ONLY
Backend->showToast(tr("Syncing packages, please do not close the application."));
#endif
// Then read conf from string // Then read conf from string
auto doc = QJsonDocument::fromJson(jsonData.toUtf8()); auto doc = QJsonDocument::fromJson(jsonData.toUtf8());
auto arr = doc.array(); auto arr = doc.array();
int i = 0;
foreach (auto e, arr) { foreach (auto e, arr) {
i++;
auto obj = e.toObject(); auto obj = e.toObject();
auto name = obj["name"].toString(); auto name = obj["name"].toString();
#ifndef FK_SERVER_ONLY
Backend->showToast(tr("[%1/%2] upgrading package '%3'").arg(i).arg(arr.count()).arg(name));
#endif
if (SelectFromDatabase( if (SelectFromDatabase(
db, db,
QString("SELECT name FROM packages WHERE name='%1';").arg(name)) QString("SELECT name FROM packages WHERE name='%1';").arg(name))
@ -72,7 +81,7 @@ void PackMan::loadSummary(const QString &jsonData, bool useThread) {
} }
void PackMan::downloadNewPack(const QString &url, bool useThread) { void PackMan::downloadNewPack(const QString &url, bool useThread) {
auto threadFunc = [=]() { static const auto threadFunc = [=]() {
int error = clone(url); int error = clone(url);
if (error < 0) if (error < 0)
return; return;

View File

@ -209,13 +209,23 @@ void Router::handlePacket(const QByteArray &rawPacket) {
const QString &jsonData) { const QString &jsonData) {
auto arr = String2Json(jsonData).array(); auto arr = String2Json(jsonData).array();
auto roomId = arr[0].toInt(); auto roomId = arr[0].toInt();
ServerInstance->findRoom(roomId)->addPlayer(sender); auto room = ServerInstance->findRoom(roomId);
if (room) {
room->addPlayer(sender);
} else {
sender->doNotify("ErrorMsg", "no such room");
}
}; };
lobby_actions["ObserveRoom"] = [](ServerPlayer *sender, lobby_actions["ObserveRoom"] = [](ServerPlayer *sender,
const QString &jsonData) { const QString &jsonData) {
auto arr = String2Json(jsonData).array(); auto arr = String2Json(jsonData).array();
auto roomId = arr[0].toInt(); auto roomId = arr[0].toInt();
ServerInstance->findRoom(roomId)->addObserver(sender); auto room = ServerInstance->findRoom(roomId);
if (room) {
room->addObserver(sender);
} else {
sender->doNotify("ErrorMsg", "no such room");
}
}; };
lobby_actions["Chat"] = [](ServerPlayer *sender, const QString &jsonData) { lobby_actions["Chat"] = [](ServerPlayer *sender, const QString &jsonData) {
sender->getRoom()->chat(sender, jsonData); sender->getRoom()->chat(sender, jsonData);

View File

@ -6,6 +6,7 @@
#include <qjsondocument.h> #include <qjsondocument.h>
#include <qjsonvalue.h> #include <qjsonvalue.h>
#include <qobject.h> #include <qobject.h>
#include <qversionnumber.h>
#include "client_socket.h" #include "client_socket.h"
#include "packman.h" #include "packman.h"
@ -193,7 +194,7 @@ void Server::processRequest(const QByteArray &msg) {
doc[2] != "Setup") doc[2] != "Setup")
valid = false; valid = false;
else else
valid = (String2Json(doc[3].toString()).array().size() == 3); valid = (String2Json(doc[3].toString()).array().size() == 4);
} }
if (!valid) { if (!valid) {
@ -211,6 +212,30 @@ void Server::processRequest(const QByteArray &msg) {
QJsonArray arr = String2Json(doc[3].toString()).array(); QJsonArray arr = String2Json(doc[3].toString()).array();
auto client_ver = QVersionNumber::fromString(arr[3].toString());
auto ver = QVersionNumber::fromString(FK_VERSION);
int cmp = QVersionNumber::compare(ver, client_ver);
if (cmp != 0) {
QJsonArray body;
body << -2;
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER |
Router::DEST_CLIENT);
body << "ErrorMsg";
body
<< (cmp < 0
? QString("[\"server is still on version %%2\",\"%1\"]")
.arg(FK_VERSION)
.arg("1")
: QString(
"[\"server is using version %%2, please update\",\"%1\"]")
.arg(FK_VERSION)
.arg("1"));
client->send(JsonArray2Bytes(body));
client->disconnectFromHost();
return;
}
handleNameAndPassword(client, arr[0].toString(), arr[1].toString(), handleNameAndPassword(client, arr[0].toString(), arr[1].toString(),
arr[2].toString()); arr[2].toString());
} }
@ -227,6 +252,16 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
if (decrypted_pw.length() > 32) { if (decrypted_pw.length() > 32) {
auto aes_bytes = decrypted_pw.first(32); auto aes_bytes = decrypted_pw.first(32);
// tell client to install aes key
QJsonArray body;
body << -2;
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER |
Router::DEST_CLIENT);
body << "InstallKey";
body << "";
client->send(JsonArray2Bytes(body));
client->installAESKey(aes_bytes); client->installAESKey(aes_bytes);
decrypted_pw.remove(0, 32); decrypted_pw.remove(0, 32);
} else { } else {

View File

@ -254,7 +254,7 @@ void QmlBackend::replyDelayTest(const QString &screenName,
auto md5 = calcFileMD5(); auto md5 = calcFileMD5();
QJsonArray arr; QJsonArray arr;
arr << screenName << cipher << md5; arr << screenName << cipher << md5 << FK_VERSION;
ClientInstance->notifyServer("Setup", JsonArray2Bytes(arr)); ClientInstance->notifyServer("Setup", JsonArray2Bytes(arr));
} }

View File

@ -53,6 +53,8 @@ public:
qreal volume() const { return m_volume; } qreal volume() const { return m_volume; }
void setVolume(qreal v) { m_volume = v; } void setVolume(qreal v) { m_volume = v; }
void showToast(const QString &s) { emit notifyUI("ShowToast", s); }
signals: signals:
void notifyUI(const QString &command, const QString &jsonData); void notifyUI(const QString &command, const QString &jsonData);
void volumeChanged(qreal); void volumeChanged(qreal);