From 408ce4650f6cf3436bcaa92ca98e5bc6720f0848 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Wed, 22 May 2019 22:38:07 -0400 Subject: [PATCH] Implement ClientListEntry::LoadTaskLockouts --- utils/sql/git/required/sharedtasks.sql | 1 + world/client.cpp | 1 + world/cliententry.cpp | 38 ++++++++++++++++++++++++++ world/cliententry.h | 2 ++ 4 files changed, 42 insertions(+) diff --git a/utils/sql/git/required/sharedtasks.sql b/utils/sql/git/required/sharedtasks.sql index 3c14cdcb6..7a12f05a6 100644 --- a/utils/sql/git/required/sharedtasks.sql +++ b/utils/sql/git/required/sharedtasks.sql @@ -23,6 +23,7 @@ CREATE TABLE `task_replay_groups` ( CREATE TABLE `character_task_lockouts` ( `charid` INT NOT NULL, `replay_group` INT NOT NULL, + `original_id` INT NOT NULL, `timestamp` INT NOT NULL, PRIMARY KEY(`charid`, `replay_group`) ); diff --git a/world/client.cpp b/world/client.cpp index bc044dae5..098de3a29 100644 --- a/world/client.cpp +++ b/world/client.cpp @@ -1221,6 +1221,7 @@ void Client::EnterWorld(bool TryBootup) { } cle->SetChar(charid, char_name); + cle->LoadTaskLockouts(); database.UpdateLiveChar(char_name, GetAccountID()); Log(Logs::General, Logs::World_Server, diff --git a/world/cliententry.cpp b/world/cliententry.cpp index 0c9f05b90..9b7c124fc 100644 --- a/world/cliententry.cpp +++ b/world/cliententry.cpp @@ -377,3 +377,41 @@ int ClientListEntry::GetTaskLockoutTimeLeft(int id) const return 0; } +/* + * Cleans up expired lockouts from the DB + */ +bool ClientListEntry::CleanExpiredTaskLockouts() const +{ + std::string query = + StringFormat("DELETE FROM `character_task_lockouts` WHERE `charid` = %i AND `timestamp` > %i", pcharid, + Timer::GetCurrentTime()); + auto results = database.QueryDatabase(query); + return results.Success(); +} + +/* + * Loads task lockouts + */ +bool ClientListEntry::LoadTaskLockouts() +{ + CleanExpiredTaskLockouts(); + std::string query = StringFormat( + "SELECT `replay_group`, `original_id`, `timestamp` FROM `character_task_lockouts` WHERE `charid` = %i", + pcharid); + auto results = database.QueryDatabase(query); + if (!results.Success()) + return false; + + if (results.RowCount() > 0) { + for (auto row = results.begin(); row != results.end(); ++row) { + TaskTimer t; + t.ID = atoi(row[0]); + t.original_id = atoi(row[1]); + t.expires = atoi(row[2]); + m_task_replay_timers.push_back(t); + } + } + + return true; +} + diff --git a/world/cliententry.h b/world/cliententry.h index 7709d9215..19b7fcaa1 100644 --- a/world/cliententry.h +++ b/world/cliententry.h @@ -91,6 +91,8 @@ public: void ProcessTellQueue(); // shared task stuff + bool CleanExpiredTaskLockouts() const; + bool LoadTaskLockouts(); int GetTaskLockoutExpire(int id) const; int GetTaskLockoutTimeLeft(int id) const; inline int GetCurrentSharedTaskID() const { return shared_task_id; }