mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-04 04:12:25 +00:00
Implement SharedTaskManager::LoadSharedTaskState
This commit is contained in:
parent
5c1ab3b24c
commit
bc0f705227
@ -321,13 +321,47 @@ bool SharedTaskManager::LoadSharedTasks(int single_task)
|
|||||||
*/
|
*/
|
||||||
bool SharedTaskManager::LoadSharedTaskState()
|
bool SharedTaskManager::LoadSharedTaskState()
|
||||||
{
|
{
|
||||||
// clean up expired tasks ... We may not want to do this if world crashes and has to be restarted
|
// one may think we should clean up expired tasks, but we don't just in case world is booting back up after a crash
|
||||||
// May need to wait to do it to cleanly inform existing zones to clean up expired tasks
|
// we will clean them up in the normal process loop so zones get told to clean up
|
||||||
|
std::string query = "SELECT `id`, `taskid`, `acceptedtime`, `locked` FROM `shared_task_state`";
|
||||||
|
auto results = database.QueryDatabase(query);
|
||||||
|
|
||||||
|
if (results.Success() && results.RowCount() > 0) {
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
int id = atoi(row[0]);
|
||||||
|
|
||||||
|
auto &task = tasks[id];
|
||||||
|
task.SetID(id);
|
||||||
|
task.SetTaskID(atoi(row[1]));
|
||||||
|
task.SetAcceptedTime(atoi(row[2]));
|
||||||
|
task.SetLocked(atoi(row[3]) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query = "SELECT `shared_id`, `charid`, `name`, `leader` FROM `shared_task_members` ORDER BY shared_id ASC";
|
||||||
|
results = database.QueryDatabase(query);
|
||||||
|
if (results.Success() && results.RowCount() > 0) {
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
int task_id = atoi(row[0]);
|
||||||
|
// hmm not sure best way to do this, fine for now
|
||||||
|
if (tasks.count(task_id) == 1)
|
||||||
|
tasks[task_id].AddMember(row[2], nullptr, atoi(row[3]) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load existing tasks. We may not want to actually do this here and wait for a client to log in
|
// Load existing tasks. We may not want to actually do this here and wait for a client to log in
|
||||||
// But the crash case may actually dictate we should :P
|
// But the crash case may actually dictate we should :P
|
||||||
|
|
||||||
// set next_id to highest used ID
|
// set next_id to highest used ID
|
||||||
|
query = "SELECT MAX(id) FROM shared_task_state";
|
||||||
|
results = database.QueryDatabase(query);
|
||||||
|
if (results.Success() && results.RowCount() == 1) {
|
||||||
|
auto row = results.begin();
|
||||||
|
next_id = atoi(row[0]);
|
||||||
|
} else {
|
||||||
|
next_id = 0; // oh well
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +369,6 @@ bool SharedTaskManager::LoadSharedTaskState()
|
|||||||
* Return the next unused ID
|
* Return the next unused ID
|
||||||
* Hopefully this does not grow too large.
|
* Hopefully this does not grow too large.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int SharedTaskManager::GetNextID()
|
int SharedTaskManager::GetNextID()
|
||||||
{
|
{
|
||||||
next_id++;
|
next_id++;
|
||||||
|
|||||||
@ -14,14 +14,14 @@ struct SharedTaskMember {
|
|||||||
ClientListEntry *cle;
|
ClientListEntry *cle;
|
||||||
bool leader;
|
bool leader;
|
||||||
// TODO: monster mission stuff
|
// TODO: monster mission stuff
|
||||||
SharedTaskMember() : leader(false), cle(nullptr) {}
|
SharedTaskMember() : cle(nullptr), leader(false) {}
|
||||||
SharedTaskMember(std::string name, ClientListEntry *cle, bool leader) : name(name), cle(cle), leader(leader) {}
|
SharedTaskMember(std::string name, ClientListEntry *cle, bool leader) : name(name), cle(cle), leader(leader) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SharedTask {
|
class SharedTask {
|
||||||
public:
|
public:
|
||||||
SharedTask() : id(0), task_id(0), locked(false) {}
|
SharedTask() : id(0), task_id(0), accepted_time(0), locked(false) {}
|
||||||
SharedTask(int id, int task_id) : id(id), task_id(task_id), locked(false) {}
|
SharedTask(int id, int task_id) : id(id), task_id(task_id), accepted_time(0), locked(false) {}
|
||||||
~SharedTask() {}
|
~SharedTask() {}
|
||||||
|
|
||||||
void AddMember(std::string name, ClientListEntry *cle = nullptr, bool leader = false)
|
void AddMember(std::string name, ClientListEntry *cle = nullptr, bool leader = false)
|
||||||
@ -37,12 +37,19 @@ public:
|
|||||||
void SetCLESharedTasks();
|
void SetCLESharedTasks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void SetID(int in) { id = in; }
|
||||||
|
inline void SetTaskID(int in) { task_id = in; }
|
||||||
|
inline void SetAcceptedTime(int in) { accepted_time = in; }
|
||||||
|
inline void SetLocked(bool in) { locked = in; }
|
||||||
int id; // id we have in our map
|
int id; // id we have in our map
|
||||||
int task_id; // ID of the task we're on
|
int task_id; // ID of the task we're on
|
||||||
|
int accepted_time; // timestamp of when accepted, initially set by zone
|
||||||
bool locked;
|
bool locked;
|
||||||
std::string leader_name;
|
std::string leader_name;
|
||||||
std::vector<SharedTaskMember> members;
|
std::vector<SharedTaskMember> members;
|
||||||
ClientTaskInformation task_state; // book keeping
|
ClientTaskInformation task_state; // book keeping
|
||||||
|
|
||||||
|
friend class SharedTaskManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SharedTaskManager {
|
class SharedTaskManager {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user