From f5a34b9a3db71178f195004846d6d169140f50d0 Mon Sep 17 00:00:00 2001 From: dongresource Date: Tue, 9 Mar 2021 17:57:33 +0100 Subject: [PATCH] Reject completion packets for missions that aren't in progress Also reject players requesting more than 6 missions. This is just a minimal measure to prevent replaying mission completion packets. This part of the codebase will be largely refactored soon, so more through changes can wait. --- src/MissionManager.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/MissionManager.cpp b/src/MissionManager.cpp index 390cb38..c90a634 100644 --- a/src/MissionManager.cpp +++ b/src/MissionManager.cpp @@ -55,6 +55,7 @@ bool MissionManager::startTask(Player* plr, int TaskID) { if (i == ACTIVE_MISSION_COUNT - 1 && plr->tasks[i] != TaskID) { std::cout << "[WARN] Player has more than 6 active missions!?" << std::endl; + return false; } return true; @@ -164,6 +165,21 @@ bool MissionManager::endTask(CNSocket *sock, int32_t taskNum, int choice) { // ugly pointer/reference juggling for the sake of operator overloading... TaskData& task = *Tasks[taskNum]; + // update player + int i; + for (i = 0; i < ACTIVE_MISSION_COUNT; i++) { + if (plr->tasks[i] == taskNum) { + plr->tasks[i] = 0; + for (int j = 0; j < 3; j++) { + plr->RemainingNPCCount[i][j] = 0; + } + } + } + if (i == ACTIVE_MISSION_COUNT - 1 && plr->tasks[i] != 0) { + std::cout << "[WARN] Player completed non-active mission!?" << std::endl; + return false; + } + // mission rewards if (Rewards.find(taskNum) != Rewards.end()) { if (giveMissionReward(sock, taskNum, choice) == -1) @@ -188,20 +204,6 @@ bool MissionManager::endTask(CNSocket *sock, int32_t taskNum, int choice) { if (task["m_iSUItem"][i] != 0) dropQuestItem(sock, taskNum, task["m_iSUInstancename"][i], task["m_iSUItem"][i], 0); - // update player - int i; - for (i = 0; i < ACTIVE_MISSION_COUNT; i++) { - if (plr->tasks[i] == taskNum) { - plr->tasks[i] = 0; - for (int j = 0; j < 3; j++) { - plr->RemainingNPCCount[i][j] = 0; - } - } - } - if (i == ACTIVE_MISSION_COUNT - 1 && plr->tasks[i] != 0) { - std::cout << "[WARN] Player completed non-active mission!?" << std::endl; - } - // if it's the last task if (task["m_iSUOutgoingTask"] == 0) { // save completed mission on player