From 68c600facc1230d7c790ff4c2a6a196017c868b7 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 20 Mar 2022 20:28:26 -0700 Subject: [PATCH 1/5] Added better bug reports --- dGame/dGameMessages/GameMessages.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 53699f4e..221a4737 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5900,6 +5900,13 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) body.push_back(character); } + auto character = entity->GetCharacter(); + if (character) { + body.append(GeneralUtils::ASCIIToUTF16(" charID: ")); + body.append(GeneralUtils::ASCIIToUTF16(std::to_string(character->GetID()))); + body.push_back(' '); + } + uint32_t clientVersionLength; inStream->Read(clientVersionLength); for (unsigned int k = 0; k < clientVersionLength; k++) { @@ -5915,7 +5922,19 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) inStream->Read(character); nOtherPlayerID.push_back(character); } - + // Convert other player id from LWOOBJID to the database id. + std::istringstream iss(nOtherPlayerID); + LWOOBJID nOtherPlayerLWOOBJID; + iss >> nOtherPlayerLWOOBJID; + if (nOtherPlayerLWOOBJID != LWOOBJID_EMPTY) { + auto otherPlayer = EntityManager::Instance()->GetEntity(nOtherPlayerLWOOBJID); + if (otherPlayer) { + auto character = otherPlayer->GetCharacter(); + if (character) { + nOtherPlayerID = std::to_string(character->GetID()); + } + } + } uint32_t selectionLength; inStream->Read(selectionLength); for (unsigned int k = 0; k < selectionLength; k++) { From 22a00de8cd7e1ad97dd821eba3f0fe2f20ff9c6a Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 20 Mar 2022 20:46:15 -0700 Subject: [PATCH 2/5] added char id column --- migrations/dlu/0_initial.sql | 1 + migrations/dlu/2_reporter_id.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 migrations/dlu/2_reporter_id.sql diff --git a/migrations/dlu/0_initial.sql b/migrations/dlu/0_initial.sql index 16cb3e7e..61380f76 100644 --- a/migrations/dlu/0_initial.sql +++ b/migrations/dlu/0_initial.sql @@ -150,6 +150,7 @@ CREATE TABLE activity_log ( DROP TABLE IF EXISTS bug_reports; CREATE TABLE bug_reports ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + reporter_id INT NOT NULL DEFAULT 0, body TEXT NOT NULL, client_version TEXT NOT NULL, other_player_id TEXT NOT NULL, diff --git a/migrations/dlu/2_reporter_id.sql b/migrations/dlu/2_reporter_id.sql new file mode 100644 index 00000000..26103342 --- /dev/null +++ b/migrations/dlu/2_reporter_id.sql @@ -0,0 +1 @@ +ALTER TABLE bug_reports ADD reporter_id INT NOT NULL DEFAULT 0; From e2bfdcd174f3bfb72b56c654ae2be51308926025 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 20 Mar 2022 20:46:34 -0700 Subject: [PATCH 3/5] moved char id storage --- dGame/dGameMessages/GameMessages.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 221a4737..297df424 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5890,6 +5890,7 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) std::string nOtherPlayerID; std::string selection; uint32_t messageLength; + int32_t reporterID; //Reading: inStream->Read(messageLength); @@ -5901,11 +5902,7 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) } auto character = entity->GetCharacter(); - if (character) { - body.append(GeneralUtils::ASCIIToUTF16(" charID: ")); - body.append(GeneralUtils::ASCIIToUTF16(std::to_string(character->GetID()))); - body.push_back(' '); - } + if (character) reporterID = character->GetID(); uint32_t clientVersionLength; inStream->Read(clientVersionLength); @@ -5944,11 +5941,12 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) } try { - sql::PreparedStatement* insertBug = Database::CreatePreppedStmt("INSERT INTO `bug_reports`(body, client_version, other_player_id, selection) VALUES (?, ?, ?, ?)"); + sql::PreparedStatement* insertBug = Database::CreatePreppedStmt("INSERT INTO `bug_reports`(body, client_version, other_player_id, selection, reporter_id) VALUES (?, ?, ?, ?, ?)"); insertBug->setString(1, GeneralUtils::UTF16ToWTF8(body)); insertBug->setString(2, clientVersion); insertBug->setString(3, nOtherPlayerID); insertBug->setString(4, selection); + insertBug->setInt(5, reporterID); insertBug->execute(); delete insertBug; } From 6499139a4949abed3a48195ee051d984befbc66b Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 24 Mar 2022 01:11:21 -0700 Subject: [PATCH 4/5] moved addition to new migration. --- migrations/dlu/0_initial.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/migrations/dlu/0_initial.sql b/migrations/dlu/0_initial.sql index 61380f76..16cb3e7e 100644 --- a/migrations/dlu/0_initial.sql +++ b/migrations/dlu/0_initial.sql @@ -150,7 +150,6 @@ CREATE TABLE activity_log ( DROP TABLE IF EXISTS bug_reports; CREATE TABLE bug_reports ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - reporter_id INT NOT NULL DEFAULT 0, body TEXT NOT NULL, client_version TEXT NOT NULL, other_player_id TEXT NOT NULL, From cf708813703e696ba0c6a8affcba63984428696d Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 31 Mar 2022 03:20:13 -0700 Subject: [PATCH 5/5] simplified conversion --- dGame/dGameMessages/GameMessages.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 297df424..70c6bcae 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5890,7 +5890,7 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) std::string nOtherPlayerID; std::string selection; uint32_t messageLength; - int32_t reporterID; + int32_t reporterID = 0; //Reading: inStream->Read(messageLength); @@ -5920,18 +5920,9 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) nOtherPlayerID.push_back(character); } // Convert other player id from LWOOBJID to the database id. - std::istringstream iss(nOtherPlayerID); - LWOOBJID nOtherPlayerLWOOBJID; - iss >> nOtherPlayerLWOOBJID; - if (nOtherPlayerLWOOBJID != LWOOBJID_EMPTY) { - auto otherPlayer = EntityManager::Instance()->GetEntity(nOtherPlayerLWOOBJID); - if (otherPlayer) { - auto character = otherPlayer->GetCharacter(); - if (character) { - nOtherPlayerID = std::to_string(character->GetID()); - } - } - } + uint32_t otherPlayer = LWOOBJID_EMPTY; + if (nOtherPlayerID != "") otherPlayer = std::atoi(nOtherPlayerID.c_str()); + uint32_t selectionLength; inStream->Read(selectionLength); for (unsigned int k = 0; k < selectionLength; k++) { @@ -5944,14 +5935,14 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) sql::PreparedStatement* insertBug = Database::CreatePreppedStmt("INSERT INTO `bug_reports`(body, client_version, other_player_id, selection, reporter_id) VALUES (?, ?, ?, ?, ?)"); insertBug->setString(1, GeneralUtils::UTF16ToWTF8(body)); insertBug->setString(2, clientVersion); - insertBug->setString(3, nOtherPlayerID); + insertBug->setString(3, std::to_string(otherPlayer)); insertBug->setString(4, selection); insertBug->setInt(5, reporterID); insertBug->execute(); delete insertBug; } catch (sql::SQLException& e) { - Game::logger->Log("HandleReportBug", "Couldn't save bug report!\n"); + Game::logger->Log("HandleReportBug", "Couldn't save bug report! (%s)\n", e.what()); } }