EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommandDB.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 */
25 
28 #include "eve-server.h"
29 
30 #include "admin/CommandDB.h"
31 
32 uint32_t CommandDB::GetSolarSystem(const char *name) {
33  //sDatabase.ReplaceSlash(name);
34  if (!sDatabase.IsSafeString(name))
35  return 0;
36 
37  std::string escaped;
38  sDatabase.DoEscapeString(escaped, name);
39 
40  DBQueryResult result;
41  if (!sDatabase.RunQuery(result,
42  "SELECT solarSystemID "
43  "FROM mapSolarSystems "
44  "WHERE solarSystemName LIKE '%%%s%%';",
45  escaped.c_str()
46  )) {
47  codelog(DATABASE__ERROR, "Error in query: %s", result.error.c_str());
48  return 0;
49  }
50 
51  DBResultRow row;
52  if (!result.GetRow(row)) {
53  codelog(COMMAND__ERROR, "Solar System query returned nothing");
54  return 0;
55  }
56 
57  return row.GetUInt(0);
58 }
59 
60 uint32_t CommandDB::GetStation(const char* name)
61 {
62  if (!sDatabase.IsSafeString(name))
63  return 0;
64 
65  std::string escaped;
66  sDatabase.DoEscapeString(escaped, name);
67 
68  DBQueryResult result;
69  if (!sDatabase.RunQuery(result,
70  "SELECT `stationID`"
71  " FROM `staStations`"
72  " WHERE `stationName` LIKE '%%%s%%';",
73  escaped.c_str()
74  )) {
75  codelog(DATABASE__ERROR, "Error in query: %s", result.error.c_str());
76  return 0;
77  }
78 
79  DBResultRow row;
80  if (!result.GetRow(row)) {
81  codelog(COMMAND__ERROR, "Station query returned nothing");
82  return 0;
83  }
84 
85  return row.GetUInt(0);
86 }
87 
88 
89 bool CommandDB::ItemSearch(const char *query, std::map<uint32, std::string> &into) {
90 
91  into.clear();
92 
93  //sDatabase.ReplaceSlash(query);
94  if (!sDatabase.IsSafeString(query))
95  return 0;
96 
97  std::string escaped;
98  sDatabase.DoEscapeString(escaped, query);
99 
100 
101  //we need to query out the primary message here... not sure how to properly
102  //grab the "main message" though... the text/plain clause is pretty hackish.
103  DBQueryResult result;
104  if (!sDatabase.RunQuery(result,
105  " SELECT typeID,typeName"
106  " FROM invTypes"
107  " WHERE"
108  " typeName rlike '%s'",
109  escaped.c_str()
110  ))
111  {
112  codelog(SERVICE__ERROR, "Error in query: %s", result.error.c_str());
113  return (false);
114  }
115 
116  DBResultRow row;
117  while(result.GetRow(row)) {
118  into[row.GetUInt(0)] = row.GetText(1);
119  }
120  return true;
121 }
122 
123 bool CommandDB::ItemSearch(uint32 typeID, uint32 &actualTypeID,
124  std::string &actualTypeName, uint32 &actualGroupID, uint32 &actualCategoryID, double &actualRadius)
125 {
126  DBQueryResult result;
127  DBResultRow row;
128 
129  if (!sDatabase.RunQuery(result,
130  "SELECT "
131  " invTypes.typeID,"
132  " invTypes.typeName,"
133  " invTypes.groupID,"
134  " invTypes.radius,"
135  " invGroups.categoryID"
136  " FROM invTypes"
137  " LEFT JOIN invGroups"
138  " ON invGroups.groupID = invTypes.groupID"
139  " WHERE typeID = %u",
140  typeID
141  ))
142  {
143  sLog.Error( "CommandDB::ItemSearch()", "Error in query: %s", result.error.c_str() );
144  return (false);
145  }
146 
147  if( !result.GetRow(row) )
148  {
149  sLog.Error( "CommandDB::ItemSearch()", "Query returned NO results: %s", result.error.c_str() );
150  return (false);
151  }
152 
153  // Extract values from the first row:
154  actualTypeID = row.GetUInt( 0 );
155  actualTypeName = row.GetText( 1 );
156  actualGroupID = row.GetUInt( 2 );
157  actualCategoryID = row.GetUInt( 4 );
158  actualRadius = row.GetDouble( 3 );
159 
160  return true;
161 }
162 
163 int CommandDB::GetAttributeID(const char *attributeName) {
164 
165  if (!sDatabase.IsSafeString(attributeName))
166  return 0;
167 
168  DBQueryResult res;
169  std::string escape;
170  sDatabase.DoEscapeString(escape, attributeName);
171 
172  if(!sDatabase.RunQuery(res,
173  " SELECT "
174  " attributeID "
175  " FROM dgmAttributeTypes "
176  " WHERE attributeName = '%s' ",
177  escape.c_str() ) )
178  {
179  codelog(DATABASE__ERROR, "Error retrieving attributeID for attributeName = '%s' ", escape.c_str() );
180  return 0;
181  }
182 
183  DBResultRow row;
184  if( !res.GetRow(row) ){
185  codelog(DATABASE__ERROR, "Null result finding attributeID for attributeName = '%s' ", escape.c_str() );
186  return 0;
187  }
188 
189  return row.GetUInt( 0 );
190 
191 }
192 
193 int CommandDB::GetAccountID(std::string name) {
194 
195  if (!sDatabase.IsSafeString(name))
196  return 0;
197 
198  DBQueryResult res;
199  if (!sDatabase.RunQuery(res, "SELECT accountID FROM chrCharacters WHERE name = '%s'", name.c_str())) {
200  sLog.Error("CommandDB", "Failed to retrieve accountID for %s", name.c_str());
201  return 0;
202  }
203 
204  DBResultRow row;
205  if (!res.GetRow(row)) {
206  sLog.Error("CommandDB", "Query Returned no results");
207  return 0;
208  }
209 
210  return row.GetInt(0);
211 }
212 
213 bool CommandDB::FullSkillList(std::vector<uint32> &skillList) {
214  skillList.clear();
215 
216  DBQueryResult result;
217  if (!sDatabase.RunQuery(result,
218  " SELECT typeID FROM `invTypes` WHERE "
219  " ((`groupID` IN (SELECT groupID FROM invGroups WHERE categoryID = 16)) AND (published = 1)) "
220  ))
221  {
222  codelog(SERVICE__ERROR, "Error in query: %s", result.error.c_str());
223  return false;
224  }
225 
226  DBResultRow row;
227  while (result.GetRow(row)) {
228  skillList.push_back( (row.GetInt(0)) );
229  }
230 
231  // Because we searched skills with published = 1 and some GM skills are not published but still usable,
232  // we will add them manually here:
233  skillList.push_back( 3755 ); // Jove Frigate
234  skillList.push_back( 3758 ); // Jove Cruiser
235  skillList.push_back( 9955 ); // Polaris
236  skillList.push_back( 10264 ); // Concord
237  skillList.push_back( 11075 ); // Jove Industrial
238  skillList.push_back( 11078 ); // Jove Battleship
239  skillList.push_back( 19430 ); // Omnipotent
240  skillList.push_back( 28604 ); // Tournament Observation
241 
242  return true;
243 }
int GetAccountID(std::string name)
Definition: CommandDB.cpp:193
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
bool ItemSearch(const char *query, std::map< uint32, std::string > &into)
Definition: CommandDB.cpp:89
uint32_t GetSolarSystem(const char *name)
Definition: CommandDB.cpp:32
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
bool FullSkillList(std::vector< uint32 > &skillList)
Definition: CommandDB.cpp:213
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
int GetAttributeID(const char *attributeName)
Definition: CommandDB.cpp:163
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
unsigned __int32 uint32
Definition: eve-compat.h:50
DBerror error
Definition: dbcore.h:69
uint32_t GetStation(const char *name)
Definition: CommandDB.cpp:60