From cee3ec279d2f37d7f55d2c1f9bfd4fe65149622c Mon Sep 17 00:00:00 2001 From: notify Date: Sat, 1 Jul 2023 23:14:30 +0800 Subject: [PATCH] Bugfix2 (#215) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修更多小bug --- Fk/Logic.js | 2 +- Fk/Pages/JoinServer.qml | 26 +++++++++++++++++++------- lua/server/events/usecard.lua | 2 ++ lua/server/room.lua | 6 ++++-- packages/maneuvering/init.lua | 2 +- src/server/server.cpp | 5 +++-- src/ui/qmlbackend.cpp | 9 +++++---- 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Fk/Logic.js b/Fk/Logic.js index 9297bc2c..e3ba7b98 100644 --- a/Fk/Logic.js +++ b/Fk/Logic.js @@ -29,7 +29,7 @@ callbacks["ServerDetected"] = (j) => { } callbacks["GetServerDetail"] = (j) => { - const [addr, ver, icon, desc, capacity, count] = JSON.parse(j); + const [ver, icon, desc, capacity, count, addr] = JSON.parse(j); const serverDialog = mainStack.currentItem.serverDialog; if (!serverDialog) { return; diff --git a/Fk/Pages/JoinServer.qml b/Fk/Pages/JoinServer.qml index e3ead7f1..7337c45a 100644 --- a/Fk/Pages/JoinServer.qml +++ b/Fk/Pages/JoinServer.qml @@ -19,6 +19,7 @@ Item { Item { height: 64 width: serverList.width - 48 + clip: true RowLayout { anchors.fill: parent @@ -31,16 +32,26 @@ Item { source: favicon } - Text { - text: serverIP - } + ColumnLayout { + Layout.fillWidth: true + Text { + Layout.fillWidth: true + horizontalAlignment: Text.AlignLeft + text: serverIP + font.bold: true + } - Text { - text: description + Text { + Layout.fillWidth: true + horizontalAlignment: Text.AlignLeft + text: description + textFormat: TextEdit.RichText + } } Text { text: online + "/" + capacity + font.pixelSize: 30 } } @@ -357,7 +368,8 @@ Item { const [ver, icon, desc, capacity, count] = data; for (let i = 0; i < serverModel.count; i++) { const item = serverModel.get(i); - if (addr.endsWith(item.serverIP)) { // endsWith是为了应付IPv6格式的ip + const ip = item.serverIP; + if (addr.endsWith(ip)) { // endsWith是为了应付IPv6格式的ip item.description = FkVersion === ver ? desc : "Ver " + ver; item.favicon = icon; item.online = count.toString(); @@ -376,7 +388,7 @@ Item { description: qsTr("Server not up"), online: "-", capacity: "-", - favicon: "https://img1.imgtp.com/2023/07/01/DGUdj8eu.png", + favicon: "", }); Backend.getServerInfo(key); } diff --git a/lua/server/events/usecard.lua b/lua/server/events/usecard.lua index 937f2b67..31cd5190 100644 --- a/lua/server/events/usecard.lua +++ b/lua/server/events/usecard.lua @@ -47,12 +47,14 @@ local sendCardEmotionAndLog = function(room, cardUseEvent) -- when this function is called, card is already in PlaceTable and no filter skill is applied. -- So filter this card manually here to get 'real' use.card local card = _card + ---[[ if not _card:isVirtual() then local temp = { card = _card } Fk:filterCard(_card.id, room:getPlayerById(from), temp) card = temp.card end cardUseEvent.card = card + --]] playCardEmotionAndSound(room, room:getPlayerById(from), card) room:doAnimate("Indicate", { diff --git a/lua/server/room.lua b/lua/server/room.lua index 48aad9c2..0f0eb7d3 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -1501,8 +1501,6 @@ function Room:handleUseCardReply(player, data) Self = player local c = skill:viewAs(selected_cards) if c then - self:useSkill(player, skill, Util.DummyFunc) - local use = {} ---@type CardUseStruct use.from = player.id use.tos = {} @@ -1515,6 +1513,9 @@ function Room:handleUseCardReply(player, data) use.card = c skill:beforeUse(player, use) + + self:useSkill(player, skill, Util.DummyFunc) + return use end end @@ -1538,6 +1539,7 @@ function Room:handleUseCardReply(player, data) if #use.tos == 0 then use.tos = nil end + Fk:filterCard(card, player) use.card = Fk:getCardById(card) return use end diff --git a/packages/maneuvering/init.lua b/packages/maneuvering/init.lua index 0048577c..f137a0b0 100644 --- a/packages/maneuvering/init.lua +++ b/packages/maneuvering/init.lua @@ -203,7 +203,7 @@ local fireAttackSkill = fk.CreateActiveSkill{ local to = room:getPlayerById(cardEffectEvent.to) if to:isKongcheng() then return end - local showCard = room:askForCard(to, 1, 1, false, self.name, false, nil, "#fire_attack-show:" .. from.id)[1] + local showCard = room:askForCard(to, 1, 1, false, self.name, false, ".|.|.|hand", "#fire_attack-show:" .. from.id)[1] to:showCards(showCard) showCard = Fk:getCardById(showCard) diff --git a/src/server/server.cpp b/src/server/server.cpp index 3ee1d558..29b97ec1 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -39,7 +39,6 @@ Server::Server(QObject *parent) : QObject(parent) { &Server::processNewConnection); udpSocket = new QUdpSocket(this); - udpSocket->bind(9527); connect(udpSocket, &QUdpSocket::readyRead, this, &Server::readPendingDatagrams); @@ -95,6 +94,7 @@ Server::~Server() { bool Server::listen(const QHostAddress &address, ushort port) { bool ret = server->listen(address, port); + udpSocket->bind(port); isListening = ret; return ret; } @@ -632,13 +632,14 @@ void Server::readPendingDatagrams() { void Server::processDatagram(const QByteArray &msg, const QHostAddress &addr, uint port) { if (msg == "fkDetectServer") { udpSocket->writeDatagram("me", addr, port); - } else if (msg == "fkGetDetail") { + } else if (msg.startsWith("fkGetDetail,")) { udpSocket->writeDatagram(JsonArray2Bytes(QJsonArray({ FK_VERSION, getConfig("iconUrl"), getConfig("description"), getConfig("capacity"), players.count(), + msg.sliced(12).constData(), })), addr, port); } udpSocket->flush(); diff --git a/src/ui/qmlbackend.cpp b/src/ui/qmlbackend.cpp index e4bf3f3a..fdc34de0 100644 --- a/src/ui/qmlbackend.cpp +++ b/src/ui/qmlbackend.cpp @@ -337,7 +337,7 @@ void QmlBackend::detectServer() { void QmlBackend::getServerInfo(const QString &address) { QString addr = "127.0.0.1"; ushort port = 9527u; - static const char *ask_str = "fkGetDetail"; + static const char *ask_str = "fkGetDetail,"; if (address.contains(QChar(':'))) { QStringList texts = address.split(QChar(':')); @@ -347,8 +347,10 @@ void QmlBackend::getServerInfo(const QString &address) { addr = address; } - udpSocket->writeDatagram(ask_str, - strlen(ask_str), + QByteArray ask(ask_str); + ask.append(address.toLatin1()); + + udpSocket->writeDatagram(ask, ask.size(), QHostAddress(addr), port); } @@ -364,7 +366,6 @@ void QmlBackend::readPendingDatagrams() { emit notifyUI("ServerDetected", addr.toString()); } else { auto arr = QJsonDocument::fromJson(data).array(); - arr.prepend(addr.toString()); emit notifyUI("GetServerDetail", JsonArray2Bytes(arr)); } }