Implement ClientListEntry::LoadTaskLockouts

This commit is contained in:
Michael Cook (mackal) 2019-05-22 22:38:07 -04:00
parent bc0f705227
commit 408ce4650f
4 changed files with 42 additions and 0 deletions

View File

@ -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`)
);

View File

@ -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,

View File

@ -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;
}

View File

@ -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; }