From 955be5122668545f8e1c000085e9b8b38a204baa Mon Sep 17 00:00:00 2001 From: notify Date: Fri, 19 Apr 2024 22:38:00 +0800 Subject: [PATCH] Changelog: v0.4.14 --- CHANGELOG.md | 7 ++ CMakeLists.txt | 2 +- Fk/Logic.js | 2 +- Fk/Pages/GeneralsOverview.qml | 5 +- Fk/Pages/Room.qml | 6 +- android/AndroidManifest.xml | 4 +- src/ui/qmlbackend.cpp | 180 +++++++++++++++++----------------- 7 files changed, 106 insertions(+), 100 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4fcffbf..a922ae23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # ChangeLog +## v0.4.13 & v0.4.14 + +- 优化重连逻辑 +- 客户端代码大量删除JSON。可能影响部分拓展 + +___ + ## v0.4.12 - 修前个版本poxi框bug diff --git a/CMakeLists.txt b/CMakeLists.txt index 07789682..a364367a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16) -project(FreeKill VERSION 0.4.13) +project(FreeKill VERSION 0.4.14) add_definitions(-DFK_VERSION=\"${CMAKE_PROJECT_VERSION}\") find_package(Qt6 REQUIRED COMPONENTS diff --git a/Fk/Logic.js b/Fk/Logic.js index 80aad400..97991935 100644 --- a/Fk/Logic.js +++ b/Fk/Logic.js @@ -76,7 +76,7 @@ callbacks["ErrorMsg"] = (jsonData) => { mainWindow.busy = false; if (sheduled_download !== "") { mainWindow.busy = true; - Pacman.loadSummary(sheduled_download, true); + Pacman.loadSummary(JSON.stringify(sheduled_download), true); sheduled_download = ""; } } diff --git a/Fk/Pages/GeneralsOverview.qml b/Fk/Pages/GeneralsOverview.qml index abb850e5..5f512f8f 100644 --- a/Fk/Pages/GeneralsOverview.qml +++ b/Fk/Pages/GeneralsOverview.qml @@ -98,7 +98,6 @@ Item { delete s.normalPkg[name]; s.banPkg[name] = []; } - console.log(JSON.stringify(config.curScheme)) config.curSchemeChanged(); } else { pkgList.currentIndex = index; @@ -394,12 +393,12 @@ Item { } onClicked: { - callbacks["LogEvent"](JSON.stringify({ + callbacks["LogEvent"]({ type: "PlaySkillSound", name: name, general: detailGeneralCard.name, i: idx, - })); + }); } } } diff --git a/Fk/Pages/Room.qml b/Fk/Pages/Room.qml index 3e4e674c..4c1de231 100644 --- a/Fk/Pages/Room.qml +++ b/Fk/Pages/Room.qml @@ -1176,12 +1176,12 @@ Item { if (!config.disableMsgAudio) try { - callbacks["LogEvent"](JSON.stringify({ + callbacks["LogEvent"]({ type: "PlaySkillSound", name: skill, general: gene, i: idx, - })); + }); } catch (e) {} const m = luatr("$" + skill + (gene ? "_" + gene : "") + (idx ? idx.toString() : "")); @@ -1278,7 +1278,7 @@ Item { roomScene.isOwner = d.isOwner; } else { lcall("ResetAddPlayer", - JSON.stringify([d.id, d.name, d.avatar, d.ready, d.gameData[3]])); + [d.id, d.name, d.avatar, d.ready, d.gameData[3]]); } lcall("SetPlayerGameData", d.id, d.gameData); Logic.getPhotoModel(d.id).isOwner = d.isOwner; diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 88f050f6..f3662015 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -3,8 +3,8 @@ + android:versionCode="414" + android:versionName="0.4.14"> diff --git a/src/ui/qmlbackend.cpp b/src/ui/qmlbackend.cpp index ffdf2a32..b86446a3 100644 --- a/src/ui/qmlbackend.cpp +++ b/src/ui/qmlbackend.cpp @@ -72,96 +72,6 @@ bool QmlBackend::isDir(const QString &file) { return QFileInfo(QUrl(file).path()).isDir(); } -#ifndef FK_SERVER_ONLY - -QQmlApplicationEngine *QmlBackend::getEngine() const { return engine; } - -void QmlBackend::setEngine(QQmlApplicationEngine *engine) { - this->engine = engine; -} - -void QmlBackend::startServer(ushort port) { - if (!ServerInstance) { - Server *server = new Server(this); - - if (!server->listen(QHostAddress::Any, port)) { - server->deleteLater(); - emit notifyUI("ErrorMsg", tr("Cannot start server!")); - } - } -} - -void QmlBackend::joinServer(QString address) { - if (ClientInstance != nullptr) - return; - Client *client = new Client(this); - connect(client, &Client::error_message, this, [=](const QString &msg) { - if (replayer) { - emit replayerShutdown(); - } - client->deleteLater(); - emit notifyUI("ErrorMsg", msg); - emit notifyUI("BackToStart", "[]"); - }); - QString addr = "127.0.0.1"; - ushort port = 9527u; - - if (address.contains(QChar(':'))) { - QStringList texts = address.split(QChar(':')); - addr = texts.value(0); - port = texts.value(1).toUShort(); - } else { - addr = address; - // SRV解析查询 - QDnsLookup* dns = new QDnsLookup(QDnsLookup::SRV, "_freekill._tcp." + addr); - QEventLoop eventLoop; - // 阻塞的SRV解析查询回调 - connect(dns, &QDnsLookup::finished,[&eventLoop](void){ - eventLoop.quit(); - }); - dns->lookup(); - eventLoop.exec(); - if (dns->error() == QDnsLookup::NoError) { // SRV解析成功 - const auto records = dns->serviceRecords(); - const QDnsServiceRecord &record = records.first(); - QHostInfo host = QHostInfo::fromName(record.target()); - if (host.error() == QHostInfo::NoError) { // 主机解析成功 - addr = host.addresses().first().toString(); - port = record.port(); - } - } - } - - client->connectToHost(addr, port); -} - -void QmlBackend::quitLobby(bool close) { - if (ClientInstance) - delete ClientInstance; - // if (ServerInstance && close) - // ServerInstance->deleteLater(); -} - -QString QmlBackend::translate(const QString &src) { - if (!ClientInstance) - return src; - - lua_State *L = ClientInstance->getLuaState(); - lua_getglobal(L, "Translate"); - auto bytes = src.toUtf8(); - lua_pushstring(L, bytes.data()); - - int err = lua_pcall(L, 1, 1, 0); - const char *result = lua_tostring(L, -1); - if (err) { - qCritical() << result; - lua_pop(L, 1); - return ""; - } - lua_pop(L, 1); - return QString(result); -} - void QmlBackend::pushLuaValue(lua_State *L, QVariant v) { QVariantList list; QVariantMap map; @@ -284,6 +194,96 @@ QVariant QmlBackend::readLuaValue(lua_State *L, int index, return QVariant(); // won't return } +#ifndef FK_SERVER_ONLY + +QQmlApplicationEngine *QmlBackend::getEngine() const { return engine; } + +void QmlBackend::setEngine(QQmlApplicationEngine *engine) { + this->engine = engine; +} + +void QmlBackend::startServer(ushort port) { + if (!ServerInstance) { + Server *server = new Server(this); + + if (!server->listen(QHostAddress::Any, port)) { + server->deleteLater(); + emit notifyUI("ErrorMsg", tr("Cannot start server!")); + } + } +} + +void QmlBackend::joinServer(QString address) { + if (ClientInstance != nullptr) + return; + Client *client = new Client(this); + connect(client, &Client::error_message, this, [=](const QString &msg) { + if (replayer) { + emit replayerShutdown(); + } + client->deleteLater(); + emit notifyUI("ErrorMsg", msg); + emit notifyUI("BackToStart", "[]"); + }); + QString addr = "127.0.0.1"; + ushort port = 9527u; + + if (address.contains(QChar(':'))) { + QStringList texts = address.split(QChar(':')); + addr = texts.value(0); + port = texts.value(1).toUShort(); + } else { + addr = address; + // SRV解析查询 + QDnsLookup* dns = new QDnsLookup(QDnsLookup::SRV, "_freekill._tcp." + addr); + QEventLoop eventLoop; + // 阻塞的SRV解析查询回调 + connect(dns, &QDnsLookup::finished,[&eventLoop](void){ + eventLoop.quit(); + }); + dns->lookup(); + eventLoop.exec(); + if (dns->error() == QDnsLookup::NoError) { // SRV解析成功 + const auto records = dns->serviceRecords(); + const QDnsServiceRecord &record = records.first(); + QHostInfo host = QHostInfo::fromName(record.target()); + if (host.error() == QHostInfo::NoError) { // 主机解析成功 + addr = host.addresses().first().toString(); + port = record.port(); + } + } + } + + client->connectToHost(addr, port); +} + +void QmlBackend::quitLobby(bool close) { + if (ClientInstance) + delete ClientInstance; + // if (ServerInstance && close) + // ServerInstance->deleteLater(); +} + +QString QmlBackend::translate(const QString &src) { + if (!ClientInstance) + return src; + + lua_State *L = ClientInstance->getLuaState(); + lua_getglobal(L, "Translate"); + auto bytes = src.toUtf8(); + lua_pushstring(L, bytes.data()); + + int err = lua_pcall(L, 1, 1, 0); + const char *result = lua_tostring(L, -1); + if (err) { + qCritical() << result; + lua_pop(L, 1); + return ""; + } + lua_pop(L, 1); + return QString(result); +} + QVariant QmlBackend::callLuaFunction(const QString &func_name, QVariantList params) { if (!ClientInstance) return QVariantMap();