EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ManagerDB.cpp
Go to the documentation of this file.
1 
10 #include "eve-server.h"
11 
12 #include "system/Asteroid.h"
14 
15 
17  if (!sDatabase.RunQuery(res, "SELECT categoryID, categoryName, description, published FROM invCategories"))
18  codelog(DATABASE__ERROR, "Error in GetCategoryData query: %s.", res.error.c_str());
19 
20  _log(DATABASE__RESULTS, "GetCategoryData returned %u items", res.GetRowCount());
21 }
22 
24 {
25  if (!sDatabase.RunQuery(res,
26  "SELECT"
27  " groupID,"
28  " categoryID,"
29  " groupName,"
30  " description,"
31  " useBasePrice,"
32  " allowManufacture,"
33  " allowRecycler,"
34  " anchored,"
35  " anchorable,"
36  " fittableNonSingleton,"
37  " published "
38  " FROM invGroups "))
39  codelog(DATABASE__ERROR, "Error in GetGroupData query: %s.", res.error.c_str());
40 
41  _log(DATABASE__RESULTS, "GetGroupData returned %u items", res.GetRowCount());
42 }
43 
45 {
46  if (!sDatabase.RunQuery(res,
47  "SELECT"
48  " t.typeID,"
49  " t.groupID,"
50  " t.typeName,"
51  " t.description,"
52  " t.radius,"
53  " t.mass,"
54  " t.volume,"
55  " t.capacity,"
56  " t.portionSize,"
57  " t.raceID,"
58  " t.basePrice,"
59  " t.published,"
60  " t.marketGroupID,"
61  " t.chanceOfDuplicating,"
62  " m.metaGroupID"
63  " FROM invTypes AS t"
64  " LEFT JOIN invMetaTypes AS m USING (typeID)"))
65  codelog(DATABASE__ERROR, "Error in GetTypeData query: %s.", res.error.c_str());
66 
67  _log(DATABASE__RESULTS, "GetTypeData returned %u items", res.GetRowCount());
68 }
69 
71 {
72  if (!sDatabase.RunQuery(res, "SELECT typeID, typeName FROM invTypes WHERE groupID IN (SELECT groupID FROM invGroups WHERE categoryID = 16)"))
73  codelog(DATABASE__ERROR, "Error in GetSkillList query: %s", res.error.c_str());
74 
75  _log(DATABASE__RESULTS, "GetSkillList returned %u items", res.GetRowCount());
76 }
77 
79 {
80  if (!sDatabase.RunQuery(res, "SELECT typeID, attributeID, valueInt, valueFloat FROM dgmTypeAttributes"))
81  codelog(DATABASE__ERROR, "Error in GetTypeAttributes query: %s", res.error.c_str());
82 
83  _log(DATABASE__RESULTS, "GetTypeAttributes returned %u items", res.GetRowCount());
84 }
85 
87 {
88  if (!sDatabase.RunQuery(res, "SELECT corporationID, factionID FROM crpNPCCorporations" ))
89  codelog(DATABASE__ERROR, "Error in LoadCorpFactionData query: %s", res.error.c_str());
90 
91  _log(DATABASE__RESULTS, "LoadCorpFactionData returned %u items", res.GetRowCount());
92 }
93 
95  DBQueryResult res;
96  if (!sDatabase.RunQuery(res, "SELECT entryTypeID, entryTypeName, entryTypeNameID FROM jnlEntryTypeIDs")) {
97  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
98  return nullptr;
99  }
100 
101  _log(DATABASE__RESULTS, "GetEntryTypes returned %u items", res.GetRowCount());
102 
103  return DBResultToRowset(res);
104 }
105 
107  DBQueryResult res;
108  if (!sDatabase.RunQuery(res, "SELECT keyID, keyType, keyName, keyNameID FROM actKeyTypes")) {
109  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
110  return nullptr;
111  }
112 
113  _log(DATABASE__RESULTS, "GetKeyMap returned %u items", res.GetRowCount());
114 
115  return DBResultToRowset(res);
116 }
117 
119  DBQueryResult res;
120  if (!sDatabase.RunQuery(res, "SELECT billTypeID, billTypeName, description FROM billTypes")) {
121  codelog(DATABASE__ERROR, "Failed to query bill types: %s.", res.error.c_str());
122  return nullptr;
123  }
124 
125  _log(DATABASE__RESULTS, "GetBillTypes returned %u items", res.GetRowCount());
126 
127  return DBResultToRowset(res);
128 }
129 
131  // NOTE: havent found data for agents in space yet....still looking.
132  DBQueryResult res;
133  if(!sDatabase.RunQuery(res,
134  "SELECT"
135  " agt.agentID,"
136  " agt.agentTypeID,"
137  " agt.divisionID,"
138  " agt.level,"
139  " agt.quality,"
140  " agt.corporationID,"
141  " chr.stationID,"
142  " chr.gender,"
143  " bl.bloodlineID"
144  " FROM agtAgents AS agt"
145  " LEFT JOIN chrNPCCharacters AS chr ON chr.characterID = agt.agentID"
146  " LEFT JOIN bloodlineTypes AS bl ON bl.typeID = chr.typeID"
147  ))
148  {
149  codelog(DATABASE__ERROR, "Error in GetAgents query: %s", res.error.c_str());
150  return nullptr;
151  }
152 
153  _log(DATABASE__RESULTS, "GetAgents returned %u items", res.GetRowCount());
154  return DBResultToCRowset(res);
155 }
156 
158  DBQueryResult res;
159  if (!sDatabase.RunQuery(res,
160  "SELECT operandID, operandKey, description, format, arg1categoryID, arg2categoryID, resultCategoryID, pythonFormat FROM dgmOperands" )) {
161  codelog(DATABASE__ERROR, "Error in GetOperands query: %s.", res.error.c_str());
162  return nullptr;
163  }
164 
165  _log(DATABASE__RESULTS, "GetOperands returned %u items", res.GetRowCount());
166 
167  return DBResultToCIndexedRowset(res, "operandID");
168 }
169 
170 void ManagerDB::LoadCorpFactions(std::map<uint32, uint32> &into) {
171  DBQueryResult res;
172  if (!sDatabase.RunQuery(res, "SELECT corporationID,factionID FROM crpNPCCorporations" )) {
173  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
174  return;
175  }
176 
177  DBResultToUIntUIntDict(res, into);
178 }
179 
180 void ManagerDB::LoadFactionStationCounts(std::map<uint32, uint32> &into) {
181  DBQueryResult res;
182  if (!sDatabase.RunQuery(res, "SELECT factionID, COUNT(DISTINCT staStations.stationID) FROM crpNPCCorporations"
183  " LEFT JOIN staStations USING (corporationID)"
184  " GROUP BY factionID"))
185  {
186  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
187  return;
188  }
189 
190  DBResultToUIntUIntDict(res, into);
191 }
192 
193 void ManagerDB::LoadFactionSystemCounts(std::map<uint32, uint32> &into) {
194  DBQueryResult res;
195  //this is not quite right, but its good enough.
196  if (!sDatabase.RunQuery(res, "SELECT factionID, COUNT(solarSystemID) FROM mapSolarSystems GROUP BY factionID"))
197  {
198  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
199  return;
200  }
201 
202  DBResultToUIntUIntDict(res, into);
203 }
204 
205 void ManagerDB::LoadFactionRegions(std::map<int32, PyRep *> &into) {
206  DBQueryResult res;
207  //this is not quite right, but its good enough.
208  if (!sDatabase.RunQuery(res, "SELECT factionID,regionID FROM mapRegions WHERE factionID IS NOT NULL"))
209  {
210  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
211  return;
212  }
213  DBResultToIntIntlistDict(res, into);
214 }
215 
216 void ManagerDB::LoadFactionConstellations(std::map<int32, PyRep *> &into) {
217  DBQueryResult res;
218  //this is not quite right, but its good enough.
219  if (!sDatabase.RunQuery(res, "SELECT factionID,constellationID FROM mapConstellations WHERE factionID IS NOT NULL" ))
220  {
221  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
222  return;
223  }
224  DBResultToIntIntlistDict(res, into);
225 }
226 
227 void ManagerDB::LoadFactionSolarSystems(std::map<int32, PyRep *> &into) {
228  DBQueryResult res;
229  //this is not quite right, but its good enough.
230  if (!sDatabase.RunQuery(res, "SELECT factionID,solarSystemID FROM mapSolarSystems WHERE factionID IS NOT NULL"))
231  {
232  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
233  return;
234  }
235  DBResultToIntIntlistDict(res, into);
236 }
237 
238 void ManagerDB::LoadFactionRaces(std::map<int32, PyRep *> &into) {
239  DBQueryResult res;
240  //this is not quite right, but its good enough.
241  if (!sDatabase.RunQuery(res, "SELECT factionID,raceID FROM facRaces WHERE factionID IS NOT NULL"))
242  {
243  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
244  return;
245  }
246  DBResultToIntIntlistDict(res, into);
247 }
248 
250  DBQueryResult res;
251  if (!sDatabase.RunQuery(res,
252  "SELECT"
253  " crp.corporationName,"
254  " ncrp.corporationID,"
255  " ncrp.size, ncrp.extent, ncrp.solarSystemID,"
256  " ncrp.factionID, ncrp.sizeFactor, ncrp.stationCount, ncrp.stationSystemCount,"
257  " crp.stationID, crp.ceoID, chr.characterName AS ceoName"
258  " FROM crpNPCCorporations AS ncrp"
259  " LEFT JOIN crpCorporation AS crp ON ncrp.corporationID = crp.corporationID"
260  " LEFT JOIN chrNPCCharacters AS chr ON ceoID=chr.characterID"))
261  {
262  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
263  return nullptr;
264  }
265 
266  return DBResultToIntRowDict(res, 1);
267 }
268 
270  DBQueryResult res;
271  if (!sDatabase.RunQuery(res,
272  "SELECT "
273  " divisionID, divisionName, description, leaderType, divisionNameID, leaderTypeID"
274  " FROM crpNPCDivisions" )) {
275  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
276  return nullptr;
277  }
278 
279  return DBResultToRowset(res);
280 }
281 
283  //facSalvage (factionID,itemID,itemName)
284  if (!sDatabase.RunQuery(res, "SELECT factionID, itemID FROM facSalvage")) {
285  codelog(DATABASE__ERROR, "Error in GetSalvageGroups query: %s", res.error.c_str());
286  return;
287  }
288 }
289 
291 {
292  if (!sDatabase.RunQuery(res, "SELECT systemSec, roidID, percent FROM roidDistribution"))
293  codelog(DATABASE__ERROR, "Error in GetRoidDist query: %s", res.error.c_str());
294 }
295 
297 {
298  if (!sDatabase.RunQuery(res,
299  "SELECT mss.solarSystemID, mss.solarSystemName, mss.constellationID, mss.regionID, mss.securityClass, md.security, mss.factionID"
300  " FROM mapSolarSystems AS mss"
301  " LEFT JOIN mapDenormalize AS md ON (md.itemID = mss.solarSystemID)"
302  ))
303  codelog(DATABASE__ERROR, "Error in GetSystemData query: %s", res.error.c_str());
304 }
305 
307 {
308  if (!sDatabase.RunQuery(res,
309  "SELECT itemID, regionID, constellationID, solarSystemID, typeID, radius, x, y, z FROM mapDenormalize WHERE solarSystemID IS NOT NULL"))
310  codelog(DATABASE__ERROR, "Error in GetStaticInfo query: %s", res.error.c_str());
311 }
312 
314 {
315  if (!sDatabase.RunQuery(res, "SELECT agentID, locationID FROM agtAgents"))
316  codelog(DATABASE__ERROR, "Error in GetAgentLocation query: %s", res.error.c_str());
317 }
318 
320 {
321  if (!sDatabase.RunQuery(res, "SELECT typeID,volume FROM invTypes WHERE groupID = %u", EVEDB::invGroups::Moon_Materials))
322  codelog(DATABASE__ERROR, "Error in GetMoonResouces query: %s", res.error.c_str());
323 }
324 
326 {// sysSignatures (sigID,sigItemID,dungeonType,sigName,systemID,sigTypeID,sigGroupID,scanGroupID,scanAttributeID,x,y,z)
327  DBerror err;
328  if (!sDatabase.RunQuery(err,
329  "INSERT INTO sysSignatures"
330  " (sigID,sigItemID,dungeonType,sigName,systemID,sigTypeID,sigGroupID,scanGroupID,scanAttributeID,x,y,z)"
331  " VALUES ('%s', %u, %u, '%s', %u, %u, %u, %u, %u, %f, %f, %f)", \
332  sig.sigID.c_str(), sig.sigItemID, sig.dungeonType, sig.sigName.c_str(), sig.systemID, sig.sigTypeID, sig.sigGroupID, \
333  sig.scanGroupID, sig.scanAttributeID, sig.position.x, sig.position.y, sig.position.z )) {
334  _log(DATABASE__ERROR, "SaveActiveDungeon - unable to save dungeon");
335  }
336 }
337 
339 {// sysSignatures (sigID,sigItemID,dungeonType,sigName,systemID,sigTypeID,sigGroupID,scanGroupID,scanAttributeID,x,y,z)
340  if(!sDatabase.RunQuery(res,
341  "SELECT sigID,sigItemID,dungeonType,sigName,systemID,sigTypeID,sigGroupID,scanGroupID,scanAttributeID,x,y,z"
342  " FROM sysSignatures"
343  " ORDER BY systemid")) {
344  _log(DATABASE__ERROR, "Error in GetAnomalyList query: %s", res.error.c_str());
345  }
346 }
347 
348 GPoint ManagerDB::GetAnomalyPos(std::string& string)
349 {
350  DBQueryResult res;
351  if (!sDatabase.RunQuery(res, "SELECT x,y,z FROM sysSignatures WHERE sigID = '%s'", string.c_str()))
352  _log(DATABASE__ERROR, "Error in GetAnomalyPos query: %s", res.error.c_str());
353 
354  DBResultRow row;
355  if (!res.GetRow(row)) {
356  _log(DATABASE__MESSAGE, "GetAnomalyPos query returned no items");
357  return NULL_ORIGIN;
358  }
359 
360  GPoint pos(row.GetDouble(0), row.GetDouble(1), row.GetDouble(2));
361  return pos;
362 }
363 
364 // these next two arent used yet. dont remember what they were for. persistant shit for restart?
366 {// sysSignatures (sigTypeID,scanGroupID,sigGroupID,scanAttributeID,sigName,sigID,x,y,z)
367  if(!sDatabase.RunQuery(res,
368  "SELECT sigTypeID, scanGroupID, sigGroupID, scanAttributeID, sigName, sigID, x, y, z"
369  " FROM sysSignatures"
370  " WHERE systemID = %u", systemID)) {
371  _log(DATABASE__ERROR, "Error in GetSystemAnomalies query: %s", res.error.c_str());
372  }
373 }
374 
375 void ManagerDB::GetSystemAnomalies(uint32 systemID, std::vector< CosmicSignature >& sigs)
376 {// sysSignatures (sigID,sigItemID,sigName,systemID,sigTypeID,sigGroupID,scanGroupID,scanAttributeID,x,y,z)
377 
378 }
379 
381  if (!sDatabase.RunQuery(res, "SELECT regionID, factionID FROM mapRegions WHERE factionID != 0"))
382  _log(DATABASE__ERROR, "Error in GetRegionFactionInfo query: %s", res.error.c_str());
383 }
384 
386  if (!sDatabase.RunQuery(res, "SELECT regionID, ratFactionID FROM mapRegions WHERE ratFactionID != 0"))
387  _log(DATABASE__ERROR, "Error in GetRegionFactionInfo query: %s", res.error.c_str());
388 }
389 
391  if (!sDatabase.RunQuery(res, "SELECT shipClass, groupID, factionID FROM npcClassGroup"))
392  _log(DATABASE__ERROR, "Error in GetFactionGroups query: %s", res.error.c_str());
393 }
394 
396  if (!sDatabase.RunQuery(res, "SELECT type, sub, f, af, d, c, ac, bc, bs, h, o, cf, cd, cc, cbc, cbs FROM npcSpawnClass"))
397  _log(DATABASE__ERROR, "Error in GetSpawnClasses query: %s", res.error.c_str());
398 }
399 
400 // this is loaded in static data, so performance isnt a priority
401 void ManagerDB::GetGroupTypeIDs(uint8 shipClass, uint16 groupID, uint32 factionID, DBQueryResult& res) {
402  // this now gets advanced frigates and cruisers based on faction (best i could think of)
403  std::string name = "";
404 
405  // there are unused types in the data for these...just sayin
406  switch (factionID) {
407  case factionAngel: { // Cyber
408  if ((shipClass == 2) or (shipClass == 5) or (shipClass == 16) or (shipClass == 19)) { // 2 = adv frig, 5 = adv cruiser, 16 = adv frig, 19 = adv cruiser
409  name = "AND typeName LIKE '%Arch%'";
410  name = "AND typeName NOT LIKE '%Cyber%'";
411  } else if ((shipClass == 1) or (shipClass == 4) or (shipClass == 15) or (shipClass == 18)) { // 1 = frig, 4 = cruiser, 15 = frig, 18 = cruiser
412  name = "AND typeName NOT LIKE '%Arch%'";
413  name = "AND typeName NOT LIKE '%Cyber%'";
414  }
415  } break;
416  case factionBloodRaider: {
417  if ((shipClass == 2) or (shipClass == 5) or (shipClass == 16) or (shipClass == 19)) {
418  name = "AND typeName LIKE '%Elder%'";
419  } else if ((shipClass == 1) or (shipClass == 4) or (shipClass == 15) or (shipClass == 18)) {
420  name = "AND typeName NOT LIKE '%Elder%'";
421  }
422  } break;
423  case factionGuristas: { //Outlaw
424  if ((shipClass == 2) or (shipClass == 5) or (shipClass == 16) or (shipClass == 19)) {
425  name = "AND typeName LIKE '%Dire%'";
426  name = "AND typeName NOT LIKE '%Outlaw%'";
427  } else if ((shipClass == 1) or (shipClass == 4) or (shipClass == 15) or (shipClass == 18)) {
428  name = "AND typeName NOT LIKE '%Dire%'";
429  name = "AND typeName NOT LIKE '%Outlaw%'";
430  }
431  } break;
432  case factionSanshas: {
433  if ((shipClass == 2) or (shipClass == 5) or (shipClass == 16) or (shipClass == 19)) {
434  name = "AND typeName LIKE '%Loyal%'";
435  } else if ((shipClass == 1) or (shipClass == 4) or (shipClass == 15) or (shipClass == 18)) {
436  name = "AND typeName NOT LIKE '%Loyal%'";
437  }
438  } break;
439  case factionSerpentis: { //Crook
440  if ((shipClass == 2) or (shipClass == 5) or (shipClass == 16) or (shipClass == 19)) {
441  name = "AND typeName LIKE '%Guardian%'";
442  name = "AND typeName NOT LIKE '%Crook%'";
443  } else if ((shipClass == 1) or (shipClass == 4) or (shipClass == 15) or (shipClass == 18)) {
444  name = "AND typeName NOT LIKE '%Guardian%'";
445  name = "AND typeName NOT LIKE '%Crook%'";
446  }
447  } break;
448  case factionRogueDrones: {
449  if ((shipClass == 2) or (shipClass == 5) or (shipClass == 16) or (shipClass == 19)) {
450  name = "AND typeName LIKE '%Strain%'";
451  } else if ((shipClass == 1) or (shipClass == 4) or (shipClass == 15) or (shipClass == 18)) {
452  name = "AND typeName NOT LIKE '%Strain%'";
453  }
454  } break;
455  }
456 
457  if (!sDatabase.RunQuery(res, "SELECT typeID FROM invTypes WHERE groupID = %u %s ORDER BY typeID", groupID, name.c_str()))
458  _log(DATABASE__ERROR, "Error in GetGroupTypeIDs query: %s", res.error.c_str());
459 }
460 
461 // called during startup/shutdown by ItemFactory
463 {
464  DBerror err;
465  sDatabase.RunQuery(err, "DELETE FROM entity WHERE customInfo LIKE '%beltrat%'");
466 }
467 
469 {
470  DBerror err;
471  sDatabase.RunQueryLID(err, adata.itemID,
472  "INSERT INTO sysAsteroids (itemName,typeID,systemID,beltID,quantity,radius,x, y, z)"
473  " VALUES ('%s', %u, %u, %u, %f, %f, %f, %f, %f)",
474  adata.itemName.c_str(), adata.typeID, adata.systemID, adata.beltID, adata.quantity, adata.radius,
475  adata.position.x, adata.position.y, adata.position.z );
476 }
477 
479 {
480  DBQueryResult res;
481  if(!sDatabase.RunQuery(res,
482  "SELECT itemName, typeID, systemID, beltID, quantity, radius, x, y, z"
483  " FROM sysAsteroids"
484  " WHERE itemID = %u", asteroidID)) {
485  _log(DATABASE__ERROR, "Error in GetAsteroidData query: %s", res.error.c_str());
486  return false;
487  }
488 
489  DBResultRow row;
490  if (res.GetRow(row)) {
491  dbData.itemID = asteroidID;
492  dbData.itemName = row.GetText(0);
493  dbData.typeID = row.GetInt(1);
494  dbData.systemID = row.GetInt(2);
495  dbData.beltID = row.GetInt(3);
496  dbData.quantity = row.GetDouble(4);
497  dbData.radius = row.GetDouble(5);
498  GPoint pos(row.GetDouble(6), row.GetDouble(7), row.GetDouble(8));
499  dbData.position = pos;
500  return true;
501  } else {
502  dbData = AsteroidData();
503  }
504 
505  return false;
506 }
507 
508 bool ManagerDB::LoadSystemRoids(uint32 systemID, uint32& beltID, std::vector< AsteroidData >& into)
509 {
510  DBQueryResult res;
511  if(!sDatabase.RunQuery(res,
512  "SELECT itemID, itemName, typeID, systemID, beltID, quantity, radius, x, y, z"
513  " FROM sysAsteroids"
514  " WHERE systemID = %u"
515  " AND beltID = %u", systemID, beltID)) {
516  _log(DATABASE__ERROR, "Error in LoadSystemRoids query: %s", res.error.c_str());
517  return false;
518  }
519 
520  _log(DATABASE__RESULTS, "LoadSystemRoids returned %u items", res.GetRowCount());
521  DBResultRow row;
522  while(res.GetRow(row)) {
523  AsteroidData entry = AsteroidData();
524  entry.itemID = row.GetInt(0);
525  entry.itemName = row.GetText(1);
526  entry.typeID = row.GetInt(2);
527  entry.systemID = row.GetInt(3);
528  entry.beltID = row.GetInt(4);
529  entry.quantity = row.GetDouble(5);
530  entry.radius = row.GetDouble(6);
531  GPoint pos(row.GetDouble(7), row.GetDouble(8), row.GetDouble(9));
532  entry.position = pos;
533  into.push_back(entry);
534  }
535 
536  return !into.empty();
537 }
538 
540 {
541  DBerror err;
542  sDatabase.RunQuery(err, "DELETE FROM sysAsteroids WHERE itemID = %u", asteroidID);
543 }
544 
546 {
547  DBerror err;
548  sDatabase.RunQuery(err, "DELETE FROM sysAsteroids WHERE 1");
549  sDatabase.RunQuery(err, "ALTER TABLE `sysAsteroids` auto_increment = 450000000");
550 }
551 
553 {
554  DBerror err;
555  if (!sDatabase.RunQuery(err,
556  "UPDATE sysAsteroids"
557  " SET quantity = %f,"
558  " radius = %f"
559  " WHERE itemID = %u",
560  data.quantity, data.radius, data.itemID))
561  {
562  _log(DATABASE__ERROR, "SaveSystemRoids - unable to save roids - %s", err.c_str());
563  }
564 }
565 
566 void ManagerDB::SaveSystemRoids(uint32 systemID, std::vector< AsteroidData >& roids)
567 {
568  std::ostringstream Inserts;
569  // start the insert into command.
570  Inserts << "INSERT INTO sysAsteroids";
571  Inserts << " (itemID,itemName,typeID,systemID,beltID,quantity,radius,x, y, z)";
572  bool first = true;
573  for (auto cur : roids) {
574  if (first) {
575  Inserts << " VALUES ";
576  first = false;
577  } else {
578  Inserts << ", ";
579  }
580  // itemID and attributeID keys.
581  Inserts << "(" << cur.itemID << ", '" << cur.itemName << "', " << cur.typeID << ", " << systemID << ", " << cur.beltID << ", ";
582  Inserts << cur.quantity << ", " << cur.radius << ", " << std::to_string(cur.position.x) << ", " << std::to_string(cur.position.y);
583  Inserts << ", " << std::to_string(cur.position.z) << ")";
584  }
585  // did we get at least 1 insert?
586  if (!first) {
587  // finish creating the command.
588  Inserts << "ON DUPLICATE KEY UPDATE ";
589  Inserts << "quantity=VALUES(quantity), ";
590  Inserts << "radius=VALUES(radius)";
591  // execute the command.
592  DBerror err;
593  if (!sDatabase.RunQuery(err, Inserts.str().c_str()))
594  _log(DATABASE__ERROR, "SaveSystemRoids - unable to save roids - %s", err.c_str());
595  }
596 }
597 
599 {
600  if (!sDatabase.RunQuery(res, "SELECT locationID, wormholeClassID FROM mapLocationWormholeClasses"))
601  _log(DATABASE__ERROR, "Error in GetWHSystemClass query: %s", res.error.c_str());
602 }
603 
605 {
606  if (!sDatabase.RunQuery(res, "SELECT dunEntryID, dunEntryName, xpos, ypos, zpos FROM dunEntryData"))
607  _log(DATABASE__ERROR, "Error in GetDunRoomData query: %s", res.error.c_str());
608 }
609 
611 {
612  if (!sDatabase.RunQuery(res, "SELECT d.dunGroupID, d.itemTypeID, d.itemGroupID, t.typeName, t.groupID, g.categoryID, t.radius, d.xpos, d.ypos, d.zpos"
613  " FROM dunGroupData AS d"
614  " LEFT JOIN invTypes AS t ON d.itemTypeID = t.typeID"
615  " LEFT JOIN invGroups AS g ON g.groupID = t.groupID" ))
616  {
617  _log(DATABASE__ERROR, "Error in GetDunGroupData query: %s", res.error.c_str());
618  }
619 }
620 
622 {
623  if (!sDatabase.RunQuery(res, "SELECT dunRoomID, dunGroupID, xpos, ypos, zpos FROM dunRoomData"))
624  _log(DATABASE__ERROR, "Error in GetDunRoomData query: %s", res.error.c_str());
625 }
626 
628 {
629  if (!sDatabase.RunQuery(res, "SELECT dunRoomID, dunRoomType, dunRoomCategory, dunRoomSpawnID, dunRoomSpawnType FROM dunRoomInfo"))
630  _log(DATABASE__ERROR, "Error in GetDunRoomInfo query: %s", res.error.c_str());
631 }
632 
634 {
635  if (!sDatabase.RunQuery(res, "SELECT dunRoomSpawnID, dunRoomSpawnType, xpos, ypos, zpos FROM dunRoomSpawnInfo"))
636  _log(DATABASE__ERROR, "Error in GetDunSpawnInfo query: %s", res.error.c_str());
637 }
638 
640 {
641  if (!sDatabase.RunQuery(res, "SELECT dunTemplateID, dunTemplateName, dunEntryID, dunSpawnID, dunRoomID FROM dunTemplates"))
642  _log(DATABASE__ERROR, "Error in GetDunTemplates query: %s", res.error.c_str());
643 }
644 
645 bool ManagerDB::GetSavedDungeons(uint32 systemID, std::vector< Dungeon::ActiveData >& into)
646 {
647  DBQueryResult res;
648 
649  if (!sDatabase.RunQuery(res,
650  "SELECT systemID, state, dunTemplateID, dunExpiryTime, xpos, ypos, zpos"
651  " FROM dunActive" //Active Dungeons
652  " WHERE systemID = %u", systemID))
653  {
654  _log(DATABASE__ERROR, "Error in GetSavedDungeons query: %s", res.error.c_str());
655  return false;
656  }
657 
658  _log(DATABASE__RESULTS, "GetSavedDungeons returned %u items", res.GetRowCount());
659  DBResultRow row;
660  while(res.GetRow(row)) {
662  entry.systemID = row.GetInt(0);
663  entry.state = row.GetInt(1);
664  entry.dunItemID = 0;
665  entry.dunTemplateID = row.GetInt(2);
666  entry.dunExpiryTime = row.GetInt64(3);
667  entry.x = row.GetInt(4);
668  entry.y = row.GetInt(5);
669  entry.z = row.GetInt(6);
670  into.push_back(entry);
671  }
672 
673  return !into.empty();
674 }
675 
677 {
678  DBerror err;
679  if (!sDatabase.RunQuery(err,
680  "INSERT INTO dunActive" //Active Dungeons
681  " (systemID, dungeonID, state, dunTemplateID, dunExpiryTime, xpos, ypos, zpos)"
682  " VALUES "
683  "(%u, %u, %u, %u, %li, %f, %f, %f)",
684  dun.systemID, dun.dunItemID, dun.state, dun.dunTemplateID, dun.dunExpiryTime, dun.x, dun.y, dun.z ))
685  {
686  _log(DATABASE__ERROR, "SaveActiveDungeon - unable to save dungeon: %s", err.c_str());
687  }
688 }
689 
691 {
692  DBerror err;
693  sDatabase.RunQuery(err, "DELETE FROM dunActive WHERE 1");
694  sDatabase.RunQuery(err, "DELETE FROM sysSignatures WHERE 1");
695  // anomaly items are all temp, except roids, so we may not need this...
696  sDatabase.RunQuery(err, "DELETE FROM entity_attributes WHERE itemID IN (SELECT itemID FROM entity WHERE customInfo LIKE 'Dungeon%%')");
697  sDatabase.RunQuery(err, "DELETE FROM entity WHERE customInfo LIKE 'Dungeon%%'");
698 }
699 
701 {
702  DBerror err;
703  sDatabase.RunQuery(err, "DELETE FROM dunActive WHERE systemID = %u", systemID);
704  sDatabase.RunQuery(err, "DELETE FROM sysSignatures WHERE systemID = %u", systemID);
705  // anomaly items are all temp, except roids, so we may not need this...
706  sDatabase.RunQuery(err, "DELETE FROM entity_attributes WHERE itemID IN (SELECT itemID FROM entity WHERE locationID = %u AND customInfo LIKE 'Dungeon%%')", systemID);
707  sDatabase.RunQuery(err, "DELETE FROM entity WHERE locationID = %u AND customInfo LIKE 'Dungeon%%'", systemID);
708 }
709 
710 /*
711  * SELECT timeStamp, timeSpan, pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket FROM srvStatisticData
712  * SELECT month, pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket FROM srvStatisticHistory
713  */
715 {
716  if (!sDatabase.RunQuery(res,
717  "SELECT pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket, probesLaunched, sitesScanned"
718  " FROM srvStatisticData"
719  " WHERE timeStamp > %li", starttime))
720  codelog(DATABASE__ERROR, "Error in GetStatisticData query: %s", res.error.c_str());
721 }
722 
724 {
725  DBerror err;
726  if (!sDatabase.RunQuery(err,
727  "INSERT INTO srvStatisticData"
728  " (timeStamp, timeSpan, pcShots, pcMissiles, ramJobs, shipsSalvaged, pcBounties, npcBounties, oreMined, iskMarket, probesLaunched, sitesScanned)"
729  " VALUES "
730  "(%f, %u, %u, %u, %u, %u, %f, %f, %f, %f, %u, %u)", GetFileTimeNow(),
731  data.span, data.pcShots, data.pcMissiles, data.ramJobs, data.shipsSalvaged, data.pcBounties, data.npcBounties, data.oreMined, data.iskMarket, data.probesLaunched, data.sitesScanned ))
732  {
733  _log(DATABASE__ERROR, "SaveStatisticData - unable to save data: %s", err.c_str());
734  }
735 }
736 
738 {
739  DBerror err;
740  if (!sDatabase.RunQuery(err,
741  "UPDATE srvStatisticHistory"
742  " SET pcShots=%u, pcMissiles=%u, ramJobs=%u, shipsSalvaged=%u, pcBounties=%f, npcBounties=%f, oreMined=%f, iskMarket=%f, probesLaunched=%u, sitesScanned=%u"
743  " WHERE idx = 1",
744  data.pcShots, data.pcMissiles, data.ramJobs, data.shipsSalvaged, data.pcBounties, data.npcBounties,
745  data.oreMined, data.iskMarket, data.probesLaunched, data.sitesScanned ))
746  {
747  _log(DATABASE__ERROR, "srvStatisticHistory - unable to save data: %s", err.c_str());
748  }
749 }
static void LoadFactionSolarSystems(std::map< int32, PyRep * > &into)
Definition: ManagerDB.cpp:227
unsigned __int8 uint8
Definition: eve-compat.h:46
static void GetSpawnClasses(DBQueryResult &res)
Definition: ManagerDB.cpp:395
#define sDatabase
Definition: dbcore.h:199
static void GetTypeData(DBQueryResult &res)
Definition: ManagerDB.cpp:44
static void LoadCorpFactions(std::map< uint32, uint32 > &into)
Definition: ManagerDB.cpp:170
static PyDict * LoadNPCCorpInfo()
Definition: ManagerDB.cpp:249
const char * GetText(uint32 index) const
Definition: dbcore.h:104
static void GetFactionGroups(DBQueryResult &res)
Definition: ManagerDB.cpp:390
static void GetStatisticData(DBQueryResult &res, int64 starttime)
Definition: ManagerDB.cpp:714
#define _log(type, fmt,...)
Definition: logsys.h:124
static void SaveActiveDungeon(Dungeon::ActiveData &dun)
Definition: ManagerDB.cpp:676
static PyObjectEx * GetAgents()
Definition: ManagerDB.cpp:130
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
static void GetDunRoomInfo(DBQueryResult &res)
Definition: ManagerDB.cpp:627
Python's dictionary.
Definition: PyRep.h:719
static void GetDunRoomData(DBQueryResult &res)
Definition: ManagerDB.cpp:621
static void LoadFactionSystemCounts(std::map< uint32, uint32 > &into)
Definition: ManagerDB.cpp:193
std::string sigID
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
void GetSystemAnomalies(uint32 systemID, DBQueryResult &res)
Definition: ManagerDB.cpp:365
static GPoint GetAnomalyPos(std::string &string)
Definition: ManagerDB.cpp:348
static void GetGroupData(DBQueryResult &res)
Definition: ManagerDB.cpp:23
static void GetAgentLocation(DBQueryResult &res)
Definition: ManagerDB.cpp:313
static void GetDunSpawnInfo(DBQueryResult &res)
Definition: ManagerDB.cpp:633
static void DeleteSpawnedRats()
Definition: ManagerDB.cpp:462
static void GetWHSystemClass(DBQueryResult &res)
Definition: ManagerDB.cpp:598
static void LoadFactionRaces(std::map< int32, PyRep * > &into)
Definition: ManagerDB.cpp:238
static void GetDunGroupData(DBQueryResult &res)
Definition: ManagerDB.cpp:610
static void GetStaticData(DBQueryResult &res)
Definition: ManagerDB.cpp:306
std::string sigName
PyObjectEx * DBResultToCIndexedRowset(DBQueryResult &result, const char *key)
Definition: EVEDBUtils.cpp:419
GaFloat x
Definition: GaTypes.h:207
uint16 shipsSalvaged
static PyObject * GetNPCDivisions()
Definition: ManagerDB.cpp:269
static void LoadFactionConstellations(std::map< int32, PyRep * > &into)
Definition: ManagerDB.cpp:216
static void LoadFactionRegions(std::map< int32, PyRep * > &into)
Definition: ManagerDB.cpp:205
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
void GetAnomalyList(DBQueryResult &res)
Definition: ManagerDB.cpp:338
Definition: gpoint.h:33
static void GetSalvageGroups(DBQueryResult &res)
Definition: ManagerDB.cpp:282
Python extended object.
Definition: PyRep.h:861
static void GetRegionFaction(DBQueryResult &res)
Definition: ManagerDB.cpp:380
const char * c_str() const
Definition: dbcore.h:48
void DBResultToIntIntlistDict(DBQueryResult &result, std::map< int32, PyRep * > &into)
Definition: EVEDBUtils.cpp:495
PyDict * DBResultToIntRowDict(DBQueryResult &result, uint32 key_index, const char *type)
Definition: EVEDBUtils.cpp:257
Python object.
Definition: PyRep.h:826
static void GetDunTemplates(DBQueryResult &res)
Definition: ManagerDB.cpp:639
uint16 probesLaunched
#define codelog(type, fmt,...)
Definition: logsys.h:128
static const GPoint NULL_ORIGIN(0, 0, 0)
static void CreateRoidItemID(ItemData &idata, AsteroidData &adata)
Definition: ManagerDB.cpp:468
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
static void GetOreBySSC(DBQueryResult &res)
Definition: ManagerDB.cpp:290
static void GetTypeAttributes(DBQueryResult &res)
Definition: ManagerDB.cpp:78
static void SaveStatisticData(StatisticData &data)
Definition: ManagerDB.cpp:723
static void LoadNPCCorpFactionData(DBQueryResult &res)
Definition: ManagerDB.cpp:86
void ClearAsteroids()
Definition: ManagerDB.cpp:545
void SaveAnomaly(CosmicSignature &sig)
Definition: ManagerDB.cpp:325
unsigned __int32 uint32
Definition: eve-compat.h:50
static bool GetAsteroidData(uint32 asteroidID, AsteroidData &dbData)
Definition: ManagerDB.cpp:478
void RemoveAsteroid(uint32 asteroidID)
Definition: ManagerDB.cpp:539
static PyObjectEx * GetOperands()
Definition: ManagerDB.cpp:157
GaFloat y
Definition: GaTypes.h:207
static void ClearDungeons()
Definition: ManagerDB.cpp:690
double GetFileTimeNow()
Definition: utils_time.cpp:84
void SaveSystemRoids(uint32 systemID, std::vector< AsteroidData > &roids)
Definition: ManagerDB.cpp:566
static void GetCategoryData(DBQueryResult &res)
Definition: ManagerDB.cpp:16
DBerror error
Definition: dbcore.h:69
signed __int64 int64
Definition: eve-compat.h:51
static void GetGroupTypeIDs(uint8 shipClass, uint16 groupID, uint32 factionID, DBQueryResult &res)
Definition: ManagerDB.cpp:401
static void GetDunEntryData(DBQueryResult &res)
Definition: ManagerDB.cpp:604
static void GetSkillList(DBQueryResult &res)
Definition: ManagerDB.cpp:70
static PyObject * GetBillTypes()
Definition: ManagerDB.cpp:118
static void GetSystemData(DBQueryResult &res)
Definition: ManagerDB.cpp:296
static void GetMoonResouces(DBQueryResult &res)
Definition: ManagerDB.cpp:319
size_t GetRowCount()
Definition: dbcore.h:72
static bool GetSavedDungeons(uint32 systemID, std::vector< Dungeon::ActiveData > &into)
Definition: ManagerDB.cpp:645
static void LoadFactionStationCounts(std::map< uint32, uint32 > &into)
Definition: ManagerDB.cpp:180
static PyObject * GetEntryTypes()
Definition: ManagerDB.cpp:94
void SaveRoid(AsteroidData &data)
Definition: ManagerDB.cpp:552
bool LoadSystemRoids(uint32 systemID, uint32 &beltID, std::vector< AsteroidData > &into)
Definition: ManagerDB.cpp:508
unsigned __int16 uint16
Definition: eve-compat.h:48
std::string itemName
Definition: dbcore.h:39
GaFloat z
Definition: GaTypes.h:207
static void UpdateStatisticHistory(StatisticData &data)
Definition: ManagerDB.cpp:737
static PyObject * GetKeyMap()
Definition: ManagerDB.cpp:106
static void GetRegionRatFaction(DBQueryResult &res)
Definition: ManagerDB.cpp:385
void DBResultToUIntUIntDict(DBQueryResult &result, std::map< uint32, uint32 > &into)
Definition: EVEDBUtils.cpp:479