OregonCore  revision fb2a440-git
Your Favourite TBC server
WardenDataStorage.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "WorldPacket.h"
20 #include "WorldSession.h"
21 #include "Log.h"
22 #include "Database/DatabaseEnv.h"
23 #include "WardenDataStorage.h"
24 #include "WardenWin.h"
25 
27 {
28  InternalDataID = 1;
29 }
30 
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 }
41 
42 void CWardenDataStorage::Init(bool reload)
43 {
44  LoadWardenDataResult(reload);
45 }
46 
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 }
132 
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 }
140 
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 }
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
void LoadWardenDataResult(bool reload=false)
#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
void Init(bool reload=false)
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
WardenDataResult * GetWardenResultById(uint32 Id)
ACE_UINT32 uint32
Definition: Define.h:71
WardenData * GetWardenDataById(uint32 Id)