EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyServiceMgr.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  Updates: Allan
25 */
26 
27 #include "eve-server.h"
28 
29 #include "Client.h"
30 #include "EntityList.h"
31 #include "cache/ObjCacheService.h"
32 #include "chat/LSCService.h"
33 #include "PyService.h"
34 #include "PyServiceMgr.h"
35 #include "PyBoundObject.h"
36 
38 : lsc_service(nullptr),
39  cache_service(nullptr),
40  m_nextBindID(100),
41  m_nodeID(nodeID)
42 {
43  elist.SetService(this);
44 }
45 
47  // these crash (segfault) on exit, and i dont know why (but not sure if it's needed...)
48  //SafeDelete(lsc_service);
49  //SafeDelete(cache_service);
50 
51  Close();
52 }
53 
55  for (auto cur : m_svcList)
56  SafeDelete(cur.second);
57 
58  PyBoundObject* bo(nullptr);
59  for (auto cur : m_boundObjects) {
60  bo = cur.second.object;
61  if (is_log_enabled(SERVICE__MESSAGE))
62  _log(SERVICE__MESSAGE, "Service Mgr Destructor: Deleting %s at node %u:%u", \
63  bo->GetName(), bo->m_nodeID, bo->m_bindID);
64  SafeDelete(bo);
65  }
66 
67  sLog.Warning(" PyServiceMgr", "Services Manager has been closed." );
68 }
69 
70 void PyServiceMgr::Initalize(double startTime)
71 {
72  PyString* str(new PyString( "machoNet.serviceInfo"));
73 
74  // look into this. what's it for? are we using it right? missing anything?
75  // client calls this, then loads cached data upon return. not sure how this is used yet
76  if (!cache_service->IsCacheLoaded(str)) {
77  PyDict *dict = new PyDict();
78  /* ServiceCallGPCS.py:197
79  * where = self.machoNet.serviceInfo[service]
80  * if where:
81  * for (k, v,) in self.machoNet.serviceInfo.iteritems():
82  * if ((k != service) and (v and (v.startswith(where) or where.startswith(v)))):
83  * nodeID = self.services.get(k, None)
84  * break
85  */
86  dict->SetItemString("account", new PyString("station"));
87  dict->SetItemString("bookmark", new PyString("station"));
88  dict->SetItemString("contractMgr", new PyString("station"));
89  dict->SetItemString("gangSvc", new PyString("station"));
90  dict->SetItemString("trademgr", new PyString("station"));
91  dict->SetItemString("tutorialSvc", new PyString("station"));
92  dict->SetItemString("slash", new PyString("station"));
93  dict->SetItemString("wormholeMgr", new PyString("location"));
94  dict->SetItemString("LSC", new PyString("location"));
95  dict->SetItemString("station", new PyString("location"));
96  dict->SetItemString("config", new PyString("locationPreferred"));
97  dict->SetItemString("scanMgr", new PyString("solarsystem"));
98  dict->SetItemString("keeper", new PyString("solarsystem"));
99  dict->SetItemString("agentMgr", PyStatic.NewNone());
100  dict->SetItemString("aggressionMgr", PyStatic.NewNone());
101  dict->SetItemString("alert", PyStatic.NewNone());
102  dict->SetItemString("allianceRegistry", PyStatic.NewNone());
103  dict->SetItemString("authentication", PyStatic.NewNone());
104  dict->SetItemString("billMgr", PyStatic.NewNone());
105  dict->SetItemString("billingMgr", PyStatic.NewNone());
106  dict->SetItemString("beyonce", PyStatic.NewNone());
107  dict->SetItemString("BSD", PyStatic.NewNone());
108  dict->SetItemString("cache", PyStatic.NewNone());
109  dict->SetItemString("calendarProxy", PyStatic.NewNone());
110  dict->SetItemString("corporationSvc", PyStatic.NewNone());
111  dict->SetItemString("corpStationMgr", PyStatic.NewNone());
112  dict->SetItemString("corpmgr", PyStatic.NewNone());
113  dict->SetItemString("corpRegistry", PyStatic.NewNone());
114  dict->SetItemString("counter", PyStatic.NewNone());
115  dict->SetItemString("certificateMgr", PyStatic.NewNone());
116  dict->SetItemString("charFittingMgr", PyStatic.NewNone());
117  dict->SetItemString("charmgr", PyStatic.NewNone());
118  dict->SetItemString("charUnboundMgr", PyStatic.NewNone());
119  dict->SetItemString("clientStatLogger", PyStatic.NewNone());
120  dict->SetItemString("clientStatsMgr", PyStatic.NewNone());
121  dict->SetItemString("clones", PyStatic.NewNone());
122  dict->SetItemString("damageTracker", PyStatic.NewNone());
123  dict->SetItemString("dataconfig", PyStatic.NewNone());
124  dict->SetItemString("DB", PyStatic.NewNone());
125  dict->SetItemString("DB2", PyStatic.NewNone());
126  dict->SetItemString("debug", PyStatic.NewNone());
127  dict->SetItemString("director", PyStatic.NewNone());
128  dict->SetItemString("dogma", PyStatic.NewNone());
129  dict->SetItemString("dogmaIM", PyStatic.NewNone());
130  dict->SetItemString("droneMgr", PyStatic.NewNone());
131  dict->SetItemString("dungeon", PyStatic.NewNone());
132  dict->SetItemString("dungeonExplorationMgr", PyStatic.NewNone());
133  dict->SetItemString("effectCompiler", PyStatic.NewNone());
134  dict->SetItemString("emailreader", PyStatic.NewNone());
135  dict->SetItemString("entity", PyStatic.NewNone());
136  dict->SetItemString("factory", PyStatic.NewNone());
137  dict->SetItemString("facWarMgr", PyStatic.NewNone());
138  dict->SetItemString("fleetMgr", PyStatic.NewNone());
139  dict->SetItemString("fleetObjectHandler", PyStatic.NewNone());
140  dict->SetItemString("fleetProxy", PyStatic.NewNone());
141  dict->SetItemString("gagger", PyStatic.NewNone());
142  dict->SetItemString("gangSvcObjectHandler", PyStatic.NewNone());
143  dict->SetItemString("http", PyStatic.NewNone());
144  dict->SetItemString("i2", PyStatic.NewNone());
145  dict->SetItemString("infoGatheringMgr", PyStatic.NewNone());
146  dict->SetItemString("insuranceSvc", PyStatic.NewNone());
147  dict->SetItemString("invbroker", PyStatic.NewNone());
148  dict->SetItemString("jumpbeaconsvc", PyStatic.NewNone());
149  dict->SetItemString("jumpCloneSvc", PyStatic.NewNone());
150  dict->SetItemString("languageSvc", PyStatic.NewNone());
151  dict->SetItemString("lien", PyStatic.NewNone());
152  dict->SetItemString("lookupSvc", PyStatic.NewNone());
153  dict->SetItemString("lootSvc", PyStatic.NewNone());
154  dict->SetItemString("LPSvc", PyStatic.NewNone());
155  dict->SetItemString("LPStore", PyStatic.NewNone());
156  dict->SetItemString("machoNet", PyStatic.NewNone());
157  dict->SetItemString("map", PyStatic.NewNone());
158  dict->SetItemString("market", PyStatic.NewNone());
159  dict->SetItemString("npcSvc", PyStatic.NewNone());
160  dict->SetItemString("objectCaching", PyStatic.NewNone());
161  dict->SetItemString("onlineStatus", PyStatic.NewNone());
162  dict->SetItemString("posMgr", PyStatic.NewNone());
163  dict->SetItemString("ram", PyStatic.NewNone());
164  dict->SetItemString("repairSvc", PyStatic.NewNone());
165  dict->SetItemString("reprocessingSvc", PyStatic.NewNone());
166  dict->SetItemString("pathfinder", PyStatic.NewNone());
167  dict->SetItemString("petitioner", PyStatic.NewNone());
168  dict->SetItemString("planetMgr", PyStatic.NewNone());
169  dict->SetItemString("search", PyStatic.NewNone());
170  dict->SetItemString("sessionMgr", PyStatic.NewNone());
171  dict->SetItemString("ship", PyStatic.NewNone());
172  dict->SetItemString("skillMgr", PyStatic.NewNone());
173  dict->SetItemString("sovMgr", PyStatic.NewNone());
174  dict->SetItemString("standing2", PyStatic.NewNone());
175  dict->SetItemString("stationSvc", PyStatic.NewNone());
176  dict->SetItemString("userSvc", PyStatic.NewNone());
177  dict->SetItemString("voiceMgr", PyStatic.NewNone());
178  dict->SetItemString("voucher", PyStatic.NewNone());
179  dict->SetItemString("warRegistry", PyStatic.NewNone());
180  dict->SetItemString("watchdog", PyStatic.NewNone());
181  dict->SetItemString("zsystem", PyStatic.NewNone());
182  dict->SetItemString("encounterSpawnServer", PyStatic.NewNone());
183  dict->SetItemString("netStateServer", PyStatic.NewNone());
184  dict->SetItemString("zActionServer", PyStatic.NewNone());
185 
186  //register it
187  cache_service->GiveCache(str, (PyRep **)&dict);
188 
189  PyDecRef(str);
190  }
191 
192  sLog.Cyan(" PyServiceMgr", "%u services registered in %.3fms", m_svcList.size(),(GetTimeMSeconds() - startTime));
193 }
194 
196  //well... we used to have something to do, but not right now...
197 }
198 
199 void PyServiceMgr::RegisterService(const std::string &name, PyService* svc)
200 {
201  m_svcList[name] = svc;
202 }
203 
204 PyService* PyServiceMgr::LookupService(const std::string &name) {
205  std::map<std::string, PyService*>::const_iterator itr = m_svcList.find(name);
206  if (itr != m_svcList.end())
207  return itr->second;
208 
209  _log(SERVICE__ERROR, "PyServiceMgr::LookupService() - Service %s not found in list.", name.c_str());
210  return nullptr;
211 }
212 
213 PySubStruct* PyServiceMgr::BindObject(Client* pClient, PyBoundObject* pObj, PyDict* dict/*nullptr*/, PyDict *oid/*nullptr*/) {
214  if (pClient == nullptr) {
215  _log(SERVICE__ERROR, "PyServiceMgr::BindObject() - Tried to bind a NULL client.");
216  return new PySubStruct(PyStatic.NewNone());
217  }
218 
219  if (pObj == nullptr) {
220  _log(SERVICE__ERROR, "PyServiceMgr::BindObject() - Tried to bind a NULL object.");
221  return new PySubStruct(PyStatic.NewNone());
222  }
223 
225 
226  // save bindID in client for ease of release later
227  pClient->AddBindID(m_nextBindID);
228 
229  BoundObj obj = BoundObj();
230  obj.client = pClient;
231  obj.object = pObj;
232  m_boundObjects[pObj->bindID()] = obj;
233 
234  std::string bindStr = pObj->GetBindStr();
235  _log(SERVICE__MESSAGE, "Service Mgr Binding %s to node %u:%u for %s", \
236  pObj->GetName(), pObj->m_nodeID, pObj->m_bindID, pClient->GetName());
237 
238  PyLong* time = new PyLong(GetFileTimeNow());
239 
240  PyTuple* tuple(nullptr);
241  if (dict == nullptr) {
242  tuple = new PyTuple(2);
243  tuple->items[0] = new PyString(bindStr);
244  tuple->items[1] = time;
245  } else {
246  tuple = new PyTuple(3);
247  tuple->items[0] = new PyString(bindStr);
248  tuple->items[1] = dict;
249  tuple->items[2] = time;
250  }
251 
252  if (oid != nullptr) {
253  PyDict *oidDict = new PyDict();
254  oidDict->SetItemString(bindStr.c_str(), time);
255  oid->SetItemString("OID+", oidDict);
256  }
257 
258  return new PySubStruct(new PySubStream(tuple));
259 }
260 
262  std::map<uint32, BoundObj>::iterator itr = m_boundObjects.find(bindID);
263  if (itr != m_boundObjects.end())
264  return itr->second.object;
265  return nullptr;
266 }
267 
269 {
270  std::map<uint32, BoundObj>::iterator itr = m_boundObjects.find(bindID);
271  if (itr == m_boundObjects.end()) {
272  _log(SERVICE__ERROR, "PyServiceMgr::ClearBoundObject() - Unable to find bound object %u to release.", bindID);
273  return;
274  }
275 
276  PyBoundObject *bo(itr->second.object);
277 
278  _log(SERVICE__MESSAGE, "Service Mgr Clearing bound object %s at %s", bo->GetName(), bo->GetBindStr().c_str());
279 
280  m_boundObjects.erase(itr);
281  bo->Release();
282 }
283 
284 void PyServiceMgr::BoundObjectVec(std::vector< BoundObj >& vec)
285 {
286  for (auto cur : m_boundObjects)
287  vec.push_back(cur.second);
288 }
289 
Base Python wire object.
Definition: PyRep.h:66
ObjectsBoundMap m_boundObjects
Definition: PyServiceMgr.h:89
#define _log(type, fmt,...)
Definition: logsys.h:124
PyBoundObject * FindBoundObject(uint32 bindID)
Python string.
Definition: PyRep.h:430
Python's dictionary.
Definition: PyRep.h:719
PyService * LookupService(const std::string &name)
Python tuple.
Definition: PyRep.h:567
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
#define is_log_enabled(type)
Definition: logsys.h:78
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
double GetTimeMSeconds()
Definition: utils_time.cpp:104
void BoundObjectVec(std::vector< BoundObj > &vec)
std::string GetBindStr() const
#define PyStatic
Definition: PyRep.h:1209
const char * GetName() const
Definition: Client.h:94
PyServiceMgr(uint32 nodeID, EntityList &elist)
#define PyDecRef(op)
Definition: PyRep.h:57
Definition: Client.h:66
unsigned __int32 uint32
Definition: eve-compat.h:50
void AddBindID(uint32 bindID)
Definition: Client.h:436
std::map< std::string, PyService * > m_svcList
Definition: PyServiceMgr.h:84
void GiveCache(const PyRep *objectID, PyRep **contents)
double GetFileTimeNow()
Definition: utils_time.cpp:84
PySubStruct * BindObject(Client *pClient, PyBoundObject *pObj, PyDict *dict=nullptr, PyDict *oid=nullptr)
void _SetNodeBindID(uint32 nodeID, uint32 bindID)
Definition: PyBoundObject.h:51
ObjCacheService * cache_service
Definition: PyServiceMgr.h:78
virtual void Release()=0
void SetService(PyServiceMgr *svc)
Definition: EntityList.h:84
uint32 m_nodeID
Definition: PyServiceMgr.h:91
PyBoundObject * object
Definition: PyServiceMgr.h:53
void RegisterService(const std::string &name, PyService *svc)
storage_type items
Definition: PyRep.h:628
void ClearBoundObject(uint32 bindID)
uint32 m_nextBindID
Definition: PyServiceMgr.h:92
uint32 bindID() const
Definition: PyBoundObject.h:40
void Initalize(double startTime)
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
bool IsCacheLoaded(const PyRep *objectID) const
const char * GetName() const
Definition: PyBoundObject.h:44
Python long integer.
Definition: PyRep.h:261