Skip to content

Commit

Permalink
Move player bug report to Lua (#4768)
Browse files Browse the repository at this point in the history
Co-authored-by: Xmish <[email protected]>
  • Loading branch information
ranisalt and xmish authored Jul 16, 2024
1 parent 98ff8a8 commit cf1c485
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 52 deletions.
5 changes: 0 additions & 5 deletions data/cpplinter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions data/scripts/events/player/default_onReportBug.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions data/scripts/network/bug_report.lua
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 0 additions & 8 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 1 addition & 18 deletions src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit cf1c485

Please sign in to comment.