mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-15 19:22:25 +08:00
Cppfix (#153)
- 更新拓展包时增加更多的提示信息 - 增加版本检测系统,同时修改了安装AES密钥的时机 - 修复了偶发性的因进房导致的闪退(或许吧)
This commit is contained in:
parent
ce2cae0aa5
commit
0d709d6a73
|
@ -45,6 +45,18 @@
|
|||
</message>
|
||||
</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>
|
||||
<name>Init</name>
|
||||
<message>
|
||||
|
@ -135,6 +147,18 @@
|
|||
<source>username or password error</source>
|
||||
<translation>用户名或密码错误</translation>
|
||||
</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>
|
||||
|
|
16
qml/Logic.js
16
qml/Logic.js
|
@ -35,12 +35,19 @@ callbacks["NetworkDelayTest"] = function(jsonData) {
|
|||
}
|
||||
config.cipherText = cipherText;
|
||||
Backend.replyDelayTest(config.screenName, cipherText);
|
||||
Backend.installAESKey();
|
||||
}
|
||||
|
||||
callbacks["ErrorMsg"] = function(jsonData) {
|
||||
console.log("ERROR: " + jsonData);
|
||||
toast.show(qsTr(jsonData), 5000);
|
||||
let log;
|
||||
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;
|
||||
if (sheduled_download !== "") {
|
||||
mainWindow.busy = true;
|
||||
|
@ -139,3 +146,6 @@ callbacks["ServerMessage"] = function(jsonData) {
|
|||
let current = mainStack.currentItem; // lobby or room
|
||||
current.sendDanmaku('<font color="gold"><b>[Server] </b></font>' + jsonData);
|
||||
}
|
||||
|
||||
callbacks["ShowToast"] = (j) => toast.show(j);
|
||||
callbacks["InstallKey"] = (j) => Backend.installAESKey();
|
||||
|
|
|
@ -32,18 +32,27 @@ QString PackMan::getPackSummary() {
|
|||
}
|
||||
|
||||
void PackMan::loadSummary(const QString &jsonData, bool useThread) {
|
||||
auto f = [=]() {
|
||||
static const auto f = [=]() {
|
||||
// First, disable all packages
|
||||
foreach (auto e, SelectFromDatabase(db, "SELECT name FROM packages;")) {
|
||||
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
|
||||
auto doc = QJsonDocument::fromJson(jsonData.toUtf8());
|
||||
auto arr = doc.array();
|
||||
int i = 0;
|
||||
foreach (auto e, arr) {
|
||||
i++;
|
||||
auto obj = e.toObject();
|
||||
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(
|
||||
db,
|
||||
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) {
|
||||
auto threadFunc = [=]() {
|
||||
static const auto threadFunc = [=]() {
|
||||
int error = clone(url);
|
||||
if (error < 0)
|
||||
return;
|
||||
|
|
|
@ -209,13 +209,23 @@ void Router::handlePacket(const QByteArray &rawPacket) {
|
|||
const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
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,
|
||||
const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
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) {
|
||||
sender->getRoom()->chat(sender, jsonData);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <qjsondocument.h>
|
||||
#include <qjsonvalue.h>
|
||||
#include <qobject.h>
|
||||
#include <qversionnumber.h>
|
||||
|
||||
#include "client_socket.h"
|
||||
#include "packman.h"
|
||||
|
@ -193,7 +194,7 @@ void Server::processRequest(const QByteArray &msg) {
|
|||
doc[2] != "Setup")
|
||||
valid = false;
|
||||
else
|
||||
valid = (String2Json(doc[3].toString()).array().size() == 3);
|
||||
valid = (String2Json(doc[3].toString()).array().size() == 4);
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
|
@ -211,6 +212,30 @@ void Server::processRequest(const QByteArray &msg) {
|
|||
|
||||
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(),
|
||||
arr[2].toString());
|
||||
}
|
||||
|
@ -227,6 +252,16 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
|
|||
|
||||
if (decrypted_pw.length() > 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);
|
||||
decrypted_pw.remove(0, 32);
|
||||
} else {
|
||||
|
|
|
@ -254,7 +254,7 @@ void QmlBackend::replyDelayTest(const QString &screenName,
|
|||
auto md5 = calcFileMD5();
|
||||
|
||||
QJsonArray arr;
|
||||
arr << screenName << cipher << md5;
|
||||
arr << screenName << cipher << md5 << FK_VERSION;
|
||||
ClientInstance->notifyServer("Setup", JsonArray2Bytes(arr));
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ public:
|
|||
qreal volume() const { return m_volume; }
|
||||
void setVolume(qreal v) { m_volume = v; }
|
||||
|
||||
void showToast(const QString &s) { emit notifyUI("ShowToast", s); }
|
||||
|
||||
signals:
|
||||
void notifyUI(const QString &command, const QString &jsonData);
|
||||
void volumeChanged(qreal);
|
||||
|
|
Loading…
Reference in New Issue
Block a user