EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StationDB.cpp
Go to the documentation of this file.
1 
11 #include "eve-server.h"
12 
13 #include "station/StationDB.h"
14 #include "station/StationDataMgr.h"
15 
16 
18 {
19  uint32 uid = 0;
20  DBerror err;
21  if (!sDatabase.RunQueryLID(err, uid,
22  "INSERT INTO staOffices (name, corporationID, stationID, officeFolderID, flag, solarSystemID, typeID, stationTypeID, lockDown, rentalFee, expiryDateTime)"
23  " VALUES"
24  " ('%s',%u,%u,%u,%u,%u, 27, %u,%u,%u,%li)",
25  odata.name.c_str(), odata.corporationID, odata.stationID, odata.folderID, idata.flag, stDataMgr.GetStationSystemID(odata.stationID), odata.typeID, odata.lockDown, odata.rentalFee, odata.expiryTime)
26  )
27  codelog(DATABASE__ERROR, "Error in CreateOffice query: %s", err.c_str());
28 
29  return (odata.officeID = uid);
30 }
31 
33 {
34  DBerror err;
35  sDatabase.RunQuery(err, "UPDATE staOffices SET lockDown = %u, rentalFee = %u, expiryDateTime = %li)", data.lockDown, data.rentalFee, data.expiryTime);
36 }
37 
39 {
40  DBQueryResult res;
41  if (!sDatabase.RunQuery(res, "SELECT COUNT(itemID) FROM staOffices WHERE corporationID = %u ", corpID)) {
42  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
43  return 0;
44  }
45 
46  DBResultRow row;
47  if (!res.GetRow(row)) {
48  codelog(CORP__DB_WARNING, "Unable to find corporation's office data (%u)", corpID);
49  return 0;
50  }
51  return row.GetInt(0);
52 }
53 
55 {
56  DBQueryResult res;
57  if (!sDatabase.RunQuery(res,
58  "SELECT"
59  " corporationID, itemID, officeFolderID"
60  " FROM staOffices"
61  " WHERE stationID = %u", stationID)
62  )
63  codelog(DATABASE__ERROR, "Error in GetOffices query: %s", res.error.c_str());
64 
65  return DBResultToCRowset(res);
66 }
67 
69 {
70  DBQueryResult res;
71  if (!sDatabase.RunQuery(res,
72  "SELECT"
73  " corporationID, stationID, typeID, lockDown, rentalFee, expiryDateTime, officeFolderID"
74  " FROM staOffices"
75  " WHERE itemID = %u", officeID)
76  ) {
77  codelog(DATABASE__ERROR, "Error in GetOfficeData query: %s", res.error.c_str());
78  return false;
79  }
80 
81  DBResultRow row;
82  if (!res.GetRow(row))
83  return false;
84 
85  odata.officeID = officeID;
86  odata.corporationID = row.GetInt(0);
87  odata.stationID = row.GetInt(1);
88  odata.typeID = row.GetInt(2);
89  odata.lockDown = row.GetBool(3);
90  odata.rentalFee = row.GetInt64(4);
91  odata.expiryTime = row.GetInt64(5);
92  odata.folderID = row.GetInt(6);
93  return true;
94 }
95 
96 
98 {
99  if (!sDatabase.RunQuery(res,
100  "SELECT"
101  " itemID, corporationID, stationID, typeID, lockDown, rentalFee, expiryDateTime, officeFolderID"
102  " FROM staOffices")
103  )
104  codelog(DATABASE__ERROR, "Error in GetStationOfficeData query: %s", res.error.c_str());
105 }
106 
107 PyRep* StationDB::GetStationOfficeIDs(uint32 locationID, uint32 corpID, const char* key)
108 {
109  DBQueryResult res;
110  if (sDataMgr.IsStation(locationID)) {
111  sDatabase.RunQuery(res, "SELECT itemID AS officeID, stationID, officeFolderID"
112  " FROM staOffices WHERE stationID = %u", locationID);
113  } else if (IsOfficeFolder(locationID)) {
114  sDatabase.RunQuery(res, "SELECT itemID AS officeID, stationID, officeFolderID"
115  " FROM staOffices WHERE officeFolderID = %u",
116  locationID - STATION_OFFICE_OFFSET);
117  } else if (IsOfficeID(locationID)) {
118  sDatabase.RunQuery(res, "SELECT itemID AS officeID, stationID, officeFolderID"
119  " FROM staOffices WHERE itemID = %u", locationID);
120  } else {
121  _log(CORP__DB_ERROR, "StationDB::GetStationOfficeIDs got invalid locationID %u", locationID);
122  }
123 
124  DBResultRow row;
125  if (res.GetRow(row))
126  return DBRowToRow(row);
127 
128  return nullptr;
129 
130  //return DBResultToCIndexedRowset(res, key);
131  //return DBResultToIndexRowset(res, key);
132  //return DBResultToCRowset(res);
133  //return DBResultToRowList(res);
134  //return DBResultToRowset(res);
135  //return DBResultToPackedRowDict(res, key);
136 }
137 
139 {
140  if (!sDatabase.RunQuery(res,
141  "SELECT"
142  " s.stationID, s.x, s.y, s.z, st.dockOrientationX, st.dockOrientationY, st.dockOrientationZ,"
143  " s.dockingCostPerVolume, s.maxShipVolumeDockable, s.officeSlots, s.officeRentalCost,"
144  " s.operationID, s.stationTypeID, s.corporationID, s.stationName,"
145  " s.reprocessingStationsTake, s.reprocessingEfficiency, s.reprocessingHangarFlag, st.conquerable, st.hangarGraphicID,"
146  " m.orbitID, m.radius, m.security, o.description, o.descriptionID, t.graphicID, s.solarSystemID, s.constellationID, s.regionID,"
147  " st.dockEntryX, st.dockEntryY, st.dockEntryZ"
148  " FROM staStations AS s"
149  " LEFT JOIN staStationTypes AS st USING (stationTypeID)"
150  " LEFT JOIN invTypes AS t ON t.typeID = s.stationTypeID"
151  " LEFT JOIN staOperations AS o ON o.operationID = s.operationID"
152  " LEFT JOIN mapDenormalize AS m ON m.itemID = s.stationID")
153  )
154  codelog(DATABASE__ERROR, "Error in GetStationData query: %s", res.error.c_str());
155 }
156 
158 {
159  if (!sDatabase.RunQuery(res, "SELECT stationID, solarSystemID FROM staStations"))
160  codelog(DATABASE__ERROR, "Error in GetStationSystem query: %s", res.error.c_str());
161 }
162 
164 {
165  if (!sDatabase.RunQuery(res, "SELECT stationID, regionID FROM staStations"))
166  codelog(DATABASE__ERROR, "Error in GetStationRegion query: %s", res.error.c_str());
167 }
168 
170 {
171  if (!sDatabase.RunQuery(res, "SELECT stationID, constellationID FROM staStations"))
172  codelog(DATABASE__ERROR, "Error in GetStationConstellation query: %s", res.error.c_str());
173 }
174 
176 {
177  sDatabase.RunQuery(res, "SELECT operationID, serviceID FROM staOperationServices");
178 }
179 
180 void StationDB::LoadOffices(OwnerData& od, std::vector< uint32 >& into)
181 {
182  DBQueryResult res;
183  if (!sDatabase.RunQuery(res, "SELECT itemID FROM staOffices WHERE stationID = %u", od.locID)) {
184  codelog(DATABASE__ERROR, "Error in LoadOffices query: %s", res.error.c_str());
185  return;
186  }
187 
188  DBResultRow row;
189  while (res.GetRow(row))
190  into.push_back(row.GetInt(0));
191 }
Base Python wire object.
Definition: PyRep.h:66
uint32 locID
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
#define IsOfficeFolder(itemID)
Definition: EVE_Defines.h:309
#define stDataMgr
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
void UpdateOfficeData(OfficeData &data)
Definition: StationDB.cpp:32
uint32 folderID
static int32 GetOfficeCount(uint32 corpID)
Definition: StationDB.cpp:38
uint32 stationID
static void GetOperationServiceIDs(DBQueryResult &res)
Definition: StationDB.cpp:175
signed __int32 int32
Definition: eve-compat.h:49
static void GetStationConstellation(DBQueryResult &res)
Definition: StationDB.cpp:169
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
bool GetBool(uint32 index) const
Definition: dbcore.cpp:647
PyObject * DBRowToRow(DBResultRow &row, const char *type)
Definition: EVEDBUtils.cpp:208
static void GetStationRegion(DBQueryResult &res)
Definition: StationDB.cpp:163
static void GetStationSystem(DBQueryResult &res)
Definition: StationDB.cpp:157
int64 expiryTime
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
uint32 officeID
static void GetStationData(DBQueryResult &res)
Definition: StationDB.cpp:138
std::string name
static bool GetOfficeData(uint32 officeID, OfficeData &odata)
Definition: StationDB.cpp:68
static void LoadOffices(OwnerData &od, std::vector< uint32 > &into)
Definition: StationDB.cpp:180
uint32 corporationID
unsigned __int32 uint32
Definition: eve-compat.h:50
static PyRep * GetOffices(uint32 stationID)
Definition: StationDB.cpp:54
EVEItemFlags flag
Definition: ItemType.h:187
#define IsOfficeID(itemID)
Definition: EVE_Defines.h:253
DBerror error
Definition: dbcore.h:69
#define STATION_OFFICE_OFFSET
Definition: EVE_Defines.h:177
static uint32 CreateOffice(ItemData &idata, OfficeData &odata)
Definition: StationDB.cpp:17
static PyRep * GetStationOfficeIDs(uint32 locationID, uint32 corpID, const char *key)
Definition: StationDB.cpp:107
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type() key(value)-Send an OnRemoteMessage" ) COMMAND( setbpattr
int64 GetInt64(uint32 index) const
Definition: dbcore.cpp:670
Definition: dbcore.h:39
static void GetStationOfficeData(DBQueryResult &res)
Definition: StationDB.cpp:97
#define sDataMgr