修一堆小bug
This commit is contained in:
notify 2023-08-27 20:21:37 +08:00 committed by GitHub
parent fa3fc966a9
commit db2910d1f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 91 additions and 62 deletions

View File

@ -40,6 +40,7 @@ QtObject {
// Client data // Client data
property string serverMotd: "" property string serverMotd: ""
property list<string> serverHiddenPacks: [] property list<string> serverHiddenPacks: []
property bool serverEnableBot: true
property int roomCapacity: 0 property int roomCapacity: 0
property int roomTimeout: 0 property int roomTimeout: 0
property bool enableFreeAssign: false property bool enableFreeAssign: false

View File

@ -100,9 +100,10 @@ callbacks["BackToStart"] = (jsonData) => {
callbacks["SetServerSettings"] = (j) => { callbacks["SetServerSettings"] = (j) => {
const data = JSON.parse(j); const data = JSON.parse(j);
const [ motd, hiddenPacks ] = data; const [ motd, hiddenPacks, enableBots ] = data;
config.serverMotd = motd; config.serverMotd = motd;
config.serverHiddenPacks = hiddenPacks; config.serverHiddenPacks = hiddenPacks;
config.serverEnableBot = enableBots;
}; };
callbacks["EnterLobby"] = (jsonData) => { callbacks["EnterLobby"] = (jsonData) => {

View File

@ -178,7 +178,6 @@ Item {
function addSkillAudio(skill) { function addSkillAudio(skill) {
if (addSpecialSkillAudio(skill)) return; if (addSpecialSkillAudio(skill)) return;
console.log(skill, 'normal add')
const skilldata = JSON.parse(Backend.callLuaFunction("GetSkillData", [skill])); const skilldata = JSON.parse(Backend.callLuaFunction("GetSkillData", [skill]));
if (!skilldata) return; if (!skilldata) return;
const extension = skilldata.extension; const extension = skilldata.extension;

View File

@ -185,6 +185,7 @@ Item {
text: Backend.translate("Add Robot") text: Backend.translate("Add Robot")
visible: isOwner && !isStarted && !isFull visible: isOwner && !isStarted && !isFull
anchors.centerIn: parent anchors.centerIn: parent
enabled: config.serverEnableBot
onClicked: { onClicked: {
ClientInstance.notifyServer("AddRobot", "[]"); ClientInstance.notifyServer("AddRobot", "[]");
} }

View File

@ -390,7 +390,12 @@ Item {
Image { Image {
// id: saveme // id: saveme
visible: root.dead || root.dying || root.surrendered visible: root.dead || root.dying || root.surrendered
source: SkinBank.DEATH_DIR + (root.dead ? root.role : root.surrendered ? "surrender" : "saveme") source: {
if (root.dead) {
return SkinBank.getRoleDeathPic(root.role);
}
return SkinBank.DEATH_DIR + (root.surrendered ? "surrender" : "saveme")
}
anchors.centerIn: photoMask anchors.centerIn: photoMask
} }

View File

@ -19,6 +19,17 @@ var PIXANIM_DIR = AppPath + "/image/anim/"
var TILE_ICON_DIR = AppPath + "/image/button/tileicon/" var TILE_ICON_DIR = AppPath + "/image/button/tileicon/"
var LOBBY_IMG_DIR = AppPath + "/image/lobby/"; var LOBBY_IMG_DIR = AppPath + "/image/lobby/";
const searchPkgResource = function(path, name, suffix) {
let ret;
for (let dir of Backend.ls(AppPath + "/packages/")) {
if (Pacman.getDisabledPacks().includes(dir) ||
dir.endsWith(".disabled") // in case
) continue;
ret = AppPath + "/packages/" + dir + path + name + suffix;
if (Backend.exists(ret)) return ret;
}
}
function getGeneralExtraPic(name, extra) { function getGeneralExtraPic(name, extra) {
const data = JSON.parse(Backend.callLuaFunction("GetGeneralData", [name])); const data = JSON.parse(Backend.callLuaFunction("GetGeneralData", [name]));
const extension = data.extension; const extension = data.extension;
@ -54,11 +65,8 @@ function getCardPicture(cidOrName) {
if (Backend.exists(path)) { if (Backend.exists(path)) {
return path; return path;
} else { } else {
for (let dir of Backend.ls(AppPath + "/packages/")) { let ret = searchPkgResource("/image/card/", name, ".png");
if (dir.endsWith(".disabled")) continue; if (ret) return ret;
path = AppPath + "/packages/" + dir + "/image/card/" + name + ".png";
if (Backend.exists(path)) return path;
}
} }
return CARD_DIR + "unknown.png"; return CARD_DIR + "unknown.png";
} }
@ -70,11 +78,8 @@ function getDelayedTrickPicture(name) {
if (Backend.exists(path)) { if (Backend.exists(path)) {
return path; return path;
} else { } else {
for (let dir of Backend.ls(AppPath + "/packages/")) { let ret = searchPkgResource("/image/card/delayedTrick/", name, ".png");
if (dir.endsWith(".disabled")) continue; if (ret) return ret;
path = AppPath + "/packages/" + dir + "/image/card/delayedTrick/" + name + ".png";
if (Backend.exists(path)) return path;
}
} }
return DELAYED_TRICK_DIR + "unknown.png"; return DELAYED_TRICK_DIR + "unknown.png";
} }
@ -88,11 +93,8 @@ function getEquipIcon(cid, icon) {
if (Backend.exists(path)) { if (Backend.exists(path)) {
return path; return path;
} else { } else {
for (let dir of Backend.ls(AppPath + "/packages/")) { let ret = searchPkgResource("/image/card/equipIcon/", name, ".png");
if (dir.endsWith(".disabled")) continue; if (ret) return ret;
path = AppPath + "/packages/" + dir + "/image/card/equipIcon/" + name + ".png";
if (Backend.exists(path)) return path;
}
} }
return EQUIP_ICON_DIR + "unknown.png"; return EQUIP_ICON_DIR + "unknown.png";
} }
@ -100,11 +102,8 @@ function getEquipIcon(cid, icon) {
function getPhotoBack(kingdom) { function getPhotoBack(kingdom) {
let path = PHOTO_BACK_DIR + kingdom + ".png"; let path = PHOTO_BACK_DIR + kingdom + ".png";
if (!Backend.exists(path)) { if (!Backend.exists(path)) {
for (let dir of Backend.ls(AppPath + "/packages/")) { let ret = searchPkgResource("/image/kingdom/", kingdom, "-back.png");
if (dir.endsWith(".disabled")) continue; if (ret) return ret;
path = AppPath + "/packages/" + dir + "/image/kingdom/" + kingdom + "-back.png";
if (Backend.exists(path)) return path;
}
} else { } else {
return path; return path;
} }
@ -114,12 +113,8 @@ function getPhotoBack(kingdom) {
function getGeneralCardDir(kingdom) { function getGeneralCardDir(kingdom) {
let path = GENERALCARD_DIR + kingdom + ".png"; let path = GENERALCARD_DIR + kingdom + ".png";
if (!Backend.exists(path)) { if (!Backend.exists(path)) {
for (let dir of Backend.ls(AppPath + "/packages/")) { let ret = searchPkgResource("/image/kingdom/", kingdom, "-back.png");
if (dir.endsWith(".disabled")) continue; if (ret) return ret.slice(0, ret.lastIndexOf('/')) + "/";
path = AppPath + "/packages/" + dir + "/image/kingdom/" + kingdom + "-back.png";
if (Backend.exists(path))
return AppPath + "/packages/" + dir + "/image/kingdom/";
}
} else { } else {
return GENERALCARD_DIR; return GENERALCARD_DIR;
} }
@ -130,20 +125,25 @@ function getRolePic(role) {
if (Backend.exists(path)) { if (Backend.exists(path)) {
return path; return path;
} else { } else {
for (let dir of Backend.ls(AppPath + "/packages/")) { let ret = searchPkgResource("/image/role/", role, ".png");
if (dir.endsWith(".disabled")) continue; if (ret) return ret;
path = AppPath + "/packages/" + dir + "/image/role/" + role + ".png";
if (Backend.exists(path)) return path;
}
} }
return ROLE_DIR + "unknown.png"; return ROLE_DIR + "unknown.png";
} }
function getMarkPic(mark) { function getRoleDeathPic(role) {
for (let dir of Backend.ls(AppPath + "/packages/")) { let path = DEATH_DIR + role + ".png";
if (dir.endsWith(".disabled")) continue; if (Backend.exists(path)) {
let path = AppPath + "/packages/" + dir + "/image/mark/" + mark + ".png"; return path;
if (Backend.exists(path)) return path; } else {
let ret = searchPkgResource("/image/role/death/", role, ".png");
if (ret) return ret;
} }
return DEATH_DIR + "hidden.png";
}
function getMarkPic(mark) {
let ret = searchPkgResource("/image/mark/", mark, ".png");
if (ret) return ret;
return ""; return "";
} }

View File

@ -5,5 +5,6 @@
"capacity": 100, "capacity": 100,
"tempBanTime": 20, "tempBanTime": 20,
"motd": "Welcome!", "motd": "Welcome!",
"hiddenPacks": [] "hiddenPacks": [],
"enableBots": true
} }

View File

@ -123,8 +123,11 @@ function Engine:loadPackages()
table.removeOne(directories, "standard_cards") table.removeOne(directories, "standard_cards")
table.removeOne(directories, "maneuvering") table.removeOne(directories, "maneuvering")
local _disable_packs = json.decode(fk.GetDisabledPacks())
for _, dir in ipairs(directories) do for _, dir in ipairs(directories) do
if (not string.find(dir, ".disabled")) and FileIO.isDir("packages/" .. dir) if (not string.find(dir, ".disabled")) and not table.contains(_disable_packs, dir)
and FileIO.isDir("packages/" .. dir)
and FileIO.exists("packages/" .. dir .. "/init.lua") then and FileIO.exists("packages/" .. dir .. "/init.lua") then
local pack = require(string.format("packages.%s", dir)) local pack = require(string.format("packages.%s", dir))
-- Note that instance of Package is a table too -- Note that instance of Package is a table too

View File

@ -137,7 +137,7 @@ end
function Player:getGeneralMaxHp() function Player:getGeneralMaxHp()
local general = Fk.generals[type(self:getMark("__heg_general")) == "string" and self:getMark("__heg_general") or self.general] local general = Fk.generals[type(self:getMark("__heg_general")) == "string" and self:getMark("__heg_general") or self.general]
local deputy = Fk.generals[type(self:getMark("__heg_deputy")) == "string" and self:getMark("__heg_deputy") or self.deputy] local deputy = Fk.generals[type(self:getMark("__heg_deputy")) == "string" and self:getMark("__heg_deputy") or self.deputyGeneral]
if not deputy then if not deputy then
return general.maxHp + general.mainMaxHpAdjustedValue return general.maxHp + general.mainMaxHpAdjustedValue
@ -492,7 +492,6 @@ function Player:distanceTo(other, mode, ignore_dead)
mode = mode or "both" mode = mode or "both"
if other == self then return 0 end if other == self then return 0 end
if not ignore_dead and other.dead then if not ignore_dead and other.dead then
print(other.general .. " is dead!")
return -1 return -1
end end
if self:isRemoved() or other:isRemoved() then if self:isRemoved() or other:isRemoved() then

View File

@ -133,6 +133,7 @@ random_cb.AskForUseCard = function(self, jsonData)
local pattern = data[2] or card_name local pattern = data[2] or card_name
local cancelable = data[4] or true local cancelable = data[4] or true
local exp = Exppattern:Parse(pattern) local exp = Exppattern:Parse(pattern)
local avail_cards = table.filter(player:getCardIds("he"), function(id) local avail_cards = table.filter(player:getCardIds("he"), function(id)
return exp:match(Fk:getCardById(id)) and not player:prohibitUse(Fk:getCardById(id)) return exp:match(Fk:getCardById(id)) and not player:prohibitUse(Fk:getCardById(id))
end) end)

View File

@ -116,6 +116,7 @@ local function _waitForReply(player, timeout)
player.room:checkNoHuman() player.room:checkNoHuman()
player.ai:readRequestData() player.ai:readRequestData()
local reply = player.ai:makeReply() local reply = player.ai:makeReply()
if reply == "" then reply = "__cancel" end
return reply return reply
end end
while true do while true do

View File

@ -18,15 +18,21 @@ PackMan::PackMan(QObject *parent) : QObject(parent) {
db = OpenDatabase("./packages/packages.db", "./packages/init.sql"); db = OpenDatabase("./packages/packages.db", "./packages/init.sql");
QDir d("packages"); QDir d("packages");
// For old version
foreach (auto e, QmlBackend::ls("packages")) {
if (e.endsWith(".disabled") && d.exists(e) && !d.exists(e.chopped(9))) {
d.rename(e, e.chopped(9));
}
}
foreach (auto e, SelectFromDatabase(db, "SELECT name, enabled FROM packages;")) { foreach (auto e, SelectFromDatabase(db, "SELECT name, enabled FROM packages;")) {
auto obj = e.toObject(); auto obj = e.toObject();
auto pack = obj["name"].toString(); auto pack = obj["name"].toString();
auto enabled = obj["enabled"].toString().toInt() == 1; auto enabled = obj["enabled"].toString().toInt() == 1;
if (enabled) { if (!enabled) {
d.rename(pack + ".disabled", pack); disabled_packs << pack;
} else {
d.rename(pack, pack + ".disabled");
} }
} }
@ -40,6 +46,10 @@ PackMan::~PackMan() {
sqlite3_close(db); sqlite3_close(db);
} }
QStringList PackMan::getDisabledPacks() {
return disabled_packs;
}
QString PackMan::getPackSummary() { QString PackMan::getPackSummary() {
return SelectFromDb( return SelectFromDb(
db, "SELECT name, url, hash FROM packages WHERE enabled = 1;"); db, "SELECT name, url, hash FROM packages WHERE enabled = 1;");
@ -142,24 +152,17 @@ void PackMan::enablePack(const QString &pack) {
ExecSQL( ExecSQL(
db, db,
QString("UPDATE packages SET enabled = 1 WHERE name = '%1';").arg(pack)); QString("UPDATE packages SET enabled = 1 WHERE name = '%1';").arg(pack));
QDir d("packages");
int i = 0; disabled_packs.removeOne(pack);
while (!d.rename(pack + ".disabled", pack) && i < 3) {
QThread::currentThread()->msleep(1);
i++;
}
} }
void PackMan::disablePack(const QString &pack) { void PackMan::disablePack(const QString &pack) {
ExecSQL( ExecSQL(
db, db,
QString("UPDATE packages SET enabled = 0 WHERE name = '%1';").arg(pack)); QString("UPDATE packages SET enabled = 0 WHERE name = '%1';").arg(pack));
QDir d("packages");
int i = 0; if (!disabled_packs.contains(pack))
while (!d.rename(pack, pack + ".disabled") && i < 3) { disabled_packs << pack;
QThread::currentThread()->msleep(1);
i++;
}
} }
void PackMan::updatePack(const QString &pack) { void PackMan::updatePack(const QString &pack) {
@ -208,7 +211,7 @@ void PackMan::removePack(const QString &pack) {
return; return;
bool enabled = result[0].toObject()["enabled"].toString().toInt() == 1; bool enabled = result[0].toObject()["enabled"].toString().toInt() == 1;
ExecSQL(db, QString("DELETE FROM packages WHERE name = '%1';").arg(pack)); ExecSQL(db, QString("DELETE FROM packages WHERE name = '%1';").arg(pack));
QDir d(QString("packages/%1%2").arg(pack).arg(enabled ? "" : ".disabled")); QDir d(QString("packages/%1").arg(pack));
d.removeRecursively(); d.removeRecursively();
} }

View File

@ -3,6 +3,7 @@
#ifndef _PACKMAN_H #ifndef _PACKMAN_H
#define _PACKMAN_H #define _PACKMAN_H
#include <qtmetamacros.h>
class PackMan : public QObject { class PackMan : public QObject {
Q_OBJECT Q_OBJECT
public: public:
@ -10,6 +11,7 @@ public:
~PackMan(); ~PackMan();
QString getPackSummary(); QString getPackSummary();
Q_INVOKABLE QStringList getDisabledPacks();
Q_INVOKABLE void loadSummary(const QString &, bool useThread = false); Q_INVOKABLE void loadSummary(const QString &, bool useThread = false);
Q_INVOKABLE void downloadNewPack(const QString &url, bool useThread = false); Q_INVOKABLE void downloadNewPack(const QString &url, bool useThread = false);
Q_INVOKABLE void enablePack(const QString &pack); Q_INVOKABLE void enablePack(const QString &pack);
@ -27,6 +29,7 @@ private:
int checkout_branch(const QString &name, const QString &branch); int checkout_branch(const QString &name, const QString &branch);
int status(const QString &name); // return 1 if the workdir is modified int status(const QString &name); // return 1 if the workdir is modified
QString head(const QString &name); // get commit hash of HEAD QString head(const QString &name); // get commit hash of HEAD
QStringList disabled_packs;
}; };
extern PackMan *Pacman; extern PackMan *Pacman;

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include "util.h" #include "util.h"
#include "packman.h"
#include <qcryptographichash.h> #include <qcryptographichash.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <qregularexpression.h> #include <qregularexpression.h>
@ -159,8 +160,9 @@ static void writeDirMD5(QFile &dest, const QString &dir,
auto entries = d.entryInfoList( auto entries = d.entryInfoList(
QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
auto re = QRegularExpression::fromWildcard(filter); auto re = QRegularExpression::fromWildcard(filter);
const auto disabled = Pacman->getDisabledPacks();
foreach (QFileInfo info, entries) { foreach (QFileInfo info, entries) {
if (info.isDir() && !info.fileName().endsWith(".disabled")) { if (info.isDir() && !info.fileName().endsWith(".disabled") && !disabled.contains(info.fileName())) {
writeDirMD5(dest, info.filePath(), filter); writeDirMD5(dest, info.filePath(), filter);
} else { } else {
if (re.match(info.fileName()).hasMatch()) { if (re.match(info.fileName()).hasMatch()) {
@ -213,6 +215,10 @@ QString GetDeviceUuid() {
#endif #endif
} }
QString GetDisabledPacks() {
return JsonArray2Bytes(QJsonArray::fromStringList(Pacman->getDisabledPacks()));
}
QString Color(const QString &raw, fkShell::TextColor color, QString Color(const QString &raw, fkShell::TextColor color,
fkShell::TextType type) { fkShell::TextType type) {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX

View File

@ -22,6 +22,8 @@ QJsonDocument String2Json(const QString &str);
QString GetDeviceUuid(); QString GetDeviceUuid();
QString GetDisabledPacks();
namespace fkShell { namespace fkShell {
enum TextColor { enum TextColor {
Black, Black,

View File

@ -280,7 +280,7 @@ void Router::handlePacket(const QByteArray &rawPacket) {
if (command == "QuitRoom") { if (command == "QuitRoom") {
room->removePlayer(player); room->removePlayer(player);
} else if (command == "AddRobot") { } else if (command == "AddRobot") {
room->addRobot(player); if (ServerInstance->getConfig("enableBots").toBool()) room->addRobot(player);
} else if (command == "KickPlayer") { } else if (command == "KickPlayer") {
int i = jsonData.toInt(); int i = jsonData.toInt();
auto p = room->findPlayer(i); auto p = room->findPlayer(i);

View File

@ -514,6 +514,7 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
player->doNotify("SetServerSettings", JsonArray2Bytes({ player->doNotify("SetServerSettings", JsonArray2Bytes({
getConfig("motd"), getConfig("motd"),
getConfig("hiddenPacks"), getConfig("hiddenPacks"),
getConfig("enableBots"),
})); }));
lobby()->addPlayer(player); lobby()->addPlayer(player);
@ -623,6 +624,7 @@ void Server::readConfig() {
SET_DEFAULT_CONFIG("tempBanTime", 20); SET_DEFAULT_CONFIG("tempBanTime", 20);
SET_DEFAULT_CONFIG("motd", "Welcome!"); SET_DEFAULT_CONFIG("motd", "Welcome!");
SET_DEFAULT_CONFIG("hiddenPacks", QJsonArray()); SET_DEFAULT_CONFIG("hiddenPacks", QJsonArray());
SET_DEFAULT_CONFIG("enableBots", true);
} }
QJsonValue Server::getConfig(const QString &key) { return config.value(key); } QJsonValue Server::getConfig(const QString &key) { return config.value(key); }

View File

@ -22,3 +22,4 @@ const char *FK_VER = FK_VERSION;
%include "server.i" %include "server.i"
extern char *FK_VER; extern char *FK_VER;
QString GetDisabledPacks();