diff --git a/Fk/Pages/Lobby.qml b/Fk/Pages/Lobby.qml index ab969a59..f67b022c 100644 --- a/Fk/Pages/Lobby.qml +++ b/Fk/Pages/Lobby.qml @@ -203,8 +203,8 @@ Item { icon.name: "application-exit" onClicked: { toast.show("Goodbye."); - Backend.quitLobby(); mainStack.pop(); + Backend.quitLobby(); } } diff --git a/lua/server/events/gameflow.lua b/lua/server/events/gameflow.lua index c1f948f9..fe0e1218 100644 --- a/lua/server/events/gameflow.lua +++ b/lua/server/events/gameflow.lua @@ -47,6 +47,16 @@ local function discardInit(room, player) end end +local function checkNoHuman(room) + for _, p in ipairs(room.players) do + -- TODO: trust + if p.serverplayer:getStateString() == "online" then + return + end + end + room:gameOver("") +end + GameEvent.functions[GameEvent.DrawInitial] = function(self) local room = self.room @@ -98,6 +108,8 @@ GameEvent.functions[GameEvent.DrawInitial] = function(self) break end + checkNoHuman(room) + coroutine.yield("__handleRequest", (remainTime - elapsed) * 1000) end diff --git a/lua/server/request.lua b/lua/server/request.lua index a7469872..afa85f03 100644 --- a/lua/server/request.lua +++ b/lua/server/request.lua @@ -10,6 +10,7 @@ local function tellRoomToObserver(self, player) player:doNotify("EnterRoom", json.encode{ #self.players, self.timeout, self.settings }) + player:doNotify("StartGame", "") -- send player data for _, p in ipairs(self:getOtherPlayers(observee, true, true)) do diff --git a/lua/server/serverplayer.lua b/lua/server/serverplayer.lua index 674d96fa..7eca40af 100644 --- a/lua/server/serverplayer.lua +++ b/lua/server/serverplayer.lua @@ -273,6 +273,7 @@ function ServerPlayer:reconnect() self:doNotify("EnterRoom", json.encode{ #room.players, room.timeout, room.settings, }) + self:doNotify("StartGame", "") room:notifyProperty(self, self, "role") -- send player data diff --git a/src/client/client.cpp b/src/client/client.cpp index 1ca84694..7b0afc9e 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -8,6 +8,8 @@ Client *ClientInstance; ClientPlayer *Self; +static ClientPlayer dummyPlayer(0, nullptr); + Client::Client(QObject *parent) : QObject(parent), callback(0) { ClientInstance = this; Self = new ClientPlayer(0, this); @@ -27,6 +29,9 @@ Client::Client(QObject *parent) : QObject(parent), callback(0) { Client::~Client() { ClientInstance = nullptr; + // Self->deleteLater(); + Self = nullptr; + Backend->getEngine()->rootContext()->setContextProperty("Self", &dummyPlayer); lua_close(L); router->getSocket()->disconnectFromHost(); router->getSocket()->deleteLater(); diff --git a/src/core/util.cpp b/src/core/util.cpp index bbe061bc..a7f6e2be 100644 --- a/src/core/util.cpp +++ b/src/core/util.cpp @@ -215,8 +215,6 @@ QString calcFileMD5() { writeDirMD5(flist, "packages", "*.qml"); writeDirMD5(flist, "packages", "*.js"); writeDirMD5(flist, "lua", "*.lua"); - writeDirMD5(flist, "qml", "*.qml"); - writeDirMD5(flist, "qml", "*.js"); writeDirMD5(flist, "Fk", "*.qml"); writeDirMD5(flist, "Fk", "*.js"); diff --git a/src/main.cpp b/src/main.cpp index f55ee6d2..0be1ba0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,12 +85,12 @@ static void prepareForLinux() { const char *home = getenv("HOME"); if (!strcmp(buf, "/usr/bin/FreeKill")) { system("mkdir -p ~/.local/share/FreeKill"); - installFkAssets("/usr/share/FreeKill", QString("%1/.local/share").arg(home)); + installFkAssets("/usr/share/FreeKill", QString("%1/.local/share/FreeKill").arg(home)); chdir(home); chdir(".local/share/FreeKill"); } else if (!strcmp(buf, "/usr/local/bin/FreeKill")) { system("mkdir -p ~/.local/share/FreeKill"); - installFkAssets("/usr/local/share/FreeKill", QString("%1/.local/share").arg(home)); + installFkAssets("/usr/local/share/FreeKill", QString("%1/.local/share/FreeKill").arg(home)); chdir(home); chdir(".local/share/FreeKill"); } diff --git a/src/server/server.cpp b/src/server/server.cpp index 3ac18bf8..3aa87567 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -52,11 +52,11 @@ Server::Server(QObject *parent) : QObject(parent) { } } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 20; i++) { if (!this->isListening) { return; } - QThread::sleep(2); + QThread::sleep(1); } foreach (auto p, this->players.values()) { @@ -75,6 +75,12 @@ Server::~Server() { isListening = false; ServerInstance = nullptr; m_lobby->deleteLater(); + foreach (auto room, idle_rooms) { + room->deleteLater(); + } + foreach (auto room, rooms) { + room->deleteLater(); + } sqlite3_close(db); RSA_free(rsa); } @@ -390,13 +396,13 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name, void Server::onRoomAbandoned() { Room *room = qobject_cast(sender()); + if (room->isRunning()) { + room->wait(); + } room->gameOver(); rooms.remove(room->getId()); updateRoomList(); // room->deleteLater(); - if (room->isRunning()) { - room->wait(); - } idle_rooms.push(room); #ifdef QT_DEBUG qDebug() << rooms.size() << "running room(s)," << idle_rooms.size() diff --git a/src/ui/qmlbackend.cpp b/src/ui/qmlbackend.cpp index 894510ad..00fbb356 100644 --- a/src/ui/qmlbackend.cpp +++ b/src/ui/qmlbackend.cpp @@ -108,9 +108,9 @@ void QmlBackend::joinServer(QString address) { void QmlBackend::quitLobby() { if (ClientInstance) - delete ClientInstance; - // if (ServerInstance) - // delete ServerInstance; + ClientInstance->deleteLater(); + if (ServerInstance) + ServerInstance->deleteLater(); } void QmlBackend::emitNotifyUI(const QString &command, const QString &jsonData) { @@ -120,6 +120,7 @@ void QmlBackend::emitNotifyUI(const QString &command, const QString &jsonData) { QString QmlBackend::translate(const QString &src) { if (!ClientInstance) return src; + lua_State *L = ClientInstance->getLuaState(); lua_getglobal(L, "Translate"); auto bytes = src.toUtf8(); @@ -172,6 +173,7 @@ void QmlBackend::pushLuaValue(lua_State *L, QVariant v) { QString QmlBackend::callLuaFunction(const QString &func_name, QVariantList params) { + if (!ClientInstance) return "{}"; lua_State *L = ClientInstance->getLuaState(); lua_getglobal(L, func_name.toLatin1().data());