EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Search.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
24 */
25 
26 
27 #include "eve-server.h"
28 
29 #include "search/Search.h"
30 
32 
34 : PyService(mgr, "search"),
35  m_dispatch(new Dispatcher(this))
36 {
37  _SetCallDispatcher(m_dispatch);
38 
40  PyCallable_REG_CALL(Search, QuickQuery);
41 }
42 
44  delete m_dispatch;
45 }
46 
47 PyResult Search::Handle_Query( PyCallArgs& call ) {
48  Call_SearchQuery args;
49  if(!args.Decode(&call.tuple)) {
50  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
51  call.client->SendErrorMsg("Search Failed. Try using a different search string.");
52  return nullptr;
53  }
54 
55  std::string str = args.str;
56  Replace(str);
57 
58  // this hits db directly, so test for possible sql injection code
59  for (const auto cur : badCharsSearch)
60  if (EvE::icontains(args.str, cur))
61  throw CustomError ("Search String contains invalid characters");
62 
63  return m_db->Query( str, &args.ids, call.client->GetCharacterID() );
64 }
65 
66 
67 PyResult Search::Handle_QuickQuery( PyCallArgs& call ) {
68 /* QuickQuery(query, groupIDList, hideNPC=hideNPC, onlyAltName=onlyAltName)
69 */
70  Call_SearchQuery args;
71  if(!args.Decode(&call.tuple)) {
72  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
73  call.client->SendErrorMsg("Search Failed. Try using a different search string.");
74  return nullptr;
75  }
76 
77  std::string str = args.str;
78  Replace(str);
79 
80  bool hideNPC = true, onlyAltName = false;
81  if (call.byname.find("hideNPC") != call.byname.end())
82  hideNPC = (PyRep::IntegerValue(call.byname.find("hideNPC")->second) != 0);
83 
84  if (call.byname.find("onlyAltName") != call.byname.end())
85  onlyAltName = (PyRep::IntegerValue(call.byname.find("onlyAltName")->second) != 0);
86 
87  // this hits db directly, so test for possible sql injection code
88  for (const auto cur : badCharsSearch)
89  if (EvE::icontains(args.str, cur))
90  throw CustomError ("Search String contains invalid characters");
91 
92  return m_db->QuickQuery( str, &args.ids, call.client->GetCharacterID(), hideNPC, onlyAltName);
93 }
94 
95 void Search::Replace(std::string &str) {
96  for (uint i = 0; i < str.length(); ++i)
97  switch (str[i]) {
98  case '*':
99  str[i] = '%';
100  }
101 }
Dispatcher *const m_dispatch
void SendErrorMsg(const char *fmt,...)
Definition: Client.cpp:2719
#define _log(type, fmt,...)
Definition: logsys.h:124
std::map< std::string, PyRep * > byname
Definition: PyCallable.h:51
Dispatcher *const m_dispatch
Definition: Search.h:41
int32 GetCharacterID() const
Definition: Client.h:113
const char * GetName() const
Definition: PyService.h:54
virtual ~Search()
Definition: Search.cpp:43
Advanced version of UserError that allows to send a full custom message.
Definition: PyExceptions.h:453
void Replace(std::string &s)
Definition: Search.cpp:95
* args
PyCallable_Make_InnerDispatcher(Search) Search
Definition: Search.cpp:31
PyRep * QuickQuery(std::string string, std::vector< int > *searchID, uint32 charID, bool hideNPC=false, bool onlyAltName=false)
Definition: SearchDB.cpp:150
Definition: Search.h:34
Client *const client
Definition: PyCallable.h:49
#define PyCallable_REG_CALL(c, m)
Definition: PyServiceCD.h:78
static const std::array< std::string, 16 > badCharsSearch
Definition: EVE_Consts.h:108
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118
PyRep * Query(std::string string, std::vector< int > *searchID, uint32 charID)
Definition: SearchDB.cpp:47
SearchDB * m_db
Definition: Search.h:48
bool icontains(std::string data, std::string toSearch, size_t pos=0)
Definition: misc.cpp:194
PyTuple * tuple
Definition: PyCallable.h:50