EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapDB.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24  Updates: Allan
25 */
26 
27 #include "eve-server.h"
28 
29 #include "map/MapDB.h"
30 
32  DBQueryResult res;
33 
34  if (!sDatabase.RunQuery(res, "SELECT solarSystemID, security FROM mapSolarSystems")) {
35  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
36  return nullptr;
37  }
38 
39  return DBResultToRowset(res);
40 }
41 
43  DBQueryResult res;
44 
45  if (!sDatabase.RunQuery(res,
46  "SELECT"
47  " stationID,"
48  " solarSystemID,"
49  " operationID,"
50  " stationTypeID,"
51  " corporationID AS ownerID"
52  " FROM staStations" )) {
53  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
54  return nullptr;
55  }
56 
57  return DBResultToRowset(res);
58 }
59 
61  DBQueryResult res;
62 
63  if (!sDatabase.RunQuery(res,
64  "SELECT operationID, serviceID FROM staOperationServices")) {
65  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
66  return nullptr;
67  }
68 
69  return DBResultToRowset(res);
70 }
71 
73  DBQueryResult res;
74 
75  if (!sDatabase.RunQuery(res,
76  "SELECT serviceID, serviceName FROM staServices ")) {
77  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
78  return nullptr;
79  }
80 
81  return DBResultToRowset(res);
82 }
83 
85 {
86  if (!sDatabase.RunQuery(res,
87  "SELECT map.solarSystemID, count(sta.stationID)"
88  " FROM mapSolarSystems AS map"
89  " LEFT JOIN staStations AS sta USING(solarSystemID)"
90  " GROUP BY map.solarSystemID"))
91  {
92  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
93  }
94 }
95 
97 {
98  DBQueryResult res;
99 
100  if (!sDatabase.RunQuery(res,
101  " SELECT"
102  " solarSystemID,"
103  " visits,"
104  " lastDateTime"
105  " FROM chrVisitedSystems"
106  " WHERE characterID = %u", charID ))
107  {
108  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
109  return nullptr;
110  }
111 
112  return DBResultToRowset(res);
113 }
114 
115 // load all dynamic statistic data for system when booting. -allan 5Aug19
116 // systemMgr handles all calculations for jumps and kills and will call updates on a 15m timer
118 {
119  DBQueryResult res;
120  if (!sDatabase.RunQuery(res,
121  "SELECT killsHour, kills24Hour, factionKills, factionKills24Hour, podKillsHour, podKills24Hour,"
122  " killsDateTime, kills24DateTime, podDateTime, pod24DateTime, factionDateTime, faction24DateTime"
123  " FROM mapDynamicData"
124  " WHERE solarSystemID = %u", sysID))
125  {
126  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
127  return;
128  }
129  DBResultRow row;
130  if (res.GetRow(row)) {
131  data.killsHour = row.GetInt(0);
132  data.kills24Hour = row.GetInt(1);
133  data.factionKills = row.GetInt(2);
134  data.factionKills24Hour = row.GetInt(3);
135  data.podKillsHour = row.GetInt(4);
136  data.podKills24Hour = row.GetInt(5);
137  data.killsDateTime = row.GetInt64(6);
138  data.kills24DateTime = row.GetInt64(7);
139  data.factionDateTime = row.GetInt64(8);
140  data.faction24DateTime = row.GetInt64(9);
141  data.podDateTime = row.GetInt64(10);
142  data.pod24DateTime = row.GetInt64(11);
143  } else {
144  data = SystemKillData();
145  }
146 }
147 
148 // called from MapService by multiple functions based on passed values.
154  DBQueryResult res;
155  switch (type) {
156  case 1: {
157  sDatabase.RunQuery(res, "SELECT solarSystemID, jumpsHour AS value1 FROM mapDynamicData" );
158  } break;
159  case 2: {
160  // cynos arent implemented yet, so this will always return 0
161  sDatabase.RunQuery(res, "SELECT solarSystemID, moduleCnt, structureCnt FROM mapDynamicData WHERE active=1" );
162  DBResultRow row;
163  PyDict* dict = new PyDict();
164  while (res.GetRow(row)) {
165  PyTuple* inner = new PyTuple(2);
166  inner->SetItem(0, new PyInt(row.GetInt(1))); // cyno modules on ships (fields)
167  inner->SetItem(1, new PyInt(row.GetInt(2))); // cyno generators (POS structures)
168  dict->SetItem(new PyInt(row.GetInt(0)), inner);
169  }
170  return dict;
171  };
172  case 3: {
173  if (time == 1) {
174  sDatabase.RunQuery(res, "SELECT solarSystemID, killsHour AS value1, factionKills AS value2, podKillsHour AS value3 FROM mapDynamicData" );
175  } else if (time == 24) {
176  sDatabase.RunQuery(res, "SELECT solarSystemID, kills24Hour AS value1, factionKills24Hour AS value2, podKills24Hour AS value3 FROM mapDynamicData" );
177  }
178  } break;
179  case 4: {
180  // not coded in client
181  } break;
182  case 5: { //FacWarSvc.GetMostDangerousSystems
183  sDatabase.RunQuery(res, "SELECT solarSystemID, killsHour AS value1, factionKills AS value2 FROM mapDynamicData" );
184  //, kills24Hour AS value3, factionKills24Hour AS value4, podKills24Hour AS value5
185  } break;
186  default:
187  return nullptr;
188  }
189 
190  return DBResultToRowset(res);
191 }
192 
193 // for MapData class
195 {
196  //sDatabase.RunQuery(res, "SELECT ctype, fromreg, fromcon, fromsol, tosol, tocon, toreg FROM mapConnections");
197  sDatabase.RunQuery(res, "SELECT ctype, fromsol, tosol FROM mapConnections");
198 }
199 
200 // methods and queries for Solar System Status page -- updated/moved 26Nov18
202 {
203  DBerror err;
204  sDatabase.RunQuery(err, "UPDATE mapDynamicData SET active = 0, jumpsHour = 0, pilotsDocked = 0, pilotsInSpace = 0, moduleCnt = 0, structureCnt = 0 WHERE 1");
205 }
206 
212 void MapDB::SetSystemActive(uint32 sysID, bool active/*false*/)
213 {
214  DBerror err;
215  sDatabase.RunQuery(err, "UPDATE mapDynamicData SET active = %u WHERE solarSystemID = %u", active?1:0, sysID );
216 }
217 
219 {
220  DBerror err;
221  sDatabase.RunQuery(err, "UPDATE mapDynamicData SET jumpsHour = jumpsHour + 1 WHERE solarSystemID = %u", sysID );
222 }
223 
224 // these next 3 are updated to use systemMgr to manage dynamic data for it's system, and call these on a timer to update periodically
225 void MapDB::UpdatePilotCount(uint32 sysID, uint16 docked/*0*/, uint16 space/*0*/)
226 {
227  DBerror err;
228  sDatabase.RunQuery(err, "UPDATE mapDynamicData SET pilotsDocked = %u, pilotsInSpace = %u WHERE solarSystemID = %u",
229  docked, space, sysID );
230 }
231 
232 void MapDB::UpdateJumps(uint32 sysID, uint16 jumps)
233 {
234  //DBerror err;
235  //sDatabase.RunQuery(err, "UPDATE mapDynamicData SET jumpsHour = %u WHERE solarSystemID = %u", jumps, sysID );
236  sLog.Warning("MapDB::UpdateJumps", "UPDATE mapDynamicData SET jumpsHour = %u WHERE solarSystemID = %u", jumps, sysID);
237 }
238 
240 {
241  DBerror err;
242  sDatabase.RunQuery(err, "UPDATE mapDynamicData SET killsHour = %u, kills24Hour = %u, factionKills = %u, factionKills24Hour = %u,"
243  " podKillsHour = %u, podKills24Hour = %u, killsDateTime = %li, kills24DateTime = %li, podDateTime = %li, pod24DateTime = %li,"
244  " factionDateTime = %li, faction24DateTime = %li",
247 }
248 
249 // client logs faction kills in total kills. return is value1(total kills) - value2(faction kills) > 0:
250 void MapDB::AddKill(uint32 sysID) {
251  DBerror err;
252  sDatabase.RunQuery(err,
253  "UPDATE mapDynamicData SET killsHour = killsHour + 1, kills24Hour = kills24Hour + 1 WHERE solarSystemID = %u", sysID);
254 }
255 
257  DBerror err;
258  sDatabase.RunQuery(err,
259  "UPDATE mapDynamicData SET factionKills = factionKills + 1, factionKills24Hour = factionKills24Hour + 1 WHERE solarSystemID = %u", sysID);
260 }
261 
263  DBerror err;
264  sDatabase.RunQuery(err,
265  "UPDATE mapDynamicData SET podKillsHour = podKillsHour + 1, podKills24Hour = podKills24Hour + 1 WHERE solarSystemID = %u", sysID);
266 }
267 
268 // will need to write methods to retrieve/manipulate/set system dynamic data as systems may/may not be loaded
269 
271 {
272 
273 }
Base Python wire object.
Definition: PyRep.h:66
unsigned __int8 uint8
Definition: eve-compat.h:46
#define sDatabase
Definition: dbcore.h:199
static PyObject * GetSolSystemVisits(uint32)
Definition: MapDB.cpp:96
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
static PyRep * GetDynamicData(uint8 type, uint8 time)
Definition: MapDB.cpp:153
static void SetSystemActive(uint32 sysID, bool active=false)
Definition: MapDB.cpp:212
Python's dictionary.
Definition: PyRep.h:719
static void GetSystemJumps(DBQueryResult &res)
Definition: MapDB.cpp:194
static PyObject * GetStationOpServices()
Definition: MapDB.cpp:60
static void AddKill(uint32 sysID)
Definition: MapDB.cpp:250
static void AddFactionKill(uint32 sysID)
Definition: MapDB.cpp:256
static void LoadDynamicData(uint32 sysID, SystemKillData &data)
Definition: MapDB.cpp:117
Python tuple.
Definition: PyRep.h:567
uint16 factionKills24Hour
static void GetStationCount(DBQueryResult &res)
Definition: MapDB.cpp:84
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
static PyObject * GetPseudoSecurities()
Definition: MapDB.cpp:31
const char * c_str() const
Definition: dbcore.h:48
static void SystemStartup()
Definition: MapDB.cpp:201
Python object.
Definition: PyRep.h:826
#define codelog(type, fmt,...)
Definition: logsys.h:128
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
static void ManipulateTimeData()
Definition: MapDB.cpp:270
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
Python integer.
Definition: PyRep.h:231
static void UpdatePilotCount(uint32 sysID, uint16 docked=0, uint16 space=0)
Definition: MapDB.cpp:225
static PyObject * GetStationExtraInfo()
Definition: MapDB.cpp:42
unsigned __int32 uint32
Definition: eve-compat.h:50
static void AddPodKill(uint32 sysID)
Definition: MapDB.cpp:262
DBerror error
Definition: dbcore.h:69
static void UpdateJumps(uint32 sysID, uint16 jumps)
Definition: MapDB.cpp:232
static void AddJump(uint32 sysID)
Definition: MapDB.cpp:218
int64 GetInt64(uint32 index) const
Definition: dbcore.cpp:670
unsigned __int16 uint16
Definition: eve-compat.h:48
static PyObject * GetStationServiceInfo()
Definition: MapDB.cpp:72
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
Definition: dbcore.h:39
static void UpdateKillData(uint32 sysID, SystemKillData &data)
Definition: MapDB.cpp:239