EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CorpBookmarkMgr.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: Ubiquitatis
24  Rewrite: Allan
25 */
26 
27 /* the distinction between bookmark Mgrs (corp/personal) is made on-the-fly when methods are called in client.
28  * most (if not all) will use same code and returns. so far, i havent seen a difference between them.
29  * this may be used to separate corp and personal bm in db on live.
30  * not sure if im gonna do that here or not yet.
31  */
32 
33 #include "eve-server.h"
34 
35 #include "Client.h"
36 #include "PyServiceCD.h"
37 #include "packets/Bookmarks.h"
38 #include "cache/ObjCacheService.h"
40 
42 
44 : PyService(mgr, "corpBookmarkMgr"),
45  m_dispatch(new Dispatcher(this))
46 {
47  _SetCallDispatcher(m_dispatch);
48 
49  PyCallable_REG_CALL(CorpBookmarkMgr, GetBookmarks);
50  PyCallable_REG_CALL(CorpBookmarkMgr, UpdateBookmark);
51  PyCallable_REG_CALL(CorpBookmarkMgr, UpdatePlayerBookmark);
52  PyCallable_REG_CALL(CorpBookmarkMgr, MoveBookmarksToFolder);
53  PyCallable_REG_CALL(CorpBookmarkMgr, CreateFolder);
54  PyCallable_REG_CALL(CorpBookmarkMgr, UpdateFolder);
55  PyCallable_REG_CALL(CorpBookmarkMgr, CopyBookmarks);
56  PyCallable_REG_CALL(CorpBookmarkMgr, DeleteFolder);
57  PyCallable_REG_CALL(CorpBookmarkMgr, MoveFoldersToDB);
58  PyCallable_REG_CALL(CorpBookmarkMgr, DeleteBookmarks);
59 }
60 
62 {
63  delete m_dispatch;
64 }
65 
66 PyResult CorpBookmarkMgr::Handle_GetBookmarks(PyCallArgs& call)
67 {
68  /*
69  ObjectCachedMethodID method_id(GetName(), "GetBookmarks");
70  if(!m_manager->cache_service->IsCacheLoaded(method_id)) {
71  PyTuple *tuple = new PyTuple(2);
72  tuple->SetItem(0, m_db.GetBookmarks(call.client->GetCorporationID()));
73  tuple->SetItem(1, m_db.GetFolders(call.client->GetCorporationID()));
74  PyRep* rep = tuple;
75 
76  m_manager->cache_service->GiveCache(method_id, &rep);
77  }
78 
79  return(m_manager->cache_service->MakeObjectCachedMethodCallResult(method_id));
80  */
81  PyTuple* result = new PyTuple(2);
82  result->SetItem(0, m_db.GetBookmarks(call.client->GetCorporationID()));
83  result->SetItem(1, m_db.GetFolders(call.client->GetCorporationID()));
84  result->Dump(BOOKMARK__RSP_DUMP, " ");
85  return result;
86 }
87 
88 PyResult CorpBookmarkMgr::Handle_UpdateBookmark(PyCallArgs& call) {
89  call.Dump(BOOKMARK__CALL_DUMP);
90  Call_UpdateBookmark args;
91  if (!args.Decode(&call.tuple)) {
92  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
93  return nullptr;
94  }
95 
96  m_db.UpdateBookmark(args.bookmarkID, args.ownerID, PyRep::StringContent(args.memo), PyRep::StringContent(args.comment), args.folderID);
97 
98  return PyStatic.NewNone();
99 }
100 
101 PyResult CorpBookmarkMgr::Handle_UpdatePlayerBookmark(PyCallArgs& call) {
102  call.Dump(BOOKMARK__CALL_DUMP);
103  Call_UpdateBookmark args;
104  if (!args.Decode(&call.tuple)) {
105  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
106  return nullptr;
107  }
108 
109  m_db.UpdateBookmark(args.bookmarkID, args.ownerID, PyRep::StringContent(args.memo), PyRep::StringContent(args.comment), args.folderID);
110 
111  return PyStatic.NewNone();
112 }
113 
114 PyResult CorpBookmarkMgr::Handle_MoveBookmarksToFolder(PyCallArgs& call)
115 {
116  // rows = bookmarkMgr.MoveBookmarksToFolder(folderID, bookmarkIDs)
117  call.Dump(BOOKMARK__CALL_DUMP);
118  Call_MoveBookmarksToFolder args;
119  if (!args.Decode(&call.tuple)) {
120  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
121  return nullptr;
122  }
123  //args.Dump(BOOKMARK__CALL_DUMP, " ");
124 
125  if (args.object->IsNone())
126  return PyStatic.NewNone();
127 
128  PyList* bmList = args.object->header()->AsTuple()->GetItem(1)->AsTuple()->GetItem(0)->AsList();
129 
130  std::vector<int32> bmIDs;
131  for (size_t i = 0; i < bmList->size(); ++i)
132  bmIDs.push_back(bmList->GetItem(i)->AsInt()->value());
133 
134  m_db.MoveBookmarkToFolder(args.folderID, &bmIDs);
135 
136  return m_db.GetBookmarksInFolder(args.folderID);
137 }
138 
139 PyResult CorpBookmarkMgr::Handle_UpdateFolder(PyCallArgs& call)
140 {
141  //if bookmarkMgr.UpdateFolder(folderID, folderName):
142  call.Dump(BOOKMARK__CALL_DUMP);
143  Call_UpdateFolder args;
144  if (!args.Decode(&call.tuple)) {
145  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
146  return PyStatic.NewFalse();
147  }
148 
150  if (!m_db.UpdateFolder(args.folderID, PyRep::StringContent(args.folderName)))
151  return PyStatic.NewFalse();
152 
153  return PyStatic.NewTrue();
154 }
155 
156 PyResult CorpBookmarkMgr::Handle_CreateFolder(PyCallArgs& call)
157 {
158  //folder = bookmarkMgr.CreateFolder(folderName)
159  call.Dump(BOOKMARK__CALL_DUMP);
161  std::string name = PyRep::StringContent(call.tuple->GetItem( 0 ));
162 
163  uint32 ownerID = call.client->GetCharacterID();
164  Rsp_CreateFolder result;
165  result.ownerID = ownerID;
166  result.folderID = m_db.SaveNewFolder(name, ownerID);
167  result.folderName = name;
168  result.creatorID = ownerID;
169 
170  result.Dump(BOOKMARK__RSP_DUMP, " ");
171  return result.Encode();
172 }
173 
174 PyResult CorpBookmarkMgr::Handle_CopyBookmarks(PyCallArgs& call)
175 {
176  call.Dump(BOOKMARK__CALL_DUMP);
177  return PyStatic.NewNone();
178 }
179 
180 PyResult CorpBookmarkMgr::Handle_DeleteFolder(PyCallArgs& call)
181 {
182  //deleteFolder, bookmarks = self.corpBookmarkMgr.DeleteFolder(folderID, bookmarkIDs)
183  call.Dump(BOOKMARK__CALL_DUMP);
184  return PyStatic.NewNone();
185 }
186 
187 PyResult CorpBookmarkMgr::Handle_MoveFoldersToDB(PyCallArgs& call)
188 {
189  //rows, folders = self.corpBookmarkMgr.MoveFoldersToDB(info)
190  call.Dump(BOOKMARK__CALL_DUMP);
191  return PyStatic.NewNone();
192 }
193 
194 PyResult CorpBookmarkMgr::Handle_DeleteBookmarks(PyCallArgs& call)
195 {
196  //deletedBookmarks = self.corpBookmarkMgr.DeleteBookmarks(bookmarkIDs)
197  call.Dump(BOOKMARK__CALL_DUMP);
198  Call_DeleteBookmarks args;
199  if (!args.Decode(&call.tuple)) {
200  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
201  return PyStatic.NewNone();
202  }
203 
204  if (args.object->IsNone())
205  return PyStatic.NewNone();
206 
207  PyList* bmList = args.object->header()->AsTuple()->GetItem(1)->AsTuple()->GetItem(0)->AsList();
208  for (size_t i = 0; i < bmList->size(); ++i)
209  m_db.ChangeOwner(bmList->GetItem(i)->AsInt()->value());
210 
211  return bmList;
212 }
PyTuple * AsTuple()
Definition: PyRep.h:138
Dispatcher *const m_dispatch
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
int32 value() const
Definition: PyRep.h:247
PyRep * GetBookmarksInFolder(uint32 folderID)
Definition: BookmarkDB.cpp:34
Dispatcher *const m_dispatch
uint32 SaveNewFolder(std::string folderName, uint32 ownerID)
Definition: BookmarkDB.cpp:323
int32 GetCharacterID() const
Definition: Client.h:113
bool UpdateBookmark(uint32 bookmarkID, uint32 ownerID, std::string memo, std::string note, uint32 folderID=0)
Definition: BookmarkDB.cpp:307
int32 GetCorporationID() const
Definition: Client.h:123
Python tuple.
Definition: PyRep.h:567
const char * GetName() const
Definition: PyService.h:54
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:674
* args
void ChangeOwner(uint32 bookmarkID, uint32 ownerID=1)
Definition: BookmarkDB.cpp:301
bool UpdateFolder(int32 folderID, std::string folderName)
Definition: BookmarkDB.cpp:340
#define codelog(type, fmt,...)
Definition: logsys.h:128
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
PyList * AsList()
Definition: PyRep.h:140
#define PyStatic
Definition: PyRep.h:1209
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
PyRep * GetBookmarks(uint32 ownerID)
Definition: BookmarkDB.cpp:79
PyCallable_Make_InnerDispatcher(CorpBookmarkMgr) CorpBookmarkMgr
virtual ~CorpBookmarkMgr()
PyRep * GetFolders(uint32 ownerID)
Definition: BookmarkDB.cpp:134
void Dump(LogType type) const
Definition: PyCallable.cpp:81
size_t size() const
Definition: PyRep.h:663
void MoveBookmarkToFolder(int32 folderID, std::vector< int32 > *bookmarkList)
Definition: BookmarkDB.cpp:369
PyInt * AsInt()
Definition: PyRep.h:122
Python list.
Definition: PyRep.h:639
PyTuple * tuple
Definition: PyCallable.h:50