EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BulkDB.cpp
Go to the documentation of this file.
1 
12 #include "cache/BulkDB.h"
13 
14 
16 {
17  m_bulkData.clear();
18  m_bulkDataChunks.clear();
19 
20  // will need to make this dynamic at some point.
21  // dunno how yet.
22  m_chunks = 43;
23  m_loaded = false;
24 }
25 
27 {
28  //Close();
29 }
30 
32 {
33  for (auto cur : m_bulkData)
34  PyDecRef(cur.second);
35 
36  for (auto cur : m_bulkDataChunks)
37  PyDecRef(cur.second);
38 
39  m_bulkData.clear();
40  m_bulkDataChunks.clear();
41  sLog.Warning(" BulkDataMgr", "Bulk Data Manager has been closed." );
42 }
43 
44 
45 /* updated files to send to client in bulkdata
46  *
47  dgmOperands = 800002, -74
48  dgmExpressions = 800003, -17758
49  dgmAttributes = 800004, -1791
50  dgmEffects = 800005, -2854
51  dgmTypeAttributes = 800006, -353290
52  dgmTypeEffects = 800007, -33777
53  dgmUnits = 800009, -57
54  invBlueprintTypes = 1200001 -3292 // may not need this one...no, data is updated thru server call
55  actKeyTypes = 2001100001 -22
56  jnlEntryTypeIDs = 2001100002 -63
57 
58  these are split in chunks of ~10k with hard-coded chunk numbers
59  as such, current (hacked) system only allows for all-or-none bulkdata file sets
60  code has been started for data 'sets' but isnt finished as i dont understand how to determine needed files by hash
61  */
62 
64 {
65  if (m_loaded)
66  return;
67 
68  double start = GetTimeMSeconds();
69 
70  m_bulkData.insert(std::pair<uint8, PyRep*>(0, GetOperands()));
71  m_bulkData.insert(std::pair<uint8, PyRep*>(1, GetDogmaAttribs()));
72  m_bulkData.insert(std::pair<uint8, PyRep*>(2, GetDogmaEffects()));
73 
74  for (int i = 1; i < m_chunks; ++i) {
75  switch (i) {
76  case 1:
77  case 2: {
78  m_bulkDataChunks.insert(std::pair<uint8, PyRep*>(i, GetExpressions(i+1)));
79  } break;
80  case 3:
81  case 4:
82  case 5:
83  case 6: {
84  uint8 chunk = i - 2; // 1 to 4
85  m_bulkDataChunks.insert(std::pair<uint8, PyRep*>(i, GetDogmaTypeEffects(chunk)));
86  } break;
87  default: {
88  uint8 chunk = i - 6; // 1 to 36
89  if (chunk > 36)
90  assert(true); // make error here for wrong chunkID
91  m_bulkDataChunks.insert(std::pair<uint8, PyRep*>(i, GetDogmaTypeAttribs(chunk)));
92  } break;
93  }
94  }
95  if (m_bulkDataChunks.size() > 0)
96  m_loaded = true;
97 
98  sLog.Cyan(" BulkDataMgr", "%u BulkData Chunks loaded in %.3fms.", m_bulkDataChunks.size(), (GetTimeMSeconds() - start));
99 }
100 
102 {
103  switch (setID) {
104  case 0: {
105  return m_chunks;
106  }
107  case 1: {
108  return 1;
109  }
110  case 2: { // dgmExpressions
111  return 2;
112  }
113  case 3: { // dgmTypeAttributes
114  return 36;
115  }
116  case 4: { // dgmTypeEffects
117  return 4;
118  }
119  }
120 
121  return 0;
122 }
124 {
125  if (chunkID > m_chunks) {
126  // error. caught in bulkMgr
127  return -1;
128  }
129  switch (setID) {
130  case 0: {
131  switch (chunkID) {
132  case 1:
133  case 2: {
134  return 800003; //dgmExpressions
135  } break;
136  case 3:
137  case 4:
138  case 5:
139  case 6: {
140  return 800007; //dgmTypeEffects
141  } break;
142  default: {
143  return 800006; //dgmTypeAttributes
144  } break;
145  }
146  } break;
147  case 1: {
148  return 800003; //dgmExpressions
149  } break;
150  case 2: {
151  return 800007; //dgmTypeEffects
152  } break;
153  case 3: {
154  return 800006; //dgmTypeAttributes
155  } break;
156  }
157 
158  // error. caught in bulkMgr
159  return -1;
160 }
161 
164 {
165  if (!m_loaded)
166  Initialize();
167 
168  std::map<uint8, PyRep*>::const_iterator itr = m_bulkData.find(chunkID);
169  if (itr != m_bulkData.end())
170  return itr->second;
171  return nullptr;
172 }
173 
175 {
176  if (!m_loaded)
177  Initialize();
178 
180  switch (setID) {
181  case 0: {
182  std::map<uint8, PyRep*>::const_iterator itr = m_bulkDataChunks.find(chunkID);
183  if (itr != m_bulkDataChunks.end())
184  return itr->second;
185  } break;
186  case 1: {
187  return GetExpressions(chunkID);
188  } break;
189  case 2: {
190  return GetDogmaTypeEffects(chunkID);
191  } break;
192  case 3: {
193  return GetDogmaTypeAttribs(chunkID);
194  } break;
195  }
196 
197  // make error here. should not reach this point.
198  return nullptr;
199 }
200 
202 { //74
203  DBQueryResult res;
204  if( !sDatabase.RunQuery(res,
205  " SELECT operandID, operandKey, description, format, arg1categoryID, arg2categoryID, resultCategoryID, pythonFormat FROM dgmOperands"))
206  {
207  codelog(DATABASE__ERROR, "Error in GetOperands: %s", res.error.c_str());
208  return nullptr;
209  }
210  return DBResultToCRowset(res);
211 }
212 
214 { //1791
215  DBQueryResult res;
216  if(!sDatabase.RunQuery(res,
217  "SELECT attributeID, attributeName, attributeCategory, description, maxAttributeID, attributeIdx, "
218  "chargeRechargeTimeID, defaultValue, published, unitID, displayName, displayNameID, stackable, highIsGood, iconID, dataID FROM dgmAttributeTypes"))
219  {
220  _log(DATABASE__ERROR, "Error in GetDogmaAttribs: %s",res.error.c_str());
221  return nullptr;
222  }
223  return DBResultToCRowset(res);
224 }
225 
227 { //2854
228  DBQueryResult res;
229  if(!sDatabase.RunQuery(res,
230  "SELECT effectID, effectName, displayNameID, descriptionID, dataID, effectCategory, preExpression, postExpression,"
231  " description, guid, isOffensive, isAssistance, durationAttributeID, trackingSpeedAttributeID, dischargeAttributeID,"
232  " rangeAttributeID, falloffAttributeID, disallowAutoRepeat, published, displayName, isWarpSafe, rangeChance,"
233  " electronicChance, propulsionChance, distribution, sfxName, npcUsageChanceAttributeID, "
234  " npcActivationChanceAttributeID, fittingUsageChanceAttributeID, iconID, modifierInfo FROM dgmEffects"))
235  {
236  _log(DATABASE__ERROR, "Error in GetDogmaEffects: %s",res.error.c_str());
237  return nullptr;
238  }
239 
240  return DBResultToCRowset(res);
241  /* this doesnt work right.... AttributeError: EveConfig instance has no attribute 'dgmeffects'
242  PyList* list = new PyList();
243  DBResultRow row;
244  while (res.GetRow(row)) {
245  PyDict* dict = new PyDict();
246  dict->SetItemString("effectID", new PyInt(row.GetInt(0)));
247  dict->SetItemString("effectName", new PyString(row.GetText(1)));
248  dict->SetItemString("displayNameID", new PyInt(row.GetInt(2)));
249  dict->SetItemString("descriptionID", new PyInt(row.GetInt(3)));
250  dict->SetItemString("dataID", new PyInt(row.GetInt(4)));
251  dict->SetItemString("effectCategory", new PyInt(row.GetInt(5)));
252  dict->SetItemString("preExpression", new PyInt(row.GetInt(6)));
253  dict->SetItemString("postExpression", new PyInt(row.GetInt(7)));
254  dict->SetItemString("description", new PyString(row.GetText(8)));
255  dict->SetItemString("guid", new PyString(row.GetText(9)));
256  dict->SetItemString("isOffensive", new PyBool(row.GetBool(10)));
257  dict->SetItemString("isAssistance", new PyBool(row.GetBool(11)));
258  dict->SetItemString("disallowAutoRepeat", new PyBool(row.GetBool(17)));
259  dict->SetItemString("published", new PyBool(row.GetBool(18)));
260  dict->SetItemString("displayName", new PyString(row.GetText(19)));
261  dict->SetItemString("isWarpSafe", new PyBool(row.GetBool(20)));
262  dict->SetItemString("rangeChance", new PyBool(row.GetBool(21)));
263  dict->SetItemString("electronicChance", new PyBool(row.GetBool(22)));
264  dict->SetItemString("propulsionChance", new PyBool(row.GetBool(23)));
265  dict->SetItemString("distribution", new PyInt(row.GetInt(24)));
266  dict->SetItemString("sfxName", new PyString(row.GetText(25)));
267  dict->SetItemString("npcUsageChanceAttributeID", new PyInt(row.GetInt(26)));
268  dict->SetItemString("npcActivationChanceAttributeID", new PyInt(row.GetInt(27)));
269  dict->SetItemString("fittingUsageChanceAttributeID", new PyInt(row.GetInt(28)));
270  dict->SetItemString("iconID", new PyInt(row.GetInt(29)));
271  dict->SetItemString("modifierInfo", new PyString(row.GetText(30)));
272 
273  // these can be null
274  if (row.IsNull(12))
275  dict->SetItemString("durationAttributeID", PyStatic.NewNone());
276  else
277  dict->SetItemString("durationAttributeID", new PyInt(row.GetInt(12)));
278  if (row.IsNull(13))
279  dict->SetItemString("trackingSpeedAttributeID", PyStatic.NewNone());
280  else
281  dict->SetItemString("trackingSpeedAttributeID", new PyInt(row.GetInt(13)));
282  if (row.IsNull(14))
283  dict->SetItemString("dischargeAttributeID", PyStatic.NewNone());
284  else
285  dict->SetItemString("dischargeAttributeID", new PyInt(row.GetInt(14)));
286  if (row.IsNull(15))
287  dict->SetItemString("rangeAttributeID", PyStatic.NewNone());
288  else
289  dict->SetItemString("rangeAttributeID", new PyInt(row.GetInt(15)));
290  if (row.IsNull(16))
291  dict->SetItemString("falloffAttributeID", PyStatic.NewNone());
292  else
293  dict->SetItemString("falloffAttributeID", new PyInt(row.GetInt(16)));
294 
295  list->AddItem(new PyObject("util.KeyVal", dict));
296  }
297 
298  return list;
299  */
300 }
301 
302 PyRep* BulkDB::GetExpressions(uint8 chunkID) // 2 chunks
303 { //17758
304  DBQueryResult res;
305  std::ostringstream q;
306  q << " SELECT expressionID, operandID, arg1, arg2, expressionValue, description, expressionName, expressionTypeID, expressionGroupID, expressionAttributeID";
307  q << " FROM dgmExpressions";
308  switch (chunkID) {
309  case 1: {
310  q << " LIMIT 0, 9000";
311  } break;
312  case 2: {
313  q << " LIMIT 9000, 18000";
314  } break;
315  };
316 
317  if( !sDatabase.RunQuery(res, q.str().c_str())) // start at row 0 and get next 8k rows
318  {
319  codelog(DATABASE__ERROR, "Error in GetExpressions: %s", res.error.c_str());
320  return nullptr;
321  }
322  return DBResultToCRowset(res);
323 }
324 
326 { //33777
327  DBQueryResult res;
328  std::ostringstream q;
329  q << "SELECT typeID,effectID,isDefault FROM dgmTypeEffects";
330  switch (chunkID) {
331  case 1: {
332  q << " LIMIT 0, 9000";
333  } break;
334  case 2: {
335  q << " LIMIT 9000, 9000";
336  } break;
337  case 3: {
338  q << " LIMIT 18000, 9000";
339  } break;
340  case 4: {
341  q << " LIMIT 27000, 9000";
342  } break;
343  };
344 
345  if(!sDatabase.RunQuery(res, q.str().c_str()))
346  {
347  _log(DATABASE__ERROR, "Error in GetDogmaTypeEffects: %s",res.error.c_str());
348  return nullptr;
349  }
350  return DBResultToCRowset(res);
351 }
352 
354 { //353290
355  DBQueryResult res;
356  std::ostringstream q;
357  q << "SELECT typeID, attributeID, IF(valueInt IS NULL, valueFloat, valueInt) AS value FROM dgmTypeAttributes";
358  switch (chunkID) {
359  case 1: {
360  q << " LIMIT 0, 10000";
361  } break;
362  case 2: {
363  q << " LIMIT 10000, 10000";
364  } break;
365  case 3: {
366  q << " LIMIT 20000, 10000";
367  } break;
368  case 4: {
369  q << " LIMIT 30000, 10000";
370  } break;
371  case 5: {
372  q << " LIMIT 40000, 10000";
373  } break;
374  case 6: {
375  q << " LIMIT 50000, 10000";
376  } break;
377  case 7: {
378  q << " LIMIT 60000, 10000";
379  } break;
380  case 8: {
381  q << " LIMIT 70000, 10000";
382  } break;
383  case 9: {
384  q << " LIMIT 80000, 10000";
385  } break;
386  case 10: {
387  q << " LIMIT 90000, 10000";
388  } break;
389  case 11: {
390  q << " LIMIT 100000, 10000";
391  } break;
392  case 12: {
393  q << " LIMIT 110000, 10000";
394  } break;
395  case 13: {
396  q << " LIMIT 120000, 10000";
397  } break;
398  case 14: {
399  q << " LIMIT 130000, 10000";
400  } break;
401  case 15: {
402  q << " LIMIT 140000, 10000";
403  } break;
404  case 16: {
405  q << " LIMIT 150000, 10000";
406  } break;
407  case 17: {
408  q << " LIMIT 160000, 10000";
409  } break;
410  case 18: {
411  q << " LIMIT 170000, 10000";
412  } break;
413  case 19: {
414  q << " LIMIT 180000, 10000";
415  } break;
416  case 20: {
417  q << " LIMIT 190000, 10000";
418  } break;
419  case 21: {
420  q << " LIMIT 200000, 10000";
421  } break;
422  case 22: {
423  q << " LIMIT 210000, 10000";
424  } break;
425  case 23: {
426  q << " LIMIT 220000, 10000";
427  } break;
428  case 24: {
429  q << " LIMIT 230000, 10000";
430  } break;
431  case 25: {
432  q << " LIMIT 240000, 10000";
433  } break;
434  case 26: {
435  q << " LIMIT 250000, 10000";
436  } break;
437  case 27: {
438  q << " LIMIT 260000, 10000";
439  } break;
440  case 28: {
441  q << " LIMIT 270000, 10000";
442  } break;
443  case 29: {
444  q << " LIMIT 280000, 10000";
445  } break;
446  case 30: {
447  q << " LIMIT 290000, 10000";
448  } break;
449  case 31: {
450  q << " LIMIT 300000, 10000";
451  } break;
452  case 32: {
453  q << " LIMIT 310000, 10000";
454  } break;
455  case 33: {
456  q << " LIMIT 320000, 10000";
457  } break;
458  case 34: {
459  q << " LIMIT 330000, 10000";
460  } break;
461  case 35: {
462  q << " LIMIT 340000, 10000";
463  } break;
464  case 36: {
465  q << " LIMIT 350000, 10000";
466  } break;
467  };
468 
469  if(!sDatabase.RunQuery(res, q.str().c_str()))
470  {
471  _log(DATABASE__ERROR, "Error in GetDogmaTypeAttribs: %s",res.error.c_str());
472  return nullptr;
473  }
474  return DBResultToCRowset(res);
475 }
Base Python wire object.
Definition: PyRep.h:66
unsigned __int8 uint8
Definition: eve-compat.h:46
#define sDatabase
Definition: dbcore.h:199
std::map< uint8, PyRep * > m_bulkDataChunks
Definition: BulkDB.h:51
#define _log(type, fmt,...)
Definition: logsys.h:124
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
BulkDB()
Definition: BulkDB.cpp:15
PyRep * GetBulkDataChunks(uint8 setID, uint8 chunkID)
Definition: BulkDB.cpp:174
uint8 GetNumChunks(uint8 setID=0)
Definition: BulkDB.cpp:101
bool m_loaded
Definition: BulkDB.h:47
void Close()
Definition: BulkDB.cpp:31
std::map< uint8, PyRep * > m_bulkData
Definition: BulkDB.h:50
signed __int32 int32
Definition: eve-compat.h:49
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
void Initialize()
Definition: BulkDB.cpp:63
const char * c_str() const
Definition: dbcore.h:48
double GetTimeMSeconds()
Definition: utils_time.cpp:104
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyRep * GetDogmaTypeEffects(uint8 chunkID)
Definition: BulkDB.cpp:325
PyRep * GetBulkData(uint8 chunkID)
Definition: BulkDB.cpp:163
#define PyDecRef(op)
Definition: PyRep.h:57
PyRep * GetDogmaAttribs()
Definition: BulkDB.cpp:213
PyRep * GetOperands()
Definition: BulkDB.cpp:201
PyRep * GetDogmaEffects()
Definition: BulkDB.cpp:226
~BulkDB()
Definition: BulkDB.cpp:26
PyRep * GetDogmaTypeAttribs(uint8 chunkID)
Definition: BulkDB.cpp:353
DBerror error
Definition: dbcore.h:69
uint8 m_chunks
Definition: BulkDB.h:48
int32 GetFileIDfromChunk(uint8 setID, uint8 chunkID)
Definition: BulkDB.cpp:123
PyRep * GetExpressions(uint8 chunkID)
Definition: BulkDB.cpp:302