EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CertificateMgrService.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 
26 #include "eve-server.h"
27 
28 #include "PyServiceCD.h"
29 #include "cache/ObjCacheService.h"
31 
33 
35 : PyService(mgr, "certificateMgr"),
36  m_dispatch(new Dispatcher(this))
37 {
38  _SetCallDispatcher(m_dispatch);
39 
40  PyCallable_REG_CALL(CertificateMgrService, GetMyCertificates);
41  PyCallable_REG_CALL(CertificateMgrService, GetCertificateCategories);
42  PyCallable_REG_CALL(CertificateMgrService, GetAllShipCertificateRecommendations);
43  PyCallable_REG_CALL(CertificateMgrService, GetCertificateClasses);
44  PyCallable_REG_CALL(CertificateMgrService, GrantCertificate);
45  PyCallable_REG_CALL(CertificateMgrService, UpdateCertificateFlags);
46  PyCallable_REG_CALL(CertificateMgrService, BatchCertificateGrant);
47  PyCallable_REG_CALL(CertificateMgrService, BatchCertificateUpdate);
48  PyCallable_REG_CALL(CertificateMgrService, GetCertificatesByCharacter);
49 }
50 
52 {
53  delete m_dispatch;
54 }
55 
56 PyResult CertificateMgrService::Handle_GetMyCertificates(PyCallArgs &call) {
57  CertMap crt = CertMap();
58  call.client->GetChar()->GetCertificates( crt );
59 
60  util_Rowset rs;
61  rs.lines = new PyList();
62  rs.header.push_back( "certificateID" );
63  rs.header.push_back( "grantDate" );
64  rs.header.push_back( "visibilityFlags" );
65 
66  for (auto cur : crt) {
67  PyList* fieldData = new PyList();
68  fieldData->AddItemInt( cur.first );
69  fieldData->AddItemLong( cur.second.grantDate );
70  fieldData->AddItemInt( cur.second.visibilityFlags );
71  rs.lines->AddItem( fieldData );
72  }
73  return rs.Encode();
74 }
75 
76 PyResult CertificateMgrService::Handle_GetCertificateCategories(PyCallArgs &call) {
77  ObjectCachedMethodID method_id(GetName(), "GetCertificateCategories");
78 
79  if (!m_manager->cache_service->IsCacheLoaded(method_id)) {
81  if (res == nullptr)
82  codelog(SERVICE__ERROR, "Failed to load cache, generating empty contents.");
83  m_manager->cache_service->GiveCache(method_id, &res);
84  }
85 
87 }
88 
89 PyResult CertificateMgrService::Handle_GetAllShipCertificateRecommendations(PyCallArgs &call) {
90  ObjectCachedMethodID method_id(GetName(), "GetAllShipCertificateRecommendations");
91 
92  if (!m_manager->cache_service->IsCacheLoaded(method_id)) {
94  if (res == nullptr)
95  codelog(SERVICE__ERROR, "Failed to load cache, generating empty contents.");
96  m_manager->cache_service->GiveCache(method_id, &res);
97  }
98 
100 }
101 
102 PyResult CertificateMgrService::Handle_GetCertificateClasses(PyCallArgs &call) {
103  ObjectCachedMethodID method_id(GetName(), "GetCertificateClasses");
104 
105  if (!m_manager->cache_service->IsCacheLoaded(method_id)) {
107  if (res == nullptr)
108  codelog(SERVICE__ERROR, "Failed to load cache, generating empty contents.");
109  m_manager->cache_service->GiveCache(method_id, &res);
110  }
111 
113 }
114 
115 PyResult CertificateMgrService::Handle_GrantCertificate(PyCallArgs &call) {
116  Call_SingleIntegerArg arg;
117  if (!arg.Decode(&call.tuple)) {
118  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
119  return PyStatic.NewNone();
120  }
121 
122  call.client->GetChar()->GrantCertificate(arg.arg);
123  return PyStatic.NewNone();
124 }
125 
126 PyResult CertificateMgrService::Handle_UpdateCertificateFlags(PyCallArgs &call) {
127  Call_TwoIntegerArgs arg;
128  if (!arg.Decode(&call.tuple)) {
129  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
130  return PyStatic.NewNone();
131  }
132 
133  call.client->GetChar()->UpdateCertificate( arg.arg1, arg.arg2 );
134  return PyStatic.NewNone();
135 }
136 
137 PyResult CertificateMgrService::Handle_BatchCertificateGrant(PyCallArgs &call) {
138  Call_SingleIntList arg;
139  if (!arg.Decode(&call.tuple)) {
140  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
141  return PyStatic.NewNone();
142  }
143 
144  PyList* res = new PyList();
145  CharacterRef ch = call.client->GetChar();
146  std::vector<int32>::iterator itr = arg.ints.begin();
147  for (; itr != arg.ints.end(); ++itr) {
148  ch->GrantCertificate(*itr);
149  res->AddItemInt(*itr);
150  }
151  return res;
152 }
153 
154 PyResult CertificateMgrService::Handle_BatchCertificateUpdate(PyCallArgs &call) {
155  Call_BatchCertificateUpdate args;
156  if (!args.Decode(&call.tuple)) {
157  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
158  return PyStatic.NewNone();
159  }
160 
161  CharacterRef ch = call.client->GetChar();
162  std::map<uint32, uint32>::iterator itr = args.update.begin();
163  for (; itr != args.update.end(); ++itr)
164  ch->UpdateCertificate( itr->first, itr->second );
165  return PyStatic.NewNone();
166 }
167 
168 PyResult CertificateMgrService::Handle_GetCertificatesByCharacter( PyCallArgs& call )
169 {
170  Call_SingleIntegerArg arg;
171  if (!arg.Decode(&call.tuple)) {
172  _log(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
173  return PyStatic.NewNone();
174  }
175 
176  CertMap crt;
177  sItemFactory.GetCharacter(arg.arg)->GetCertificates(crt);
178 
179  util_Rowset rs;
180  rs.lines = new PyList();
181  rs.header.push_back("grantDate");
182  rs.header.push_back("certificateID");
183  rs.header.push_back("visibilityFlags");
184 
185  for (auto cur : crt) {
186  PyList* fieldData = new PyList();
187  fieldData->AddItemLong( cur.second.grantDate );
188  fieldData->AddItemInt( cur.second.certificateID );
189  fieldData->AddItemInt( cur.second.visibilityFlags );
190  rs.lines->AddItem( fieldData );
191  }
192  return rs.Encode();
193 }
Base Python wire object.
Definition: PyRep.h:66
Dispatcher *const m_dispatch
PyRep * GetAllShipCertificateRecommendations()
#define _log(type, fmt,...)
Definition: logsys.h:124
PyCallable_Make_InnerDispatcher(CertificateMgrService) CertificateMgrService
PyRep * GetCertificateClasses()
void GetCertificates(CertMap &crt)
Definition: Character.cpp:1323
Dispatcher *const m_dispatch
void UpdateCertificate(uint32 certificateID, bool pub)
Definition: Character.cpp:1337
CharacterRef GetChar() const
Definition: Client.h:164
const char * GetName() const
Definition: PyService.h:54
std::map< uint16, CharCerts > CertMap
* args
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyServiceMgr *const m_manager
Definition: PyService.h:91
#define PyStatic
Definition: PyRep.h:1209
void AddItemInt(int32 intval)
Definition: PyRep.h:702
PyRep * GetCertificateCategories()
Client *const client
Definition: PyCallable.h:49
#define PyCallable_REG_CALL(c, m)
Definition: PyServiceCD.h:78
void GiveCache(const PyRep *objectID, PyRep **contents)
void GrantCertificate(uint32 certificateID)
Definition: Character.cpp:1327
ObjCacheService * cache_service
Definition: PyServiceMgr.h:78
void AddItemLong(int64 intval)
Definition: PyRep.h:703
#define sItemFactory
Definition: ItemFactory.h:165
PyObject * MakeObjectCachedMethodCallResult(const PyRep *objectID, const char *versionCheck="run")
Python list.
Definition: PyRep.h:639
bool IsCacheLoaded(const PyRep *objectID) const
PyTuple * tuple
Definition: PyCallable.h:50