EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ScanMgrService.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 #include "eve-server.h"
27 
28 #include "Client.h"
29 #include "PyBoundObject.h"
30 #include "PyServiceCD.h"
31 #include "Probes.h"
33 #include "system/DestinyManager.h"
34 #include "system/SystemManager.h"
35 #include "system/SystemBubble.h"
36 
37 /* SCAN__ERROR
38  * SCAN__WARNING
39  * SCAN__MESSAGE
40  * SCAN__DEBUG
41  * SCAN__INFO
42  * SCAN__TRACE
43  * SCAN__DUMP
44  */
45 
46 class ScanBound
47 : public PyBoundObject
48 {
49 public:
51 
53  : PyBoundObject(mgr),
54  m_dispatch(new Dispatcher(this)),
55  m_client(pClient)
56  {
58 
59  m_strBoundObjectName = "ScanBound";
60 
61  PyCallable_REG_CALL(ScanBound, ConeScan);
62  PyCallable_REG_CALL(ScanBound, RequestScans);
63  PyCallable_REG_CALL(ScanBound, RecoverProbes);
64  PyCallable_REG_CALL(ScanBound, ReconnectToLostProbes);
65  PyCallable_REG_CALL(ScanBound, DestroyProbe);
66 
67  }
80  virtual ~ScanBound() {delete m_dispatch;}
81  virtual void Release() {
82  //I hate this statement
83  delete this;
84  }
85 
86  PyCallable_DECL_CALL(RequestScans);
87  PyCallable_DECL_CALL(ConeScan);
88  PyCallable_DECL_CALL(ReconnectToLostProbes);
89  PyCallable_DECL_CALL(RecoverProbes);
90  PyCallable_DECL_CALL(DestroyProbe);
91 
92 protected:
93  Dispatcher *const m_dispatch;
97 };
98 
100 
102 : PyService(mgr, "scanMgr"),
103  m_dispatch(new Dispatcher(this))
104 {
105  _SetCallDispatcher(m_dispatch);
106 
107  PyCallable_REG_CALL(ScanMgrService, GetSystemScanMgr);
108 
109 }
110 
112  delete m_dispatch;
113 }
114 
115 PyResult ScanMgrService::Handle_GetSystemScanMgr( PyCallArgs& call ) {
116  DestinyManager* pDestiny = call.client->GetShipSE()->DestinyMgr();
117  if (pDestiny == nullptr) {
118  codelog(CLIENT__ERROR, "%s: Client has no destiny manager!", call.client->GetName());
119  return PyStatic.NewNone();
120  }
121 
122  ScanBound* pSB = new ScanBound(m_manager, call.client);
123  PyRep* result = m_manager->BindObject(call.client, pSB);
124  return result;
125 }
126 
127 PyResult ScanBound::Handle_ConeScan( PyCallArgs& call ) {
128  //result = sm.GetService('scanSvc').ConeScan(self.scanangle, rnge * 1000, vec.x, vec.y, vec.z)
129  //return sm.RemoteSvc('scanMgr').GetSystemScanMgr().ConeScan(scanangle, scanRange, x, y, z)
130  //_log(SCAN__TRACE, "ScanBound::Handle_ConeScan() - size= %u", call.tuple->size() );
131  //call.Dump(SCAN__DUMP);
132 
133  Call_ConeScan args;
134  if (!args.Decode(&call.tuple)) {
135  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
136  //TODO: throw exception
137  return PyStatic.NewNone();
138  }
139 
140  DestinyManager* pDestiny = m_client->GetShipSE()->DestinyMgr();
141  if (pDestiny == nullptr) {
142  codelog(CLIENT__ERROR, "%s: Client has no destiny manager!", m_client->GetName());
143  return PyStatic.NewNone();
144  } else if (pDestiny->IsWarping()) {
145  call.client->SendNotifyMsg( "You can't scan while warping");
146  return PyStatic.NewNone();
147  }
148 
149  if (m_client->GetShipSE()->SysBubble() == nullptr)
150  sBubbleMgr.Add(m_client->GetShipSE());
151 
152  if (m_client->scan() == nullptr)
153  m_client->SetScan(new Scan(m_client));
154 
157  return m_client->scan()->ConeScan(args);
158 }
159 
160 PyResult ScanBound::Handle_RequestScans( PyCallArgs& call ) {
161  _log(SCAN__TRACE, "ScanBound::Handle_RequestScans() - size= %u", call.tuple->size() );
162  call.Dump(SCAN__DUMP);
163 
164  DestinyManager* pDestiny = m_client->GetShipSE()->DestinyMgr();
165  if (pDestiny == nullptr) {
166  codelog(CLIENT__ERROR, "%s: Client has no destiny manager!", call.client->GetName());
167  return PyStatic.NewNone();
168  } else if (pDestiny->IsWarping()) {
169  call.client->SendNotifyMsg( "You can't scan while warping");
170  return PyStatic.NewNone();
171  }
172 
173  if (m_client->GetShipSE()->SysBubble() == nullptr)
174  sBubbleMgr.Add(m_client->GetShipSE());
175 
176  if (m_client->scan() == nullptr)
177  m_client->SetScan(new Scan(m_client));
178 
179  PyDict* dict(nullptr);
180  if (call.tuple->GetItem( 0 )->IsDict())
181  dict = call.tuple->GetItem(0)->AsDict();
182 
183  m_client->scan()->RequestScans(dict);
184 
185  // this call returns a PyNone
186  return PyStatic.NewNone();
187 }
188 
189 PyResult ScanBound::Handle_RecoverProbes( PyCallArgs& call ) {
190  //successProbeIDs = sm.RemoteSvc('scanMgr').GetSystemScanMgr().RecoverProbes(probeIDs)
191  // list of probes successfully scooped to cargo
192  // this is tested and added in Probe::RecoverProbe()
193  PyList* list = new PyList();
194 
195  Call_SingleIntList args;
196  if (!args.Decode(&call.tuple)) {
197  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
198  //TODO: throw exception
199  return list;
200  }
201 
202  SystemEntity* pSE(nullptr);
203  for (auto cur : args.ints) {
204  pSE = m_client->SystemMgr()->GetSE(cur);
205  if (pSE == nullptr)
206  continue;
207  if (pSE->IsProbeSE())
208  pSE->GetProbeSE()->RecoverProbe(list);
209  }
210 
211  return list;
212 }
213 
214 PyResult ScanBound::Handle_DestroyProbe( PyCallArgs& call ) {
215  //scanMan = sm.RemoteSvc('scanMgr').GetSystemScanMgr()
216  //scanMan.DestroyProbe(probeID)
217  _log(SCAN__TRACE, "ScanBound::Handle_DestroyProbe() - size= %u", call.tuple->size() );
218  call.Dump(SCAN__DUMP);
219 
220  Call_SingleIntegerArg arg;
221  if (!arg.Decode(&call.tuple)) {
222  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
223  //TODO: throw exception
224  return nullptr;
225  }
226 
227  SystemEntity* pSE(m_client->SystemMgr()->GetSE(arg.arg));
228  if (pSE != nullptr)
229  pSE->Delete();
230  SafeDelete(pSE);
231 
232  return nullptr;
233 }
234 
235 PyResult ScanBound::Handle_ReconnectToLostProbes( PyCallArgs& call ) {
236  // no args
237  // will have to test against client launcher vs probe m_moduleID
238  // will have to write *something* to loop thru active probes in system for this....
239 
240  // search inactive probes in system for ownerID, reset variables as per launch, add to all maps, then send client update
241  // will need separate map for probes to use this? or just loop thru EVERYTHING in system in the off chance we'll find a lost probe?
242  // i dunno...both kinda suck at this point
243  return nullptr;
244 }
Base Python wire object.
Definition: PyRep.h:66
Dispatcher *const m_dispatch
PyCallable_DECL_CALL(RequestScans)
SystemEntity * GetSE(uint32 entityID) const
virtual ProbeSE * GetProbeSE()
Definition: SystemEntity.h:112
#define _log(type, fmt,...)
Definition: logsys.h:124
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
Python's dictionary.
Definition: PyRep.h:719
size_t size() const
Definition: PyRep.h:591
SystemBubble * SysBubble()
Definition: SystemEntity.h:195
virtual void Release()
std::string m_strBoundObjectName
Definition: PyBoundObject.h:54
virtual ~ScanBound()
void SendNotifyMsg(const char *fmt,...)
Definition: Client.cpp:2776
Scan * scan()
Definition: Client.h:302
Dispatcher *const m_dispatch
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
virtual void Delete()
void _SetCallDispatcher(CallDispatcher *d)
Definition: PyCallable.h:87
* args
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
#define codelog(type, fmt,...)
Definition: logsys.h:128
SystemManager * SystemMgr() const
Definition: Client.h:92
void RequestScans(PyDict *dict)
Definition: Scan.cpp:139
PyDict * AsDict()
Definition: PyRep.h:142
PyCallable_Make_InnerDispatcher(ScanMgrService) ScanMgrService
PyServiceMgr *const m_manager
Definition: PyService.h:91
#define PyStatic
Definition: PyRep.h:1209
Client * pClient
PyRep * ConeScan(Call_ConeScan args)
Definition: Scan.cpp:99
const char * GetName() const
Definition: Client.h:94
Client *const client
Definition: PyCallable.h:49
#define PyCallable_REG_CALL(c, m)
Definition: PyServiceCD.h:78
Definition: Client.h:66
Client * m_client
PyCallable_Make_Dispatcher(ScanBound) ScanBound(PyServiceMgr *mgr
PySubStruct * BindObject(Client *pClient, PyBoundObject *pObj, PyDict *dict=nullptr, PyDict *oid=nullptr)
bool IsDict() const
Definition: PyRep.h:110
ShipSE * GetShipSE()
Definition: Client.h:168
void SetScan(Scan *pScan)
Definition: Client.h:303
Dispatcher *const m_dispatch
void Dump(LogType type) const
Definition: PyCallable.cpp:81
void RecoverProbe(PyList *list)
Definition: Probes.cpp:324
virtual ~ScanMgrService()
#define sBubbleMgr
ScanningDB * m_db
Definition: Scan.h:32
Python list.
Definition: PyRep.h:639
const char * GetName() const
Definition: PyBoundObject.h:44
PyTuple * tuple
Definition: PyCallable.h:50