diff --git a/CHANGELOG.md b/CHANGELOG.md index ba438d47..62feda30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ # ChangeLog -## v0.4.16 +## v0.4.16 & v0.4.17 在引入freekill-core之后的第一次版本更新,甚至无法保证这次更新是否正常 +UI是半成品,0.4.17修复各种爆炸以及半成品UI稍微人性化一点 + 1. 改进processPrompt,支持双将和暗将 2. 副将长名旋转 3. 国战体力上限优化,包括一览和选将框 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5139f0b7..cfcfbf2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16) -project(FreeKill VERSION 0.4.16) +project(FreeKill VERSION 0.4.17) add_definitions(-DFK_VERSION=\"${CMAKE_PROJECT_VERSION}\") find_package(Qt6 REQUIRED COMPONENTS diff --git a/Fk/Pages/Init.qml b/Fk/Pages/Init.qml index 44d58183..884c2edb 100644 --- a/Fk/Pages/Init.qml +++ b/Fk/Pages/Init.qml @@ -107,6 +107,7 @@ Item { } Text { + id: faqTxt anchors.right: parent.right anchors.bottom: parent.bottom anchors.rightMargin: 8 @@ -123,6 +124,24 @@ Item { } } } + + Text { + anchors.right: faqTxt.left + anchors.bottom: parent.bottom + anchors.rightMargin: 8 + anchors.bottomMargin: 8 + text: qsTr("ResFix") + color: "blue" + font.pixelSize: 24 + font.underline: true + visible: OS === "Android" + + TapHandler { + onTapped: { + Backend.askFixResource(); + } + } + } } } diff --git a/Fk/Pages/Lobby.qml b/Fk/Pages/Lobby.qml index 4931978c..63de27e9 100644 --- a/Fk/Pages/Lobby.qml +++ b/Fk/Pages/Lobby.qml @@ -22,7 +22,7 @@ Item { radius: 8 height: 124 - 8 width: 124 - 8 - color: outdated ? "#E2E2E2" : "lightgreen" + color: outdated ? "#E2E2E2" : "#DDDDDDDD" Text { id: roomNameText @@ -281,7 +281,7 @@ Item { Rectangle { Layout.fillHeight: true - Layout.preferredWidth: childrenRect.width + 48 + Layout.preferredWidth: childrenRect.width + 72 gradient: Gradient { orientation: Gradient.Horizontal diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 5db8de1a..9155809d 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -3,8 +3,8 @@ + android:versionCode="417" + android:versionName="0.4.17"> diff --git a/lang/zh_CN.ts b/lang/zh_CN.ts index d033ea87..bf2ecc4b 100644 --- a/lang/zh_CN.ts +++ b/lang/zh_CN.ts @@ -109,7 +109,7 @@ packages/%1: some error occured. - 拓展包 %1 出了点问题,尝试在管理拓展包中删除之再试试 + 拓展包 %1 出了点问题,可以尝试:进入“管理拓展包”,找到 %1,删除,然后再尝试 @@ -125,7 +125,7 @@ help: unknown password error - 提示:请尝试重新启动程序 + 提示:请使用“编辑服务器”删除该服务器,然后重新添加服务器并重新输入用户名和密码;若为单机启动则在“加入服务器”中选中服务器127.0.0.1,编辑服务器->删除,然后再单机启动 help: you have been banned! @@ -141,7 +141,19 @@ help: username or password error - 提示:可能该用户名已被占用,或者密码错误,如果你是初次注册的话考虑用另一个用户名密码进行登入 + 提示:可能该用户名已被占用,或者密码错误,如果你是初次注册的话考虑用另一个用户名密码进行登入;若为单机启动则在“加入服务器”中选中服务器127.0.0.1,编辑服务器->删除,然后再单机启动 + + + help: md5 fail + 检测到MD5错误且未发生拓展包变动,若该情况多次发生请考虑点击主界面“资源修复”蓝色文字 + + + fix resource + 修复资源文件 + + + help: fix resource + 点击“确定”将立刻关闭游戏,下次启动时重新复制资源文件,适用于进入服务器多次提示MD5失败,是否继续? @@ -179,6 +191,10 @@ FAQ 常见疑问 + + ResFix + 资源修复 + $LoginFAQ @@ -318,6 +334,10 @@ MD5 check failed! MD5检测失败!请与服务端保持一致后再登入 + + md5 fail + 资源文件错误 + others logged in with this name 已经有人用这个名字登入了 diff --git a/src/network/server_socket.cpp b/src/network/server_socket.cpp index 777f2575..bb9d696c 100644 --- a/src/network/server_socket.cpp +++ b/src/network/server_socket.cpp @@ -24,8 +24,9 @@ bool ServerSocket::listen(const QHostAddress &address, ushort port) { void ServerSocket::processNewConnection() { QTcpSocket *socket = server->nextPendingConnection(); ClientSocket *connection = new ClientSocket(socket); - connect(connection, &ClientSocket::disconnected, this, - [connection]() { connection->deleteLater(); }); + // 这里怎么能一断连就自己删呢,应该让上层的来 + //connect(connection, &ClientSocket::disconnected, this, + // [connection]() { connection->deleteLater(); }); emit new_connection(connection); } diff --git a/src/server/auth.cpp b/src/server/auth.cpp index fac1cde5..270ba8b5 100644 --- a/src/server/auth.cpp +++ b/src/server/auth.cpp @@ -169,7 +169,7 @@ QJsonObject AuthManager::checkPassword(ClientSocket *client, const QString &name if (players.value(id)) { auto player = players.value(id); // 顶号机制,如果在线的话就让他变成不在线 - if (player->getState() == Player::Online) { + if (player->getState() == Player::Online || player->getState() == Player::Robot) { player->doNotify("ErrorDlg", "others logged in again with this name"); emit player->kicked(); } diff --git a/src/server/room.cpp b/src/server/room.cpp index 60e20aed..1724d34d 100644 --- a/src/server/room.cpp +++ b/src/server/room.cpp @@ -240,9 +240,6 @@ void Room::removePlayer(ServerPlayer *player) { // 然后基于跑路玩家的socket,创建一个新ServerPlayer对象用来通信 ServerPlayer *runner = new ServerPlayer(this); runner->setSocket(socket); - connect(runner, &ServerPlayer::disconnected, server, - &Server::onUserDisconnected); - connect(runner, &Player::stateChanged, server, &Server::onUserStateChanged); runner->setScreenName(player->getScreenName()); runner->setAvatar(player->getAvatar()); runner->setId(player->getId()); @@ -512,7 +509,7 @@ void Room::gameOver() { } } server->endTransaction(); - insideGameOver = true; + insideGameOver = false; } void Room::manuallyStart() { diff --git a/src/server/roombase.cpp b/src/server/roombase.cpp index 0abb85db..3a5cc64d 100644 --- a/src/server/roombase.cpp +++ b/src/server/roombase.cpp @@ -37,15 +37,16 @@ void RoomBase::chat(ServerPlayer *sender, const QString &jsonData) { auto type = doc["type"].toInt(); doc["sender"] = sender->getId(); - // 屏蔽.号,防止有人在HTML文本发链接,而正常发链接看不出来有啥改动 auto msg = doc["msg"].toString(); - msg.replace(".", "․"); - // 300字限制,与客户端相同 - msg.erase(msg.begin() + 300, msg.end()); - doc["msg"] = msg; if (!server->checkBanWord(msg)) { return; } + // 屏蔽.号和百分号,防止有人在HTML文本发链接,而正常发链接看不出来有啥改动 + msg.replace(".", "․"); + msg.replace("%", "%"); + // 300字限制,与客户端相同 + msg.erase(msg.begin() + 300, msg.end()); + doc["msg"] = msg; if (type == 1) { doc["userName"] = sender->getScreenName(); @@ -57,6 +58,9 @@ void RoomBase::chat(ServerPlayer *sender, const QString &jsonData) { doBroadcastNotify(observers, "Chat", json); } - qInfo("[Chat] %s: %s", sender->getScreenName().toUtf8().constData(), + qInfo("[Chat/%s] %s: %s", + isLobby() ? "Lobby" : QString("#%1").arg(qobject_cast(this) + ->getId()).toUtf8().constData(), + sender->getScreenName().toUtf8().constData(), doc["msg"].toString().toUtf8().constData()); } diff --git a/src/server/server.cpp b/src/server/server.cpp index 6500f8ae..fbda6f88 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -261,7 +261,7 @@ void Server::processNewConnection(ClientSocket *client) { void Server::processRequest(const QByteArray &msg) { ClientSocket *client = qobject_cast(sender()); - client->disconnect(this, SLOT(processRequest(const QByteArray &))); + disconnect(client, &ClientSocket::message_got, this, &Server::processRequest); client->timerSignup.stop(); bool valid = true; @@ -339,9 +339,6 @@ void Server::processRequest(const QByteArray &msg) { ServerPlayer *player = new ServerPlayer(lobby()); player->setSocket(client); client->disconnect(this); - connect(player, &ServerPlayer::disconnected, this, - &Server::onUserDisconnected); - connect(player, &Player::stateChanged, this, &Server::onUserStateChanged); player->setScreenName(name); player->setAvatar(obj["avatar"].toString()); player->setId(id); @@ -374,56 +371,6 @@ void Server::onRoomAbandoned() { room->getThread()->removeRoom(room); } -void Server::onUserDisconnected() { - auto player = qobject_cast(sender()); - qInfo() << "Player" << player->getId() << "disconnected"; - if (players.count() <= 10) { - broadcast("ServerMessage", tr("%1 logged out").arg(player->getScreenName())); - } - - auto _room = player->getRoom(); - if (_room->isLobby()) { - player->setState(Player::Robot); // 大厅!然而又不能设Offline - player->deleteLater(); - } else { - auto room = qobject_cast(_room); - if (room->isStarted()) { - if (room->getObservers().contains(player)) { - room->removeObserver(player); - player->deleteLater(); - return; - } - player->setState(Player::Offline); - player->setSocket(nullptr); - // TODO: add a robot - } else { - player->setState(Player::Robot); // 大厅!然而又不能设Offline - // 这里有一个多线程问题,可能与Room::gameOver同时deleteLater导致出事 - // FIXME: 这种解法肯定不安全 - if (!room->insideGameOver) - player->deleteLater(); - } - } -} - -void Server::onUserStateChanged() { - ServerPlayer *player = qobject_cast(sender()); - auto _room = player->getRoom(); - if (!_room || _room->isLobby()) return; - auto room = qobject_cast(_room); - if (room->isAbandoned()) return; - - auto state = player->getState(); - room->doBroadcastNotify(room->getPlayers(), "NetStateChanged", - QString("[%1,\"%2\"]").arg(player->getId()).arg(player->getStateString())); - - if (state == Player::Online) { - player->resumeGameTimer(); - } else { - player->pauseGameTimer(); - } -} - #define SET_DEFAULT_CONFIG(k, v) do {\ if (config.value(k).isUndefined()) { \ config[k] = (v); \ diff --git a/src/server/server.h b/src/server/server.h index 593195cb..6e9daaea 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -66,8 +66,6 @@ public slots: void processRequest(const QByteArray &msg); void onRoomAbandoned(); - void onUserDisconnected(); - void onUserStateChanged(); private: friend class Shell; diff --git a/src/server/serverplayer.cpp b/src/server/serverplayer.cpp index ac3825b4..38132990 100644 --- a/src/server/serverplayer.cpp +++ b/src/server/serverplayer.cpp @@ -14,6 +14,7 @@ ServerPlayer::ServerPlayer(RoomBase *room) { this->room = room; server = room->getServer(); connect(this, &ServerPlayer::kicked, this, &ServerPlayer::kick); + connect(this, &Player::stateChanged, this, &ServerPlayer::onStateChanged); alive = true; m_busy = false; @@ -42,7 +43,7 @@ void ServerPlayer::setSocket(ClientSocket *socket) { this->socket = nullptr; if (socket != nullptr) { connect(socket, &ClientSocket::disconnected, this, - &ServerPlayer::disconnected); + &ServerPlayer::onDisconnected); this->socket = socket; } @@ -108,6 +109,9 @@ void ServerPlayer::kick() { setState(Player::Offline); if (socket != nullptr) { socket->disconnectFromHost(); + } else { + // 还是得走一遍这个流程才行 + onDisconnected(); } setSocket(nullptr); } @@ -115,7 +119,7 @@ void ServerPlayer::kick() { void ServerPlayer::reconnect(ClientSocket *client) { setSocket(client); alive = true; - client->disconnect(this); + // client->disconnect(this); if (server->getPlayers().count() <= 10) { server->broadcast("ServerMessage", tr("%1 backed").arg(getScreenName())); } @@ -159,3 +163,51 @@ void ServerPlayer::resumeGameTimer() { int ServerPlayer::getGameTime() { return gameTime + (getState() == Player::Online ? gameTimer.elapsed() / 1000 : 0); } + +void ServerPlayer::onStateChanged() { + auto _room = getRoom(); + if (!_room || _room->isLobby()) return; + auto room = qobject_cast(_room); + if (room->isAbandoned()) return; + + auto state = getState(); + room->doBroadcastNotify(room->getPlayers(), "NetStateChanged", + QString("[%1,\"%2\"]").arg(getId()).arg(getStateString())); + + if (state == Player::Online) { + resumeGameTimer(); + } else { + pauseGameTimer(); + } +} + +void ServerPlayer::onDisconnected() { + qInfo() << "Player" << getId() << "disconnected"; + if (server->getPlayers().count() <= 10) { + server->broadcast("ServerMessage", tr("%1 logged out").arg(getScreenName())); + } + + auto _room = getRoom(); + if (_room->isLobby()) { + setState(Player::Robot); // 大厅!然而又不能设Offline + deleteLater(); + } else { + auto room = qobject_cast(_room); + if (room->isStarted()) { + if (room->getObservers().contains(this)) { + room->removeObserver(this); + deleteLater(); + return; + } + setState(Player::Offline); + setSocket(nullptr); + // TODO: add a robot + } else { + setState(Player::Robot); // 大厅!然而又不能设Offline + // 这里有一个多线程问题,可能与Room::gameOver同时deleteLater导致出事 + // FIXME: 这种解法肯定不安全 + if (!room->insideGameOver) + deleteLater(); + } + } +} diff --git a/src/server/serverplayer.h b/src/server/serverplayer.h index 9bbf8d2d..6960bf77 100644 --- a/src/server/serverplayer.h +++ b/src/server/serverplayer.h @@ -52,9 +52,12 @@ public: int getGameTime(); signals: - void disconnected(); void kicked(); +public slots: + void onStateChanged(); + void onDisconnected(); + private: ClientSocket *socket; // socket for communicating with client Router *router; diff --git a/src/ui/qmlbackend.cpp b/src/ui/qmlbackend.cpp index db4f363f..5bb6a5a7 100644 --- a/src/ui/qmlbackend.cpp +++ b/src/ui/qmlbackend.cpp @@ -570,6 +570,18 @@ void QmlBackend::showDialog(const QString &type, const QString &text, const QStr } } +void QmlBackend::askFixResource() { +#if defined(Q_OS_ANDROID) || defined(Q_OS_LINUX) + auto box = new QMessageBox(QMessageBox::Question, tr("fix resource"), + tr("help: fix resource"), QMessageBox::Ok | QMessageBox::Cancel); + connect(box, &QMessageBox::accepted, box, []() { + QFile::remove("fk_ver"); qApp->exit(); }); + connect(box, &QMessageBox::finished, box, &QObject::deleteLater); + box->setWindowModality(Qt::NonModal); + box->show(); +#endif +} + void QmlBackend::removeRecord(const QString &fname) { QFile::remove("recording/" + fname); } diff --git a/src/ui/qmlbackend.h b/src/ui/qmlbackend.h index 53be74c4..8aaba5bd 100644 --- a/src/ui/qmlbackend.h +++ b/src/ui/qmlbackend.h @@ -66,6 +66,7 @@ public: Q_INVOKABLE void showDialog(const QString &type, const QString &text, const QString &orig = QString()); + Q_INVOKABLE void askFixResource(); qreal volume() const { return m_volume; } void setVolume(qreal v) { m_volume = v; }