EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SparseBound.cpp
Go to the documentation of this file.
1 /* SparseBound.cpp
2  * class to manage very specific data for corp offices
3  * ** cannot get this to work right.
4  *
5  * this class' response data is required for the following corp functions:
6  * item lockdown
7  * RAM where bp or mat'l are in corp hangars
8  * some vote items
9  * member hangar auditing
10  *
11  */
12 
14 #include "station/StationDataMgr.h"
15 
16 SparseBound::SparseBound(PyServiceMgr *mgr, CorporationDB& db, uint32 corpID)
17 : PyBoundObject(mgr),
18 m_dispatch(new Dispatcher(this)),
19 m_db(db),
20 m_corpID(corpID)
21 {
23 
25  PyCallable_REG_CALL(SparseBound, FetchByKey);
27  PyCallable_REG_CALL(SparseBound, SelectByUniqueColumnValues);
28 }
29 
30 PyResult SparseBound::Handle_Fetch(PyCallArgs &call)
31 {
32  //(startPos, fetchSize)
33  Call_TwoIntegerArgs args;
34  if (!args.Decode(&call.tuple)) {
35  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
36  return nullptr;
37  }
38 
39  return m_db.Fetch(call.client->GetCorporationID(), args.arg1, args.arg2);
40 }
41 
42 // this is called in a few places to get officeID
43 // uses a method chain from GetOffices() (from bound office object) and is only called when accessing containers and item(s) owned by corp.
44 // however, for these items to show in containers' inventory, current code requires they have to be:
45 // 1) owned by the hangar's owner
46 // 2) owned by the viewer (whom shall also be hangar's owner)
47 // this poses a problem for corp staff when viewing member's hangars. not sure how to 'fix' this yet.
48 // and i still havent gotten this to work dependably
49 PyResult SparseBound::Handle_SelectByUniqueColumnValues(PyCallArgs &call)
50 {
51  // no packet data for this call
52 
53  _log(CORP__CALL, "SparseBound::Handle_SelectByUniqueColumnValues()");
54  call.Dump(CORP__WARNING); //so this will dump on all calls
55 
56  std::string str = PyRep::StringContent(call.tuple->GetItem(0));
57  // could this be multiple locations? doubt it.
58  uint32 locationID = PyRep::IntegerValueU32(call.tuple->GetItem(1)->AsList()->GetItem(0));
59 
60  std::vector<OfficeData> data;
61  stDataMgr.GetStationOfficeIDs(locationID, data); // this method checks for the type of locationID sent.
62 
63  /* IndexError: list assignment index out of range
64  PyTuple* header = new PyTuple(3);
65  header->SetItemString(0, "officeID");
66  header->SetItemString(1, "folderID");
67  header->SetItemString(2, "stationID");
68  PyList* lines = new PyList();
69  for (auto cur : data) {
70  PyTuple* line = new PyTuple(3);
71  line->SetItem(0, new PyInt(cur.officeID));
72  line->SetItem(1, new PyInt(cur.folderID));
73  line->SetItem(2, new PyInt(cur.stationID));
74  lines->AddItem(line);
75  }
76 
77  PyDict* dict = new PyDict();
78  dict->SetItemString("header", header);
79  dict->SetItemString("RowClass", new PyToken("util.Row"));
80  dict->SetItemString("lines", lines);
81 
82  PyRep* rsp = new PyObject("util.Rowset", dict);
83 
84  if (is_log_enabled(CORP__RSP_DUMP))
85  rsp->Dump(CORP__RSP_DUMP, "");
86 
87  return rsp;
88  */
89 
90  /* IndexError: list assignment index out of range
91  *
92  PyList* rsp = new PyList();
93  for (auto cur : data) {
94  PyTuple* tuple = new PyTuple(3);
95  tuple->SetItem(0, new PyInt(cur.officeID));
96  tuple->SetItem(1, new PyInt(cur.folderID));
97  tuple->SetItem(2, new PyInt(cur.stationID));
98  rsp->AddItem(tuple);
99  }
100  */
101 
102  //* original -- TypeError: iteration over non-sequence
103 
104  PyList* rsp = new PyList();
105  for (auto cur : data) {
106  PyDict* dict = new PyDict();
107  dict->SetItemString("stationID", new PyInt(cur.stationID));
108  dict->SetItemString("officeFolderID", new PyInt(cur.folderID));
109  dict->SetItemString("officeID", new PyInt(cur.officeID));
110  // keep this as KeyVal for proper indexing
111  rsp->AddItem(new PyObject("util.KeyVal", dict));
112  }
113 
114  //if (is_log_enabled(CORP__RSP_DUMP))
115  // rsp->Dump(CORP__RSP_DUMP, "");
116 
117  return PyStatic.mtList();
118 }
119 
120 
121 PyResult SparseBound::Handle_FetchByKey(PyCallArgs &call) {
122  // this is something about getting member data....
123  sLog.Error("SparseBound", "Handle_FetchByKey()");
124  call.Dump(CORP__WARNING); //so this will dump on all calls
125 
126  /*
127  * call
128  * [PyTuple 4 items]
129  * [PyString "N=699765:12950"]
130  * [PyString "FetchByKey"]
131  * [PyTuple 1 items]
132  * [PyList 1 items]
133  * [PyInt 649670823] // charID ?
134  *
135  * return
136  * [PySubStream 71 bytes]
137  * [PyList 1 items]
138  * [PyTuple 3 items]
139  * [PyInt 1661059544]
140  * [PyInt 0]
141  * [PyList 19 items]
142  * [PyInt 1661059544]
143  * [PyInt 98038978]
144  * [PyNone]
145  * [PyNone]
146  * [PyString ""]
147  * [PyIntegerVar 0]
148  * [PyIntegerVar 0]
149  * [PyIntegerVar 129492958800000000] // timestamp
150  * [PyNone]
151  * [PyIntegerVar 0]
152  * [PyIntegerVar 0]
153  * [PyIntegerVar 0]
154  * [PyIntegerVar 0]
155  * [PyIntegerVar 0]
156  * [PyIntegerVar 0]
157  * [PyInt 0]
158  * [PyInt 1004]
159  * [PyIntegerVar 129492958800000000] // timestamp
160  * [PyInt 0]
161  */
162  return nullptr;
163 }
164 
165 PyResult SparseBound::Handle_GetByKey(PyCallArgs &call) {
166  sLog.Error("SparseBound", "Handle_GetByKey()");
167  call.Dump(CORP__WARNING); //so this will dump on all calls
168 
169  // no packet data for this call
170 
171  return nullptr;
172 }
PyRep * Fetch(uint32 corpID, uint32 from, uint32 count)
Dispatcher *const m_dispatch
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
#define _log(type, fmt,...)
Definition: logsys.h:124
#define stDataMgr
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
Python's dictionary.
Definition: PyRep.h:719
int32 GetCorporationID() const
Definition: Client.h:123
static uint32 IntegerValueU32(PyRep *pRep)
Definition: PyRep.cpp:134
void AddItem(PyRep *i)
Definition: PyRep.h:701
void _SetCallDispatcher(CallDispatcher *d)
Definition: PyCallable.h:87
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:674
* args
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
Python object.
Definition: PyRep.h:826
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyList * AsList()
Definition: PyRep.h:140
Python integer.
Definition: PyRep.h:231
Dispatcher *const m_dispatch
Definition: LPStore.h:40
#define PyStatic
Definition: PyRep.h:1209
CorporationDB & m_db
Definition: SparseBound.h:33
Client *const client
Definition: PyCallable.h:49
#define PyCallable_REG_CALL(c, m)
Definition: PyServiceCD.h:78
unsigned __int32 uint32
Definition: eve-compat.h:50
void Dump(LogType type) const
Definition: PyCallable.cpp:81
Python list.
Definition: PyRep.h:639
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
const char * GetName() const
Definition: PyBoundObject.h:44
PyTuple * tuple
Definition: PyCallable.h:50