From cf1c4856d7d03a173db4b849e7c02f6f732eef6a Mon Sep 17 00:00:00 2001 From: Ranieri Althoff <1993083+ranisalt@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:17:05 +0200 Subject: [PATCH] Move player bug report to Lua (#4768) Co-authored-by: Xmish <95135755+xmish@users.noreply.github.com> --- data/cpplinter.lua | 5 ----- data/events/scripts/player.lua | 4 ++-- .../events/player/default_onReportBug.lua | 4 ++-- data/scripts/network/bug_report.lua | 20 +++++++++++++++++++ src/enums.h | 8 -------- src/game.cpp | 10 ---------- src/game.h | 1 - src/luascript.cpp | 5 ----- src/protocolgame.cpp | 19 +----------------- src/protocolgame.h | 1 - 10 files changed, 25 insertions(+), 52 deletions(-) create mode 100644 data/scripts/network/bug_report.lua diff --git a/data/cpplinter.lua b/data/cpplinter.lua index 1ec43bd420..2ade631a98 100644 --- a/data/cpplinter.lua +++ b/data/cpplinter.lua @@ -2432,11 +2432,6 @@ GAME_STATE_SHUTDOWN = 4 GAME_STATE_CLOSING = 5 GAME_STATE_MAINTAIN = 6 -BUG_CATEGORY_MAP = 0 -BUG_CATEGORY_TYPO = 1 -BUG_CATEGORY_TECHNICAL = 2 -BUG_CATEGORY_OTHER = 3 - REPORT_TYPE_NAME = 0 REPORT_TYPE_STATEMENT = 1 REPORT_TYPE_BOT = 2 diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index b2122a0ad5..b66b32b883 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -81,9 +81,9 @@ function Player:onReportRuleViolation(targetName, reportType, reportReason, comm end end -function Player:onReportBug(message, position, category) +function Player:onReportBug(message, position) if hasEvent.onReportBug then - return Event.onReportBug(self, message, position, category) + return Event.onReportBug(self, message, position) end return true end diff --git a/data/scripts/events/player/default_onReportBug.lua b/data/scripts/events/player/default_onReportBug.lua index ac0e2f805d..6e1be92bb9 100644 --- a/data/scripts/events/player/default_onReportBug.lua +++ b/data/scripts/events/player/default_onReportBug.lua @@ -1,6 +1,6 @@ local event = Event() -event.onReportBug = function(self, message, position, category) +event.onReportBug = function(self, message, position) if self:getAccountType() == ACCOUNT_TYPE_NORMAL then return false end @@ -16,7 +16,7 @@ event.onReportBug = function(self, message, position, category) io.output(file) io.write("------------------------------\n") io.write("Name: " .. name) - if category == BUG_CATEGORY_MAP then + if position ~= nil then io.write(" [Map position: " .. position.x .. ", " .. position.y .. ", " .. position.z .. "]") end local playerPosition = self:getPosition() diff --git a/data/scripts/network/bug_report.lua b/data/scripts/network/bug_report.lua new file mode 100644 index 0000000000..df09f29566 --- /dev/null +++ b/data/scripts/network/bug_report.lua @@ -0,0 +1,20 @@ +local handler = PacketHandler(0xE6) + +local BUG_CATEGORY_MAP = 0 +local BUG_CATEGORY_TYPO = 1 +local BUG_CATEGORY_TECHNICAL = 2 +local BUG_CATEGORY_OTHER = 3 + +function handler.onReceive(player, msg) + local category = msg:getByte() + local message = msg:getString() + + local position + if category == BUG_CATEGORY_MAP then + position = msg:getPosition() + end + + player:onReportBug(message, position) +end + +handler:register() diff --git a/src/enums.h b/src/enums.h index 03d054e7d1..ffa90bcf4a 100644 --- a/src/enums.h +++ b/src/enums.h @@ -36,14 +36,6 @@ enum RuleViolationReasons_t : uint8_t REPORT_REASON_SERVICEAGREEMENT = 20 }; -enum BugReportType_t : uint8_t -{ - BUG_CATEGORY_MAP = 0, - BUG_CATEGORY_TYPO = 1, - BUG_CATEGORY_TECHNICAL = 2, - BUG_CATEGORY_OTHER = 3 -}; - enum ThreadState { THREAD_STATE_RUNNING, diff --git a/src/game.cpp b/src/game.cpp index a29ebd252c..7b10f38afa 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5087,16 +5087,6 @@ void Game::playerReportRuleViolation(uint32_t playerId, const std::string& targe g_events->eventPlayerOnReportRuleViolation(player, targetName, reportType, reportReason, comment, translation); } -void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category) -{ - Player* player = getPlayerByID(playerId); - if (!player) { - return; - } - - g_events->eventPlayerOnReportBug(player, message, position, category); -} - void Game::playerDebugAssert(uint32_t playerId, const std::string& assertLine, const std::string& date, const std::string& description, const std::string& comment) { diff --git a/src/game.h b/src/game.h index 1075ee7868..25cc3df568 100644 --- a/src/game.h +++ b/src/game.h @@ -297,7 +297,6 @@ class Game void sendGuildMotd(uint32_t playerId); void kickPlayer(uint32_t playerId, bool displayEffect); - void playerReportBug(uint32_t playerId, const std::string& message, const Position& position, uint8_t category); void playerDebugAssert(uint32_t playerId, const std::string& assertLine, const std::string& date, const std::string& description, const std::string& comment); void playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice); diff --git a/src/luascript.cpp b/src/luascript.cpp index 3b06db23cb..24b0d43d69 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -1309,11 +1309,6 @@ void LuaScriptInterface::registerFunctions() registerEnum(L, AMMO_STONE); registerEnum(L, AMMO_SNOWBALL); - registerEnum(L, BUG_CATEGORY_MAP); - registerEnum(L, BUG_CATEGORY_TYPO); - registerEnum(L, BUG_CATEGORY_TECHNICAL); - registerEnum(L, BUG_CATEGORY_OTHER); - registerEnum(L, CALLBACK_PARAM_LEVELMAGICVALUE); registerEnum(L, CALLBACK_PARAM_SKILLVALUE); registerEnum(L, CALLBACK_PARAM_TARGETTILE); diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index 952d10cba5..744d2ff123 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -749,9 +749,7 @@ void ProtocolGame::parsePacket(NetworkMessage& msg) // case 0xE0: break; // premium shop (?) // case 0xE4: break; // buy charm rune // case 0xE5: break; // request character info (cyclopedia) - case 0xE6: - parseBugReport(msg); - break; + // case 0xE6: break // parse bug report case 0xE7: /* thank you */ break; case 0xE8: @@ -1435,21 +1433,6 @@ void ProtocolGame::parseRuleViolationReport(NetworkMessage& msg) }); } -void ProtocolGame::parseBugReport(NetworkMessage& msg) -{ - uint8_t category = msg.getByte(); - auto message = msg.getString(); - - Position position; - if (category == BUG_CATEGORY_MAP) { - position = msg.getPosition(); - } - - g_dispatcher.addTask([=, playerID = player->getID(), message = std::string{message}]() { - g_game.playerReportBug(playerID, message, position, category); - }); -} - void ProtocolGame::parseDebugAssert(NetworkMessage& msg) { if (debugAssertSent) { diff --git a/src/protocolgame.h b/src/protocolgame.h index 7b38125d2f..1e9cff5255 100644 --- a/src/protocolgame.h +++ b/src/protocolgame.h @@ -100,7 +100,6 @@ class ProtocolGame final : public Protocol void parseFollow(NetworkMessage& msg); void parseEquipObject(NetworkMessage& msg); - void parseBugReport(NetworkMessage& msg); void parseDebugAssert(NetworkMessage& msg); void parseRuleViolationReport(NetworkMessage& msg);