OregonCore  revision fb2a440-git
Your Favourite TBC server
CWardenDataStorage Class Reference

#include <WardenDataStorage.h>

Public Member Functions

 CWardenDataStorage ()
 
 ~CWardenDataStorage ()
 
uint32 GenerateInternalDataID ()
 
WardenDataGetWardenDataById (uint32 Id)
 
WardenDataResultGetWardenResultById (uint32 Id)
 
void Init (bool reload=false)
 

Public Attributes

uint32 InternalDataID
 
std::vector< uint32MemCheckIds
 

Protected Member Functions

void LoadWardenDataResult (bool reload=false)
 

Private Attributes

std::map< uint32, WardenData * > _data_map
 
std::map< uint32, WardenDataResult * > _result_map
 

Detailed Description

Definition at line 39 of file WardenDataStorage.h.

Constructor & Destructor Documentation

CWardenDataStorage::CWardenDataStorage ( )

Definition at line 26 of file WardenDataStorage.cpp.

References InternalDataID.

27 {
28  InternalDataID = 1;
29 }
CWardenDataStorage::~CWardenDataStorage ( )

Definition at line 31 of file WardenDataStorage.cpp.

References _data_map, and _result_map.

32 {
33  std::map<uint32, WardenData*>::iterator itr1 = _data_map.begin();
34  for (; itr1 != _data_map.end(); ++itr1)
35  delete itr1->second;
36 
37  std::map<uint32, WardenDataResult*>::iterator itr2 = _result_map.begin();
38  for (; itr2 != _result_map.end(); ++itr2)
39  delete itr2->second;
40 }
std::map< uint32, WardenDataResult * > _result_map
std::map< uint32, WardenData * > _data_map

Member Function Documentation

uint32 CWardenDataStorage::GenerateInternalDataID ( )
inline

Definition at line 52 of file WardenDataStorage.h.

References WardenDataStorage.

Referenced by LoadWardenDataResult().

53  {
54  return InternalDataID++;
55  }
WardenData * CWardenDataStorage::GetWardenDataById ( uint32  Id)

Definition at line 133 of file WardenDataStorage.cpp.

References _data_map.

Referenced by WardenWin::HandleData(), and WardenWin::RequestData().

134 {
135  std::map<uint32, WardenData*>::const_iterator itr = _data_map.find(Id);
136  if (itr != _data_map.end())
137  return itr->second;
138  return NULL;
139 }
std::map< uint32, WardenData * > _data_map
WardenDataResult * CWardenDataStorage::GetWardenResultById ( uint32  Id)

Definition at line 141 of file WardenDataStorage.cpp.

References _result_map.

Referenced by WardenWin::HandleData().

142 {
143  std::map<uint32, WardenDataResult*>::const_iterator itr = _result_map.find(Id);
144  if (itr != _result_map.end())
145  return itr->second;
146  return NULL;
147 }
std::map< uint32, WardenDataResult * > _result_map
void CWardenDataStorage::Init ( bool  reload = false)

Definition at line 42 of file WardenDataStorage.cpp.

References LoadWardenDataResult().

Referenced by World::SetInitialWorldSettings().

43 {
44  LoadWardenDataResult(reload);
45 }
void LoadWardenDataResult(bool reload=false)
void CWardenDataStorage::LoadWardenDataResult ( bool  reload = false)
protected

Definition at line 47 of file WardenDataStorage.cpp.

References _data_map, _result_map, WardenData::Address, BigNumber::AsByteArray(), DRIVER_CHECK, GenerateInternalDataID(), Field::GetCppString(), BigNumber::GetNumBytes(), WardenData::i, WardenData::id, InternalDataID, WardenData::Length, LUA_STR_CHECK, MEM_CHECK, MemCheckIds, MODULE_CHECK, MPQ_CHECK, PAGE_CHECK_A, PAGE_CHECK_B, PROC_CHECK, Database::Query(), WardenDataResult::res, BigNumber::SetBinary(), BigNumber::SetHexStr(), sLog, WardenData::str, WardenData::Type, and WorldDatabase.

Referenced by Init().

48 {
49  if (reload)
50  {
51  _data_map.clear();
52  _result_map.clear();
53  InternalDataID = 1;
54  }
55 
56  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT `check`, `data`, `result`, `address`, `length`, `str`, `id` FROM warden_data_result");
57 
58  uint32 count = 0;
59 
60  if (!result)
61  {
62  sLog.outString(">> Loaded %u warden data and results", count);
63  return;
64  }
65 
66 
67  do
68  {
69  ++count;
70 
71  Field* fields = result->Fetch();
72 
73  uint8 type = fields[0].GetUInt8();
74 
76  WardenData* wd = new WardenData();
77  wd->Type = type;
78  wd->id = fields[6].GetUInt16();
79 
80  if (type == PAGE_CHECK_A || type == PAGE_CHECK_B || type == DRIVER_CHECK)
81  {
82  std::string data = fields[1].GetCppString();
83  wd->i.SetHexStr(data.c_str());
84  int len = data.size() / 2;
85  if (wd->i.GetNumBytes() < len)
86  {
87  uint8 temp[24];
88  memset(temp, 0, len);
89  memcpy(temp, wd->i.AsByteArray(), wd->i.GetNumBytes());
90  std::reverse(temp, temp + len);
91  wd->i.SetBinary((uint8*)temp, len);
92  }
93  }
94 
95  if (type == MEM_CHECK || type == MODULE_CHECK)
96  MemCheckIds.push_back(id);
97 
98  if (type == MEM_CHECK || type == PAGE_CHECK_A || type == PAGE_CHECK_B || type == PROC_CHECK)
99  {
100  wd->Address = fields[3].GetUInt32();
101  wd->Length = fields[4].GetUInt8();
102  }
103 
104  // PROC_CHECK support missing
105  if (type == MEM_CHECK || type == MPQ_CHECK || type == LUA_STR_CHECK || type == DRIVER_CHECK || type == MODULE_CHECK)
106  wd->str = fields[5].GetCppString();
107 
108  _data_map[id] = wd;
109 
110  if (type == MPQ_CHECK || type == MEM_CHECK)
111  {
112  std::string result = fields[2].GetCppString();
114  wr->res.SetHexStr(result.c_str());
115  int len = result.size() / 2;
116  if (wr->res.GetNumBytes() < len)
117  {
118  uint8* temp = new uint8[len];
119  memset(temp, 0, len);
120  memcpy(temp, wr->res.AsByteArray(), wr->res.GetNumBytes());
121  std::reverse(temp, temp + len);
122  wr->res.SetBinary((uint8*)temp, len);
123  delete [] temp;
124  }
125  _result_map[id] = wr;
126  }
127  }
128  while (result->NextRow());
129 
130  sLog.outString(">> Loaded %u warden data and results", count);
131 }
uint8 * AsByteArray(int minSize=0, bool reverse=true)
Definition: BigNumber.cpp:166
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
int GetNumBytes(void)
Definition: BigNumber.cpp:151
std::map< uint32, WardenDataResult * > _result_map
Definition: Field.h:24
#define sLog
Log class singleton.
Definition: Log.h:187
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
uint32 GenerateInternalDataID()
std::vector< uint32 > MemCheckIds
std::map< uint32, WardenData * > _data_map
void SetBinary(const uint8 *bytes, int len)
Definition: BigNumber.cpp:59
ACE_UINT8 uint8
Definition: Define.h:73
std::string GetCppString() const
Definition: Field.h:52
void SetHexStr(const char *str)
Definition: BigNumber.cpp:66
std::string str
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
ACE_UINT32 uint32
Definition: Define.h:71

Member Data Documentation

std::map<uint32, WardenData*> CWardenDataStorage::_data_map
private
std::map<uint32, WardenDataResult*> CWardenDataStorage::_result_map
private
uint32 CWardenDataStorage::InternalDataID

Definition at line 44 of file WardenDataStorage.h.

Referenced by CWardenDataStorage(), and LoadWardenDataResult().

std::vector<uint32> CWardenDataStorage::MemCheckIds

Definition at line 45 of file WardenDataStorage.h.

Referenced by LoadWardenDataResult(), and WardenWin::RequestData().


The documentation for this class was generated from the following files: