-
Notifications
You must be signed in to change notification settings - Fork 104
/
ConfigDB.cpp
563 lines (500 loc) · 18.5 KB
/
ConfigDB.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*
------------------------------------------------------------------------------------
LICENSE:
------------------------------------------------------------------------------------
This file is part of EVEmu: EVE Online Server Emulator
Copyright 2006 - 2021 The EVEmu Team
For the latest information visit https://github.com/evemuproject/evemu_server
------------------------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
------------------------------------------------------------------------------------
Author: Zhur
Rewrite: Allan
*/
#include "eve-server.h"
#include "config/ConfigDB.h"
PyRep *ConfigDB::GetMultiOwnersEx(const std::vector<int32> &entityIDs) {
// separate list of ids into respective groups
std::vector<int32> player, corp, ally, owner, npc, station;
player.clear();
corp.clear();
ally.clear();
owner.clear();
npc.clear();
station.clear();
for (auto cur : entityIDs) {
if (IsCorp(cur)) {
corp.push_back(cur);
} else if (IsAlliance(cur)) {
ally.push_back(cur);
} else if (IsCharacter(cur)) {
player.push_back(cur);
} else if (cur < 33000) {
npc.push_back(cur);
} else if (IsStation(cur)) {
station.push_back(cur);
} else {
owner.push_back(cur);
}
// add check here for trader joe.
// will have to hardcode data, then run thru db query cause i dont know how to build packet for this return
}
DBQueryResult res;
std::string ids = "";
if (corp.size()) {
ListToINString(corp, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" corporationID AS ownerID,"
" corporationName AS ownerName,"
" 2 AS typeID," // corp typeID
" false AS gender,"
" NULL AS ownerNameID" // this is a messageID - have not taken time to find and insert
" FROM crpCorporation"
" WHERE corporationID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
ids = "";
}
if (ally.size()) {
ListToINString(ally, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" allianceID AS ownerID,"
" allianceShortName AS ownerName,"
" 16159 AS typeID," // alliance typeID.
" false AS gender,"
" NULL AS ownerNameID"
" FROM alnAlliance"
" WHERE allianceID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
ids = "";
}
if (player.size()) {
ListToINString(player, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" characterID AS ownerID,"
" characterName AS ownerName,"
" typeID,"
" gender,"
" NULL AS ownerNameID"
" FROM chrCharacters"
" WHERE characterID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
ids = "";
}
if (npc.size()) {
ListToINString(npc, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" typeID AS ownerID,"
" typeName AS ownerName,"
" typeID,"
" 1 AS gender,"
" typeNameID AS ownerNameID"
" FROM invTypes"
" WHERE typeID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
ids = "";
}
if (station.size()) {
ListToINString(station, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" corporationID AS ownerID,"
" corporationName AS name,"
" 2 AS typeID" // corp typeID
" FROM crpCorporation"
" WHERE corporationID IN (SELECT corporationID FROM staStations WHERE stationID IN (%s))", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
ids = "";
}
if (owner.size()) {
ListToINString(owner, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" ownerID,"
" ownerName,"
" typeID,"
" true AS gender,"
" NULL AS ownerNameID"
" FROM eveStaticOwners"
" WHERE ownerID IN (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
}
return DBResultToTupleSet(res);
}
PyRep *ConfigDB::GetMultiAllianceShortNamesEx(const std::vector<int32> &entityIDs) {
std::string ids;
ListToINString(entityIDs, ids);
DBQueryResult res;
if (!sDatabase.RunQuery(res, "SELECT allianceID, shortName FROM alnAlliance" )) {
codelog(DATABASE__ERROR, "Error in GetMultiAllianceShortNamesEx query: %s", res.error.c_str());
return new PyInt(0);
}
return DBResultToTupleSet(res);
}
PyRep *ConfigDB::GetMultiLocationsEx(const std::vector<int32> &entityIDs) {
// this is locations only....region, const, system, station, ship
// wtf are asteroids seen in this call???
std::vector<int32> staticItems, dynamicItems, asteroidItems;
staticItems.clear();
dynamicItems.clear();
asteroidItems.clear();
for (auto cur : entityIDs) {
if (IsStaticItem(cur)) {
staticItems.push_back(cur);
} else if (IsAsteroid(cur)) {
asteroidItems.push_back(cur);
} else {
dynamicItems.push_back(cur);
}
}
DBQueryResult res;
std::string ids = "";
if (staticItems.size()) {
ListToINString(staticItems, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" itemID AS locationID,"
" itemName AS locationName,"
" x, y, z,"
" itemNameID AS locationNameID" //locationName = localization.GetByMessageID(self.locationNameID)
" FROM mapDenormalize"
" WHERE itemID in (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in GetMultiLocationsEx query: %s", res.error.c_str());
}
ids = "";
}
if (dynamicItems.size()) {
ListToINString(dynamicItems, ids);
if (!sDatabase.RunQuery(res,
"SELECT "
" itemID AS locationID,"
" itemName AS locationName,"
" x, y, z,"
" NULL AS locationNameID"
" FROM entity"
" WHERE itemID in (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in GetMultiLocationsEx query: %s", res.error.c_str());
}
ids = "";
}
if (asteroidItems.size()) {
ListToINString(asteroidItems, ids);
sLog.Warning("GetMultiLocationsEx", "Asteroid Items (%s) requested.", ids.c_str());
if (!sDatabase.RunQuery(res,
"SELECT "
" itemID AS locationID,"
" itemName AS locationName,"
" x, y, z,"
" NULL AS locationNameID"
" FROM sysAsteroids"
" WHERE itemID in (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in GetMultiLocationsEx query: %s", res.error.c_str());
}
}
return DBResultToTupleSet(res);
}
PyRep* ConfigDB::GetMultiStationEx(const std::vector< int32 >& entityIDs)
{
std::string ids;
ListToINString(entityIDs, ids);
DBQueryResult res;
if (!sDatabase.RunQuery(res, "SELECT stationID, stationName, stationTypeID, solarSystemID, x, y, z FROM staStations WHERE stationID in (%s)", ids.c_str())) {
codelog(DATABASE__ERROR, "Error in GetMultiStationEx query: %s", res.error.c_str());
}
return DBResultToTupleSet(res);
}
PyRep *ConfigDB::GetMultiCorpTickerNamesEx(const std::vector<int32> &entityIDs)
{
std::string ids;
ListToINString(entityIDs, ids);
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT "
" corporationID, tickerName,"
" shape1, shape2, shape3,"
" color1, color2, color3 "
" FROM crpCorporation"
" WHERE corporationID in (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in GetMultiCorpTickerNamesEx query: %s", res.error.c_str());
return new PyInt(0);
}
return DBResultToRowList(res);
}
PyRep *ConfigDB::GetMultiGraphicsEx(const std::vector<int32> &entityIDs) {
std::string ids;
ListToINString(entityIDs, ids);
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT"
" graphicID, url3D, urlWeb, icon, urlSound, explosionID"
" FROM eveGraphics "
" WHERE graphicID in (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in GetMultiGraphicsEx query: %s", res.error.c_str());
return new PyInt(0);
}
return DBResultToRowList(res);
}
PyObject *ConfigDB::GetUnits()
{
DBQueryResult res;
if (!sDatabase.RunQuery(res, "SELECT unitID, unitName, displayName FROM eveUnits")) {
codelog(DATABASE__ERROR, "Error in GetUnits query: %s", res.error.c_str());
return nullptr;
}
return DBResultToIndexRowset(res, "unitID");
}
PyObjectEx *ConfigDB::GetMapObjects(uint32 entityID, bool wantRegions,
bool wantConstellations, bool wantSystems, bool wantStations)
{ // corrected query -allan 8Dec14
const char *key = "solarSystemID";
if (wantRegions) {
entityID = 3; /* a little hackish... */
key = "typeID";
} else if (wantConstellations) {
key = "regionID";
} else if (wantSystems) {
key = "constellationID";
} else if (wantStations) {
key = "solarSystemID";
}
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT "
" groupID, typeID, itemID, itemName,"
" solarSystemID AS locationID, IFNULL(orbitID, 0) AS orbitID,"
" x, y, z"
" FROM mapDenormalize"
" WHERE %s=%u", key, entityID )) {
codelog(DATABASE__ERROR, "Error in GetMapObjects query: %s", res.error.c_str());
return nullptr;
}
return DBResultToCRowset(res);
}
PyObject *ConfigDB::GetMap(uint32 solarSystemID) {
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT "
" s.solarSystemID AS locationID,"
" s.xMin, s.xMax, s.yMin,"
" s.yMax, s.zMin, s.zMax,"
" s.luminosity,"
" d.x, d.y, d.z,"
" d.itemID,"
" d.itemName,"
" d.typeID,"
" d.orbitID,"
" j.celestialID AS destinations"
" FROM mapSolarSystems AS s"
" LEFT JOIN mapDenormalize AS d USING (solarSystemID)"
" LEFT JOIN mapJumps AS j ON j.stargateID = d.itemID"
" WHERE solarSystemID=%u", solarSystemID
)) {
codelog(DATABASE__ERROR, "Error in GetMap query: %s", res.error.c_str());
return nullptr;
}
return DBResultToRowset(res);
}
PyObject *ConfigDB::ListLanguages() {
DBQueryResult res;
if (!sDatabase.RunQuery(res, "SELECT languageID,languageName,translatedLanguageName FROM languages")) {
codelog(DATABASE__ERROR, "Error in ListLanguages query: %s", res.error.c_str());
return nullptr;
}
return DBResultToRowset(res);
}
PyRep *ConfigDB::GetMultiInvTypesEx(const std::vector<int32> &entityIDs) {
std::string ids;
ListToINString(entityIDs, ids);
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT"
" typeID,groupID,typeName,description,graphicID,radius,"
" mass,volume,capacity,portionSize,raceID,basePrice,"
" published,marketGroupID,chanceOfDuplicating "
" FROM invTypes "
" WHERE typeID in (%s)", ids.c_str()))
{
codelog(DATABASE__ERROR, "Error in GetMultiInvTypesEx query: %s", res.error.c_str());
return new PyInt(0);
}
return DBResultToRowList(res);
}
PyRep *ConfigDB::GetStationSolarSystemsByOwner(uint32 ownerID) {
DBQueryResult res;
if (!sDatabase.RunQuery(res,
" SELECT "
" stationID, solarSystemID "
" FROM staStations "
" WHERE corporationID = %u ", ownerID))
{
codelog(DATABASE__ERROR, "Error in GetStationSolarSystemsByOwner query: %s", res.error.c_str());
return nullptr;
}
return DBResultToRowset(res);
}
PyRep *ConfigDB::GetCelestialStatistic(uint32 celestialID) {
// corrected db query -allan 8Dec14
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT"
" celestialID,"
" temperature,"
" spectralClass,"
" luminosity,"
" age,"
" life,"
" orbitRadius,"
" eccentricity,"
" massDust,"
" massGas,"
" fragmented,"
" density,"
" surfaceGravity,"
" escapeVelocity,"
" orbitPeriod,"
" rotationRate,"
" locked,"
" pressure,"
" radius,"
" mass"
" FROM mapCelestialStatistics"
" WHERE celestialID = %u", celestialID))
{
codelog(DATABASE__ERROR, "Error in GetCelestialStatistic query: %s", res.error.c_str());
return new PyInt(0);
}
return DBResultToCRowset(res);
}
PyRep *ConfigDB::GetDynamicCelestials(uint32 solarSystemID) {
// corrected query and return type per packet info
// this returns ONLY OUTPOSTS. -allan 8Dec14
/* this packet is from a crowded (73 items) system (including pos'), yet is only return from this call.
[PyObjectEx Type2]
[PyTuple 2 items]
[PyTuple 1 items]
[PyToken dbutil.CRowset]
[PyDict 1 kvp]
[PyString "header"]
[PyPackedRow 50 bytes]
["groupID" => <15> [I2]]
["typeID" => <21645> [I4]] <-- Gallente Administrative Outpost
["itemID" => <61000562> [I4]]
["itemName" => <5E-EZC VI - X333 GEORGIOU'S PLACE> [WStr]]
["locationID" => <30004168> [I4]]
["orbitID" => <40264214> [I4]]
["connector" => <0> [I4]]
["x" => <-435188244480> [R8]]
["y" => <27742740480> [R8]]
["z" => <430524948480> [R8]]
["celestialIndex" => <6> [UI1]]
["orbitIndex" => <0> [UI1]]
*/
DBQueryResult result;
if (!sDatabase.RunQuery(result,
"SELECT"
" groupID,"
" typeID,"
" itemID,"
" itemName,"
" solarSystemID AS locationID,"
" IFNULL(orbitID, 0) AS orbitID,"
" 0 AS connector," //this is connector field....have only seen 0 in server packets.
" x, y, z,"
" celestialIndex," // this index denotes which planet this item orbits (PLANET #....NOT moon #)
" orbitIndex" // this index denotes which asteroid belt this item belongs to
" FROM mapDenormalize"
" WHERE solarSystemID = %u"
" AND groupID = %d"
" AND itemID > %d", //this is min itemid for outposts (pos' do NOT go here)
solarSystemID, EVEDB::invGroups::Station, maxNPCStation )) {
codelog(DATABASE__ERROR, "Error in GetDynamicCelestials query: %s", result.error.c_str());
return new PyInt(0);
}
return DBResultToCRowset(result);
}
PyRep *ConfigDB::GetTextsForGroup(const std::string & langID, uint32 textgroup) {
DBQueryResult res;
if (!sDatabase.RunQuery(res, "SELECT textLabel, `text` FROM intro WHERE langID = '%s' AND textgroup = %u", langID.c_str(), textgroup)) {
codelog(DATABASE__ERROR, "Error in GetTextsForGroup query: %s", res.error.c_str());
return new PyInt(0);
}
return DBResultToRowset(res);
}
PyObject *ConfigDB::GetMapOffices(uint32 solarSystemID) {
DBQueryResult res;
if (!sDatabase.RunQuery(res, "SELECT corporationID, stationID FROM staStations WHERE solarSystemID=%u", solarSystemID)) {
codelog(DATABASE__ERROR, "Error in GetMapOffices query: %s", res.error.c_str());
return nullptr;
}
return DBResultToRowset(res);
}
/** @todo more map data in /eve/client/script/ui/shared/maps/mapcommon.py */
PyObject *ConfigDB::GetMapConnections(uint32 id, bool sol, bool reg, bool con, uint16 cel, uint16 _c) {
sLog.Warning ("ConfigDB::GetMapConnections", "DB query - System:%u, Sol:%u, Reg:%u, Con:%u, Cel:%u, cached:%u", id, sol, reg, con, cel, _c);
const char *key = "fromsol";
if (sol) {
key = "fromsol";
} else if (reg) {
key = "fromreg";
} else if (con) {
key = "fromcon";
} else {
sLog.Error ("ConfigDB::GetMapConnections()", "Bad argument (id: %u, sol: %u, reg: %u, con: %u) passed to key.", id, sol, reg, con );
}
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT ctype, fromreg, fromcon, fromsol, stargateID, celestialID, tosol, tocon, toreg"
" FROM mapConnections"
" WHERE %s = %u", key, id )) {
codelog(DATABASE__ERROR, "Error in GetMapConnections query: %s", res.error.c_str());
sLog.Error ("ConfigDB::GetMapConnections()", "No Data for key: %s, id: %u.", key, id);
return nullptr;
}
return DBResultToRowset(res);
}
PyObject *ConfigDB::GetMapLandmarks() { // working 29June14
DBQueryResult res;
if (!sDatabase.RunQuery(res,
"SELECT"
" landmarkID,"
" landmarkName,"
" 0 AS landmarkNameID,"
" x, y, z,"
" radius"
" FROM mapLandmarks" ))
{
codelog(DATABASE__ERROR, "Error in GetMapLandmarks query: %s", res.error.c_str());
return nullptr;
}
return DBResultToRowset(res);
}