From fff6c1d51f6a7f73641f3bc5c1729582a5f0f70a Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 13 May 2019 13:25:43 +0800 Subject: [PATCH] Add success status to player who reports --- src/network/protocols/client_lobby.cpp | 17 +++++++++++++++++ src/network/protocols/client_lobby.hpp | 1 + src/network/protocols/server_lobby.cpp | 20 +++++++++++++++++--- src/network/protocols/server_lobby.hpp | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 4a5d456fb..ece2c7c6a 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -172,6 +172,7 @@ bool ClientLobby::notifyEvent(Event* event) case LE_LIVE_JOIN_ACK: liveJoinAcknowledged(event); break; case LE_KART_INFO: handleKartInfo(event); break; case LE_START_RACE: startGame(event); break; + case LE_REPORT_PLAYER: reportSuccess(event); break; default: return false; break; @@ -1448,3 +1449,19 @@ void ClientLobby::addSpectateHelperMessage() const "or <%s> for the camera position.", left, right, back); MessageQueue::add(MessageQueue::MT_GENERIC, msg); } // addSpectateHelperMessage + +// ---------------------------------------------------------------------------- +void ClientLobby::reportSuccess(Event* event) +{ + bool succeeded = false; + core::stringw reporting_name; + succeeded = event->data().getUInt8() == 1; + if (succeeded) + event->data().decodeStringW(&reporting_name); + if (succeeded && !reporting_name.empty()) + { + // I18N: Tell player he has successfully report this named player + core::stringw msg = _("Successfully reported %s.", reporting_name); + MessageQueue::add(MessageQueue::MT_GENERIC, msg); + } +} // reportSuccess diff --git a/src/network/protocols/client_lobby.hpp b/src/network/protocols/client_lobby.hpp index a5ae57e87..74123809d 100644 --- a/src/network/protocols/client_lobby.hpp +++ b/src/network/protocols/client_lobby.hpp @@ -66,6 +66,7 @@ private: void updatePlayerList(Event* event); void handleChat(Event* event); void handleServerInfo(Event* event); + void reportSuccess(Event* event); void handleBadTeam(); void handleBadConnection(); void becomingServerOwner(); diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 1c5531dbe..d371d7b7f 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -783,12 +783,13 @@ void ServerLobby::cleanupDatabase() //----------------------------------------------------------------------------- /** Run simple query with write lock waiting and optional function, this * function has no callback for the return (if any) by the query. + * Return true if no error occurs */ -void ServerLobby::easySQLQuery(const std::string& query, +bool ServerLobby::easySQLQuery(const std::string& query, std::function bind_function) const { if (!m_db) - return; + return false; sqlite3_stmt* stmt = NULL; int ret = sqlite3_prepare_v2(m_db, query.c_str(), -1, &stmt, 0); if (ret == SQLITE_OK) @@ -802,6 +803,7 @@ void ServerLobby::easySQLQuery(const std::string& query, Log::error("ServerLobby", "Error finalize database for easy query %s: %s", query.c_str(), sqlite3_errmsg(m_db)); + return false; } } else @@ -809,7 +811,9 @@ void ServerLobby::easySQLQuery(const std::string& query, Log::error("ServerLobby", "Error preparing database for easy query %s: %s", query.c_str(), sqlite3_errmsg(m_db)); + return false; } + return true; } // easySQLQuery //----------------------------------------------------------------------------- @@ -928,7 +932,8 @@ void ServerLobby::writePlayerReport(Event* event) ServerConfig::m_player_reports_table.c_str(), reporter->getAddress().getIP(), reporter_npp->getOnlineId(), reporting_peer->getAddress().getIP(), reporting_npp->getOnlineId()); - easySQLQuery(query, [reporter_npp, reporting_npp, info](sqlite3_stmt* stmt) + bool written = easySQLQuery(query, + [reporter_npp, reporting_npp, info](sqlite3_stmt* stmt) { // SQLITE_TRANSIENT to copy string if (sqlite3_bind_text(stmt, 1, ServerConfig::m_server_uid.c_str(), @@ -959,6 +964,15 @@ void ServerLobby::writePlayerReport(Event* event) StringUtils::wideToUtf8(reporting_npp->getName()).c_str()); } }); + if (written) + { + NetworkString* success = getNetworkString(); + success->setSynchronous(true); + success->addUInt8(LE_REPORT_PLAYER).addUInt8(1) + .encodeString(reporting_npp->getName()); + event->getPeer()->sendPacket(success, true/*reliable*/); + delete success; + } #endif } // writePlayerReport diff --git a/src/network/protocols/server_lobby.hpp b/src/network/protocols/server_lobby.hpp index b11eed145..4d1af011f 100644 --- a/src/network/protocols/server_lobby.hpp +++ b/src/network/protocols/server_lobby.hpp @@ -88,7 +88,7 @@ private: void cleanupDatabase(); - void easySQLQuery(const std::string& query, + bool easySQLQuery(const std::string& query, std::function bind_function = nullptr) const; void checkTableExists(const std::string& table, bool& result);