EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SearchDB.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: Allan, bb2k
24 */
25 
26 #include "eve-server.h"
27 
28 #include "search/SearchDB.h"
29 
47 PyRep *SearchDB::Query(std::string string, std::vector<int> *searchID, uint32 charID) {
48  std::string id = "";
49 
50  PyDict *dict = new PyDict();
51  DBQueryResult res;
52 
53  for (uint8 i = 0; i < searchID->size(); i++) {
54  switch(searchID->at(i)) {
55  case 1: //searchResultAgent = 1
56  sDatabase.RunQuery(res,
57  "SELECT"
58  " characterID AS agentID"
59  " FROM chrNPCCharacters"
60  " WHERE characterName LIKE '%s' "
61  " LIMIT 0, 10", string.c_str() );
62  id = "agentID";
63  break;
64  case 2: //searchResultCharacter = 2
65  sDatabase.RunQuery(res,
66  "SELECT"
67  " characterID AS ownerID"
68  " FROM chrCharacters"
69  " WHERE characterName LIKE '%s' ", string.c_str() );
70  id = "ownerID";
71  break;
72  case 3: //searchResultCorporation = 3
73  sDatabase.RunQuery(res,
74  "SELECT"
75  " corporationID AS ownerID"
76  " FROM crpCorporation"
77  " WHERE corporationName LIKE '%s' "
78  " LIMIT 0, 10", string.c_str() );
79  id = "ownerID";
80  break;
81  case 4: //searchResultAlliance = 4
82  sDatabase.RunQuery(res,
83  "SELECT allianceID AS ownerID"
84  " FROM alnAlliance"
85  " WHERE shortName LIKE '%s' "
86  " LIMIT 0, 10", string.c_str() );
87  id = "ownerID";
88  break;
89  case 5: //searchResultFaction = 5
90  sDatabase.RunQuery(res,
91  "SELECT factionID AS ownerID"
92  " FROM facFactions"
93  " WHERE factionName LIKE '%s' "
94  " LIMIT 0, 10", string.c_str() );
95  id = "ownerID";
96  break;
97  case 6: //searchResultConstellation = 6
98  sDatabase.RunQuery(res,
99  "SELECT"
100  " constellationID AS itemID"
101  " FROM mapConstellations"
102  " WHERE constellationName LIKE '%s' "
103  " LIMIT 0, 10", string.c_str() );
104  id = "itemID";
105  break;
106  case 7: //searchResultSolarSystem = 7
107  sDatabase.RunQuery(res,
108  "SELECT "
109  " solarSystemID AS itemID"
110  " FROM mapSolarSystems "
111  " WHERE solarSystemName LIKE '%s' "
112  " LIMIT 0, 10", string.c_str() );
113  id = "itemID";
114  break;
115  case 8: //searchResultRegion = 8
116  sDatabase.RunQuery(res,
117  "SELECT "
118  " regionID AS itemID"
119  " FROM mapRegions"
120  " WHERE regionName LIKE '%s' "
121  " LIMIT 0, 10", string.c_str() );
122  id = "itemID";
123  break;
124  case 9: //searchResultStation = 9
125  sDatabase.RunQuery(res,
126  "SELECT "
127  " stationID AS itemID"
128  " FROM staStations "
129  " WHERE stationName LIKE '%s' "
130  " LIMIT 0, 10", string.c_str() );
131  id = "itemID";
132  break;
133  case 10: //searchResultInventoryType = 10
134  sDatabase.RunQuery(res,
135  "SELECT"
136  " typeID"
137  " FROM entity"
138  " WHERE itemName LIKE '%s'"
139  " AND ownerID = %u", string.c_str(), charID );
140  id = "typeID";
141  break;
142  }
143  if (res.GetRowCount())
144  dict->SetItem(new PyInt(searchID->at(i)),DBResultToIntIntDict(res));
145  }
146 
147  return dict;
148 }
149 
150 PyRep *SearchDB::QuickQuery(std::string string, std::vector<int> *searchID, uint32 charID, bool hideNPC, bool onlyAltName) {
151 
152  uint8 size = searchID->size();
153 
154  if (((size == 1) && (searchID->at(0) == 2)) || (hideNPC)) {
156  }
157 
158  PyList *result = new PyList();
159  DBQueryResult res;
160  DBResultRow row;
161 
162  for (uint8 i=0; i < searchID->size(); i++) {
163  switch(searchID->at(i)) {
164  case 1: //searchResultAgent = 1
165  sDatabase.RunQuery(res,
166  "SELECT characterID"
167  " FROM chrNPCCharacters"
168  " WHERE characterName LIKE '%s' "
169  " LIMIT 0, 10", string.c_str() );
170  break;
171  case 2: //searchResultCharacter = 2
172  sDatabase.RunQuery(res,
173  "SELECT characterID"
174  " FROM chrCharacters"
175  " WHERE characterName LIKE '%s' ", string.c_str() );
176  break;
177  case 3: //searchResultCorporation = 3
178  sDatabase.RunQuery(res,
179  "SELECT corporationID"
180  " FROM crpCorporation"
181  " WHERE corporationName LIKE '%s' "
182  " LIMIT 0, 10", string.c_str() );
183  break;
184  case 4: //searchResultAlliance = 4
185  sDatabase.RunQuery(res,
186  "SELECT allianceID"
187  " FROM alnAlliance"
188  " WHERE shortName LIKE '%s' "
189  " LIMIT 0, 10", string.c_str() );
190  break;
191  case 5: //searchResultFaction = 5
192  sDatabase.RunQuery(res,
193  "SELECT factionID"
194  " FROM facFactions"
195  " WHERE factionName LIKE '%s' "
196  " LIMIT 0, 10", string.c_str() );
197  break;
198  case 6: //searchResultConstellation = 6
199  sDatabase.RunQuery(res,
200  "SELECT constellationID"
201  " FROM mapConstellations"
202  " WHERE constellationName LIKE '%s' "
203  " LIMIT 0, 10", string.c_str() );
204  break;
205  case 7: //searchResultSolarSystem = 7
206  sDatabase.RunQuery(res,
207  "SELECT solarSystemID"
208  " FROM mapSolarSystems "
209  " WHERE solarSystemName LIKE '%s' "
210  " LIMIT 0, 10", string.c_str() );
211  break;
212  case 8: //searchResultRegion = 8
213  sDatabase.RunQuery(res,
214  "SELECT regionID"
215  " FROM mapRegions"
216  " WHERE regionName LIKE '%s' "
217  " LIMIT 0, 10", string.c_str() );
218  break;
219  case 9: //searchResultStation = 9
220  sDatabase.RunQuery(res,
221  "SELECT stationID"
222  " FROM staStations "
223  " WHERE stationName LIKE '%s' "
224  " LIMIT 0, 10", string.c_str() );
225  break;
226  case 10: //searchResultInventoryType = 10
227  sDatabase.RunQuery(res,
228  "SELECT typeID"
229  " FROM entity"
230  " WHERE itemName LIKE '%s'"
231  " AND ownerID = %u", string.c_str(), charID );
232  break;
233  }
234  while (res.GetRow(row)) {
235  result->AddItem( new PyInt(row.GetUInt(0) ));
236  }
237  }
238 
239  return result;
240 }
Base Python wire object.
Definition: PyRep.h:66
unsigned __int8 uint8
Definition: eve-compat.h:46
#define sDatabase
Definition: dbcore.h:199
Python's dictionary.
Definition: PyRep.h:719
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
PyDict * DBResultToIntIntDict(DBQueryResult &result)
Definition: EVEDBUtils.cpp:273
void AddItem(PyRep *i)
Definition: PyRep.h:701
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
Python integer.
Definition: PyRep.h:231
PyRep * QuickQuery(std::string string, std::vector< int > *searchID, uint32 charID, bool hideNPC=false, bool onlyAltName=false)
Definition: SearchDB.cpp:150
unsigned __int32 uint32
Definition: eve-compat.h:50
size_t GetRowCount()
Definition: dbcore.h:72
PyRep * Query(std::string string, std::vector< int > *searchID, uint32 charID)
Definition: SearchDB.cpp:47
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
Python list.
Definition: PyRep.h:639